orm

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2024 License: AGPL-3.0 Imports: 28 Imported by: 2

README

sqlc

数据库相关的访问代码全部使用sqlc从sql文件生成go代码。
kline1m等不需要sqlc生成的,全部写到schema2.sql中。
sqlc不支持windows直接使用,需要启动Docker Desktop,然后在命令行执行下面命令:

docker run --rm -v "E:/trade/go/banbot/orm:/src" -w /src sqlc/sqlc generate

Documentation

Index

Constants

View Source
const (
	InOutStatusInit = iota
	InOutStatusPartEnter
	InOutStatusFullEnter
	InOutStatusPartExit
	InOutStatusFullExit
	InOutStatusDelete
)
View Source
const (
	OdStatusInit = iota
	OdStatusPartOK
	OdStatusClosed
)
View Source
const (
	OdInfoLegalCost = "LegalCost"
	OdInfoStopAfter = "StopAfter"
)
View Source
const (
	OdActionEnter      = "Enter"
	OdActionExit       = "Exit"
	OdActionLimitEnter = "LimitEnter"
	OdActionLimitExit  = "LimitExit"
	OdActionStopLoss   = "StopLoss"
	OdActionTakeProfit = "TakeProfit"
)
View Source
const (
	KeyStatusMsg = "status_msg"
)

Variables

View Source
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 ApplyAdj

func ApplyAdj(adjs []*AdjInfo, klines []*banexg.Kline, adj int, cutEnd int64, limit int) []*banexg.Kline

ApplyAdj Calculate the K-line after adjustment 计算复权后K线 adjs Must be in ascending order 必须已升序 cutEnd Maximum end time of interception 截取的最大结束时间 adj Type of adjustment of Rights 复权类型 limit 返回数量

func BulkDownOHLCV

func BulkDownOHLCV(exchange banexg.BanExchange, exsList map[int32]*ExSymbol, timeFrame string, startMS, endMS int64, limit int) *errs.Error

BulkDownOHLCV Batch simultaneous download of K-line 批量同时下载K线

func CalcAdjFactors

func CalcAdjFactors(args *config.CmdArgs) *errs.Error

CalcAdjFactors Calculate and update all weighting factors 计算更新所有复权因子

func DownOHLCV2DB

func DownOHLCV2DB(exchange banexg.BanExchange, exs *ExSymbol, timeFrame string, startMS, endMS int64,
	pBar *utils.PrgBar) (int, *errs.Error)

func EnsureCurSymbols

func EnsureCurSymbols(symbols []string) *errs.Error

func EnsureExgSymbols

func EnsureExgSymbols(exchange banexg.BanExchange) *errs.Error

func EnsureSymbols

func EnsureSymbols(symbols []*ExSymbol, exchanges ...string) *errs.Error

func FastBulkOHLCV

func FastBulkOHLCV(exchange banexg.BanExchange, symbols []string, timeFrame string,
	startMS, endMS int64, limit int, handler func(string, string, []*banexg.Kline, []*AdjInfo)) *errs.Error

FastBulkOHLCV Quickly obtain K-lines in bulk. Download all the required currencies first, then perform batch queries and group returns. Suitable for situations where there are multiple currencies, the required start and end times are consistent, and most of them have already been downloaded. For combination varieties, return the unweighted candlestick and the weighting factor, and call ApplyAdj for weighting as needed 快速批量获取K线。先下载所有需要的币种,然后批量查询再分组返回。

适用于币种较多,且需要的开始结束时间一致,且大部分已下载的情况。
对于组合品种,返回未复权的K线,和复权因子,自行根据需要调用ApplyAdj复权

func FetchApiOHLCV

func FetchApiOHLCV(ctx context.Context, exchange banexg.BanExchange, pair, timeFrame string, startMS, endMS int64, out chan []*banexg.Kline) *errs.Error

FetchApiOHLCV Download the K-line data of the trading pair according to the given time period. If you need to download from the end to the beginning, you should make startMS>endMS 按给定时间段下载交易对的K线数据。 如果需要从后往前下载,应该使startMS>endMS

func GetAlignOff

func GetAlignOff(sid int32, toTfMSecs int64) int64

func GetDownTF

func GetDownTF(timeFrame string) (string, *errs.Error)

GetDownTF Retrieve the download time period corresponding to the specified period. Only 1m and 1h allow downloading and writing to the super table. All other dimensions are aggregated from these two dimensions.

获取指定周期对应的下载的时间周期。
只有1m和1h允许下载并写入超表。其他维度都是由这两个维度聚合得到。

func GetExSymbols

func GetExSymbols(exgName, market string) map[int32]*ExSymbol

func GetOpenODs

func GetOpenODs(account string) (map[int64]*InOutOrder, *sync.Mutex)

func GetTaskAcc

func GetTaskAcc(id int64) string

func GetTaskID

func GetTaskID(account string) int64

func GetTriggerODs

func GetTriggerODs(account string) (map[string]map[int64]*InOutOrder, *sync.Mutex)

func InitExg

func InitExg(exchange banexg.BanExchange) *errs.Error

func InitListDates

func InitListDates() *errs.Error

func InitTask

func InitTask() *errs.Error

func LoadAllExSymbols

func LoadAllExSymbols() *errs.Error

func LoadMarkets

func LoadMarkets(exchange banexg.BanExchange, reload bool) (banexg.MarketMap, *errs.Error)

func MapExSymbols

func MapExSymbols(exchange banexg.BanExchange, symbols []string) (map[int32]*ExSymbol, *errs.Error)

func NewDbErr

func NewDbErr(code int, err_ error) *errs.Error

func OpenNum

func OpenNum(account string, status int16) int

OpenNum Returns the number of open orders that match the specified status 返回符合指定状态的尚未平仓订单的数量

func ResetVars

func ResetVars()

func SaveDirtyODs

func SaveDirtyODs(account string) *errs.Error

SaveDirtyODs Find unsaved orders from open orders and save them all to the database 从打开的订单中查找未保存的订单,全部保存到数据库

func Setup

func Setup() *errs.Error

func SyncKlineTFs

func SyncKlineTFs() *errs.Error

SyncKlineTFs Check the data consistency of each kline table. If there is more low dimensional data than high dimensional data, aggregate and update to high dimensional data 检查各kline表的数据一致性,如果低维度数据比高维度多,则聚合更新到高维度

Types

type AddAdjFactorsParams

type AddAdjFactorsParams struct {
	Sid     int32   `json:"sid"`
	SubID   int32   `json:"sub_id"`
	StartMs int64   `json:"start_ms"`
	Factor  float64 `json:"factor"`
}

type AddCalendarsParams

type AddCalendarsParams struct {
	Name    string `json:"name"`
	StartMs int64  `json:"start_ms"`
	StopMs  int64  `json:"stop_ms"`
}

type AddExOrderParams

type AddExOrderParams struct {
	TaskID    int32   `json:"task_id"`
	InoutID   int32   `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    int16   `json:"status"`
	Fee       float64 `json:"fee"`
	FeeType   string  `json:"fee_type"`
	UpdateAt  int64   `json:"update_at"`
}

type AddIOrderParams

type AddIOrderParams struct {
	TaskID      int32   `json:"task_id"`
	Symbol      string  `json:"symbol"`
	Sid         int32   `json:"sid"`
	Timeframe   string  `json:"timeframe"`
	Short       bool    `json:"short"`
	Status      int16   `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      int32   `json:"stg_ver"`
	MaxDrawDown float64 `json:"max_draw_down"`
	ProfitRate  float64 `json:"profit_rate"`
	Profit      float64 `json:"profit"`
	Info        string  `json:"info"`
}

type AddKHolesParams

type AddKHolesParams struct {
	Sid       int32  `json:"sid"`
	Timeframe string `json:"timeframe"`
	Start     int64  `json:"start"`
	Stop      int64  `json:"stop"`
}

type AddKInfoParams

type AddKInfoParams struct {
	Sid       int32  `json:"sid"`
	Timeframe string `json:"timeframe"`
	Start     int64  `json:"start"`
	Stop      int64  `json:"stop"`
}

type AddSymbolsParams

type AddSymbolsParams struct {
	Exchange string `json:"exchange"`
	ExgReal  string `json:"exg_real"`
	Market   string `json:"market"`
	Symbol   string `json:"symbol"`
}

type AddTaskParams

type AddTaskParams struct {
	Mode     string `json:"mode"`
	Name     string `json:"name"`
	CreateAt int64  `json:"create_at"`
	StartAt  int64  `json:"start_at"`
	StopAt   int64  `json:"stop_at"`
	Info     string `json:"info"`
}

type AdjFactor

type AdjFactor struct {
	ID      int32   `json:"id"`
	Sid     int32   `json:"sid"`
	SubID   int32   `json:"sub_id"`
	StartMs int64   `json:"start_ms"`
	Factor  float64 `json:"factor"`
}

type AdjInfo

type AdjInfo struct {
	*ExSymbol
	Factor    float64 // Original adjacent weighting factor 原始相邻复权因子
	CumFactor float64 // Cumulative weighting factor 累计复权因子
	StartMS   int64   // start timestamp 开始时间
	StopMS    int64   // stop timestamp 结束时间
}

func AutoFetchOHLCV

func AutoFetchOHLCV(exchange banexg.BanExchange, exs *ExSymbol, timeFrame string, startMS, endMS int64,
	limit int, withUnFinish bool, pBar *utils.PrgBar) ([]*AdjInfo, []*banexg.Kline, *errs.Error)

AutoFetchOHLCV

Get K-line data for a given trading pair, a given time dimension, and a given range.
Try to read from local first, download from the exchange if it doesn't exist, and then return.
获取给定交易对,给定时间维度,给定范围的K线数据。
先尝试从本地读取,不存在时从交易所下载,然后返回。

func GetOHLCV

func GetOHLCV(exs *ExSymbol, timeFrame string, startMS, endMS int64, limit int, withUnFinish bool) ([]*AdjInfo, []*banexg.Kline, *errs.Error)

GetOHLCV Get the variety K-line, if you need to rebalance, it will be automatically reweighted 获取品种K线,如需复权自动前复权

func (*AdjInfo) Apply

func (a *AdjInfo) Apply(bars []*banexg.Kline, adj int) []*banexg.Kline

type BotTask

type BotTask struct {
	ID       int64  `json:"id"`
	Mode     string `json:"mode"`
	Name     string `json:"name"`
	CreateAt int64  `json:"create_at"`
	StartAt  int64  `json:"start_at"`
	StopAt   int64  `json:"stop_at"`
	Info     string `json:"info"`
}

func GetTask

func GetTask(account string) *BotTask

type Calendar

type Calendar struct {
	ID      int32  `json:"id"`
	Name    string `json:"name"`
	StartMs int64  `json:"start_ms"`
	StopMs  int64  `json:"stop_ms"`
}

type DBTX

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
	CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
}

type DelKHoleRangeParams

type DelKHoleRangeParams struct {
	Sid       int32  `json:"sid"`
	Timeframe string `json:"timeframe"`
	Start     int64  `json:"start"`
	Stop      int64  `json:"stop"`
}

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    int16   `json:"status"`
	Fee       float64 `json:"fee"`
	FeeType   string  `json:"fee_type"`
	UpdateAt  int64   `json:"update_at"`
}

func (*ExOrder) CutPart

func (i *ExOrder) CutPart(rate float64, fill bool) *ExOrder

type ExSymbol

type ExSymbol struct {
	ID       int32  `json:"id"`
	Exchange string `json:"exchange"`
	ExgReal  string `json:"exg_real"`
	Market   string `json:"market"`
	Symbol   string `json:"symbol"`
	Combined bool   `json:"combined"`
	ListMs   int64  `json:"list_ms"`
	DelistMs int64  `json:"delist_ms"`
}

func GetAllExSymbols

func GetAllExSymbols() []*ExSymbol

GetAllExSymbols Gets all the objects that have been loaded into the cache 获取已加载到缓存的所有标的

func GetExSymbol

func GetExSymbol(exchange banexg.BanExchange, symbol string) (*ExSymbol, *errs.Error)

func GetExSymbolCur

func GetExSymbolCur(symbol string) (*ExSymbol, *errs.Error)

func GetSymbolByID

func GetSymbolByID(id int32) *ExSymbol

func ParseShort

func ParseShort(exgName, short string) (*ExSymbol, *errs.Error)

func (*ExSymbol) GetValidStart

func (s *ExSymbol) GetValidStart(startMS int64) int64

func (*ExSymbol) ToShort

func (s *ExSymbol) ToShort() string

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 FindTaskParams struct {
	Mode string `json:"mode"`
	Name string `json:"name"`
}

type GetKHolesParams

type GetKHolesParams struct {
	Sid       int32  `json:"sid"`
	Timeframe string `json:"timeframe"`
}

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表示指定任务
	CloseAfter  int64 // Start timestamp 开始时间戳
	CloseBefore int64 // End timestamp 结束时间戳
	Limit       int
	AfterID     int
	OrderBy     string
}

type GetTaskPairsParams

type GetTaskPairsParams struct {
	TaskID    int32 `json:"task_id"`
	EnterAt   int64 `json:"enter_at"`
	EnterAt_2 int64 `json:"enter_at_2"`
}

type IOrder

type IOrder struct {
	ID          int64   `json:"id"`
	TaskID      int64   `json:"task_id"`
	Symbol      string  `json:"symbol"`
	Sid         int32   `json:"sid"`
	Timeframe   string  `json:"timeframe"`
	Short       bool    `json:"short"`
	Status      int16   `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      int32   `json:"stg_ver"`
	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
	Exit       *ExOrder
	Info       map[string]interface{}
	DirtyMain  bool // IOrder has unsaved temporary changes 有未保存的临时修改
	DirtyEnter bool // Enter has unsaved temporary changes 有未保存的临时修改
	DirtyExit  bool // Exit has unsaved temporary changes 有未保存的临时修改
	DirtyInfo  bool // Info has unsaved temporary changes 有未保存的临时修改
	// contains filtered or unexported fields
}

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

func (i *InOutOrder) LocalExit(tag string, price float64, msg, odType string) *errs.Error

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) Save

func (i *InOutOrder) Save(sess *Queries) *errs.Error

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

func (i *InOutOrder) UpdateFee(price float64, forEnter bool, isHistory bool) *errs.Error

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 InOutSnap

type InOutSnap struct {
	EnterLimit      float64
	ExitLimit       float64
	StopLoss        float64
	TakeProfit      float64
	StopLossLimit   float64
	TakeProfitLimit float64
}

type InfoKline

type InfoKline struct {
	*banexg.PairTFKline
	Adj      *AdjInfo
	IsWarmUp bool
}

type KHole

type KHole struct {
	ID        int64  `json:"id"`
	Sid       int32  `json:"sid"`
	Timeframe string `json:"timeframe"`
	Start     int64  `json:"start"`
	Stop      int64  `json:"stop"`
}

type KHoleExt

type KHoleExt struct {
	*KHole
	TfMSecs int64
}

type KInfo

type KInfo struct {
	Sid       int32  `json:"sid"`
	Timeframe string `json:"timeframe"`
	Start     int64  `json:"start"`
	Stop      int64  `json:"stop"`
}

type KInfoExt

type KInfoExt struct {
	KInfo
	TfMSecs int64
}

type KlineAgg

type KlineAgg struct {
	TimeFrame string
	MSecs     int64
	Table     string
	AggFrom   string
	AggStart  string
	AggEnd    string
	AggEvery  string
	CpsBefore string
	Retention string
}

func GetKlineAggs

func GetKlineAggs() []*KlineAgg

func NewKlineAgg

func NewKlineAgg(TimeFrame, Table, AggFrom, AggStart, AggEnd, AggEvery, CpsBefore, Retention string) *KlineAgg

type KlineSid

type KlineSid struct {
	banexg.Kline
	Sid int32
}

type KlineUn

type KlineUn struct {
	Sid       int32   `json:"sid"`
	StartMs   int64   `json:"start_ms"`
	StopMs    int64   `json:"stop_ms"`
	Timeframe string  `json:"timeframe"`
	Open      float64 `json:"open"`
	High      float64 `json:"high"`
	Low       float64 `json:"low"`
	Close     float64 `json:"close"`
	Volume    float64 `json:"volume"`
	Info      float64 `json:"info"`
}

type ListTaskPairsParams

type ListTaskPairsParams struct {
	TaskID    int32 `json:"task_id"`
	EnterAt   int64 `json:"enter_at"`
	EnterAt_2 int64 `json:"enter_at_2"`
}

type Overlay

type Overlay struct {
	ID       int64  `json:"id"`
	User     int32  `json:"user"`
	Sid      int32  `json:"sid"`
	StartMs  int64  `json:"start_ms"`
	StopMs   int64  `json:"stop_ms"`
	TfMsecs  int32  `json:"tf_msecs"`
	UpdateAt int64  `json:"update_at"`
	Data     string `json:"data"`
}

type PriceVol

type PriceVol struct {
	Sid   int32
	Price float64
	Vol   float64
}

type Queries

type Queries struct {
	// contains filtered or unexported fields
}

func Conn

func Conn(ctx context.Context) (*Queries, *pgxpool.Conn, *errs.Error)

func New

func New(db DBTX) *Queries

func (*Queries) AddAdjFactors

func (q *Queries) AddAdjFactors(ctx context.Context, arg []AddAdjFactorsParams) (int64, error)

func (*Queries) AddCalendars

func (q *Queries) AddCalendars(ctx context.Context, arg []AddCalendarsParams) (int64, error)

func (*Queries) AddExOrder

func (q *Queries) AddExOrder(ctx context.Context, arg AddExOrderParams) (int64, error)

func (*Queries) AddIOrder

func (q *Queries) AddIOrder(ctx context.Context, arg AddIOrderParams) (int64, error)

func (*Queries) AddKHoles

func (q *Queries) AddKHoles(ctx context.Context, arg []AddKHolesParams) (int64, error)

func (*Queries) AddKInfo

func (q *Queries) AddKInfo(ctx context.Context, arg AddKInfoParams) (*KInfo, error)

func (*Queries) AddSymbols

func (q *Queries) AddSymbols(ctx context.Context, arg []AddSymbolsParams) (int64, error)

func (*Queries) AddTask

func (q *Queries) AddTask(ctx context.Context, arg AddTaskParams) (*BotTask, error)

func (*Queries) CalcKLineRange

func (q *Queries) CalcKLineRange(sid int32, timeFrame string, start, end int64) (int64, int64, *errs.Error)

CalcKLineRange Calculate the effective range of the specified period K-line within the specified range. 计算指定周期K线在指定范围内,有效区间。

func (*Queries) CalcKLineRanges

func (q *Queries) CalcKLineRanges(timeFrame string) (map[int32][2]int64, *errs.Error)

func (*Queries) DelAdjFactors

func (q *Queries) DelAdjFactors(ctx context.Context, sid int32) error

func (*Queries) DelFactors

func (q *Queries) DelFactors(sid int32) *errs.Error

func (*Queries) DelKHoleIDs

func (q *Queries) DelKHoleIDs(ids ...int64) *errs.Error

func (*Queries) DelKHoleRange

func (q *Queries) DelKHoleRange(ctx context.Context, arg DelKHoleRangeParams) error

func (*Queries) DelKHoles

func (q *Queries) DelKHoles(sid int32, timeFrame string) *errs.Error

func (*Queries) DelKInfo

func (q *Queries) DelKInfo(sid int32, timeFrame string) *errs.Error

func (*Queries) DelKLineUn

func (q *Queries) DelKLineUn(sid int32, timeFrame string) *errs.Error

func (*Queries) DelKLines

func (q *Queries) DelKLines(sid int32, timeFrame string) *errs.Error

func (*Queries) DelOrder

func (q *Queries) DelOrder(od *InOutOrder) *errs.Error

func (*Queries) DownOHLCV2DB

func (q *Queries) DownOHLCV2DB(exchange banexg.BanExchange, exs *ExSymbol, timeFrame string, startMS, endMS int64,
	pBar *utils.PrgBar) (int, *errs.Error)

DownOHLCV2DB Download K-line to database. This method should be called in a transaction, otherwise there will be errors in querying and updating related data. 下载K线到数据库,应在事务中调用此方法,否则查询更新相关数据会有错误

func (*Queries) DumpOrdersToDb

func (q *Queries) DumpOrdersToDb() *errs.Error

func (*Queries) Exec

func (q *Queries) Exec(sql string, args ...interface{}) *errs.Error

func (*Queries) FindTask

func (q *Queries) FindTask(ctx context.Context, arg FindTaskParams) (*BotTask, error)

func (*Queries) GetAdjFactors

func (q *Queries) GetAdjFactors(ctx context.Context, sid int32) ([]*AdjFactor, error)

func (*Queries) GetAdjOHLCV

func (q *Queries) GetAdjOHLCV(adjs []*AdjInfo, timeFrame string, startMS, endMS int64, limit int, withUnFinish bool) ([]*banexg.Kline, *errs.Error)

GetAdjOHLCV Obtain K-line and weighted information (returns K-line that has not been weighted yet, needs to call ApplyAdj for weighted) 获取K线和复权信息(返回的是尚未复权的K线,需调用ApplyAdj复权)

func (*Queries) GetAdjs

func (q *Queries) GetAdjs(sid int32) ([]*AdjInfo, *errs.Error)

func (*Queries) GetCalendars

func (q *Queries) GetCalendars(name string, startMS, stopMS int64) ([][2]int64, *errs.Error)

func (*Queries) GetExOrders

func (q *Queries) GetExOrders(ctx context.Context, inoutID int32) ([]*ExOrder, error)

func (*Queries) GetExSHoles

func (q *Queries) GetExSHoles(exchange banexg.BanExchange, exs *ExSymbol, start, stop int64, full bool) ([][2]int64, *errs.Error)

GetExSHoles Retrieve all non trading time ranges for the specified Sid within a certain time period. For the 365 * 24 coin circle, it will not stop and return empty 获取指定Sid在某个时间段内,所有非交易时间范围。 对于币圈365*24不休,返回空

func (*Queries) GetHistOrderTfs

func (q *Queries) GetHistOrderTfs(taskId int64, stagy string) (map[string]string, *errs.Error)

GetHistOrderTfs Retrieve the specified task and the latest usage time period of the specified policy 获取指定任务,指定策略的最新使用的时间周期

func (*Queries) GetIOrder

func (q *Queries) GetIOrder(ctx context.Context, id int64) (*IOrder, error)

func (*Queries) GetKHoles

func (q *Queries) GetKHoles(ctx context.Context, arg GetKHolesParams) ([]*KHole, error)

func (*Queries) GetKlineRange

func (q *Queries) GetKlineRange(sid int32, timeFrame string) (int64, int64)

func (*Queries) GetKlineRanges

func (q *Queries) GetKlineRanges(sidList []int32, timeFrame string) map[int32][2]int64

func (*Queries) GetOHLCV

func (q *Queries) GetOHLCV(exs *ExSymbol, timeFrame string, startMS, endMS int64, limit int, withUnFinish bool) ([]*AdjInfo, []*banexg.Kline, *errs.Error)

GetOHLCV Obtain the variety K-line, return the unweighted K-line and the weighting factor, and the caller can call ApplyAdj to re-weight 获取品种K线,返回未复权K线和复权因子,调用方可调用ApplyAdj进行复权

func (*Queries) GetOrders

func (q *Queries) GetOrders(args GetOrdersArgs) ([]*InOutOrder, *errs.Error)

func (*Queries) GetTask

func (q *Queries) GetTask(ctx context.Context, id int64) (*BotTask, error)

func (*Queries) GetTaskPairs

func (q *Queries) GetTaskPairs(ctx context.Context, arg GetTaskPairsParams) ([]string, error)

func (*Queries) InsertKLines

func (q *Queries) InsertKLines(timeFrame string, sid int32, arr []*banexg.Kline) (int64, *errs.Error)

InsertKLines Only batch insert K-lines. To update associated information simultaneously, please use InsertKLinesAuto 只批量插入K线,如需同时更新关联信息,请使用InsertKLinesAuto

func (*Queries) InsertKLinesAuto

func (q *Queries) InsertKLinesAuto(timeFrame string, sid int32, arr []*banexg.Kline, aggBig bool) (int64, *errs.Error)

InsertKLinesAuto Insert K-line into the database and call updateKRange to update associated information Before calling this method, it is necessary to determine whether it already exists in the database through GetKlineRange to avoid duplicate insertions 插入K线到数据库,同时调用UpdateKRange更新关联信息 调用此方法前必须通过GetKlineRange自行判断数据库中是否已存在,避免重复插入

func (*Queries) ListExchanges

func (q *Queries) ListExchanges(ctx context.Context) ([]string, error)

func (*Queries) ListKHoles

func (q *Queries) ListKHoles(ctx context.Context) ([]*KHole, error)

func (*Queries) ListKInfos

func (q *Queries) ListKInfos(ctx context.Context) ([]*KInfo, error)

func (*Queries) ListSymbols

func (q *Queries) ListSymbols(ctx context.Context, exchange string) ([]*ExSymbol, error)

func (*Queries) ListTaskPairs

func (q *Queries) ListTaskPairs(ctx context.Context, arg ListTaskPairsParams) ([]string, error)

func (*Queries) ListTasks

func (q *Queries) ListTasks(ctx context.Context) ([]*BotTask, error)

func (*Queries) LoadExgSymbols

func (q *Queries) LoadExgSymbols(exgName string) *errs.Error

func (*Queries) NewTx

func (q *Queries) NewTx(ctx context.Context) (*Tx, *Queries, *errs.Error)

func (*Queries) PurgeKlineUn

func (q *Queries) PurgeKlineUn() *errs.Error

func (*Queries) QueryOHLCV

func (q *Queries) QueryOHLCV(sid int32, timeframe string, startMs, endMs int64, limit int, withUnFinish bool) ([]*banexg.Kline, *errs.Error)

func (*Queries) QueryOHLCVBatch

func (q *Queries) QueryOHLCVBatch(sids []int32, timeframe string, startMs, endMs int64, limit int, handle func(int32, []*banexg.Kline)) *errs.Error

func (*Queries) SetCalendars

func (q *Queries) SetCalendars(name string, items [][2]int64) *errs.Error

func (*Queries) SetExOrder

func (q *Queries) SetExOrder(ctx context.Context, arg SetExOrderParams) error

func (*Queries) SetIOrder

func (q *Queries) SetIOrder(ctx context.Context, arg SetIOrderParams) error

func (*Queries) SetKHole

func (q *Queries) SetKHole(ctx context.Context, arg SetKHoleParams) error

func (*Queries) SetKInfo

func (q *Queries) SetKInfo(ctx context.Context, arg SetKInfoParams) error

func (*Queries) SetListMS

func (q *Queries) SetListMS(ctx context.Context, arg SetListMSParams) error

func (*Queries) UpdateKRange

func (q *Queries) UpdateKRange(sid int32, timeFrame string, startMS, endMS int64, klines []*banexg.Kline, aggBig bool) *errs.Error

UpdateKRange 1. Update the effective range of the K-line 2. Search for holes and update Khole 3. Update continuous aggregation with larger cycles 1. 更新K线的有效区间 2. 搜索空洞,更新Khole 3. 更新更大周期的连续聚合

func (*Queries) WithTx

func (q *Queries) WithTx(tx pgx.Tx) *Queries

type SetExOrderParams

type SetExOrderParams struct {
	TaskID    int32   `json:"task_id"`
	InoutID   int32   `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    int16   `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      int32   `json:"task_id"`
	Symbol      string  `json:"symbol"`
	Sid         int32   `json:"sid"`
	Timeframe   string  `json:"timeframe"`
	Short       bool    `json:"short"`
	Status      int16   `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      int32   `json:"stg_ver"`
	MaxDrawDown float64 `json:"max_draw_down"`
	ProfitRate  float64 `json:"profit_rate"`
	Profit      float64 `json:"profit"`
	Info        string  `json:"info"`
	ID          int64   `json:"id"`
}

type SetKHoleParams

type SetKHoleParams struct {
	ID    int64 `json:"id"`
	Start int64 `json:"start"`
	Stop  int64 `json:"stop"`
}

type SetKInfoParams

type SetKInfoParams struct {
	Sid       int32  `json:"sid"`
	Timeframe string `json:"timeframe"`
	Start     int64  `json:"start"`
	Stop      int64  `json:"stop"`
}

type SetListMSParams

type SetListMSParams struct {
	ID       int32 `json:"id"`
	ListMs   int64 `json:"list_ms"`
	DelistMs int64 `json:"delist_ms"`
}

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()

type Tx

type Tx struct {
	// contains filtered or unexported fields
}

func (*Tx) Close

func (t *Tx) Close(ctx context.Context, commit bool) *errs.Error

type User

type User struct {
	ID             int32  `json:"id"`
	UserName       string `json:"user_name"`
	Avatar         string `json:"avatar"`
	Mobile         string `json:"mobile"`
	MobileVerified bool   `json:"mobile_verified"`
	Email          string `json:"email"`
	EmailVerified  bool   `json:"email_verified"`
	PwdSalt        string `json:"pwd_salt"`
	LastIp         string `json:"last_ip"`
	CreateAt       int64  `json:"create_at"`
	LastLogin      int64  `json:"last_login"`
	VipType        int32  `json:"vip_type"`
	VipExpireAt    int64  `json:"vip_expire_at"`
	InviterID      int32  `json:"inviter_id"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL