Documentation
¶
Overview ¶
Package longport provides functionality for communicating with the LongPort API through WebSocket connections with protobuf message encoding.
Index ¶
- Constants
- Variables
- type Api
- type AssetApi
- type BaseOrder
- type BuyLimitReq
- type BuyLimitRsp
- type Cash
- type CommonOrder
- type Currency
- type HistoryQuery
- type Longport
- func (l *Longport) CancelOrder(orderId string) error
- func (l *Longport) ConnQuote() QuoteConn
- func (l *Longport) ConnTrade() TradeConn
- func (l *Longport) Delete(path string, body, rsp any) error
- func (l *Longport) Get(path string, rsp any, params url.Values) error
- func (l *Longport) GetCash(c ...Currency) (*Cash, error)
- func (l *Longport) GetStock(symbols ...string) (*Stocks, error)
- func (l *Longport) ListHistoryOrder(query HistoryQuery) (*Orders, error)
- func (l *Longport) ListTodayOrder(query OrderQuery) (*Orders, error)
- func (l *Longport) MaxOrderNum(req BuyLimitReq) (*BuyLimitRsp, error)
- func (l *Longport) ModifyOrder(modify ModifyOrder) error
- func (l *Longport) Post(path string, body, rsp any) error
- func (l *Longport) Put(path string, body, rsp any) error
- func (l *Longport) SubmitOrder(req SubmitOrder) (*OrderRsp, error)
- type Market
- type Method
- type ModifyOrder
- type Order
- type OrderApi
- type OrderEvent
- type OrderQuery
- type OrderRsp
- type OrderSide
- type OrderStatus
- type OrderType
- type Orders
- type QuoteConn
- type Stock
- type Stocks
- type SubmitOrder
- type TimeType
- type TradeConn
- type TriggerStatus
- type UnixTime
Constants ¶
View Source
const ( REQUEST msgType = 1 // Outgoing request message RESPONSE msgType = 2 // Incoming response message PUSH msgType = 3 // Server-initiated push message )
Variables ¶
View Source
var NotReporteds = []OrderStatus{NotReported, ReplacedNotReported, ProtectedNotReported, VarietiesNotReported}
Functions ¶
This section is empty.
Types ¶
type AssetApi ¶
type AssetApi interface {
// 获取账户资金, 参数: 币种(可选)
GetCash(c ...Currency) (*Cash, error)
// 获取股票持仓, 参数: 股票代码(可选),使用 ticker.region 格式,例如:AAPL.US
GetStock(symbols ...string) (*Stocks, error)
}
资产接口
type BaseOrder ¶
type BaseOrder struct {
Symbol string `json:"symbol,omitempty"` // required
OrderType OrderType `json:"order_type,omitempty"` // required
Side OrderSide `json:"side,omitempty"` // required
TriggerPrice string `json:"trigger_price,omitempty"` // LIT / MIT Order Required
LimitOffset string `json:"limit_offset,omitempty"` // TSLPAMT / TSLPPCT Order Required
TrailingAmount string `json:"trailing_amount,omitempty"` // TSLPAMT / TSMAMT Order Required
TrailingPercent string `json:"trailing_percent,omitempty"` // TSLPPCT / TSMAPCT Order Required
Remark string `json:"remark,omitempty"`
}
基础订单信息
type BuyLimitReq ¶
type BuyLimitRsp ¶
type Cash ¶
type Cash struct {
List []struct {
TotalCash decimal.Decimal `json:"total_cash"`
MaxFinanceAmount decimal.Decimal `json:"max_finance_amount"`
RemainingFinanceAmount decimal.Decimal `json:"remaining_finance_amount"`
RiskLevel string `json:"risk_level"`
MarginCall string `json:"margin_call"`
Currency string `json:"currency"`
NetAssets decimal.Decimal `json:"net_assets"`
InitMargin decimal.Decimal `json:"init_margin"`
MaintenanceMargin decimal.Decimal `json:"maintenance_margin"`
BuyPower decimal.Decimal `json:"buy_power"`
CashInfos []struct {
WithdrawCash decimal.Decimal `json:"withdraw_cash"`
AvailableCash decimal.Decimal `json:"available_cash"`
FrozenCash decimal.Decimal `json:"frozen_cash"`
SettlingCash decimal.Decimal `json:"settling_cash"`
Currency Currency `json:"currency"`
} `json:"cash_infos"`
FrozenTransactionFees []struct {
Currency Currency `json:"currency"`
FrozenTransactionFee decimal.Decimal `json:"frozen_transaction_fee"`
} `json:"frozen_transaction_fees"`
} `json:"list"`
}
type CommonOrder ¶
type CommonOrder struct {
*BaseOrder
StockName string `json:"stock_name,omitempty"`
Quantity decimal.Decimal `json:"quantity,omitempty"`
ExecutedQuantity decimal.Decimal `json:"executed_quantity,omitempty"`
ExecutedPrice decimal.Decimal `json:"executed_price,omitempty"`
Price string `json:"price,omitempty"`
OrderID string `json:"order_id,omitempty"`
Currency string `json:"currency,omitempty"`
Status OrderStatus `json:"status,omitempty"`
TriggerStatus TriggerStatus `json:"trigger_status,omitempty"`
SubmittedAt UnixTime `json:"submitted_at,omitempty"`
UpdatedAt UnixTime `json:"updated_at,omitempty"`
Msg string `json:"msg,omitempty"`
Tag string `json:"tag,omitempty"`
TriggerAt string `json:"trigger_at,omitempty"`
}
订单公共信息
type HistoryQuery ¶
type HistoryQuery struct {
*OrderQuery
Start int64
End int64
}
type Longport ¶
type Longport struct {
Host string `json:"host,omitempty"`
AppKey string `json:"app_key,omitempty"`
AppSecret string `json:"app_secret,omitempty"`
AccessToken string `json:"access_token,omitempty"`
}
func (*Longport) CancelOrder ¶
func (*Longport) ListHistoryOrder ¶
func (l *Longport) ListHistoryOrder(query HistoryQuery) (*Orders, error)
func (*Longport) ListTodayOrder ¶
func (l *Longport) ListTodayOrder(query OrderQuery) (*Orders, error)
func (*Longport) MaxOrderNum ¶
func (l *Longport) MaxOrderNum(req BuyLimitReq) (*BuyLimitRsp, error)
func (*Longport) ModifyOrder ¶
func (l *Longport) ModifyOrder(modify ModifyOrder) error
func (*Longport) SubmitOrder ¶
func (l *Longport) SubmitOrder(req SubmitOrder) (*OrderRsp, error)
type ModifyOrder ¶
type ModifyOrder struct {
OrderID string `json:"order_id,omitempty"`
Quantity decimal.Decimal `json:"quantity,omitempty"`
Price string `json:"price,omitempty"`
TriggerPrice string `json:"trigger_price,omitempty"`
LimitOffset decimal.Decimal `json:"limit_offset,omitempty"`
TrailingAmount string `json:"trailing_amount,omitempty"`
TrailingPercent string `json:"trailing_percent,omitempty"`
Remark string `json:"remark,omitempty"`
}
type Order ¶
type Order struct {
*CommonOrder
LastDone string `json:"last_done,omitempty"`
TimeInForce TimeType `json:"time_in_force,omitempty"`
ExpireDate string `json:"expire_date,omitempty"`
OutsideRth string `json:"outside_rth,omitempty"`
}
订单信息
type OrderApi ¶
type OrderApi interface {
// 获取历史订单
ListHistoryOrder(query HistoryQuery) (*Orders, error)
// 获取今日订单
ListTodayOrder(query OrderQuery) (*Orders, error)
//预估最大购买数量
MaxOrderNum(req BuyLimitReq) (*BuyLimitRsp, error)
// 提交订单
SubmitOrder(req SubmitOrder) (*OrderRsp, error)
// 修改订单
ModifyOrder(modify ModifyOrder) error
// 撤销订单
CancelOrder(orderId string) error
}
订单接口
type OrderEvent ¶
type OrderEvent struct {
Event string `json:"event,omitempty"`
Data struct {
AccountNo string `json:"account_no,omitempty"`
LastShare string `json:"last_share,omitempty"`
LastPrice string `json:"last_price,omitempty"`
SubmittedPrice decimal.Decimal `json:"submitted_price,omitempty"`
SubmittedQuantity decimal.Decimal `json:"submitted_quantity,omitempty"`
*CommonOrder
} `json:"data"`
}
type OrderQuery ¶
type OrderQuery struct {
Symbol string
Side OrderSide
Market Market
Status []OrderStatus
}
type OrderStatus ¶
type OrderStatus string
const ( NotReported OrderStatus = "NotReported" //待提交 ReplacedNotReported OrderStatus = "ReplacedNotReported" //待提交 (改单成功) ProtectedNotReported OrderStatus = "ProtectedNotReported" //待提交 (保价订单) VarietiesNotReported OrderStatus = "VarietiesNotReported" //待提交 (条件单) FilledStatus OrderStatus = "FilledStatus" //已成交 WaitToNew OrderStatus = "WaitToNew" //已提待报 NewStatus OrderStatus = "NewStatus" //已委托 WaitToReplace OrderStatus = "WaitToReplace" //修改待报 PendingReplaceStatus OrderStatus = "PendingReplaceStatus" //待修改 ReplacedStatus OrderStatus = "ReplacedStatus" //已修改 PartialFilledStatus OrderStatus = "PartialFilledStatus" //部分成交 WaitToCancel OrderStatus = "WaitToCancel" //撤销待报 PendingCancelStatus OrderStatus = "PendingCancelStatus" //待撤回 RejectedStatus OrderStatus = "RejectedStatus" //已拒绝 CanceledStatus OrderStatus = "CanceledStatus" //已撤单 ExpiredStatus OrderStatus = "ExpiredStatus" //已过期 PartialWithdrawal OrderStatus = "PartialWithdrawal" //部分撤单 )
type OrderType ¶
type OrderType string
const ( LO OrderType = "LO" //限价单 ELO OrderType = "ELO" //增强限价单 MO OrderType = "MO" //市价单 AO OrderType = "AO" //竞价市价单 ALO OrderType = "ALO" //竞价限价单 ODD OrderType = "ODD" //碎股单挂单 LIT OrderType = "LIT" //触价限价单 MIT OrderType = "MIT" //触价市价单 TSLPAMT OrderType = "TSLPAMT" //跟踪止损限价单 (跟踪金额) TSLPPCT OrderType = "TSLPPCT" //跟踪止损限价单 (跟踪涨跌幅) TSMAMT OrderType = "TSMAMT" //跟踪止损市价单 (跟踪金额) TSMPCT OrderType = "TSMPCT" //跟踪止损市价单 (跟踪涨跌幅) SLO OrderType = "SLO" //特殊限价单,不支持改单 )
type QuoteConn ¶
type QuoteConn interface {
// 可自定义执行 quotev1.Command 命令
Rpc(cmd quotev1.Command, req proto.Message, rsp proto.Message) error
// 注册实时价格回调函数
OnPushQuote(func(*quotev1.PushQuote))
// 注册实时盘口回调函数
OnPushDepth(func(*quotev1.PushDepth))
// 注册实时经纪队列回调函数
OnPushBrokers(func(*quotev1.PushBrokers))
// 注册实时成交明细回调函数
OnPushTrade(func(*quotev1.PushTrade))
// 订阅行情数据, 建议注册回调函数后调用
Subscribe(req *quotev1.SubscribeRequest) (*quotev1.SubscriptionResponse, error)
//取消订阅行情数据
Unsubscribe(req *quotev1.UnsubscribeRequest) error
// 获取已订阅标的行情
ListSubscription() (*quotev1.SubscriptionResponse, error)
// 查询交易时间段
QueryMarketTradePeriod() (*quotev1.MarketTradePeriodResponse, error)
// 查询标的基础信息
QuerySymbolStaticInfo(symbols ...string) (*quotev1.SecurityStaticInfoResponse, error)
// 获取标的实时行情
QuerySymbolQuote(symbols ...string) (*quotev1.SecurityQuoteResponse, error)
}
行情长连接
type Stock ¶
type Stock struct {
Symbol string `json:"symbol"`
SymbolName string `json:"symbol_name"`
Currency Currency `json:"currency"`
Quantity decimal.Decimal `json:"quantity"`
Market Market `json:"market"`
AvailableQuantity decimal.Decimal `json:"available_quantity"`
CostPrice decimal.Decimal `json:"cost_price,omitempty"`
InitQuantity decimal.Decimal `json:"init_quantity"`
}
type SubmitOrder ¶
type SubmitOrder struct {
*BaseOrder
TimeInForce TimeType `json:"time_in_force,omitempty"` // required
ExpireDate string `json:"expire_date,omitempty"` // required when time_in_force is GTD
SubmittedQuantity decimal.Decimal `json:"submitted_quantity,omitempty"` // required
SubmittedPrice string `json:"submitted_price,omitempty"` // LO / ELO / ALO / ODD / LIT Order Required
}
订单提交信息
type TradeConn ¶
type TradeConn interface {
// 订阅
Subscribe(func(*OrderEvent)) error
// 取消订阅
Unsubscribe() error
}
交易长连接
type TriggerStatus ¶
type TriggerStatus string
const ( NOT_USED TriggerStatus = "NOT_USED" // 未激活 DEACTIVE TriggerStatus = "DEACTIVE" // 已失效 ACTIVE TriggerStatus = "ACTIVE" // 已激活 RELEASED TriggerStatus = "RELEASED" // 已触发 )
Click to show internal directories.
Click to hide internal directories.