Documentation
¶
Index ¶
- Constants
- type InstrumentInterface
- type InstrumentQueryInterface
- type NewStoreOptions
- type Price
- func (price *Price) Close() string
- func (price *Price) CloseFloat() float64
- func (price *Price) High() string
- func (price *Price) HighFloat() float64
- func (price *Price) ID() string
- func (price *Price) Low() string
- func (price *Price) LowFloat() float64
- func (price *Price) Open() string
- func (price *Price) OpenFloat() float64
- func (price *Price) SetClose(close string) PriceInterface
- func (price *Price) SetHigh(high string) PriceInterface
- func (price *Price) SetID(id string) PriceInterface
- func (price *Price) SetLow(low string) PriceInterface
- func (price *Price) SetOpen(open string) PriceInterface
- func (price *Price) SetTime(timeUtc string) PriceInterface
- func (price *Price) SetVolume(volume string) PriceInterface
- func (price *Price) Time() string
- func (price *Price) TimeCarbon() *carbon.Carbon
- func (price *Price) Volume() string
- func (price *Price) VolumeFloat() float64
- type PriceInterface
- type PriceQueryInterface
- type Store
- func (store *Store) AutoMigrateInstruments(ctx context.Context) error
- func (store *Store) AutoMigratePrices(ctx context.Context) error
- func (st *Store) DB() *sql.DB
- func (st *Store) EnableDebug(debug bool)
- func (store *Store) InstrumentCount(ctx context.Context, options InstrumentQueryInterface) (int64, error)
- func (store *Store) InstrumentCreate(ctx context.Context, instrument InstrumentInterface) error
- func (store *Store) InstrumentDelete(ctx context.Context, instrument InstrumentInterface) error
- func (store *Store) InstrumentDeleteByID(ctx context.Context, id string) error
- func (store *Store) InstrumentExists(ctx context.Context, options InstrumentQueryInterface) (bool, error)
- func (store *Store) InstrumentFindByID(ctx context.Context, id string) (InstrumentInterface, error)
- func (store *Store) InstrumentList(ctx context.Context, options InstrumentQueryInterface) ([]InstrumentInterface, error)
- func (store *Store) InstrumentSoftDelete(ctx context.Context, instrument InstrumentInterface) error
- func (store *Store) InstrumentSoftDeleteByID(ctx context.Context, id string) error
- func (store *Store) InstrumentUpdate(ctx context.Context, instrument InstrumentInterface) error
- func (store *Store) PriceCount(ctx context.Context, symbol string, exchange string, timeframe string, ...) (int64, error)
- func (store *Store) PriceCreate(ctx context.Context, symbol string, exchange string, timeframe string, ...) error
- func (store *Store) PriceDelete(ctx context.Context, symbol string, exchange string, timeframe string, ...) error
- func (store *Store) PriceDeleteByID(ctx context.Context, symbol string, exchange string, timeframe string, ...) error
- func (store *Store) PriceExists(ctx context.Context, symbol string, exchange string, timeframe string, ...) (bool, error)
- func (store *Store) PriceFindByID(ctx context.Context, symbol string, exchange string, timeframe string, ...) (PriceInterface, error)
- func (store *Store) PriceList(ctx context.Context, symbol string, exchange string, timeframe string, ...) ([]PriceInterface, error)
- func (store *Store) PriceTableName(symbol string, exchange string, timeframe string) string
- func (store *Store) PriceUpdate(ctx context.Context, symbol string, exchange string, timeframe string, ...) error
- type StoreInterface
Constants ¶
const ASSET_CLASS_BOND = "BOND"
Asset Class (from https://en.wikipedia.org/wiki/Asset_classes)
const ASSET_CLASS_COMMODITY = "COMMODITY" // Commodities, such as gold, oil, and agricultural products
const ASSET_CLASS_CRYPTO = "CRYPTO" // Cryptocurrency
const ASSET_CLASS_CURRENCY = "CURRENCY" // Currencies
const ASSET_CLASS_DERIVATIVE = "DERIVATIVE" // Derivatives
const ASSET_CLASS_ETF = "ETF" // Exchange Traded Funds
const ASSET_CLASS_FOREX = "FOREX" // Foreign Exchange
const ASSET_CLASS_FUTURE = "FUTURE" // Futures
const ASSET_CLASS_INDEX = "INDEX" // Index
const ASSET_CLASS_OPTION = "OPTION" // Options
const ASSET_CLASS_REIT = "REIT" // Real Estate Investment Trust
const ASSET_CLASS_STOCK = "STOCK" // Stocks
const ASSET_CLASS_UNKNOWN = "UNKNOWN" // Unknown
const COLUMN_ASSET_CLASS = "asset_class"
Column names
const COLUMN_CLOSE = "close"
const COLUMN_CREATED_AT = "created_at"
const COLUMN_DESCRIPTION = "description"
const COLUMN_EXCHANGE = "exchange"
const COLUMN_HIGH = "high"
const COLUMN_ID = "id"
const COLUMN_LOW = "low"
const COLUMN_MEMO = "memo"
const COLUMN_METAS = "metas"
const COLUMN_NAME = "name"
const COLUMN_OPEN = "open"
const COLUMN_SOFT_DELETED_AT = "soft_deleted_at"
const COLUMN_STATUS = "status"
const COLUMN_SYMBOL = "symbol"
const COLUMN_TIME = "time"
const COLUMN_TIMEFRAMES = "timeframes"
const COLUMN_UPDATED_AT = "updated_at"
const COLUMN_VOLUME = "volume"
const INSTRUMENT_STATUS_ACTIVE = "active"
const INSTRUMENT_STATUS_DISABLED = "disabled"
const INSTRUMENT_STATUS_DRAFT = "draft"
Instrument Status
const INSTRUMENT_STATUS_INACTIVE = "inactive"
const NIL_FLOAT = -0.0000000001
Nil float
const TIMEFRAME_15_MINUTES = "15min"
const TIMEFRAME_1_DAY = "1day"
const TIMEFRAME_1_HOUR = "1hour"
const TIMEFRAME_1_MINUTE = "1min"
Timeframe
const TIMEFRAME_1_MONTH = "1month"
const TIMEFRAME_1_WEEK = "1week"
const TIMEFRAME_1_YEAR = "1year"
const TIMEFRAME_30_MINUTES = "30min"
const TIMEFRAME_4_HOURS = "4hour"
const TIMEFRAME_5_MINUTES = "5min"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type InstrumentInterface ¶
type InstrumentInterface interface {
// from dataobject
Data() map[string]string
DataChanged() map[string]string
MarkAsNotDirty()
AssetClass() string
SetAssetClass(assetClass string) InstrumentInterface
Exchange() string
SetExchange(exchange string) InstrumentInterface
Description() string
SetDescription(description string) InstrumentInterface
ID() string
SetID(id string) InstrumentInterface
Meta(key string) (string, error)
SetMeta(key string, value string) error
DeleteMeta(key string) error
Metas() (map[string]string, error)
SetMetas(metas map[string]string) error
Memo() string
SetMemo(memo string) InstrumentInterface
Name() string
SetName(name string) InstrumentInterface
Status() string
SetStatus(status string) InstrumentInterface
Symbol() string
SetSymbol(symbol string) InstrumentInterface
Timeframes() []string
SetTimeframes(timeframes []string) InstrumentInterface
CreatedAt() string
CreatedAtCarbon() *carbon.Carbon
SetCreatedAt(createdAt string) InstrumentInterface
UpdatedAt() string
UpdatedAtCarbon() *carbon.Carbon
SetUpdatedAt(updatedAt string) InstrumentInterface
SoftDeletedAt() string
SoftDeletedAtCarbon() *carbon.Carbon
SetSoftDeletedAt(softDeletedAt string) InstrumentInterface
}
func NewInstrument ¶
func NewInstrument() InstrumentInterface
func NewInstrumentFromExistingData ¶
func NewInstrumentFromExistingData(data map[string]string) InstrumentInterface
type InstrumentQueryInterface ¶
type InstrumentQueryInterface interface {
// Validation
Validate() error
// Asset Class
SetAssetClass(assetClass string) InstrumentQueryInterface
IsAssetClassSet() bool
AssetClass() string
// Exchange
IsExchangeSet() bool
Exchange() string
SetExchange(exchange string) InstrumentQueryInterface
// Columns
IsColumnsSet() bool
Columns() []string
SetColumns(columns []string) InstrumentQueryInterface
// Count Only
SetCountOnly(countOnly bool) InstrumentQueryInterface
IsCountOnly() bool
// ID
SetID(id string) InstrumentQueryInterface
IsIDSet() bool
ID() string
SetIDIn(ids []string) InstrumentQueryInterface
IsIDInSet() bool
IDIn() []string
// Limit
IsLimitSet() bool
Limit() int
SetLimit(limit int) InstrumentQueryInterface
// Offset
IsOffsetSet() bool
Offset() int
SetOffset(offset int) InstrumentQueryInterface
// Order By
IsOrderBySet() bool
OrderBy() string
SetOrderBy(orderBy string) InstrumentQueryInterface
// Order Direction
IsOrderDirectionSet() bool
OrderDirection() string
SetOrderDirection(orderDirection string) InstrumentQueryInterface
// Status
SetStatus(status string) InstrumentQueryInterface
IsStatusSet() bool
Status() string
// Symbol
IsSymbolSet() bool
Symbol() string
SetSymbol(symbol string) InstrumentQueryInterface
// Symbol Like
IsSymbolLikeSet() bool
SymbolLike() string
SetSymbolLike(symbolLike string) InstrumentQueryInterface
}
func InstrumentQuery ¶
func InstrumentQuery() InstrumentQueryInterface
InstrumentQuery is a shortcut to create a new instrument query
func NewInstrumentQuery ¶
func NewInstrumentQuery() InstrumentQueryInterface
NewInstrumentQuery creates a new instrument query
type NewStoreOptions ¶
type NewStoreOptions struct {
// PriceTableNamePrefix is the prefix of the price table
PriceTableNamePrefix string
// InstrumentTableName is the name of the instrument table
InstrumentTableName string
// UseMultipleExchanges is used to create a new price table for each exchange
// if false, the price table will be created without the exchange name as the table name (i.e. price_btc_usdt)
// if true, the price table will be created with the exchange name as the table name (i.e. price_btc_binance_usdt)
UseMultipleExchanges bool
// DB is the underlying database connection
DB *sql.DB
// DbDriverName is the name of the database driver
DbDriverName string
// AutomigrateEnabled is used to auto migrate the instrument table
// Note: You will need to call AutoMigratePrices after creating a new instrument
AutomigrateEnabled bool
// DebugEnabled is used to enable debug mode
DebugEnabled bool
}
NewStoreOptions define the options for creating a new tradingstore
type Price ¶
type Price struct {
dataobject.DataObject
}
Price represents an OHLCV data object, for storing the pricing data in the database
func (*Price) CloseFloat ¶
func (*Price) SetClose ¶
func (price *Price) SetClose(close string) PriceInterface
func (*Price) SetHigh ¶
func (price *Price) SetHigh(high string) PriceInterface
func (*Price) SetID ¶
func (price *Price) SetID(id string) PriceInterface
func (*Price) SetLow ¶
func (price *Price) SetLow(low string) PriceInterface
func (*Price) SetOpen ¶
func (price *Price) SetOpen(open string) PriceInterface
func (*Price) SetTime ¶
func (price *Price) SetTime(timeUtc string) PriceInterface
SetTime sets the time for a Price, must be in UTC. The time is stored as an ISO8601 formatted string.
Parameters: - timeUtc: time in UTC format
Returns: - *Price: the Price
func (*Price) SetVolume ¶
func (price *Price) SetVolume(volume string) PriceInterface
func (*Price) Time ¶
Time returns the time as a Iso8601 formatted string.
Parameters: - none
Returns: - string: the time in ISO8601 format
func (*Price) TimeCarbon ¶
func (*Price) VolumeFloat ¶
type PriceInterface ¶
type PriceInterface interface {
Data() map[string]string
DataChanged() map[string]string
MarkAsNotDirty()
// setters and getters
ID() string
SetID(id string) PriceInterface
Close() string
CloseFloat() float64
SetClose(close string) PriceInterface
High() string
HighFloat() float64
SetHigh(high string) PriceInterface
Low() string
LowFloat() float64
SetLow(low string) PriceInterface
Open() string
OpenFloat() float64
SetOpen(open string) PriceInterface
Time() string
TimeCarbon() *carbon.Carbon
SetTime(time string) PriceInterface
Volume() string
VolumeFloat() float64
SetVolume(volume string) PriceInterface
}
func NewPrice ¶
func NewPrice() PriceInterface
func NewPriceFromExistingData ¶
func NewPriceFromExistingData(data map[string]string) PriceInterface
type PriceQueryInterface ¶
type PriceQueryInterface interface {
Validate() error
IsColumnsSet() bool
Columns() []string
SetColumns(columns []string) PriceQueryInterface
IsCountOnlySet() bool
IsCountOnly() bool
SetCountOnly(countOnly bool) PriceQueryInterface
IsTimeSet() bool
Time() string
SetTime(createdAt string) PriceQueryInterface
IsTimeGteSet() bool
TimeGte() string
SetTimeGte(createdAtGte string) PriceQueryInterface
IsTimeLteSet() bool
TimeLte() string
SetTimeLte(createdAtLte string) PriceQueryInterface
IsIDSet() bool
ID() string
SetID(id string) PriceQueryInterface
IsIDInSet() bool
IDIn() []string
SetIDIn(idIn []string) PriceQueryInterface
IsLimitSet() bool
Limit() int
SetLimit(limit int) PriceQueryInterface
IsOffsetSet() bool
Offset() int
SetOffset(offset int) PriceQueryInterface
IsOrderBySet() bool
OrderBy() string
SetOrderBy(orderBy string) PriceQueryInterface
IsOrderDirectionSet() bool
OrderDirection() string
SetOrderDirection(orderDirection string) PriceQueryInterface
// contains filtered or unexported methods
}
func NewPriceQuery ¶
func NewPriceQuery() PriceQueryInterface
NewPriceQuery creates a new price query
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) AutoMigrateInstruments ¶
AutoMigrateInstruments auto migrates the instrument table
func (*Store) AutoMigratePrices ¶
AutoMigratePrices auto migrates the price tables It will create a price table for each instrument and each timeframe You will need to call this method when you create a new instrument
func (*Store) EnableDebug ¶
EnableDebug - enables the debug option
func (*Store) InstrumentCount ¶
func (store *Store) InstrumentCount(ctx context.Context, options InstrumentQueryInterface) (int64, error)
InstrumentCount returns the number of instruments based on the given query options
func (*Store) InstrumentCreate ¶
func (store *Store) InstrumentCreate(ctx context.Context, instrument InstrumentInterface) error
InstrumentCreate creates a new instrument
func (*Store) InstrumentDelete ¶
func (store *Store) InstrumentDelete(ctx context.Context, instrument InstrumentInterface) error
InstrumentDelete deletes an instrument
func (*Store) InstrumentDeleteByID ¶
InstrumentDeleteByID deletes an instrument by its ID
func (*Store) InstrumentExists ¶
func (store *Store) InstrumentExists(ctx context.Context, options InstrumentQueryInterface) (bool, error)
InstrumentExists returns true if an instrument exists based on the given query options
func (*Store) InstrumentFindByID ¶
InstrumentFindByID returns an instrument by its ID
func (*Store) InstrumentList ¶
func (store *Store) InstrumentList(ctx context.Context, options InstrumentQueryInterface) ([]InstrumentInterface, error)
InstrumentList returns a list of instruments based on the given query options
func (*Store) InstrumentSoftDelete ¶ added in v0.5.0
func (store *Store) InstrumentSoftDelete(ctx context.Context, instrument InstrumentInterface) error
InstrumentSoftDelete soft deletes an instrument
func (*Store) InstrumentSoftDeleteByID ¶ added in v0.5.0
InstrumentSoftDeleteByID soft deletes an instrument by ID
func (*Store) InstrumentUpdate ¶
func (store *Store) InstrumentUpdate(ctx context.Context, instrument InstrumentInterface) error
InstrumentUpdate updates an instrument
func (*Store) PriceCount ¶
func (store *Store) PriceCount(ctx context.Context, symbol string, exchange string, timeframe string, options PriceQueryInterface) (int64, error)
PriceCount returns the number of prices based on the given query options
func (*Store) PriceCreate ¶
func (store *Store) PriceCreate(ctx context.Context, symbol string, exchange string, timeframe string, price PriceInterface) error
PriceCreate creates a new price
func (*Store) PriceDelete ¶
func (store *Store) PriceDelete(ctx context.Context, symbol string, exchange string, timeframe string, price PriceInterface) error
PriceDelete deletes a price
func (*Store) PriceDeleteByID ¶
func (store *Store) PriceDeleteByID(ctx context.Context, symbol string, exchange string, timeframe string, id string) error
PriceDeleteByID deletes a price by its ID
func (*Store) PriceExists ¶
func (store *Store) PriceExists(ctx context.Context, symbol string, exchange string, timeframe string, options PriceQueryInterface) (bool, error)
PriceExists returns true if a price exists based on the given query options
func (*Store) PriceFindByID ¶
func (store *Store) PriceFindByID(ctx context.Context, symbol string, exchange string, timeframe string, priceID string) (PriceInterface, error)
PriceFindByID returns a price by its ID
func (*Store) PriceList ¶
func (store *Store) PriceList(ctx context.Context, symbol string, exchange string, timeframe string, options PriceQueryInterface) ([]PriceInterface, error)
PriceList returns a list of prices based on the given query options
func (*Store) PriceTableName ¶
func (*Store) PriceUpdate ¶
type StoreInterface ¶
type StoreInterface interface {
// AutoMigrateInstruments automatically creates the schema if it does not exist
AutoMigrateInstruments(ctx context.Context) error
// AutoMigratePrices automatically creates the price tables if they do not exist
// It will create a price table for each instrument and each timeframe
// You will need to call this method when you create a new instrument
AutoMigratePrices(ctx context.Context) error
// DB returns the underlying sql.DB connection
DB() *sql.DB
// EnableDebug enables debug mode
EnableDebug(bool)
// InstrumentCount returns the number of instruments that match the criteria
InstrumentCount(ctx context.Context, options InstrumentQueryInterface) (int64, error)
// InstrumentCreate creates a new instrument in the database
InstrumentCreate(ctx context.Context, instrument InstrumentInterface) error
// InstrumentDelete deletes an instrument
InstrumentDelete(ctx context.Context, instrument InstrumentInterface) error
// InstrumentDeleteByID deletes an instrument by ID
InstrumentDeleteByID(ctx context.Context, id string) error
// InstrumentExists checks if an instrument exists by checking a number of criteria
InstrumentExists(ctx context.Context, options InstrumentQueryInterface) (bool, error)
// InstrumentFindByID finds an instrument by its ID
InstrumentFindByID(ctx context.Context, id string) (InstrumentInterface, error)
// InstrumentList returns a list of instruments from the database based on criteria
InstrumentList(ctx context.Context, options InstrumentQueryInterface) ([]InstrumentInterface, error)
// InstrumentSoftDelete soft deletes an instrument
InstrumentSoftDelete(ctx context.Context, instrument InstrumentInterface) error
// InstrumentSoftDeleteByID soft deletes an instrument by ID
InstrumentSoftDeleteByID(ctx context.Context, id string) error
// InstrumentUpdate updates an instrument
InstrumentUpdate(ctx context.Context, instrument InstrumentInterface) error
// PriceCount returns the number of prices that match the criteria
PriceCount(ctx context.Context, symbol string, exchange string, timeframe string, options PriceQueryInterface) (int64, error)
// PriceCreate creates a new price in the database
PriceCreate(ctx context.Context, symbol string, exchange string, timeframe string, price PriceInterface) error
// PriceDelete deletes a price
PriceDelete(ctx context.Context, symbol string, exchange string, timeframe string, price PriceInterface) error
// PriceDeleteByID deletes a price by ID
PriceDeleteByID(ctx context.Context, symbol string, exchange string, timeframe string, priceID string) error
// PriceExists checks if a price exists by checking a number of criteria
PriceExists(ctx context.Context, symbol string, exchange string, timeframe string, options PriceQueryInterface) (bool, error)
// PriceFindByID finds a price by its ID
PriceFindByID(ctx context.Context, symbol string, exchange string, timeframe string, priceID string) (PriceInterface, error)
// PriceList returns a list of prices from the database based on criteria
PriceList(ctx context.Context, symbol string, exchange string, timeframe string, options PriceQueryInterface) ([]PriceInterface, error)
// PriceUpdate updates a price
PriceUpdate(ctx context.Context, symbol string, exchange string, timeframe string, price PriceInterface) error
}
StoreInterface defines the interface for a store
func NewStore ¶
func NewStore(opts NewStoreOptions) (StoreInterface, error)
NewStore creates a new trading store