Documentation ¶
Index ¶
- Constants
- Variables
- func AddTriggerOd(account string, od *InOutOrder)
- func DumpOrdersGob(path string) *errs.Error
- func GetOpenODs(account string) (map[int64]*InOutOrder, *sync.Mutex)
- func GetTaskAcc(id int64) string
- func GetTaskID(account string) int64
- func GetTriggerODs(account string) (map[string]map[int64]*InOutOrder, *sync.Mutex)
- func InitTask(showLog bool, outDir string) *errs.Error
- func LegalDoneProfits(off int) float64
- func OpenNum(account string, status int64) int
- func ResetVars()
- func SaveDirtyODs(path string, account string) *errs.Error
- type AddExOrderParams
- type AddIOrderParams
- type AddTaskParams
- type BotTask
- type DBTX
- type ExOrder
- type ExitTrigger
- type FindTaskParams
- type GetOrdersArgs
- type GetTaskPairsParams
- type IOrder
- type InOutEdit
- type InOutOrder
- func (i *InOutOrder) CalcProfit(price float64) float64
- func (i *InOutOrder) CanClose() bool
- func (i *InOutOrder) ClientId(random bool) string
- func (i *InOutOrder) CutPart(enterAmt, exitAmt float64) *InOutOrder
- func (i *InOutOrder) EnterCost() float64
- func (i *InOutOrder) ForceExit(tag string, msg string)
- func (i *InOutOrder) GetExitTrigger(key string) *TriggerState
- func (i *InOutOrder) GetInfoFloat64(key string) float64
- func (i *InOutOrder) GetInfoInt64(key string) int64
- func (i *InOutOrder) GetInfoString(key string) string
- func (i *InOutOrder) GetInfoText() (string, *errs.Error)
- func (i *InOutOrder) GetStopLoss() *TriggerState
- func (i *InOutOrder) GetTakeProfit() *TriggerState
- func (i *InOutOrder) HoldAmount() float64
- func (i *InOutOrder) HoldCost() float64
- func (i *InOutOrder) IsDirty() bool
- func (i *InOutOrder) Key() string
- func (i *InOutOrder) LocalExit(tag string, price float64, msg, odType string) *errs.Error
- func (i *InOutOrder) Lock() *sync.Mutex
- func (i *InOutOrder) NanInfTo(v float64)
- func (i *InOutOrder) Save(sess *Queries) *errs.Error
- func (i *InOutOrder) SetEnterLimit(price float64) *errs.Error
- func (i *InOutOrder) SetExit(tag, orderType string, limit float64)
- func (i *InOutOrder) SetExitTrigger(key string, args *ExitTrigger)
- func (i *InOutOrder) SetInfo(key string, val interface{})
- func (i *InOutOrder) SetStopLoss(args *ExitTrigger)
- func (i *InOutOrder) SetTakeProfit(args *ExitTrigger)
- func (i *InOutOrder) TakeSnap() *InOutSnap
- func (i *InOutOrder) UpdateFee(price float64, forEnter bool, isHistory bool) *errs.Error
- func (i *InOutOrder) UpdateProfits(price float64)
- type InOutSnap
- type ListTaskPairsParams
- type Querier
- type Queries
- func (q *Queries) AddExOrder(ctx context.Context, arg AddExOrderParams) (int64, error)
- func (q *Queries) AddIOrder(ctx context.Context, arg AddIOrderParams) (int64, error)
- func (q *Queries) AddTask(ctx context.Context, arg AddTaskParams) (*BotTask, error)
- func (q *Queries) DelOrder(od *InOutOrder) *errs.Error
- func (q *Queries) FindTask(ctx context.Context, arg FindTaskParams) (*BotTask, error)
- func (q *Queries) GetAccTask(account string) (*BotTask, *errs.Error)
- func (q *Queries) GetExOrders(ctx context.Context, inoutID int64) ([]*ExOrder, error)
- func (q *Queries) GetHistOrderTfs(taskId int64, stagy string) (map[string]string, *errs.Error)
- func (q *Queries) GetIOrder(ctx context.Context, id int64) (*IOrder, error)
- func (q *Queries) GetOrders(args GetOrdersArgs) ([]*InOutOrder, *errs.Error)
- func (q *Queries) GetTask(ctx context.Context, id int64) (*BotTask, error)
- func (q *Queries) GetTaskPairs(ctx context.Context, arg GetTaskPairsParams) ([]string, error)
- func (q *Queries) ListTaskPairs(ctx context.Context, arg ListTaskPairsParams) ([]string, error)
- func (q *Queries) ListTasks(ctx context.Context) ([]*BotTask, error)
- func (q *Queries) SetExOrder(ctx context.Context, arg SetExOrderParams) error
- func (q *Queries) SetIOrder(ctx context.Context, arg SetIOrderParams) error
- func (q *Queries) WithTx(tx *sql.Tx) *Queries
- type SetExOrderParams
- type SetIOrderParams
- type TriggerState
Constants ¶
const ( InOutStatusInit = iota InOutStatusPartEnter InOutStatusFullEnter InOutStatusPartExit InOutStatusFullExit InOutStatusDelete )
const ( OdStatusInit = iota OdStatusPartOK OdStatusClosed )
const ( OdInfoLegalCost = "LegalCost" OdInfoStopAfter = "StopAfter" OdInfoStopLoss = "StopLoss" OdInfoTakeProfit = "TakeProfit" )
const ( OdActionEnter = "Enter" OdActionExit = "Exit" OdActionLimitEnter = "LimitEnter" OdActionLimitExit = "LimitExit" OdActionStopLoss = "StopLoss" OdActionTakeProfit = "TakeProfit" )
const (
KeyStatusMsg = "status_msg"
)
Variables ¶
var ( HistODs []*InOutOrder // Historical orders, used as storage for backtesting. 历史订单,回测时作为存储用 FakeOdId = int64(1) // Virtual order ID, used for temporary maintenance during backtesting. 虚拟订单ID,用于回测时临时维护 )
Functions ¶
func AddTriggerOd ¶
func AddTriggerOd(account string, od *InOutOrder)
func DumpOrdersGob ¶
func GetOpenODs ¶
func GetOpenODs(account string) (map[int64]*InOutOrder, *sync.Mutex)
func GetTaskAcc ¶
func GetTriggerODs ¶
func LegalDoneProfits ¶
LegalDoneProfits Calculate the fiat value of realized profits 计算已实现利润的法币价值
Types ¶
type AddExOrderParams ¶
type AddExOrderParams struct { TaskID int64 `json:"task_id"` InoutID int64 `json:"inout_id"` Symbol string `json:"symbol"` Enter bool `json:"enter"` OrderType string `json:"order_type"` OrderID string `json:"order_id"` Side string `json:"side"` CreateAt int64 `json:"create_at"` Price float64 `json:"price"` Average float64 `json:"average"` Amount float64 `json:"amount"` Filled float64 `json:"filled"` Status int64 `json:"status"` Fee float64 `json:"fee"` FeeType string `json:"fee_type"` UpdateAt int64 `json:"update_at"` }
type AddIOrderParams ¶
type AddIOrderParams struct { TaskID int64 `json:"task_id"` Symbol string `json:"symbol"` Sid int64 `json:"sid"` Timeframe string `json:"timeframe"` Short bool `json:"short"` Status int64 `json:"status"` EnterTag string `json:"enter_tag"` InitPrice float64 `json:"init_price"` QuoteCost float64 `json:"quote_cost"` ExitTag string `json:"exit_tag"` Leverage float64 `json:"leverage"` EnterAt int64 `json:"enter_at"` ExitAt int64 `json:"exit_at"` Strategy string `json:"strategy"` StgVer int64 `json:"stg_ver"` MaxPftRate float64 `json:"max_pft_rate"` MaxDrawDown float64 `json:"max_draw_down"` ProfitRate float64 `json:"profit_rate"` Profit float64 `json:"profit"` Info string `json:"info"` }
type AddTaskParams ¶
type BotTask ¶
type ExOrder ¶
type ExOrder struct { ID int64 `json:"id"` TaskID int64 `json:"task_id"` InoutID int64 `json:"inout_id"` Symbol string `json:"symbol"` Enter bool `json:"enter"` OrderType string `json:"order_type"` OrderID string `json:"order_id"` Side string `json:"side"` CreateAt int64 `json:"create_at"` Price float64 `json:"price"` Average float64 `json:"average"` Amount float64 `json:"amount"` Filled float64 `json:"filled"` Status int64 `json:"status"` Fee float64 `json:"fee"` FeeType string `json:"fee_type"` UpdateAt int64 `json:"update_at"` }
type ExitTrigger ¶
type ExitTrigger struct { Price float64 `json:"price"` // Trigger Price 触发价格 Limit float64 `json:"limit"` // Submit limit order price after triggering, otherwise market order. 触发后提交限价单价格,否则市价单 Rate float64 `json:"rate"` // Stop-profit and stop-loss ratio, (0,1], 0 means all. 止盈止损比例,(0,1],0表示全部 Tag string `json:"tag"` // Reason, used for ExitTag. 原因,用于ExitTag }
func (*ExitTrigger) Clone ¶
func (t *ExitTrigger) Clone() *ExitTrigger
func (*ExitTrigger) Equal ¶
func (t *ExitTrigger) Equal(o *ExitTrigger) bool
type FindTaskParams ¶
type GetOrdersArgs ¶
type GetOrdersArgs struct { Strategy string Pairs []string TimeFrame string Status int // 0 represents all, 1 represents open interest, 2 represents historical orders 0表示所有,1表示未平仓,2表示历史订单 TaskID int64 // 0 represents all,>0 represents specified task 0表示所有,>0表示指定任务 EnterTag string ExitTag string CloseAfter int64 // Start timestamp 开始时间戳 CloseBefore int64 // End timestamp 结束时间戳 Limit int AfterID int OrderBy string }
type GetTaskPairsParams ¶
type IOrder ¶
type IOrder struct { ID int64 `json:"id"` TaskID int64 `json:"task_id"` Symbol string `json:"symbol"` Sid int64 `json:"sid"` Timeframe string `json:"timeframe"` Short bool `json:"short"` Status int64 `json:"status"` EnterTag string `json:"enter_tag"` InitPrice float64 `json:"init_price"` QuoteCost float64 `json:"quote_cost"` ExitTag string `json:"exit_tag"` Leverage float64 `json:"leverage"` EnterAt int64 `json:"enter_at"` ExitAt int64 `json:"exit_at"` Strategy string `json:"strategy"` StgVer int64 `json:"stg_ver"` MaxPftRate float64 `json:"max_pft_rate"` MaxDrawDown float64 `json:"max_draw_down"` ProfitRate float64 `json:"profit_rate"` Profit float64 `json:"profit"` Info string `json:"info"` }
type InOutEdit ¶
type InOutEdit struct { Order *InOutOrder Action string }
type InOutOrder ¶
type InOutOrder struct { *IOrder Enter *ExOrder `json:"enter"` Exit *ExOrder `json:"exit"` Info map[string]interface{} `json:"info"` DirtyMain bool `json:"-"` // IOrder has unsaved temporary changes 有未保存的临时修改 DirtyEnter bool `json:"-"` // Enter has unsaved temporary changes 有未保存的临时修改 DirtyExit bool `json:"-"` // Exit has unsaved temporary changes 有未保存的临时修改 DirtyInfo bool `json:"-"` // Info has unsaved temporary changes 有未保存的临时修改 // contains filtered or unexported fields }
func LoadOrdersGob ¶
func LoadOrdersGob(path string) ([]*InOutOrder, *errs.Error)
func (*InOutOrder) CalcProfit ¶
func (i *InOutOrder) CalcProfit(price float64) float64
CalcProfit Return profit (before deducting commission) 返回利润(未扣除手续费)
func (*InOutOrder) CanClose ¶
func (i *InOutOrder) CanClose() bool
func (*InOutOrder) ClientId ¶
func (i *InOutOrder) ClientId(random bool) string
ClientId Generate the exchange's ClientOrderId 生成交易所的ClientOrderId
func (*InOutOrder) CutPart ¶
func (i *InOutOrder) CutPart(enterAmt, exitAmt float64) *InOutOrder
CutPart Split a small InOutOrder from the current order to solve the problem of one buy and multiple sell 从当前订单分割出一个小的InOutOrder,解决一次买入,多次卖出问题
func (*InOutOrder) EnterCost ¶
func (i *InOutOrder) EnterCost() float64
func (*InOutOrder) ForceExit ¶
func (i *InOutOrder) ForceExit(tag string, msg string)
ForceExit Force exit order, if already purchased, exit at market price. If the purchase is not executed, cancel the pending order. If it has not been submitted, delete the order directly
Generation mode: Submit a request to the exchange. Simulation mode: Exit after the next bar appears
强制退出订单,如已买入,则以市价单退出。如买入未成交,则取消挂单,如尚未提交,则直接删除订单
生成模式:提交请求到交易所。 模拟模式:在下一个bar出现后完成退出
func (*InOutOrder) GetExitTrigger ¶
func (i *InOutOrder) GetExitTrigger(key string) *TriggerState
func (*InOutOrder) GetInfoFloat64 ¶
func (i *InOutOrder) GetInfoFloat64(key string) float64
func (*InOutOrder) GetInfoInt64 ¶
func (i *InOutOrder) GetInfoInt64(key string) int64
func (*InOutOrder) GetInfoString ¶
func (i *InOutOrder) GetInfoString(key string) string
func (*InOutOrder) GetInfoText ¶
func (i *InOutOrder) GetInfoText() (string, *errs.Error)
func (*InOutOrder) GetStopLoss ¶
func (i *InOutOrder) GetStopLoss() *TriggerState
func (*InOutOrder) GetTakeProfit ¶
func (i *InOutOrder) GetTakeProfit() *TriggerState
func (*InOutOrder) HoldAmount ¶
func (i *InOutOrder) HoldAmount() float64
func (*InOutOrder) HoldCost ¶
func (i *InOutOrder) HoldCost() float64
func (*InOutOrder) IsDirty ¶
func (i *InOutOrder) IsDirty() bool
func (*InOutOrder) Key ¶
func (i *InOutOrder) Key() string
func (*InOutOrder) LocalExit ¶
LocalExit Forcefully exiting the order locally takes effect immediately, without waiting for the next bar. This does not involve wallet updates, the wallet needs to be updated on its own. When calling this function on a real drive, it will be saved to the database 在本地强制退出订单,立刻生效,无需等到下一个bar。这里不涉及钱包更新,钱包需要自行更新。 实盘时调用此函数会保存到数据库
func (*InOutOrder) Lock ¶
func (i *InOutOrder) Lock() *sync.Mutex
Return to modify the lock of the current order. A successful return indicates that the lock has been obtained 返回修改当前订单的锁,返回成功表示已获取锁
func (*InOutOrder) NanInfTo ¶
func (i *InOutOrder) NanInfTo(v float64)
func (*InOutOrder) SetEnterLimit ¶
func (i *InOutOrder) SetEnterLimit(price float64) *errs.Error
func (*InOutOrder) SetExit ¶
func (i *InOutOrder) SetExit(tag, orderType string, limit float64)
func (*InOutOrder) SetExitTrigger ¶
func (i *InOutOrder) SetExitTrigger(key string, args *ExitTrigger)
func (*InOutOrder) SetInfo ¶
func (i *InOutOrder) SetInfo(key string, val interface{})
func (*InOutOrder) SetStopLoss ¶
func (i *InOutOrder) SetStopLoss(args *ExitTrigger)
func (*InOutOrder) SetTakeProfit ¶
func (i *InOutOrder) SetTakeProfit(args *ExitTrigger)
func (*InOutOrder) TakeSnap ¶
func (i *InOutOrder) TakeSnap() *InOutSnap
func (*InOutOrder) UpdateFee ¶
UpdateFee Calculates commission for entry/exit orders. Must be called after Filled is assigned a value, otherwise the calculation is empty 为入场/出场订单计算手续费,必须在Filled赋值后调用,否则计算为空
func (*InOutOrder) UpdateProfits ¶
func (i *InOutOrder) UpdateProfits(price float64)
type ListTaskPairsParams ¶
type Querier ¶
type Querier interface { AddExOrder(ctx context.Context, arg AddExOrderParams) (int64, error) AddIOrder(ctx context.Context, arg AddIOrderParams) (int64, error) AddTask(ctx context.Context, arg AddTaskParams) (*BotTask, error) FindTask(ctx context.Context, arg FindTaskParams) (*BotTask, error) GetExOrders(ctx context.Context, inoutID int64) ([]*ExOrder, error) GetIOrder(ctx context.Context, id int64) (*IOrder, error) GetTask(ctx context.Context, id int64) (*BotTask, error) GetTaskPairs(ctx context.Context, arg GetTaskPairsParams) ([]string, error) ListTaskPairs(ctx context.Context, arg ListTaskPairsParams) ([]string, error) ListTasks(ctx context.Context) ([]*BotTask, error) SetExOrder(ctx context.Context, arg SetExOrderParams) error SetIOrder(ctx context.Context, arg SetIOrderParams) error }
type Queries ¶
type Queries struct {
// contains filtered or unexported fields
}
func (*Queries) AddExOrder ¶
func (*Queries) GetExOrders ¶
func (*Queries) GetHistOrderTfs ¶
GetHistOrderTfs Retrieve the specified task and the latest usage time period of the specified policy 获取指定任务,指定策略的最新使用的时间周期
func (*Queries) GetOrders ¶
func (q *Queries) GetOrders(args GetOrdersArgs) ([]*InOutOrder, *errs.Error)
func (*Queries) GetTaskPairs ¶
func (*Queries) ListTaskPairs ¶
func (*Queries) SetExOrder ¶
func (q *Queries) SetExOrder(ctx context.Context, arg SetExOrderParams) error
type SetExOrderParams ¶
type SetExOrderParams struct { TaskID int64 `json:"task_id"` InoutID int64 `json:"inout_id"` Symbol string `json:"symbol"` Enter bool `json:"enter"` OrderType string `json:"order_type"` OrderID string `json:"order_id"` Side string `json:"side"` CreateAt int64 `json:"create_at"` Price float64 `json:"price"` Average float64 `json:"average"` Amount float64 `json:"amount"` Filled float64 `json:"filled"` Status int64 `json:"status"` Fee float64 `json:"fee"` FeeType string `json:"fee_type"` UpdateAt int64 `json:"update_at"` ID int64 `json:"id"` }
type SetIOrderParams ¶
type SetIOrderParams struct { TaskID int64 `json:"task_id"` Symbol string `json:"symbol"` Sid int64 `json:"sid"` Timeframe string `json:"timeframe"` Short bool `json:"short"` Status int64 `json:"status"` EnterTag string `json:"enter_tag"` InitPrice float64 `json:"init_price"` QuoteCost float64 `json:"quote_cost"` ExitTag string `json:"exit_tag"` Leverage float64 `json:"leverage"` EnterAt int64 `json:"enter_at"` ExitAt int64 `json:"exit_at"` Strategy string `json:"strategy"` StgVer int64 `json:"stg_ver"` MaxPftRate float64 `json:"max_pft_rate"` MaxDrawDown float64 `json:"max_draw_down"` ProfitRate float64 `json:"profit_rate"` Profit float64 `json:"profit"` Info string `json:"info"` ID int64 `json:"id"` }
type TriggerState ¶
type TriggerState struct { *ExitTrigger Range float64 `json:"range"` // The stop-profit and stop-loss range is the range from the entry price to the exit price. 止盈止损区间,入场价格到离场价格的区间 Hit bool `json:"hit"` // whether trigger price has been triggered? 是否已触发 OrderId string `json:"order_id"` Old *ExitTrigger }
func (*TriggerState) Clone ¶
func (s *TriggerState) Clone() *TriggerState
func (*TriggerState) SaveOld ¶
func (s *TriggerState) SaveOld()