Documentation
¶
Overview ¶
Package trade provide TradeContext
Index ¶
- Constants
- type AccountBalance
- type AccountBalances
- type BalanceType
- type CashFlow
- type CashFlows
- type CashInfo
- type ChargeCategoryCode
- type CommissionFreeStatus
- type Currency
- type DeductionStatus
- type EstimateMaxPurchaseQuantityResponse
- type Execution
- type Executions
- type FundPosition
- type FundPositionChannel
- type FundPositions
- type GetAccountBalance
- type GetCashFlow
- type GetEstimateMaxPurchaseQuantity
- type GetFundPositions
- type GetHistoryExecutions
- type GetHistoryOrders
- type GetStockPositions
- type GetTodayExecutions
- type GetTodayOrders
- type MarginRatio
- type Market
- type OfDirection
- type Option
- type Options
- type Order
- type OrderChargeDetail
- type OrderChargeFee
- type OrderChargeItem
- type OrderDetail
- type OrderHistoryDetail
- type OrderSide
- type OrderStatus
- type OrderTag
- type OrderType
- type Orders
- type OutsideRTH
- type PushEvent
- type PushOrderChanged
- type ReplaceOrder
- type StockPosition
- type StockPositionChannel
- type StockPositions
- type SubResponse
- type SubResponseFail
- type SubmitOrder
- type TimeType
- type TradeContext
- func (c *TradeContext) AccountBalance(ctx context.Context, params *GetAccountBalance) (accounts []*AccountBalance, err error)
- func (c *TradeContext) CancelOrder(ctx context.Context, orderId string) (err error)
- func (c *TradeContext) CashFlow(ctx context.Context, params *GetCashFlow) (cashflows []*CashFlow, err error)
- func (c *TradeContext) Close() error
- func (c *TradeContext) EstimateMaxPurchaseQuantity(ctx context.Context, params *GetEstimateMaxPurchaseQuantity) (empqr EstimateMaxPurchaseQuantityResponse, err error)
- func (c *TradeContext) FundPositions(ctx context.Context, symbols []string) (fundPositionChannels []*FundPositionChannel, err error)
- func (c *TradeContext) HistoryExecutions(ctx context.Context, params *GetHistoryExecutions) (trades []*Execution, err error)
- func (c *TradeContext) HistoryOrders(ctx context.Context, params *GetHistoryOrders) (orders []*Order, hasMore bool, err error)
- func (c *TradeContext) MarginRatio(ctx context.Context, symbol string) (marginRatio MarginRatio, err error)
- func (c *TradeContext) OnTrade(f func(*PushEvent))
- func (c *TradeContext) OrderDetail(ctx context.Context, orderId string) (orderDetail OrderDetail, err error)
- func (c *TradeContext) ReplaceOrder(ctx context.Context, params *ReplaceOrder) (err error)
- func (c *TradeContext) StockPositions(ctx context.Context, symbols []string) (stockPositionChannels []*StockPositionChannel, err error)
- func (c *TradeContext) SubmitOrder(ctx context.Context, params *SubmitOrder) (orderId string, err error)
- func (c *TradeContext) Subscribe(ctx context.Context, topics []string) (subRes *SubResponse, err error)
- func (c *TradeContext) TodayExecutions(ctx context.Context, params *GetTodayExecutions) (trades []*Execution, err error)
- func (c *TradeContext) TodayOrders(ctx context.Context, params *GetTodayOrders) (orders []*Order, err error)
- func (c *TradeContext) Unsubscribe(ctx context.Context, topics []string) (unsubRes *UnsubResponse, err error)
- func (c *TradeContext) WithdrawOrder(ctx context.Context, orderId string) (err error)
- type TriggerStatus
- type UnsubResponse
Constants ¶
const ( // Balance type BalanceTypeUnknown BalanceType = 0 // unknown type BalanceTypeCash BalanceType = 1 // cash BalanceTypeStock BalanceType = 2 // stock BalanceTypeFund BalanceType = 3 // fund // Outflow direction OfDirectionUnkown OfDirection = 0 OfDirectionOut OfDirection = 1 // outflow OfDirectionIn OfDirection = 2 // inflow // Time force in type TimeTypeDay TimeType = "Day" // Day Order TimeTypeGTC TimeType = "GTC" // Good Til Canceled Order TimeTypeGTD TimeType = "GTD" // Good Til Date Order // Order type OrderTypeLO OrderType = "LO" // Limit Order OrderTypeELO OrderType = "ELO" // Enhanced Limit Order OrderTypeMO OrderType = "MO" // Market Order OrderTypeAO OrderType = "AO" // At-auction Order OrderTypeALO OrderType = "ALO" // At-auction Limit Order OrderTypeODD OrderType = "ODD" // Odd Lots Order OrderTypeLIT OrderType = "LIT" // Limit If Touched OrderTypeMIT OrderType = "MIT" // Market If Touched OrderTypeTSLPAMT OrderType = "TSLPAMT" // Trailing Limit If Touched (Trailing Amount) OrderTypeTSLPPCT OrderType = "TSLPPCT" // Trailing Limit If Touched (Trailing Percent) OrderTypeTSMAMT OrderType = "TSMAMT" // Trailing Market If Touched (Trailing Amount) OrderTypeTSMPCT OrderType = "TSMPCT" // Trailing Market If Touched (Trailing Percent) OrderTypeSLO OrderType = "SLO" // SLO order // Order side OrderSideBuy OrderSide = "Buy" OrderSideSell OrderSide = "Sell" // Order status OrderNotReported OrderStatus = "NotReported" OrderReplacedNotReported OrderStatus = "ReplacedNotReported" OrderProtectedNotReported OrderStatus = "ProtectedNotReported" OrderVarietiesNotReported OrderStatus = "VarietiesNotReported" OrderFilledStatus OrderStatus = "FilledStatus" OrderWaitToNew OrderStatus = "WaitToNew" OrderNewStatus OrderStatus = "NewStatus" OrderWaitToReplace OrderStatus = "WaitToReplace" OrderPendingReplaceStatus OrderStatus = "PendingReplaceStatus" OrderReplacedStatus OrderStatus = "ReplacedStatus" OrderPartialFilledStatus OrderStatus = "PartialFilledStatus" OrderWaitToCancel OrderStatus = "WaitToCancel" OrderPendingCancelStatus OrderStatus = "PendingCancelStatus" OrderRejectedStatus OrderStatus = "RejectedStatus" OrderCanceledStatus OrderStatus = "CanceledStatus" OrderExpiredStatus OrderStatus = "ExpiredStatus" OrderPartialWithdrawal OrderStatus = "PartialWithdrawn" // Outside RTH OutsideRTHOnly OutsideRTH = "RTH_ONLY" // Regular trading hour only OutsideRTHAny OutsideRTH = "ANY_TIME" // Any time OutsideRTHUnknown OutsideRTH = "UnknownOutsideRth" // Default is UnknownOutsideRth when the order is not a US stock // Commission-free Status CommissionFreeStatusNone CommissionFreeStatus = "None" CommissionFreeStatusCaculated CommissionFreeStatus = "Calculated" // Commission-free amount to be calculated CommissionFreeStatusPending CommissionFreeStatus = "Pending" // Pending commission-free CommissionFreeStatusReady CommissionFreeStatus = "Ready" // Commission-free applied // Deduction status/Cashback Status DeductionStatusNone DeductionStatus = "NONE" DeductionStatusNoData DeductionStatus = "NO_DATA" DeductionStatusPending DeductionStatus = "PENDING" DeductionStatusDone DeductionStatus = "DONE" // Charge category code ChargeCategoryCodeUnknown ChargeCategoryCode = "UNKNOWN" ChargeCategoryCodeBrokerFees ChargeCategoryCode = "BROKER_FEES" ChargeCategoryCodeThirdFees ChargeCategoryCode = "THIRD_FEES" // Currency CurrencyHKD Currency = "HKD" CurrencyUSD Currency = "USD" CurrencyCNH Currency = "CNH" CurrencyDefault Currency = "" )
const (
DefaultTradeUrl = "wss://openapi-trade.longportapp.com/v2"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountBalance ¶
type AccountBalance struct { TotalCash *decimal.Decimal MaxFinanceAmount *decimal.Decimal RemainingFinanceAmount *decimal.Decimal RiskLevel string MarginCall *decimal.Decimal NetAssets *decimal.Decimal // net asset InitMargin *decimal.Decimal // initial margin MaintenanceMargin *decimal.Decimal // maintenance margin Currency string CashInfos []*CashInfo }
AccountBalance is user account balance
type AccountBalances ¶
type AccountBalances struct {
List []*AccountBalance
}
AccountBalances has a AccountBalance list
type BalanceType ¶
type BalanceType int32
type CashFlow ¶
type CashFlow struct { TransactionFlowName string Direction OfDirection BusinessType BalanceType Balance *decimal.Decimal Currency string BusinessTime string Symbol string Description string }
CashFlow is cash flow details
type CashInfo ¶
type CashInfo struct { WithdrawCash *decimal.Decimal AvailableCash *decimal.Decimal FrozenCash *decimal.Decimal SettlingCash *decimal.Decimal Currency string }
CashInfo
type ChargeCategoryCode ¶
type ChargeCategoryCode string
type CommissionFreeStatus ¶
type CommissionFreeStatus string
type DeductionStatus ¶
type DeductionStatus string
type EstimateMaxPurchaseQuantityResponse ¶
type EstimateMaxPurchaseQuantityResponse struct { CashMaxQty int64 // Cash available quantity MarginMaxQty int64 // Margin available quantity }
EstimateMaxPurchaseQuantity is response for estimate maximum purchase quantity
type Execution ¶
type Execution struct { OrderId string TradeId string Symbol string TradeDoneAt time.Time Quantity string Price *decimal.Decimal }
Execution is execution details
type FundPosition ¶
type FundPosition struct { Symbol string CurrentNetAssetValue *decimal.Decimal NetAssetValueDay int64 SymbolName string Currency string CostNetAssetValue *decimal.Decimal HoldingUnits *decimal.Decimal }
FundPosition is fund position details
type FundPositionChannel ¶
type FundPositionChannel struct { AccountChannel string Positions []*FundPosition }
FundPositionChannel is a account channel's fund position details
type FundPositions ¶
type FundPositions struct {
List []*FundPositionChannel
}
FundPositions has a FundPosition list
type GetAccountBalance ¶ added in v0.14.0
type GetAccountBalance struct {
Currency Currency // optional
}
func (*GetAccountBalance) Values ¶ added in v0.14.0
func (r *GetAccountBalance) Values() url.Values
type GetCashFlow ¶
type GetCashFlow struct { StartAt int64 // start timestamp , required EndAt int64 // end timestamp, required BusinessType BalanceType Symbol string Page int64 Size int64 }
func (*GetCashFlow) Values ¶
func (r *GetCashFlow) Values() url.Values
type GetEstimateMaxPurchaseQuantity ¶
type GetEstimateMaxPurchaseQuantity struct { Symbol string OrderType OrderType Price decimal.Decimal Currency string OrderId string Side OrderSide }
func (*GetEstimateMaxPurchaseQuantity) Values ¶
func (r *GetEstimateMaxPurchaseQuantity) Values() url.Values
type GetFundPositions ¶
type GetFundPositions struct {
Symbols []string // optional
}
func (*GetFundPositions) Values ¶
func (r *GetFundPositions) Values() url.Values
type GetHistoryExecutions ¶
type GetHistoryExecutions struct { Symbol string // optional StartAt time.Time // optional EndAt time.Time // optional }
func (*GetHistoryExecutions) Values ¶
func (req *GetHistoryExecutions) Values() url.Values
type GetHistoryOrders ¶
type GetHistoryOrders struct { Symbol string // optional Status []OrderStatus // optional Side OrderSide // optional Market openapi.Market // optional StartAt int64 // optional EndAt int64 // optional }
func (*GetHistoryOrders) Values ¶
func (r *GetHistoryOrders) Values() url.Values
type GetStockPositions ¶
type GetStockPositions struct {
Symbols []string // optional
}
func (*GetStockPositions) Values ¶
func (r *GetStockPositions) Values() url.Values
type GetTodayExecutions ¶
func (*GetTodayExecutions) Values ¶
func (req *GetTodayExecutions) Values() url.Values
type GetTodayOrders ¶
type GetTodayOrders struct { Symbol string // optional Status []OrderStatus // optional Side OrderSide // optional Market openapi.Market // optional }
func (*GetTodayOrders) Values ¶
func (r *GetTodayOrders) Values() url.Values
type MarginRatio ¶
type MarginRatio struct { ImFactor *decimal.Decimal // Initial margin ratio MmFactor *decimal.Decimal // Maintain the initial margin ratio FmFactor *decimal.Decimal // Forced close-out margin ratio }
MarginRatio contains some ratio
type OfDirection ¶
type OfDirection int32
type Option ¶
type Option func(*Options)
Option
func WithHttpClient ¶
WithHttpClient to set http client for trade context
func WithLbOptions ¶
func WithLbOptions(opts *longbridge.Options) Option
func WithLogger ¶
WithLogger use custom protocol.Logger implementation
func WithTradeURL ¶
WithTradeURL to set trade url for trade context
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options for quote context
type Order ¶
type Order struct { OrderId string Status OrderStatus StockName string Quantity string ExecutedQuantity string Price *decimal.Decimal ExecutedPrice *decimal.Decimal SubmittedAt string Side OrderSide Symbol string OrderType OrderType LastDone *decimal.Decimal TriggerPrice *decimal.Decimal Msg string Tag OrderTag TimeInForce TimeType ExpireDate string UpdatedAt string TriggerAt string TrailingAmount *decimal.Decimal TrailingPercent *decimal.Decimal LimitOffset *decimal.Decimal TriggerStatus TriggerStatus Currency string OutsideRth OutsideRTH Remark string }
Order is order details
type OrderChargeDetail ¶
type OrderChargeDetail struct { TotalAmount decimal.Decimal Currency string Items []OrderChargeItem }
type OrderChargeFee ¶
type OrderChargeFee struct { Code ChargeCategoryCode Name string Fees []OrderChargeFee }
type OrderChargeItem ¶
type OrderChargeItem struct { Code ChargeCategoryCode Name string Fees []OrderChargeFee }
type OrderDetail ¶
type OrderDetail struct { OrderId string Status OrderStatus StockName string Quantity int64 // Submitted quantity ExecutedQuantity int64 Price *decimal.Decimal // Submitted price ExecutedPrice *decimal.Decimal SubmittedAt string // Submitted time Side OrderSide /// Order side Symbol string OrderType OrderType LastDone *decimal.Decimal TriggerPrice *decimal.Decimal Msg string // Rejected Message or remark Tag OrderTag TimeInForce TimeType ExpireDate string UpdatedAt string TriggerAt string // Conditional order trigger time TrailingAmount *decimal.Decimal TrailingPercent *decimal.Decimal LimitOffset *decimal.Decimal TriggerStatus TriggerStatus Currency string OutsideRth OutsideRTH /// Enable or disable outside regular trading hours Remark string FreeStatus CommissionFreeStatus FreeAmount *decimal.Decimal FreeCurrency string DeductionsStatus DeductionStatus DeductionsAmount *decimal.Decimal DeductionsCurrency string PlatformDeductedStatus DeductionStatus PlatformDeductedAmount *decimal.Decimal PlatformDeductedCurrency string History OrderHistoryDetail ChargeDetail OrderChargeDetail }
type OrderHistoryDetail ¶
type OrderHistoryDetail struct { // Executed price for executed orders, submitted price for expired, // canceled, rejected orders, etc. Price decimal.Decimal // Executed quantity for executed orders, remaining quantity for expired, // canceled, rejected orders, etc. Quantity int64 Status OrderStatus Msg string // Execution or error message Time string // Occurrence time }
type OrderStatus ¶
type OrderStatus string
type OutsideRTH ¶
type OutsideRTH string // Outside regular trading hours
type PushEvent ¶
type PushEvent struct { Event string Data *PushOrderChanged }
PushEvent is quote context callback event
type PushOrderChanged ¶
type PushOrderChanged struct { AccountNo string Currency string ExecutedPrice *decimal.Decimal ExecutedQuantity *decimal.Decimal LastPrice *decimal.Decimal LimitOffset string Msg string OrderId string OrderType OrderType Side OrderSide Status OrderStatus StockName string SubmittedAt string Price *decimal.Decimal Quantity *decimal.Decimal Symbol string Tag OrderTag TrailingAmount *decimal.Decimal TrailingPercent string TriggerAt string TriggerPrice *decimal.Decimal TriggerStatus TriggerStatus UpdatedAt string Remark string }
PushOrderChanged is order change event details
type ReplaceOrder ¶
type ReplaceOrder struct { OrderId string // required Quantity uint64 // required Price decimal.Decimal // LO / ELO / ALO / ODD / LIT Order Required TriggerPrice decimal.Decimal // LIT / MIT Order Required LimitOffset decimal.Decimal // TSLPAMT / TSLPPCT Order Required TrailingAmount decimal.Decimal // TSLPAMT / TSMAMT Order Required TrailingPercent decimal.Decimal // TSLPPCT / TSMAPCT Order Required Remark string }
type StockPosition ¶
type StockPosition struct { Symbol string SymbolName string Quantity string AvailableQuantity string Currency string CostPrice *decimal.Decimal Market openapi.Market }
StockPosition is user stock position details
type StockPositionChannel ¶
type StockPositionChannel struct { AccountChannel string Positions []*StockPosition }
StockPositionChannel is a account channel's stock positions details
type StockPositions ¶
type StockPositions struct {
List []*StockPositionChannel
}
StockPositions has a StockPosition list
type SubResponse ¶
type SubResponse struct { Success []string Fail []*SubResponseFail Current []string }
SubResponse is subscribe function response
type SubResponseFail ¶
SubResponseFail contains subscribe failed reason
type SubmitOrder ¶
type SubmitOrder struct { Symbol string // required OrderType OrderType // required Side OrderSide // required SubmittedQuantity uint64 // required SubmittedPrice decimal.Decimal // LO / ELO / ALO / ODD / LIT Order Required TriggerPrice decimal.Decimal // LIT / MIT Order Required LimitOffset decimal.Decimal // TSLPAMT / TSLPPCT Order Required TrailingAmount decimal.Decimal // TSLPAMT / TSMAMT Order Required TrailingPercent decimal.Decimal // TSLPPCT / TSMAPCT Order Required ExpireDate *time.Time // required when time_in_force is GTD OutsideRTH OutsideRTH Remark string TimeInForce TimeType // required }
type TradeContext ¶
type TradeContext struct {
// contains filtered or unexported fields
}
TradeContext is a client for interacting with Longbridge Trade OpenAPI. Longbrige Quote OpenAPI document is https://open.longportapp.com/en/docs/trade/trade-overview
Example:
conf, err := config.NewFromEnv() tctx, err := trade.NewFromCfg(conf) tctx.OnTrade(func(orderEvent *trade.PushEvent) { fmt.Printf("order event: %v", orderEvent) }) _, err := tctx.Subscribe(context.Background(), []string{"private"}) price := decimal.NewFromString("175.62") oid, err := tctx.SubmitOrder(context.Background(), &trade.SubmitOrder{ Symbol: "AAPL.US", OrderType: trade.OrderTypeLO, Side: trade.OrderSideBuy, SubmittedPrice: price, SubmittedQuantity: 2, TimeInForce: trade.TimeTypeDay, })
func New ¶
func New(opt ...Option) (*TradeContext, error)
New return TradeContext with option. A connection will be created with Trade server.
func NewFormEnv
deprecated
func NewFormEnv() (*TradeContext, error)
Deprecated: NewFormEnv return TradeContext with environment variables, use NewFromCfg plz
func NewFromCfg ¶
func NewFromCfg(cfg *config.Config) (*TradeContext, error)
NewFromCfg return TradeContext with config.Config.
func (*TradeContext) AccountBalance ¶
func (c *TradeContext) AccountBalance(ctx context.Context, params *GetAccountBalance) (accounts []*AccountBalance, err error)
AccountBalance to obtain the available, desirable, frozen, to-be-settled, and in-transit funds (fund purchase and redemption) information for each currency of the user. Reference: https://open.longportapp.com/en/docs/trade/asset/account Example:
conf, err := config.NewFromEnv() tctx, err := trade.NewFromCfg(conf) ab, err := trade.AccountBalance(context.Background(), &trade.GetAccountBalance{Currency: trade.CurrencyHKD})
func (*TradeContext) CancelOrder ¶ added in v0.15.0
func (c *TradeContext) CancelOrder(ctx context.Context, orderId string) (err error)
CancelOrder to close an open order Reference: https://open.longportapp.com/en/docs/trade/order/withdraw Example:
conf, err := config.NewFromEnv() tctx, err := trade.NewFromCfg(conf) err = tctx.CancelOrder(context.Background(), "12123123")
func (*TradeContext) CashFlow ¶
func (c *TradeContext) CashFlow(ctx context.Context, params *GetCashFlow) (cashflows []*CashFlow, err error)
CashFlow to obtain capital inflow/outflow direction, capital type, capital amount, occurrence time, associated stock code and capital flow description information. Reference: https://open.longportapp.com/en/docs/trade/asset/cashflow Example:
conf, err := config.NewFromEnv() tctx, err := trade.NewFromCfg(conf) start := time.Date(2024, 5, 1, 0, 0, 0, 0, time.UTC).Unix() end := time.Date(2024, 6, 1, 0, 0, 0, 0, time.UTC).Unix() flows, err := tctx.CashFlow(context.Background(), trade.GetCashFlow{ StartAt: start, EndAt: end, BussinessType: trade.BalanceTypeCash, })
func (*TradeContext) EstimateMaxPurchaseQuantity ¶
func (c *TradeContext) EstimateMaxPurchaseQuantity(ctx context.Context, params *GetEstimateMaxPurchaseQuantity) (empqr EstimateMaxPurchaseQuantityResponse, err error)
EstimateMaxPurchaseQuantity is used for estimating the maximum purchase quantity for Hong Kong and US stocks, warrants, and options. Reference: https://open.longportapp.com/en/docs/trade/order/estimate_available_buy_limit Example:
conf, err := config.NewFromEnv() tctx, err := trade.NewFromCfg(conf) price, _ := decimal.NewFromString("175.62") empqr, err := trade.EstimateMaxPurchaseQuantity(context.Background(), &trade.GetEstimateMaxPurchaseQuantity{ Symbol: "AAPL.US", Price: price, OrderType: trade.OrderTypeLO, Currency: "USD", Side: trade.OrderSideBuy, })
func (*TradeContext) FundPositions ¶
func (c *TradeContext) FundPositions(ctx context.Context, symbols []string) (fundPositionChannels []*FundPositionChannel, err error)
FundPositions to obtain fund position information including account, fund code, holding share, cost net worth, current net worth, and currency. Reference: https://open.longportapp.com/en/docs/trade/asset/fund Example:
conf, err := config.NewFromEnv() tctx, err := trade.NewFromCfg(conf) channels, err := tctx.FundPositions(context.Background, []string{"AAPL.US", "700.HK"})
func (*TradeContext) HistoryExecutions ¶
func (c *TradeContext) HistoryExecutions(ctx context.Context, params *GetHistoryExecutions) (trades []*Execution, err error)
HistoryExecutions will return history executions. Reference: https://open.longportapp.com/en/docs/trade/execution/history_executions
Example:
conf, err := config.NewFromEnv() tctx, err := trade.NewFromCfg(conf) trades, err := tctx.HistoryExecutions(context.Background(), &trade.GetHistoryExecutions{ Symbol: "AAPL.US", StartAt: time.Date(2024, 5, 1, 0, 0, 0, 0, time.UTC), EndAt: time.Date(2024, 5, 10, 0, 0, 0, 0, time.UTC), })
func (*TradeContext) HistoryOrders ¶
func (c *TradeContext) HistoryOrders(ctx context.Context, params *GetHistoryOrders) (orders []*Order, hasMore bool, err error)
HistoryOrders will return history orders Reference: https://open.longportapp.com/en/docs/trade/order/history_orders Example:
conf, err := config.NewFromEnv() tctx, err := trade.NewFromCfg(conf) orders, hasMore, err := tctx.HistoryOrders(context.Background(), &trade.GetHistoryOrders{ Symbol: "AAPL.US", Status: []trade.OrderStatus{trade.OrderFilledStatus}, })
func (*TradeContext) MarginRatio ¶
func (c *TradeContext) MarginRatio(ctx context.Context, symbol string) (marginRatio MarginRatio, err error)
MarginRatio is used to obtain the initial margin ratio, maintain the margin ratio and strengthen the margin ratio of stocks. Reference: https://open.longportapp.com/en/docs/trade/asset/margin_ratio Example:
conf, err := config.NewFromEnv() tctx, err := trade.NewFromCfg(conf) mr, err := tctx.MarginRatio(context.Background(), "AAPL.US")
func (*TradeContext) OnTrade ¶
func (c *TradeContext) OnTrade(f func(*PushEvent))
OnQuote set callback function which will be called when server push events.
func (*TradeContext) OrderDetail ¶
func (c *TradeContext) OrderDetail(ctx context.Context, orderId string) (orderDetail OrderDetail, err error)
OrderDetail is used for order detail query Reference: https://open.longportapp.com/en/docs/trade/order/order_detail Example:
conf, err := config.NewFromEnv() tctx, err := trade.NewFromCfg(conf) od, err := tctx.OrderDetail(context.Background(), "1123123123")
func (*TradeContext) ReplaceOrder ¶
func (c *TradeContext) ReplaceOrder(ctx context.Context, params *ReplaceOrder) (err error)
ReplaceOrder modify quantity or price Reference: https://open.longportapp.com/en/docs/trade/order/replace
Example:
conf, err := config.NewFromEnv() tctx, err := trade.NewFromCfg(conf) err := tctx.ReplaceOrder(context.Background(), &trade.ReplaceOrder{OrderId: "123123", Quantity: 2, Remark: "just replace the order"})
func (*TradeContext) StockPositions ¶
func (c *TradeContext) StockPositions(ctx context.Context, symbols []string) (stockPositionChannels []*StockPositionChannel, err error)
StockPositions to obtain stock position information including account, stock code, number of shares held, number of available shares, average position price (calculated according to account settings), and currency. Reference: https://open.longportapp.com/en/docs/trade/asset/stock Example:
conf, err := config.NewFromEnv() tctx, err := trade.NewFromCfg(conf) channels, err := tctx.StockPositions(context.Background(), []string{"AAPL.US"})
func (*TradeContext) SubmitOrder ¶
func (c *TradeContext) SubmitOrder(ctx context.Context, params *SubmitOrder) (orderId string, err error)
func (*TradeContext) Subscribe ¶
func (c *TradeContext) Subscribe(ctx context.Context, topics []string) (subRes *SubResponse, err error)
Subscribe topics then the handler will receive push event. Reference: https://open.longportapp.com/en/docs/trade/trade-push#subscribe
func (*TradeContext) TodayExecutions ¶
func (c *TradeContext) TodayExecutions(ctx context.Context, params *GetTodayExecutions) (trades []*Execution, err error)
TodayExecutions will return today's executions Reference: https://open.longportapp.com/en/docs/trade/execution/today_executions Example:
conf, err := config.NewFromEnv() tctx, err := trade.NewFromCfg(conf) trades, err := tctx.TodayExecutions(context.Background(), &trade.GetTodayExecutions{Symbol: "AAPL.US"})
func (*TradeContext) TodayOrders ¶
func (c *TradeContext) TodayOrders(ctx context.Context, params *GetTodayOrders) (orders []*Order, err error)
TodayOrders will return today orders Reference: https://open.longportapp.com/en/docs/trade/order/today_orders
Example:
conf, err := config.NewFromEnv() tctx, err := trade.NewFromCfg(conf) orders, err := tctx.TodayOrders(context.Background(), &trade.GetTodayOrders{Symbol: "AAPL.US"})
func (*TradeContext) Unsubscribe ¶
func (c *TradeContext) Unsubscribe(ctx context.Context, topics []string) (unsubRes *UnsubResponse, err error)
Unsubscribe topics then the handler will not receive the symbol's event. Reference: https://open.longportapp.com/en/docs/trade/trade-push#cancel-subscribe
func (*TradeContext) WithdrawOrder ¶
func (c *TradeContext) WithdrawOrder(ctx context.Context, orderId string) (err error)
WithdrawOrder to close an open order. It is same as CancelOrder function. Reference: https://open.longportapp.com/en/docs/trade/order/withdraw Example:
conf, err := config.NewFromEnv() tctx, err := trade.NewFromCfg(conf) err = tctx.WithdrawOrder(context.Background(), "12123123")
type TriggerStatus ¶
type TriggerStatus string
type UnsubResponse ¶
type UnsubResponse struct {
Current []string
}