Documentation ¶
Index ¶
- Variables
- func NewDefaultTotpKey() (*otp.Key, error)
- func ReformatMysqlDSN(dsn string) (string, error)
- func SelectKLineTimePoints(ex types.ExchangeName, symbol string, interval types.Interval, ...) sq.SelectBuilder
- func SelectKLineTimeRange(ex types.ExchangeName, symbol string, interval types.Interval, ...) sq.SelectBuilder
- func SelectLastKLines(ex types.ExchangeName, symbol string, interval types.Interval, ...) sq.SelectBuilder
- func SelectLastMarginInterests(ex types.ExchangeName, limit uint64) sq.SelectBuilder
- func SelectLastMarginLiquidations(ex types.ExchangeName, limit uint64) sq.SelectBuilder
- func SelectLastMarginLoans(ex types.ExchangeName, limit uint64) sq.SelectBuilder
- func SelectLastMarginRepays(ex types.ExchangeName, limit uint64) sq.SelectBuilder
- func SelectLastOrders(ex types.ExchangeName, symbol string, isMargin, isFutures, isIsolated bool, ...) sq.SelectBuilder
- func SelectLastTrades(ex types.ExchangeName, symbol string, isMargin, isFutures, isIsolated bool, ...) sq.SelectBuilder
- func SelectLastWithdraws(ex types.ExchangeName, limit uint64) sq.SelectBuilder
- type AccountService
- type AggOrder
- type BacktestService
- func (s *BacktestService) BatchInsert(kline []types.KLine) error
- func (s *BacktestService) FindMissingTimeRanges(ctx context.Context, ex types.Exchange, symbol string, interval types.Interval, ...) ([]TimeRange, error)
- func (s *BacktestService) Insert(kline types.KLine) error
- func (s *BacktestService) QueryExistingDataRange(ctx context.Context, ex types.Exchange, symbol string, interval types.Interval, ...) (start, end *types.Time, err error)
- func (s *BacktestService) QueryFirstKLine(ex types.ExchangeName, symbol string, interval types.Interval) (*types.KLine, error)
- func (s *BacktestService) QueryKLine(ex types.ExchangeName, symbol string, interval types.Interval, orderBy string, ...) (*types.KLine, error)
- func (s *BacktestService) QueryKLinesBackward(exchange types.ExchangeName, symbol string, interval types.Interval, ...) ([]types.KLine, error)
- func (s *BacktestService) QueryKLinesCh(since, until time.Time, exchange types.Exchange, symbols []string, ...) (chan types.KLine, chan error)
- func (s *BacktestService) QueryKLinesForward(exchange types.ExchangeName, symbol string, interval types.Interval, ...) ([]types.KLine, error)
- func (s *BacktestService) SyncFresh(ctx context.Context, exchange types.Exchange, symbol string, ...) error
- func (s *BacktestService) SyncKLineByInterval(ctx context.Context, exchange types.Exchange, symbol string, ...) error
- func (s *BacktestService) SyncPartial(ctx context.Context, ex types.Exchange, symbol string, interval types.Interval, ...) error
- func (s *BacktestService) Verify(sourceExchange types.Exchange, symbols []string, startTime time.Time, ...) error
- type CurrencyPositionMap
- type DatabaseService
- type DepositService
- func (s *DepositService) Insert(deposit types.Deposit) error
- func (s *DepositService) Query(exchangeName types.ExchangeName) ([]types.Deposit, error)
- func (s *DepositService) QueryLast(ex types.ExchangeName, limit int) ([]types.Deposit, error)
- func (s *DepositService) Sync(ctx context.Context, ex types.Exchange) error
- type JsonPersistenceConfig
- type JsonPersistenceService
- type JsonStore
- type MarginService
- type MemoryService
- type MemoryStore
- type OrderService
- type PersistenceService
- type PersistenceServiceFacade
- type PositionService
- type ProfitService
- type QueryOrdersOptions
- type QueryTradesOptions
- type RedisPersistenceConfig
- type RedisPersistenceService
- type RedisStore
- type ReflectCache
- type RewardService
- func (s *RewardService) AggregateUnspentCurrencyPosition(ctx context.Context, ex types.ExchangeName, since time.Time) (CurrencyPositionMap, error)
- func (s *RewardService) Insert(reward types.Reward) error
- func (s *RewardService) MarkAsSpent(ctx context.Context, uuid string) error
- func (s *RewardService) MarkCurrencyAsSpent(ctx context.Context, currency string) error
- func (s *RewardService) QueryLast(ex types.ExchangeName, limit int) ([]types.Reward, error)
- func (s *RewardService) QueryUnspent(ctx context.Context, ex types.ExchangeName, rewardTypes ...types.RewardType) ([]types.Reward, error)
- func (s *RewardService) QueryUnspentSince(ctx context.Context, ex types.ExchangeName, since time.Time, ...) ([]types.Reward, error)
- func (s *RewardService) Sync(ctx context.Context, exchange types.Exchange) error
- type Store
- type SyncService
- func (s *SyncService) SyncDepositHistory(ctx context.Context, exchange types.Exchange) error
- func (s *SyncService) SyncMarginHistory(ctx context.Context, exchange types.Exchange, startTime time.Time, ...) error
- func (s *SyncService) SyncRewardHistory(ctx context.Context, exchange types.Exchange) error
- func (s *SyncService) SyncSessionSymbols(ctx context.Context, exchange types.Exchange, startTime time.Time, ...) error
- func (s *SyncService) SyncWithdrawHistory(ctx context.Context, exchange types.Exchange, startTime time.Time) error
- type SyncTask
- type TimeRange
- type TradeService
- func (s *TradeService) DeleteAll() error
- func (s *TradeService) Insert(trade types.Trade) error
- func (s *TradeService) Load(ctx context.Context, id int64) (*types.Trade, error)
- func (s *TradeService) Mark(ctx context.Context, id int64, strategyID string) error
- func (s *TradeService) Query(options QueryTradesOptions) ([]types.Trade, error)
- func (s *TradeService) QueryForTradingFeeCurrency(ex types.ExchangeName, symbol string, feeCurrency string) ([]types.Trade, error)
- func (s *TradeService) QueryLast(ex types.ExchangeName, symbol string, isMargin, isFutures, isIsolated bool, ...) ([]types.Trade, error)
- func (s *TradeService) QueryTradingVolume(startTime time.Time, options TradingVolumeQueryOptions) ([]TradingVolume, error)
- func (s *TradeService) Sync(ctx context.Context, exchange types.Exchange, symbol string, ...) error
- func (s *TradeService) UpdatePnL(ctx context.Context, id int64, pnl float64) error
- type TradingVolume
- type TradingVolumeQueryOptions
- type WithdrawService
- func (s *WithdrawService) Insert(withdrawal types.Withdraw) error
- func (s *WithdrawService) Query(exchangeName types.ExchangeName) ([]types.Withdraw, error)
- func (s *WithdrawService) QueryLast(ex types.ExchangeName, limit int) ([]types.Withdraw, error)
- func (s *WithdrawService) Sync(ctx context.Context, ex types.Exchange, startTime time.Time) error
Constants ¶
This section is empty.
Variables ¶
var ErrExchangeRewardServiceNotImplemented = errors.New("exchange does not implement ExchangeRewardService interface")
var ErrNotImplemented = errors.New("not implemented")
var ErrPersistenceNotExists = errors.New("persistent data does not exists")
var ErrTradeNotFound = errors.New("trade not found")
Functions ¶
func NewDefaultTotpKey ¶ added in v1.4.0
func ReformatMysqlDSN ¶ added in v1.11.0
func SelectKLineTimePoints ¶ added in v1.33.0
func SelectKLineTimePoints(ex types.ExchangeName, symbol string, interval types.Interval, args ...time.Time) sq.SelectBuilder
func SelectKLineTimeRange ¶ added in v1.33.0
func SelectKLineTimeRange(ex types.ExchangeName, symbol string, interval types.Interval, args ...time.Time) sq.SelectBuilder
SelectKLineTimeRange returns the existing klines time range (since < kline.start_time < until)
func SelectLastKLines ¶ added in v1.33.0
func SelectLastKLines(ex types.ExchangeName, symbol string, interval types.Interval, startTime, endTime time.Time, limit uint64) sq.SelectBuilder
TODO: add is_futures column since the klines data is different
func SelectLastMarginInterests ¶ added in v1.33.0
func SelectLastMarginInterests(ex types.ExchangeName, limit uint64) sq.SelectBuilder
func SelectLastMarginLiquidations ¶ added in v1.33.0
func SelectLastMarginLiquidations(ex types.ExchangeName, limit uint64) sq.SelectBuilder
func SelectLastMarginLoans ¶ added in v1.33.0
func SelectLastMarginLoans(ex types.ExchangeName, limit uint64) sq.SelectBuilder
func SelectLastMarginRepays ¶ added in v1.33.0
func SelectLastMarginRepays(ex types.ExchangeName, limit uint64) sq.SelectBuilder
func SelectLastOrders ¶ added in v1.33.0
func SelectLastOrders(ex types.ExchangeName, symbol string, isMargin, isFutures, isIsolated bool, limit uint64) sq.SelectBuilder
func SelectLastTrades ¶ added in v1.33.0
func SelectLastTrades(ex types.ExchangeName, symbol string, isMargin, isFutures, isIsolated bool, limit uint64) sq.SelectBuilder
func SelectLastWithdraws ¶ added in v1.33.0
func SelectLastWithdraws(ex types.ExchangeName, limit uint64) sq.SelectBuilder
Types ¶
type AccountService ¶ added in v1.21.0
func NewAccountService ¶ added in v1.21.0
func NewAccountService(db *sqlx.DB) *AccountService
func (*AccountService) InsertAsset ¶ added in v1.21.0
func (s *AccountService) InsertAsset(time time.Time, session string, name types.ExchangeName, account string, isMargin bool, isIsolatedMargin bool, isolatedMarginSymbol string, assets types.AssetMap) error
TODO: should pass bbgo.ExchangeSession to this function, but that might cause cyclic import
type BacktestService ¶
func (*BacktestService) BatchInsert ¶ added in v1.21.0
func (s *BacktestService) BatchInsert(kline []types.KLine) error
BatchInsert Note: all kline should be same exchange, or it will cause issue.
func (*BacktestService) FindMissingTimeRanges ¶ added in v1.33.0
func (s *BacktestService) FindMissingTimeRanges(ctx context.Context, ex types.Exchange, symbol string, interval types.Interval, since, until time.Time) ([]TimeRange, error)
FindMissingTimeRanges returns the missing time ranges, the start/end time represents the existing data time points. So when sending kline query to the exchange API, we need to add one second to the start time and minus one second to the end time.
func (*BacktestService) QueryExistingDataRange ¶ added in v1.33.0
func (*BacktestService) QueryFirstKLine ¶ added in v1.19.3
func (s *BacktestService) QueryFirstKLine(ex types.ExchangeName, symbol string, interval types.Interval) (*types.KLine, error)
func (*BacktestService) QueryKLine ¶ added in v1.19.3
func (s *BacktestService) QueryKLine(ex types.ExchangeName, symbol string, interval types.Interval, orderBy string, limit int) (*types.KLine, error)
QueryKLine queries the klines from the database
func (*BacktestService) QueryKLinesBackward ¶
func (*BacktestService) QueryKLinesCh ¶
func (*BacktestService) QueryKLinesForward ¶
func (s *BacktestService) QueryKLinesForward(exchange types.ExchangeName, symbol string, interval types.Interval, startTime time.Time, limit int) ([]types.KLine, error)
QueryKLinesForward is used for querying klines to back-testing
func (*BacktestService) SyncKLineByInterval ¶ added in v1.14.0
func (*BacktestService) SyncPartial ¶ added in v1.33.0
func (s *BacktestService) SyncPartial(ctx context.Context, ex types.Exchange, symbol string, interval types.Interval, since, until time.Time) error
SyncPartial find the existing data time range (t1, t2) scan if there is a missing part create a time range slice []TimeRange iterate the []TimeRange slice to sync data.
type CurrencyPositionMap ¶ added in v1.13.0
type CurrencyPositionMap map[string]fixedpoint.Value
type DatabaseService ¶ added in v1.11.0
func NewDatabaseService ¶ added in v1.11.0
func NewDatabaseService(driver, dsn string) *DatabaseService
func (*DatabaseService) Close ¶ added in v1.11.0
func (s *DatabaseService) Close() error
func (*DatabaseService) Connect ¶ added in v1.11.0
func (s *DatabaseService) Connect() error
func (*DatabaseService) Insert ¶ added in v1.33.0
func (s *DatabaseService) Insert(record interface{}) error
type DepositService ¶ added in v1.14.0
func (*DepositService) Insert ¶ added in v1.14.0
func (s *DepositService) Insert(deposit types.Deposit) error
func (*DepositService) Query ¶ added in v1.14.0
func (s *DepositService) Query(exchangeName types.ExchangeName) ([]types.Deposit, error)
func (*DepositService) QueryLast ¶ added in v1.14.0
func (s *DepositService) QueryLast(ex types.ExchangeName, limit int) ([]types.Deposit, error)
type JsonPersistenceConfig ¶ added in v1.12.0
type JsonPersistenceConfig struct {
Directory string `yaml:"directory" json:"directory"`
}
type JsonPersistenceService ¶ added in v1.12.0
type JsonPersistenceService struct {
Directory string
}
type MarginService ¶ added in v1.33.0
type MemoryService ¶ added in v1.12.0
type MemoryService struct {
Slots map[string]interface{}
}
func NewMemoryService ¶ added in v1.12.0
func NewMemoryService() *MemoryService
type MemoryStore ¶ added in v1.12.0
type MemoryStore struct { Key string // contains filtered or unexported fields }
func (*MemoryStore) Load ¶ added in v1.12.0
func (store *MemoryStore) Load(val interface{}) error
func (*MemoryStore) Reset ¶ added in v1.12.0
func (store *MemoryStore) Reset() error
func (*MemoryStore) Save ¶ added in v1.12.0
func (store *MemoryStore) Save(val interface{}) error
type OrderService ¶
func (*OrderService) Query ¶
func (s *OrderService) Query(options QueryOrdersOptions) ([]AggOrder, error)
type PersistenceService ¶ added in v1.12.0
type PersistenceServiceFacade ¶ added in v1.12.0
type PersistenceServiceFacade struct { Redis *RedisPersistenceService Json *JsonPersistenceService Memory *MemoryService }
func (*PersistenceServiceFacade) Get ¶ added in v1.12.0
func (facade *PersistenceServiceFacade) Get() PersistenceService
Get returns the preferred persistence service by fallbacks Redis will be preferred at the first position.
type PositionService ¶ added in v1.28.0
func NewPositionService ¶ added in v1.28.0
func NewPositionService(db *sqlx.DB) *PositionService
func (*PositionService) Insert ¶ added in v1.28.0
func (s *PositionService) Insert(position *types.Position, trade types.Trade, profit fixedpoint.Value) error
type ProfitService ¶ added in v1.28.0
type QueryOrdersOptions ¶ added in v1.11.0
type QueryOrdersOptions struct { Exchange types.ExchangeName Symbol string LastGID int64 Ordering string }
type QueryTradesOptions ¶ added in v1.11.0
type RedisPersistenceConfig ¶ added in v1.12.0
type RedisPersistenceService ¶ added in v1.12.0
type RedisPersistenceService struct {
// contains filtered or unexported fields
}
func NewRedisPersistenceService ¶ added in v1.12.0
func NewRedisPersistenceService(config *RedisPersistenceConfig) *RedisPersistenceService
type RedisStore ¶ added in v1.12.0
type RedisStore struct { ID string // contains filtered or unexported fields }
func (*RedisStore) Load ¶ added in v1.12.0
func (store *RedisStore) Load(val interface{}) error
func (*RedisStore) Reset ¶ added in v1.12.0
func (store *RedisStore) Reset() error
func (*RedisStore) Save ¶ added in v1.12.0
func (store *RedisStore) Save(val interface{}) error
type ReflectCache ¶ added in v1.33.0
type ReflectCache struct {
// contains filtered or unexported fields
}
func NewReflectCache ¶ added in v1.33.0
func NewReflectCache() *ReflectCache
func (*ReflectCache) FieldsOf ¶ added in v1.33.0
func (c *ReflectCache) FieldsOf(t interface{}) []string
func (*ReflectCache) InsertSqlOf ¶ added in v1.33.0
func (c *ReflectCache) InsertSqlOf(t interface{}) string
func (*ReflectCache) PlaceholderOf ¶ added in v1.33.0
func (c *ReflectCache) PlaceholderOf(t interface{}) []string
func (*ReflectCache) TableNameOf ¶ added in v1.33.0
func (c *ReflectCache) TableNameOf(t interface{}) string
type RewardService ¶ added in v1.13.0
RewardService collects the reward records from the exchange, currently it's only available for MAX exchange. TODO: add summary query for calculating the reward amounts CREATE VIEW reward_summary_by_years AS SELECT YEAR(created_at) as year, reward_type, currency, SUM(quantity) FROM rewards WHERE reward_type != 'airdrop' GROUP BY YEAR(created_at), reward_type, currency ORDER BY year DESC;
func (*RewardService) AggregateUnspentCurrencyPosition ¶ added in v1.13.0
func (s *RewardService) AggregateUnspentCurrencyPosition(ctx context.Context, ex types.ExchangeName, since time.Time) (CurrencyPositionMap, error)
func (*RewardService) Insert ¶ added in v1.13.0
func (s *RewardService) Insert(reward types.Reward) error
func (*RewardService) MarkAsSpent ¶ added in v1.13.0
func (s *RewardService) MarkAsSpent(ctx context.Context, uuid string) error
func (*RewardService) MarkCurrencyAsSpent ¶ added in v1.13.0
func (s *RewardService) MarkCurrencyAsSpent(ctx context.Context, currency string) error
func (*RewardService) QueryLast ¶ added in v1.13.0
func (s *RewardService) QueryLast(ex types.ExchangeName, limit int) ([]types.Reward, error)
func (*RewardService) QueryUnspent ¶ added in v1.13.0
func (s *RewardService) QueryUnspent(ctx context.Context, ex types.ExchangeName, rewardTypes ...types.RewardType) ([]types.Reward, error)
func (*RewardService) QueryUnspentSince ¶ added in v1.13.0
func (s *RewardService) QueryUnspentSince(ctx context.Context, ex types.ExchangeName, since time.Time, rewardTypes ...types.RewardType) ([]types.Reward, error)
type SyncService ¶
type SyncService struct { TradeService *TradeService OrderService *OrderService RewardService *RewardService WithdrawService *WithdrawService DepositService *DepositService MarginService *MarginService }
func (*SyncService) SyncDepositHistory ¶ added in v1.31.0
func (*SyncService) SyncMarginHistory ¶ added in v1.33.0
func (*SyncService) SyncRewardHistory ¶ added in v1.31.0
func (*SyncService) SyncSessionSymbols ¶ added in v1.11.1
func (s *SyncService) SyncSessionSymbols(ctx context.Context, exchange types.Exchange, startTime time.Time, symbols ...string) error
SyncSessionSymbols syncs the trades from the given exchange session
func (*SyncService) SyncWithdrawHistory ¶ added in v1.31.0
type SyncTask ¶ added in v1.33.0
type SyncTask struct { // Type is the element type of this sync task // Since it will create a []Type slice from this type, you should not set pointer to this field Type interface{} // ID is a function that returns the unique identity of the object // This function will be used for detecting duplicated objects. ID func(obj interface{}) string // Time is a function that returns the time of the object // This function will be used for sorting records Time func(obj interface{}) time.Time // Select is the select query builder for querying existing db records // The built SQL will be used for querying existing db records. // And then the ID function will be used for filtering duplicated object. Select squirrel.SelectBuilder // OnLoad is an optional field, which is called when the records are loaded from the database OnLoad func(objs interface{}) // Filter is an optional field, which is used for filtering the remote records Filter func(obj interface{}) bool // BatchQuery is used for querying remote records. BatchQuery func(ctx context.Context, startTime, endTime time.Time) (interface{}, chan error) // Insert is an option field, which is used for customizing the record insert Insert func(obj interface{}) error // Insert is an option field, which is used for customizing the record batch insert BatchInsert func(obj interface{}) error BatchInsertBuffer int // LogInsert logs the insert record in INFO level LogInsert bool }
SyncTask defines the behaviors for syncing remote records
type TradeService ¶
func NewTradeService ¶
func NewTradeService(db *sqlx.DB) *TradeService
func (*TradeService) DeleteAll ¶ added in v1.17.0
func (s *TradeService) DeleteAll() error
func (*TradeService) Query ¶
func (s *TradeService) Query(options QueryTradesOptions) ([]types.Trade, error)
func (*TradeService) QueryForTradingFeeCurrency ¶
func (s *TradeService) QueryForTradingFeeCurrency(ex types.ExchangeName, symbol string, feeCurrency string) ([]types.Trade, error)
func (*TradeService) QueryLast ¶
func (s *TradeService) QueryLast(ex types.ExchangeName, symbol string, isMargin, isFutures, isIsolated bool, limit int) ([]types.Trade, error)
QueryLast queries the last trade from the database
func (*TradeService) QueryTradingVolume ¶ added in v1.11.0
func (s *TradeService) QueryTradingVolume(startTime time.Time, options TradingVolumeQueryOptions) ([]TradingVolume, error)
type TradingVolume ¶ added in v1.11.0
type TradingVolume struct { Year int `db:"year" json:"year"` Month int `db:"month" json:"month,omitempty"` Day int `db:"day" json:"day,omitempty"` Time time.Time `json:"time,omitempty"` Exchange string `db:"exchange" json:"exchange,omitempty"` Symbol string `db:"symbol" json:"symbol,omitempty"` QuoteVolume float64 `db:"quote_volume" json:"quoteVolume"` }
type TradingVolumeQueryOptions ¶ added in v1.11.0
type WithdrawService ¶ added in v1.14.0
func (*WithdrawService) Insert ¶ added in v1.14.0
func (s *WithdrawService) Insert(withdrawal types.Withdraw) error
func (*WithdrawService) Query ¶ added in v1.14.0
func (s *WithdrawService) Query(exchangeName types.ExchangeName) ([]types.Withdraw, error)
func (*WithdrawService) QueryLast ¶ added in v1.14.0
func (s *WithdrawService) QueryLast(ex types.ExchangeName, limit int) ([]types.Withdraw, error)