Documentation
¶
Overview ¶
Package grid provides a client for the Longbridge grid trading OpenAPI. It supports submitting, replacing, querying, and controlling (cancel / suspend / restart) grid trading orders, as well as fetching order-window info.
Index ¶
- type GetGridOrderDetail
- type GetGridOrders
- type GetGridTriggerHistory
- type GridBidSize
- type GridChannelInfo
- type GridContext
- func (c *GridContext) Cancel(ctx context.Context, orderId string) (err error)
- func (c *GridContext) Detail(ctx context.Context, params *GetGridOrderDetail) (detail *GridOrderDetail, err error)
- func (c *GridContext) List(ctx context.Context, params *GetGridOrders) (orders *GridOrders, err error)
- func (c *GridContext) ListByIds(ctx context.Context, orderIds []string) (orders []*GridOrder, err error)
- func (c *GridContext) Replace(ctx context.Context, params *ReplaceGridOrder) (err error)
- func (c *GridContext) Restart(ctx context.Context, orderId string) (err error)
- func (c *GridContext) Submit(ctx context.Context, params *SubmitGridOrder) (orderId string, err error)
- func (c *GridContext) Suspend(ctx context.Context, orderId string) (err error)
- func (c *GridContext) SymbolInfo(ctx context.Context, symbol string) (info *GridSymbolInfo, err error)
- func (c *GridContext) TriggerHistory(ctx context.Context, params *GetGridTriggerHistory) (history *GridTriggerHistory, err error)
- type GridLimitEvent
- type GridOrder
- type GridOrderDetail
- type GridOrderHistory
- type GridOrderSubOrder
- type GridOrders
- type GridSymbolInfo
- type GridTimeInForce
- type GridTradeRule
- func (r *GridTradeRule) Depths(sell, buy int32) *GridTradeRule
- func (r *GridTradeRule) ExpireTimeAt(unixSeconds int64) *GridTradeRule
- func (r *GridTradeRule) LimitEvents(upper, lower GridLimitEvent) *GridTradeRule
- func (r *GridTradeRule) MultipleTriggerFlag(value bool) *GridTradeRule
- func (r *GridTradeRule) OrderTypes(up, down string) *GridTradeRule
- func (r *GridTradeRule) RthFlag(value int32) *GridTradeRule
- func (r *GridTradeRule) SupportShortsellFlag(value bool) *GridTradeRule
- type GridTrigger
- type GridTriggerHistory
- type ReplaceGridOrder
- type SubmitGridOrder
- type TriggerOrder
- type TriggerPriceType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GetGridOrderDetail ¶
type GetGridOrderDetail struct {
OrderId string // required
HistoryId string // optional, history cursor for paging
Limit int32 // optional, history page size
}
GetGridOrderDetail is the request for a grid order detail.
func (*GetGridOrderDetail) Values ¶
func (r *GetGridOrderDetail) Values() url.Values
type GetGridOrders ¶
type GetGridOrders struct {
Page int32 // optional
Limit int32 // optional
Market openapi.Market // optional
Status string // optional, comma-joined (e.g. "Performing,Suspended")
Symbol string // optional, e.g. 700.HK
SortBy string // optional
SortOrder string // optional
}
GetGridOrders is the request for the grid orders list.
func (*GetGridOrders) Values ¶
func (r *GetGridOrders) Values() url.Values
type GetGridTriggerHistory ¶
type GetGridTriggerHistory struct {
GridOrderId string // required
Page int32 // optional
Limit int32 // optional
}
GetGridTriggerHistory is the request for grid trigger history. Note: the required parameter is named grid_order_id (not order_id).
func (*GetGridTriggerHistory) Values ¶
func (r *GetGridTriggerHistory) Values() url.Values
type GridBidSize ¶
type GridBidSize struct {
StrProceed *decimal.Decimal `json:"str_proceed"`
EndProceed *decimal.Decimal `json:"end_proceed"`
BidSize *decimal.Decimal `json:"bid_size"`
}
GridBidSize is a price-step (bid-size) rule entry from the symbol-info response.
type GridChannelInfo ¶
type GridChannelInfo struct {
StrategyGranted bool `json:"strategy_granted"`
SupportRth bool `json:"support_rth"`
Currency string `json:"currency"`
SettlementCurrency []string `json:"settlement_currency"`
}
GridChannelInfo is the channel / authorization info nested in symbol-info.
type GridContext ¶
type GridContext struct {
// contains filtered or unexported fields
}
GridContext is a client for the Longbridge grid trading OpenAPI.
Example:
conf, err := config.NewFromEnv()
gctx, err := grid.NewFromCfg(conf)
orders, err := gctx.GridOrders(ctx, &grid.GetGridOrders{})
func NewFromCfg ¶
func NewFromCfg(cfg *config.Config) (*GridContext, error)
NewFromCfg creates a GridContext from a *config.Config.
func NewFromEnv ¶
func NewFromEnv() (*GridContext, error)
NewFromEnv returns a GridContext configured from environment variables.
func (*GridContext) Cancel ¶
func (c *GridContext) Cancel(ctx context.Context, orderId string) (err error)
Cancel cancels a grid trading order. Reference: https://open.longbridge.com/en/docs/trade/gridtrading/cancel
func (*GridContext) Detail ¶
func (c *GridContext) Detail(ctx context.Context, params *GetGridOrderDetail) (detail *GridOrderDetail, err error)
Detail returns the detail (and paged history) of a grid trading order. Reference: https://open.longbridge.com/en/docs/trade/gridtrading/detail
func (*GridContext) List ¶
func (c *GridContext) List(ctx context.Context, params *GetGridOrders) (orders *GridOrders, err error)
List returns a paged list of grid trading orders. Reference: https://open.longbridge.com/en/docs/trade/gridtrading/list
func (*GridContext) ListByIds ¶
func (c *GridContext) ListByIds(ctx context.Context, orderIds []string) (orders []*GridOrder, err error)
ListByIds queries grid trading orders by their IDs. Reference: https://open.longbridge.com/en/docs/trade/gridtrading/list
func (*GridContext) Replace ¶
func (c *GridContext) Replace(ctx context.Context, params *ReplaceGridOrder) (err error)
Replace replaces (modifies) a grid trading order. Reference: https://open.longbridge.com/en/docs/trade/gridtrading/replace
func (*GridContext) Restart ¶
func (c *GridContext) Restart(ctx context.Context, orderId string) (err error)
Restart restarts a grid trading order. Reference: https://open.longbridge.com/en/docs/trade/gridtrading/restart
func (*GridContext) Submit ¶
func (c *GridContext) Submit(ctx context.Context, params *SubmitGridOrder) (orderId string, err error)
Submit submits a grid trading order. Reference: https://open.longbridge.com/en/docs/trade/gridtrading/submit
func (*GridContext) Suspend ¶
func (c *GridContext) Suspend(ctx context.Context, orderId string) (err error)
Suspend suspends a grid trading order. Reference: https://open.longbridge.com/en/docs/trade/gridtrading/suspend
func (*GridContext) SymbolInfo ¶
func (c *GridContext) SymbolInfo(ctx context.Context, symbol string) (info *GridSymbolInfo, err error)
SymbolInfo returns the security (symbol) info used to build a grid order (lot size, authorization flag, settlement currency, etc.).
func (*GridContext) TriggerHistory ¶
func (c *GridContext) TriggerHistory(ctx context.Context, params *GetGridTriggerHistory) (history *GridTriggerHistory, err error)
TriggerHistory returns the trigger history of a grid trading order. Reference: https://open.longbridge.com/en/docs/trade/gridtrading/trigger_history
type GridLimitEvent ¶
type GridLimitEvent int32
GridLimitEvent is the action taken when a grid boundary is reached (wire: int32).
const ( // GridLimitEventUnknown is the unknown / unset value. GridLimitEventUnknown GridLimitEvent = 0 // GridLimitEventIgnore keeps the grid running when the boundary is reached. GridLimitEventIgnore GridLimitEvent = 1 // GridLimitEventCloseAtLast closes the position at the last price. GridLimitEventCloseAtLast GridLimitEvent = 2 )
type GridOrder ¶
type GridOrder struct {
OrderId string `json:"order_id"`
Symbol string `json:"symbol"`
StockName string `json:"stock_name"`
Market string `json:"market"`
Status string `json:"status"`
GridStatus string `json:"grid_status"`
SubmittedBasePrice *decimal.Decimal `json:"submitted_base_price"`
CurrentBasePrice *decimal.Decimal `json:"current_base_price"`
PreTriggerBasePrice *decimal.Decimal `json:"pre_trigger_base_price"`
PostTriggerBasePrice *decimal.Decimal `json:"post_trigger_base_price"`
UpperLimitPrice *decimal.Decimal `json:"upper_limit_price"`
LowerLimitPrice *decimal.Decimal `json:"lower_limit_price"`
TriggerPriceType TriggerPriceType `json:"trigger_price_type"` // Spread / Percent
TriggerSpreadUp *decimal.Decimal `json:"trigger_spread_up"`
TriggerSpreadDown *decimal.Decimal `json:"trigger_spread_down"`
TriggerPercentUp *decimal.Decimal `json:"trigger_percent_up"`
TriggerPercentDown *decimal.Decimal `json:"trigger_percent_down"`
PullbackPercent *decimal.Decimal `json:"pullback_percent"`
PullbackSpread *decimal.Decimal `json:"pullback_spread"`
ReboundPercent *decimal.Decimal `json:"rebound_percent"`
ReboundSpread *decimal.Decimal `json:"rebound_spread"`
TriggerSellOrderType string `json:"trigger_sell_order_type"`
TriggerBuyOrderType string `json:"trigger_buy_order_type"`
TriggerSellDepth int32 `json:"trigger_sell_depth"`
TriggerBuyDepth int32 `json:"trigger_buy_depth"`
TriggerQuantity *decimal.Decimal `json:"trigger_quantity"`
TriggerSellQuantity *decimal.Decimal `json:"trigger_sell_quantity"`
TriggerBuyQuantity *decimal.Decimal `json:"trigger_buy_quantity"`
UpperLimitQuantity *decimal.Decimal `json:"upper_limit_quantity"`
LowerLimitQuantity *decimal.Decimal `json:"lower_limit_quantity"`
UpperLimitEvent GridLimitEvent `json:"upper_limit_event"`
LowerLimitEvent GridLimitEvent `json:"lower_limit_event"`
MultipleTrigger bool `json:"multiple_trigger"`
TriggerTimes int32 `json:"trigger_times"`
TotalBuyQuantity *decimal.Decimal `json:"total_buy_quantity"`
TotalSellQuantity *decimal.Decimal `json:"total_sell_quantity"`
TotalProfitBalance *decimal.Decimal `json:"total_profit_balance"`
SettlementCurrency string `json:"settlement_currency"`
TimeInForce GridTimeInForce `json:"time_in_force"` // Day / GTC / GTD
Gtd string `json:"gtd"`
CreatedAt string `json:"created_at"`
Rth int32 `json:"rth"`
SupportShortsell bool `json:"support_shortsell"`
GridOrderTypeUp string `json:"grid_order_type_up"` // GMO / GLO / GTG
GridOrderTypeDown string `json:"grid_order_type_down"` // GMO / GLO / GTG
}
GridOrder is a grid trading order (element of the list / by-ids responses).
type GridOrderDetail ¶
type GridOrderDetail struct {
OrderId string `json:"order_id"`
Symbol string `json:"symbol"`
StockName string `json:"stock_name"`
Status string `json:"status"`
GridStatus string `json:"grid_status"`
SuspendReason string `json:"suspend_reason"`
SleepingReason string `json:"sleeping_reason"`
SubmittedBasePrice *decimal.Decimal `json:"submitted_base_price"`
CurrentBasePrice *decimal.Decimal `json:"current_base_price"`
UpperLimitPrice *decimal.Decimal `json:"upper_limit_price"`
LowerLimitPrice *decimal.Decimal `json:"lower_limit_price"`
TriggerPriceType TriggerPriceType `json:"trigger_price_type"`
TriggerSpreadUp *decimal.Decimal `json:"trigger_spread_up"`
TriggerSpreadDown *decimal.Decimal `json:"trigger_spread_down"`
TriggerPercentUp *decimal.Decimal `json:"trigger_percent_up"`
TriggerPercentDown *decimal.Decimal `json:"trigger_percent_down"`
PullbackPercent *decimal.Decimal `json:"pullback_percent"`
PullbackSpread *decimal.Decimal `json:"pullback_spread"`
ReboundPercent *decimal.Decimal `json:"rebound_percent"`
ReboundSpread *decimal.Decimal `json:"rebound_spread"`
MultipleTrigger bool `json:"multiple_trigger"`
TimeInForce GridTimeInForce `json:"time_in_force"`
TriggerQuantity *decimal.Decimal `json:"trigger_quantity"`
TriggerSellQuantity *decimal.Decimal `json:"trigger_sell_quantity"`
TriggerBuyQuantity *decimal.Decimal `json:"trigger_buy_quantity"`
UpperLimitQuantity *decimal.Decimal `json:"upper_limit_quantity"`
LowerLimitQuantity *decimal.Decimal `json:"lower_limit_quantity"`
UpperLimitEvent GridLimitEvent `json:"upper_limit_event"`
LowerLimitEvent GridLimitEvent `json:"lower_limit_event"`
TriggerSellDepth int32 `json:"trigger_sell_depth"`
TriggerBuyDepth int32 `json:"trigger_buy_depth"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
SettlementCurrency string `json:"settlement_currency"`
ExpireTime string `json:"expire_time"`
Gtd string `json:"gtd"`
GridSubOrders []*GridOrderSubOrder `json:"grid_sub_orders"`
SubHasMore bool `json:"sub_has_more"`
GridOrderHistory []*GridOrderHistory `json:"grid_order_history"`
HistoryHasMore bool `json:"history_has_more"`
SupportShortsell bool `json:"support_shortsell"`
Rth int32 `json:"rth"`
GridOrderTypeUp string `json:"grid_order_type_up"`
GridOrderTypeDown string `json:"grid_order_type_down"`
}
GridOrderDetail is the detail of a grid trading order.
type GridOrderHistory ¶
type GridOrderHistory struct {
HistoryId string `json:"history_id"`
CreatedAt string `json:"created_at"`
Status string `json:"status"`
SuspendReason string `json:"suspend_reason"`
Reason string `json:"reason"`
}
GridOrderHistory is a grid order lifecycle-history entry.
type GridOrderSubOrder ¶
type GridOrderSubOrder struct {
Id string `json:"id"`
Price *decimal.Decimal `json:"price"`
OrderType string `json:"order_type"`
Quantity *decimal.Decimal `json:"quantity"`
ExecutedQty *decimal.Decimal `json:"executed_qty"`
Action int32 `json:"action"`
Status string `json:"status"`
SubmittedAt string `json:"submitted_at"`
Rth int32 `json:"rth"`
}
GridOrderSubOrder is a triggered sub-order carried in the grid order detail.
type GridOrders ¶
type GridOrders struct {
GridOrder []*GridOrder `json:"grid_order"`
HasMore bool `json:"has_more"`
}
GridOrders is the response for the grid orders list request.
type GridSymbolInfo ¶
type GridSymbolInfo struct {
Name string `json:"name"`
LastDone *decimal.Decimal `json:"last_done"`
LotSize *decimal.Decimal `json:"lot_size"`
BuyLotSize *decimal.Decimal `json:"buy_lot_size"`
SellLotSize *decimal.Decimal `json:"sell_lot_size"`
BidSizes []*GridBidSize `json:"bid_sizes"`
ChannelInfo GridChannelInfo `json:"channel_info"`
}
GridSymbolInfo is the /v1/orders/info response — the security (symbol) info used to build a grid order.
type GridTimeInForce ¶
type GridTimeInForce int32
GridTimeInForce is the time in force for a grid order (wire: int32). Values other than the named ones are preserved verbatim.
const ( // GridTimeInForceDay is a day order. GridTimeInForceDay GridTimeInForce = 0 // GridTimeInForceGoodTilCanceled is a good-til-canceled order. GridTimeInForceGoodTilCanceled GridTimeInForce = 1 // GridTimeInForceGoodTilDate is a good-til-date order. GridTimeInForceGoodTilDate GridTimeInForce = 6 )
type GridTradeRule ¶
type GridTradeRule struct {
SubmittedBasePrice decimal.Decimal // Base price the grid is anchored to
UpperLimitPrice decimal.Decimal // Upper price bound
LowerLimitPrice decimal.Decimal // Lower price bound
TriggerPriceType TriggerPriceType // Trigger price type (Spread / Percent)
TriggerSpreadUp decimal.Decimal // Upward trigger spread (absolute)
TriggerSpreadDown decimal.Decimal // Downward trigger spread (absolute)
TriggerPercentUp decimal.Decimal // Upward trigger percent
TriggerPercentDown decimal.Decimal // Downward trigger percent
MultipleTrigger bool // Whether a single grid level may trigger multiple times
TimeInForce GridTimeInForce // Time in force (Day / GTC / GTD)
UpperLimitQuantity decimal.Decimal // Quantity handled when the upper bound is reached
LowerLimitQuantity decimal.Decimal // Quantity handled when the lower bound is reached
ExpireTime int64 // Expiry time (unix seconds), used with GTD
UpperLimitEvent GridLimitEvent // Action when the upper bound is reached
LowerLimitEvent GridLimitEvent // Action when the lower bound is reached
TriggerSellDepth int32 // Sell-side order-book depth (-5..5, 0 = use GridOrderTypeUp)
TriggerBuyDepth int32 // Buy-side order-book depth (-5..5, 0 = use GridOrderTypeDown)
TriggerQuantity decimal.Decimal // Quantity per trigger
SupportShortsell bool // Whether short selling is allowed
Rth int32 // Regular trading hours flag (0 / 1 / 2)
GridOrderTypeUp string // Sell-side order type when depth is 0 (GMO / GLO / GTG)
GridOrderTypeDown string // Buy-side order type when depth is 0 (GMO / GLO / GTG)
}
GridTradeRule is the grid trading rule for submit / replace requests. Prices and quantities use decimal.Decimal; unset (zero-value) decimals are omitted from the request. Enum-like fields are raw integers whose code tables are documented inline.
func NewGridTradeRule ¶
func NewGridTradeRule( basePrice decimal.Decimal, upperPrice decimal.Decimal, lowerPrice decimal.Decimal, trigger GridTrigger, quantity decimal.Decimal, upperQuantity decimal.Decimal, lowerQuantity decimal.Decimal, timeInForce GridTimeInForce, ) *GridTradeRule
NewGridTradeRule creates a rule with the fields a valid grid order requires. The gateway still validates business rules, but this makes the minimum field set visible in the signature instead of leaving all fields optional. Chain the setter methods to populate the optional fields.
func (*GridTradeRule) Depths ¶
func (r *GridTradeRule) Depths(sell, buy int32) *GridTradeRule
Depths sets the sell / buy order-book depths (0 = use the order type).
func (*GridTradeRule) ExpireTimeAt ¶
func (r *GridTradeRule) ExpireTimeAt(unixSeconds int64) *GridTradeRule
ExpireTimeAt sets the expiry time (unix seconds), used with a GTD time-in-force.
func (*GridTradeRule) LimitEvents ¶
func (r *GridTradeRule) LimitEvents(upper, lower GridLimitEvent) *GridTradeRule
LimitEvents sets the actions taken at the upper / lower bounds.
func (*GridTradeRule) MultipleTriggerFlag ¶
func (r *GridTradeRule) MultipleTriggerFlag(value bool) *GridTradeRule
MultipleTriggerFlag allows a single grid level to trigger multiple times.
func (*GridTradeRule) OrderTypes ¶
func (r *GridTradeRule) OrderTypes(up, down string) *GridTradeRule
OrderTypes sets the sell / buy order types (GMO / GLO / GTG).
func (*GridTradeRule) RthFlag ¶
func (r *GridTradeRule) RthFlag(value int32) *GridTradeRule
RthFlag sets the regular-trading-hours flag (0 / 1 / 2).
func (*GridTradeRule) SupportShortsellFlag ¶
func (r *GridTradeRule) SupportShortsellFlag(value bool) *GridTradeRule
SupportShortsellFlag allows short selling.
type GridTrigger ¶
type GridTrigger struct {
// contains filtered or unexported fields
}
GridTrigger expresses a grid's up/down trigger thresholds. Percent and spread are mutually exclusive; use PercentTrigger or SpreadTrigger to build one so the choice is explicit (instead of four independent optional fields).
func PercentTrigger ¶
func PercentTrigger(up, down decimal.Decimal) GridTrigger
PercentTrigger builds a percent-based grid trigger.
func SpreadTrigger ¶
func SpreadTrigger(up, down decimal.Decimal) GridTrigger
SpreadTrigger builds an absolute-spread-based grid trigger.
type GridTriggerHistory ¶
type GridTriggerHistory struct {
TriggerOrders []*TriggerOrder `json:"trigger_orders"`
HasMore bool `json:"has_more"`
}
GridTriggerHistory is the response for the grid trigger history request.
type ReplaceGridOrder ¶
type ReplaceGridOrder struct {
OrderId string // required
GridTradingRule GridTradeRule // required
}
ReplaceGridOrder is the request for replacing a grid trading order.
type SubmitGridOrder ¶
type SubmitGridOrder struct {
Symbol string // required, e.g. 700.HK
SettlementCurrency string // required, e.g. HKD
GridTradingRule GridTradeRule // required
}
SubmitGridOrder is the request for submitting a grid trading order.
type TriggerOrder ¶
type TriggerOrder struct {
Id string `json:"id"`
Status string `json:"status"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Price *decimal.Decimal `json:"price"`
Quantity *decimal.Decimal `json:"quantity"`
ExecutedPrice *decimal.Decimal `json:"executed_price"`
ExecutedQty *decimal.Decimal `json:"executed_qty"`
SubmittedAt string `json:"submitted_at"`
Action int32 `json:"action"`
OrderType string `json:"order_type"`
TriggerPrice *decimal.Decimal `json:"trigger_price"`
Msg string `json:"msg"`
Currency string `json:"currency"`
LastDone *decimal.Decimal `json:"last_done"`
UpdatedAt string `json:"updated_at"`
TimeInForce GridTimeInForce `json:"time_in_force"`
Gtd string `json:"gtd"`
TriggerAt string `json:"trigger_at"`
TriggerStatus int32 `json:"trigger_status"`
}
TriggerOrder is a grid trigger-history entry (one triggered order).
type TriggerPriceType ¶
type TriggerPriceType int32
TriggerPriceType is how grid trigger thresholds are interpreted (wire: int32).
const ( // TriggerPriceTypeUnknown is the unknown / unset value. TriggerPriceTypeUnknown TriggerPriceType = 0 // TriggerPriceTypeSpread triggers by an absolute price spread. TriggerPriceTypeSpread TriggerPriceType = 1 // TriggerPriceTypePercent triggers by percent. TriggerPriceTypePercent TriggerPriceType = 2 )