Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrPublisherNotConfigured = errors.New("broker: publisher not configured") ErrSubscriberNotConfigured = errors.New("broker: subscriber not configured") )
Functions ¶
This section is empty.
Types ¶
type Broker ¶
type Broker interface { // Publisher返回一个Publisher实例。 Publisher() (Publisher, error) // Subscriber返回一个Subscriber实例。 Subscriber() (Subscriber, error) // Close关闭整个BrokerClient,释放底层连接和资源。 Close() error }
Broker 定义统一的Broker客户端接口。 通过此接口可获得Publisher与Subscriber实例。 此接口也可包括如健康检查(HealthCheck)或全局Close等方法。 不论是Kafka、Redis还是其他系统的实现,都应遵从此接口。
type FrameErrorEvent ¶
type FrameErrorEvent struct { // Error 错误信息 Error string // PositionID 仓位ID PositionID string // TransactionID 交易ID TransactionID string // AccountID 账户ID AccountID string // Timestamp 当前时间戳 Timestamp int64 // ClientOrderID 自定义客户端订单号 ClientOrderID string }
FrameErrorEvent 帧错误事件
type KlineEvent ¶
type KlineEvent struct { // Symbol 交易对 Symbol string // OpenTime 开盘时间 OpenTime int64 // Open 开盘价 Open decimal.Decimal // High 最高价 High decimal.Decimal // Low 最低价 Low decimal.Decimal // Close 收盘价 Close decimal.Decimal // Volume 成交量 Volume decimal.Decimal // CloseTime 收盘时间 CloseTime int64 // QuoteAssetVolume 成交额 QuoteAssetVolume decimal.Decimal // NumberOfTrades 成交笔数 NumberOfTrades int64 // TakerBuyBaseAssetVolume 买方成交量 TakerBuyBaseAssetVolume decimal.Decimal // TakerBuyQuoteAssetVolume 买方成交额 TakerBuyQuoteAssetVolume decimal.Decimal // Confirm 0 代表 K 线未完结,1 代表 K 线已完结。 Confirm string }
KlineEvent K线事件
type Message ¶
type Message struct { Key string Value []byte Topic string Headers map[string]string Metadata map[string]interface{} // 用于存放特定实现的额外信息,如偏移量、分区信息等 }
Message 表示传递的消息载体。 Value为消息内容主体,Key为可选的用于路由/分区的键,Topic表示逻辑上的主题/频道。 Metadata则是实现方可选填充的元数据,用于区别实现的特定属性(例如:Kafka的Offset、Partition、Redis的Stream ID等)。
type Option ¶
type Option func(*Options)
func OptionsContextWithValue ¶
func OptionsContextWithValue(k, v interface{}) Option
func WithContext ¶
type Options ¶
func NewOptions ¶
type OrderResultEvent ¶
type OrderResultEvent struct { // AccountID 账户ID AccountID string // ID 交易ID TransactionID string // Exchange 交易所 Exchange string // PositionID 仓位ID PositionID string // ClientOrderID 自定义客户端订单号 ClientOrderID string // Symbol 交易对 Symbol string // OrderID 交易所订单号 OrderID string // FeeAsset 手续费资产 FeeAsset string // TransactionTime 交易时间 TransactionTime int64 // By 是否是挂单方 MAKER, TAKER By string // CreatedBy 创建者 USER,SYSTEM CreatedBy string // Instrument 种类 SPOT, FUTURES MarketType types.MarketType // Status 订单状态: OpeningPosition, HoldingPosition, ClosingPosition, ClosedPosition Status types.PositionStatus // ExecutionType 本次订单执行类型:NEW, TRADE, CANCELED, REJECTED, EXPIRED ExecutionType types.ExecutionType // State 当前订单执行类型:NEW, PARTIALLY_FILLED, FILLED, CANCELED, REJECTED, EXPIRED State types.OrderState // PositionSide LONG,SHORT PositionSide types.PositionSide // SideType BUY,SELL Side types.SideType // OrderType LIMIT,MARKET Type types.OrderType // Volume 原交易数量 Volume decimal.Decimal // Price 交易价格 Price decimal.Decimal // LatestVolume 最新交易数量 LatestVolume decimal.Decimal // FilledVolume 已成交数量 FilledVolume decimal.Decimal // LatestPrice 最新交易价格 LatestPrice decimal.Decimal // FeeCost 手续费 FeeCost decimal.Decimal // FilledQuoteVolume 已成交金额 FilledQuoteVolume decimal.Decimal // LatestQuoteVolume 最新成交金额 LatestQuoteVolume decimal.Decimal // QuoteVolume 交易金额 QuoteVolume decimal.Decimal // AvgPrice 平均成交价格 AvgPrice decimal.Decimal }
OrderResultEvent 订单结果事件
type Publisher ¶
type Publisher interface { // Publish发布消息到指定的主题(或通道)。 // 返回错误用于告知发布失败,具体重试策略由上层或底层实现负责。 Publish(ctx context.Context, message *Message, opts ...Option) error // Close用于释放发布者相关资源。 Close() error }
Publisher 定义通用的消息发布者接口。 不关心底层是Kafka Topic、Redis Channel、RabbitMQ Exchange,统一为Publish操作。
type StrategySignalEvent ¶
type StrategySignalEvent struct { // PositionID 仓位ID PositionID string // ID 交易ID TransactionID string // AccountID 账户ID AccountID string // Timestamp 当前时间戳 Timestamp int64 // ClientOrderID 自定义客户端订单号 ClientOrderID string // Exchange 交易所 Exchange string // TimeInForce GTC,IOC,FOK,GTX,GTD TimeInForce types.TimeInForce // SideType BUY,SELL Side types.SideType // OrderType LIMIT,MARKET OrderType types.OrderType // PositionSide LONG,SHORT PositionSide types.PositionSide // MarketType 种类 SPOT, FUTURES, MARGIN MarketType types.MarketType // Symbol 交易对 Symbol string // Size 头寸数量 Size decimal.Decimal // Price 交易价格 Price decimal.Decimal // CreatedBy 创建者 USER, SYSTEM CreatedBy string }
StrategySignalEvent 策略信号事件
type Subscriber ¶
type Subscriber interface { // Subscribe接收一个或多个主题,并将收到的消息交给handler处理。 // 订阅可以是阻塞式,也可以异步在内部协程中进行消息消费。 Subscribe(ctx context.Context, topics []string, handler Handler, opts ...Option) error // Close用于释放订阅者相关资源,断开与底层系统的连接。 Close() error }
Subscriber 定义通用的消息订阅者接口。 上层通过为Subscriber注册一个MessageHandler来处理指定主题的消息。 底层实现例如Kafka的Consumer、Redis的Subscriber等负责调用handler。
type TradeEvent ¶
type TradeEvent struct { // Timestamp 当前时间戳 Timestamp int64 // TradeID 交易ID TradeID string // Symbol 交易对 Symbol string // Exchange 交易所 Exchange string // Volume 交易数量 Volume decimal.Decimal // Price 交易价格 Price decimal.Decimal // Side 交易方向 Side types.SideType // MarketType 市场类型 MarketType types.MarketType }
TradeEvent 交易事件
Click to show internal directories.
Click to hide internal directories.