Documentation ¶
Index ¶
- Constants
- Variables
- type ApiOption
- func ApiAccessKeyOption(accessKey string) ApiOption
- func ApiApiURLOption(apiURL string) ApiOption
- func ApiDebugModeOption(debugMode bool) ApiOption
- func ApiHttpClientOption(httpClient *http.Client) ApiOption
- func ApiPassPhraseOption(passPhrase string) ApiOption
- func ApiProxyURLOption(proxyURL string) ApiOption
- func ApiSecretKeyOption(secretKey string) ApiOption
- func ApiTestnetOption(testnet bool) ApiOption
- func ApiWebSocketOption(enabled bool) ApiOption
- func ApiWsURLOption(wsURL string) ApiOption
- type Balance
- type Direction
- type Event
- type Exchange
- type Item
- type LogItem
- type LogItems
- type LogStats
- type Market
- type Order
- type OrderBook
- type OrderOption
- type OrderParameter
- type OrderStatus
- type OrderType
- type Parameters
- type Position
- type Record
- type Stats
- type Strategy
- type StrategyBase
- func (s *StrategyBase) GetOptions() (optionMap map[string]*StrategyOption)
- func (s *StrategyBase) SetOptions(options map[string]interface{}) error
- func (s *StrategyBase) SetSelf(self Strategy) error
- func (s *StrategyBase) Setup(mode TradeMode, exchanges ...Exchange) error
- func (s *StrategyBase) TradeMode() TradeMode
- type StrategyOption
- type Trade
- type TradeMode
- type WSEvent
- type WebSocket
Constants ¶
View Source
const ( ContractTypeNone = "" // Non-delivery contract 非交割合约 ContractTypeW1 = "W1" // week 当周合约 ContractTypeW2 = "W2" // two week 次周合约 ContractTypeM1 = "M1" // month 月合约 ContractTypeQ1 = "Q1" // quarter 季度合约 ContractTypeQ2 = "Q2" // two quarter 次季度合约 )
ContractType 合约类型
View Source
const ( PERIOD_1MIN = "1m" PERIOD_3MIN = "3m" PERIOD_5MIN = "5m" PERIOD_15MIN = "15m" PERIOD_30MIN = "30m" PERIOD_60MIN = "60m" PERIOD_1H = "1h" PERIOD_2H = "2h" PERIOD_3H = "3h" PERIOD_4H = "4h" PERIOD_6H = "6h" PERIOD_8H = "8h" PERIOD_12H = "12h" PERIOD_1DAY = "1d" PERIOD_3DAY = "3d" PERIOD_1WEEK = "1w" PERIOD_1MONTH = "1M" PERIOD_1YEAR = "1y" )
K线周期
View Source
const (
// StrategyOptionTag 选项Tag
StrategyOptionTag = "opt"
)
Variables ¶
Functions ¶
This section is empty.
Types ¶
type ApiOption ¶ added in v1.1.1
type ApiOption func(p *Parameters)
func ApiAccessKeyOption ¶ added in v1.1.1
func ApiApiURLOption ¶ added in v1.1.4
func ApiDebugModeOption ¶ added in v1.1.1
func ApiHttpClientOption ¶ added in v1.1.1
func ApiPassPhraseOption ¶ added in v1.1.1
func ApiProxyURLOption ¶ added in v1.1.1
func ApiSecretKeyOption ¶ added in v1.1.1
func ApiTestnetOption ¶ added in v1.1.1
func ApiWebSocketOption ¶ added in v1.1.2
func ApiWsURLOption ¶ added in v1.1.4
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
type Exchange ¶ added in v1.1.2
type Exchange interface { // 获取 Exchange 名称 GetName() (name string) // 获取账号余额 GetBalance(currency string) (result Balance, err error) // 获取订单薄(OrderBook) GetOrderBook(symbol string, depth int) (result OrderBook, err error) // 获取K线数据 // period: 数据周期. 分钟或者关键字1m(minute) 1h 1d 1w 1M(month) 1y 枚举值:1 3 5 15 30 60 120 240 360 720 "5m" "4h" "1d" ... GetRecords(symbol string, period string, from int64, end int64, limit int) (records []Record, err error) // 设置合约类型 // currencyPair: 交易对,如: BTC-USD(OKEX) BTC(HBDM) // contractType: W1,W2,Q1,Q2 SetContractType(currencyPair string, contractType string) (err error) // 获取当前设置的合约ID GetContractID() (symbol string, err error) // 设置杠杆大小 SetLeverRate(value float64) (err error) // 开多 OpenLong(symbol string, orderType OrderType, price float64, size float64) (result Order, err error) // 开空 OpenShort(symbol string, orderType OrderType, price float64, size float64) (result Order, err error) // 平多 CloseLong(symbol string, orderType OrderType, price float64, size float64) (result Order, err error) // 平空 CloseShort(symbol string, orderType OrderType, price float64, size float64) (result Order, err error) // 下单 PlaceOrder(symbol string, direction Direction, orderType OrderType, price float64, size float64, opts ...OrderOption) (result Order, err error) // 获取活跃委托单列表 GetOpenOrders(symbol string) (result []Order, err error) // 获取委托信息 GetOrder(symbol string, id string) (result Order, err error) // 撤销全部委托单 CancelAllOrders(symbol string) (err error) // 撤销单个委托单 CancelOrder(symbol string, id string) (result Order, err error) // 修改委托 AmendOrder(symbol string, id string, price float64, size float64) (result Order, err error) // 获取持仓 GetPositions(symbol string) (result []Position, err error) // 订阅成交记录 SubscribeTrades(market Market, callback func(trades []Trade)) error // 订阅L2 OrderBook SubscribeLevel2Snapshots(market Market, callback func(ob *OrderBook)) error // 订阅委托 SubscribeOrders(market Market, callback func(orders []Order)) error // 订阅持仓 SubscribePositions(market Market, callback func(positions []Position)) error // 运行一次(回测系统调用) RunEventLoopOnce() (err error) // Run sim match for backtest only }
Exchange 交易所接口
type LogItem ¶
type LogItem struct { Time time.Time `json:"time"` RawTime time.Time `json:"raw_time"` Ask float64 `json:"ask"` Bid float64 `json:"bid"` Stats []LogStats `json:"stats"` }
func (*LogItem) TotalEquity ¶
type Market ¶ added in v0.9.9
type Market struct {
Symbol string // BTCUSDT(OKEX)/XBTUSD(BitMEX)/...
}
Market 市场信息
type Order ¶
type Order struct { ID string `json:"id"` // ID Symbol string `json:"symbol"` // 标 Price float64 `json:"price"` // 价格 StopPx float64 `json:"stop_px"` // 触发价 Size float64 `json:"size"` // 委托数量 AvgPrice float64 `json:"avg_price"` // 平均成交价 FilledAmount float64 `json:"filled_amount"` // 成交数量 Direction Direction `json:"direction"` // 委托方向 Type OrderType `json:"type"` // 委托类型 PostOnly bool `json:"post_only"` // 只做Maker选项 ReduceOnly bool `json:"reduce_only"` // 只减仓选项 Status OrderStatus `json:"status"` // 委托状态 }
Order 委托
type OrderOption ¶ added in v1.1.3
type OrderOption func(p *OrderParameter)
订单选项
func OrderPostOnlyOption ¶ added in v1.1.3
func OrderPostOnlyOption(postOnly bool) OrderOption
被动委托选项
func OrderPriceTypeOption ¶ added in v1.1.3
func OrderPriceTypeOption(priceType string) OrderOption
OrderPriceType 选项
func OrderReduceOnlyOption ¶ added in v1.1.3
func OrderReduceOnlyOption(reduceOnly bool) OrderOption
只减仓选项
type OrderParameter ¶ added in v1.1.3
func ParseOrderParameter ¶ added in v1.1.3
func ParseOrderParameter(opts ...OrderOption) *OrderParameter
type OrderStatus ¶
type OrderStatus int
OrderStatus 委托状态
const ( OrderStatusCreated OrderStatus = iota // 创建委托 OrderStatusRejected // 委托被拒绝 OrderStatusNew // 委托待成交 OrderStatusPartiallyFilled // 委托部分成交 OrderStatusFilled // 委托完全成交 OrderStatusCancelPending // 委托取消 OrderStatusCancelled // 委托被取消 OrderStatusUntriggered // 等待触发条件委托单 OrderStatusTriggered // 已触发条件单 )
func (OrderStatus) String ¶
func (s OrderStatus) String() string
type Parameters ¶ added in v1.1.1
type Position ¶
type Position struct { Symbol string `json:"symbol"` // 标 OpenTime time.Time `json:"open_time"` // 开仓时间 OpenPrice float64 `json:"open_price"` // 开仓价 Size float64 `json:"size"` // 仓位大小 AvgPrice float64 `json:"avg_price"` // 平均价 }
Position 持仓
type Record ¶ added in v0.9.8
type Record struct { Symbol string `json:"symbol"` // 标 Timestamp time.Time `json:"timestamp"` // 时间 Open float64 `json:"open"` // 开盘价 High float64 `json:"high"` // 最高价 Low float64 `json:"low"` // 最低价 Close float64 `json:"close"` // 收盘价 Volume float64 `json:"volume"` // 量 }
Record 表示K线数据
type Stats ¶
type Stats struct { Start time.Time `json:"start"` End time.Time `json:"end"` Duration time.Duration `json:"duration"` EntryPrice float64 `json:"entry_price"` ExitPrice float64 `json:"exit_price"` EntryEquity float64 `json:"entry_equity"` ExitEquity float64 `json:"exit_equity"` BaHReturn float64 `json:"bah_return"` // Buy & Hold Return BaHReturnPnt float64 `json:"bah_return_pnt"` // Buy & Hold Return EquityReturn float64 `json:"equity_return"` EquityReturnPnt float64 `json:"equity_return_pnt"` }
Stats Backtesting Statistics
func (*Stats) PrintResult ¶
func (s *Stats) PrintResult()
type Strategy ¶
type Strategy interface { SetSelf(self Strategy) error Setup(mode TradeMode, exchanges ...Exchange) error TradeMode() TradeMode SetOptions(options map[string]interface{}) error Run() error OnInit() error OnTick() error OnDeinit() error }
Strategy interface
type StrategyBase ¶
type StrategyBase struct { Exchanges []Exchange Exchange Exchange // contains filtered or unexported fields }
StrategyBase Strategy base class
func (*StrategyBase) GetOptions ¶ added in v1.1.4
func (s *StrategyBase) GetOptions() (optionMap map[string]*StrategyOption)
GetOptions Returns the options of strategy
func (*StrategyBase) SetOptions ¶ added in v1.1.4
func (s *StrategyBase) SetOptions(options map[string]interface{}) error
SetOptions Sets the options for the strategy
func (*StrategyBase) SetSelf ¶ added in v1.1.4
func (s *StrategyBase) SetSelf(self Strategy) error
SetSelf 设置 self 对象
func (*StrategyBase) Setup ¶
func (s *StrategyBase) Setup(mode TradeMode, exchanges ...Exchange) error
Setup Setups the exchanges
func (*StrategyBase) TradeMode ¶ added in v1.1.4
func (s *StrategyBase) TradeMode() TradeMode
type StrategyOption ¶ added in v1.1.4
type StrategyOption struct { Name string `json:"name"` Description string `json:"description"` Type string `json:"type"` Value interface{} `json:"value"` DefaultValue interface{} `json:"default_value"` }
StrategyOption 策略参数
type Trade ¶ added in v0.9.10
type Trade struct { ID string `json:"id"` // ID Direction Direction `json:"type"` // 主动成交方向 Price float64 `json:"price"` // 价格 Amount float64 `json:"amount"` // 成交量(张),买卖双边成交量之和 Ts int64 `json:"ts"` // 订单成交时间 unix time (ms) Symbol string `json:"omitempty"` }
Trade 成交记录
type WebSocket ¶ added in v0.9.9
type WebSocket interface { SubscribeTrades(market Market, callback func(trades []Trade)) error SubscribeLevel2Snapshots(market Market, callback func(ob *OrderBook)) error //SubscribeBalances(market Market, callback func(balance *Balance)) error SubscribeOrders(market Market, callback func(orders []Order)) error SubscribePositions(market Market, callback func(positions []Position)) error }
WebSocket 代表WS连接
Source Files ¶
Click to show internal directories.
Click to hide internal directories.