orm Package
The orm package provides database access and data model definition functionality.
Important Structures
AdjFactor
Price adjustment factor structure, used for handling forward and backward price adjustments.
Fields:
ID int32
- Adjustment factor IDSid int32
- Trading pair IDSubID int32
- Sub trading pair IDStartMs int64
- Start timestamp (milliseconds)Factor float64
- Adjustment factor value
Calendar
Trading calendar structure, used to record trading time periods.
Fields:
ID int32
- Calendar IDName string
- Calendar nameStartMs int64
- Start timestamp (milliseconds)StopMs int64
- End timestamp (milliseconds)
ExSymbol
Trading pair information structure, containing basic information about exchange and trading pair.
Fields:
ID int32
- Trading pair IDExchange string
- Exchange nameExgReal string
- Actual exchange identifierMarket string
- Market typeSymbol string
- Trading pair symbolCombined bool
- Whether it's a combined trading pairListMs int64
- Listing timestamp (milliseconds)DelistMs int64
- Delisting timestamp (milliseconds)
InsKline
candlestick insertion task structure, used to manage candlestick data insertion operations.
Fields:
ID int32
- Task IDSid int32
- Trading pair IDTimeframe string
- Time periodStartMs int64
- Start timestamp (milliseconds)StopMs int64
- End timestamp (milliseconds)
KHole
candlestick data gap structure, used to record missing periods in candlestick data.
Fields:
ID int64
- Gap record IDSid int32
- Trading pair IDTimeframe string
- Time periodStart int64
- Start timestamp (milliseconds)Stop int64
- End timestamp (milliseconds)NoData bool
- Whether confirmed no data exists
KInfo
candlestick information structure, used to record basic information about candlestick data.
Fields:
Sid int32
- Trading pair IDTimeframe string
- Time periodStart int64
- Start timestamp (milliseconds)Stop int64
- End timestamp (milliseconds)
KlineUn
Unadjusted candlestick data structure, containing raw candlestick data.
Fields:
Sid int32
- Trading pair IDStartMs int64
- Start timestamp (milliseconds)StopMs int64
- End timestamp (milliseconds)Timeframe string
- Time periodOpen float64
- Opening priceHigh float64
- Highest priceLow float64
- Lowest priceClose float64
- Closing priceVolume float64
- Trading volumeInfo float64
- Additional information
InfoKline
candlestick data structure with additional information.
Fields:
PairTFKline *banexg.PairTFKline
- Base candlestick dataAdj *AdjInfo
- Price adjustment informationIsWarmUp bool
- Whether it's warm-up data
AdjInfo
Price adjustment information structure, containing detailed information about price adjustments.
Fields:
ExSymbol *ExSymbol
- Trading pair informationFactor float64
- Original adjacent adjustment factorCumFactor float64
- Cumulative adjustment factorStartMS int64
- Start timestamp (milliseconds)StopMS int64
- End timestamp (milliseconds)
KlineAgg
candlestick data aggregation configuration structure, used to manage candlestick aggregation for different time periods.
Fields:
TimeFrame string
- Time periodMSecs int64
- Period in millisecondsTable string
- Data table nameAggFrom string
- Aggregation sourceAggStart string
- Aggregation start timeAggEnd string
- Aggregation end timeAggEvery string
- Aggregation intervalCpsBefore string
- Completion deadlineRetention string
- Data retention time
Database Connection Related
Setup
Initialize database connection pool.
Returns:
*errs.Error
- Error information during initialization
Conn
Get database connection and query object.
Parameters:
ctx context.Context
- Context object for controlling request lifecycle
Returns:
*Queries
- Database query object*pgxpool.Conn
- Database connection object*errs.Error
- Error information
SetDbPath
Set database path.
Parameters:
key string
- Database identifier keypath string
- Database file path
DbLite
Create SQLite database connection.
Parameters:
src string
- Data source namepath string
- Database file pathwrite bool
- Whether writable
Returns:
*sql.DB
- Database connection object*errs.Error
- Error information
NewDbErr
Create database error object.
Parameters:
code int
- Error codeerr_ error
- Original error
Returns:
*errs.Error
- Formatted error information
Exchange Related
LoadMarkets
Load exchange market data.
Parameters:
exchange banexg.BanExchange
- Exchange interfacereload bool
- Whether to force reload
Returns:
banexg.MarketMap
- Market data mapping*errs.Error
- Error information
InitExg
Initialize exchange configuration.
Parameters:
exchange banexg.BanExchange
- Exchange interface
Returns:
*errs.Error
- Error information
Trading Pair Related
GetExSymbols
Get all trading pair information for specified exchange and market.
Parameters:
exgName string
- Exchange namemarket string
- Market name
Returns:
map[int32]*ExSymbol
- Mapping from trading pair ID to trading pair information
GetExSymbolMap
Get all trading pair information for specified exchange and market (keyed by trading pair name).
Parameters:
exgName string
- Exchange namemarket string
- Market name
Returns:
map[string]*ExSymbol
- Mapping from trading pair name to trading pair information
GetSymbolByID
Get trading pair information by ID.
Parameters:
id int32
- Trading pair ID
Returns:
*ExSymbol
- Trading pair information
GetExSymbolCur
Get trading pair information for current default exchange.
Parameters:
symbol string
- Trading pair name
Returns:
*ExSymbol
- Trading pair information*errs.Error
- Error information
GetExSymbol
Get trading pair information for specified exchange.
Parameters:
exchange banexg.BanExchange
- Exchange interfacesymbol string
- Trading pair name
Returns:
*ExSymbol
- Trading pair information*errs.Error
- Error information
EnsureExgSymbols
Ensure trading pair information for exchange is loaded.
Parameters:
exchange banexg.BanExchange
- Exchange interface
Returns:
*errs.Error
- Error information
EnsureCurSymbols
Ensure trading pair information for current exchange is loaded.
Parameters:
symbols []string
- List of trading pair names
Returns:
*errs.Error
- Error information
EnsureSymbols
Ensure trading pair information for specified exchanges is loaded.
Parameters:
symbols []*ExSymbol
- List of trading pair informationexchanges ...string
- List of exchange names
Returns:
*errs.Error
- Error information
LoadAllExSymbols
Load all trading pair information.
Returns:
*errs.Error
- Error information
GetAllExSymbols
Get all loaded trading pair information.
Returns:
map[int32]*ExSymbol
- Mapping from trading pair ID to trading pair information
InitListDates
Initialize listing date information for trading pairs.
Returns:
*errs.Error
- Error information
EnsureListDates
Ensure listing date information for trading pairs is loaded.
Parameters:
sess *Queries
- Database query objectexchange banexg.BanExchange
- Exchange interfaceexsMap map[int32]*ExSymbol
- Trading pair mappingexsList []*ExSymbol
- Trading pair list
Returns:
*errs.Error
- Error information
ParseShort
Parse short format trading pair name.
Parameters:
exgName string
- Exchange nameshort string
- Short format trading pair name
Returns:
*ExSymbol
- Trading pair information*errs.Error
- Error information
MapExSymbols
Map trading pair name list to trading pair information mapping.
Parameters:
exchange banexg.BanExchange
- Exchange interfacesymbols []string
- List of trading pair names
Returns:
map[int32]*ExSymbol
- Mapping from trading pair ID to trading pair information*errs.Error
- Error information
candlestick Data Related
AutoFetchOHLCV
Automatically fetch candlestick data, supporting data completion and unfinished candlesticks.
Parameters:
exchange banexg.BanExchange
- Exchange interfaceexs *ExSymbol
- Trading pair informationtimeFrame string
- Time framestartMS int64
- Start time (milliseconds)endMS int64
- End time (milliseconds)limit int
- Limit countwithUnFinish bool
- Whether to include unfinished candlestickspBar *utils.PrgBar
- Progress bar
Returns:
[]*AdjInfo
- Price adjustment information[]*banexg.Kline
- candlestick data*errs.Error
- Error information
GetOHLCV
Get candlestick data.
Parameters:
exs *ExSymbol
- Trading pair informationtimeFrame string
- Time framestartMS int64
- Start time (milliseconds)endMS int64
- End time (milliseconds)limit int
- Limit countwithUnFinish bool
- Whether to include unfinished candlesticks
Returns:
[]*AdjInfo
- Price adjustment information[]*banexg.Kline
- candlestick data*errs.Error
- Error information
BulkDownOHLCV
Bulk download candlestick data.
Parameters:
exchange banexg.BanExchange
- Exchange interfaceexsList map[int32]*ExSymbol
- Trading pair listtimeFrame string
- Time framestartMS int64
- Start time (milliseconds)