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) 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_CURRENCY = "CURRENCY"
const ASSET_CLASS_ETF = "ETF"
const ASSET_CLASS_INDEX = "INDEX"
const ASSET_CLASS_REIT = "REIT"
const ASSET_CLASS_STOCK = "STOCK"
const ASSET_CLASS_UNKNOWN = "UNKNOWN"
const COLUMN_ASSET_CLASS = "asset_class"
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_OPEN = "open"
const COLUMN_SOFT_DELETED_AT = "soft_deleted_at"
const COLUMN_SYMBOL = "symbol"
const COLUMN_TIME = "time"
const COLUMN_TIMEFRAMES = "timeframes"
const COLUMN_UPDATED_AT = "updated_at"
const COLUMN_VOLUME = "volume"
const NIL_FLOAT = -0.0000000001
const TIMEFRAME_15_MINUTES = "15min"
const TIMEFRAME_1_DAY = "1day"
const TIMEFRAME_1_HOUR = "1hour"
const TIMEFRAME_1_MINUTE = "1min"
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()
// setters and getters
AssetClass() string
SetAssetClass(assetClass string) InstrumentInterface
Exchange() string
SetExchange(exchange string) InstrumentInterface
Description() string
SetDescription(description string) InstrumentInterface
ID() string
SetID(id string) InstrumentInterface
Symbol() string
SetSymbol(symbol string) InstrumentInterface
Timeframes() []string
SetTimeframes(timeframes []string) InstrumentInterface
}
func NewInstrument ¶
func NewInstrument() InstrumentInterface
func NewInstrumentFromExistingData ¶
func NewInstrumentFromExistingData(data map[string]string) InstrumentInterface
type InstrumentQueryInterface ¶
type InstrumentQueryInterface interface {
// Validation
Validate() error
// Columns
Columns() []string
// Options
SetCountOnly(countOnly bool) InstrumentQueryInterface
IsCountOnly() bool
// Limit, Offset
SetLimit(limit int) InstrumentQueryInterface
HasLimit() bool
Limit() int
SetOffset(offset int) InstrumentQueryInterface
HasOffset() bool
Offset() int
// Order By
SetOrderBy(orderBy string) InstrumentQueryInterface
HasOrderBy() bool
OrderBy() string
SetSortDirection(sortDirection string) InstrumentQueryInterface
HasSortDirection() bool
SortDirection() string
// ID
SetID(id string) InstrumentQueryInterface
HasID() bool
ID() string
SetIDIn(ids []string) InstrumentQueryInterface
HasIDIn() bool
IDIn() []string
// Symbol
SetSymbol(symbol string) InstrumentQueryInterface
HasSymbol() bool
Symbol() string
SetSymbolLike(symbolLike string) InstrumentQueryInterface
HasSymbolLike() bool
SymbolLike() string
// Exchange
SetExchange(exchange string) InstrumentQueryInterface
HasExchange() bool
Exchange() string
// Asset Class
SetAssetClass(assetClass string) InstrumentQueryInterface
HasAssetClass() bool
AssetClass() string
}
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 ¶ added in v0.3.0
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 ¶ added in v0.3.0
Time returns the time as a Iso8601 formatted string.
Parameters: - none
Returns: - string: the time in ISO8601 format
func (*Price) TimeCarbon ¶ added in v0.3.0
func (*Price) VolumeFloat ¶ added in v0.3.0
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
Columns() []string
SetColumns(columns []string) PriceQueryInterface
HasCountOnly() bool
IsCountOnly() bool
SetCountOnly(countOnly bool) PriceQueryInterface
HasTime() bool
Time() string
SetTime(createdAt string) PriceQueryInterface
HasTimeGte() bool
TimeGte() string
SetTimeGte(createdAtGte string) PriceQueryInterface
HasTimeLte() bool
TimeLte() string
SetTimeLte(createdAtLte string) PriceQueryInterface
HasID() bool
ID() string
SetID(id string) PriceQueryInterface
HasIDIn() bool
IDIn() []string
SetIDIn(idIn []string) PriceQueryInterface
HasLimit() bool
Limit() int
SetLimit(limit int) PriceQueryInterface
HasOffset() bool
Offset() int
SetOffset(offset int) PriceQueryInterface
HasOrderBy() bool
OrderBy() string
SetOrderBy(orderBy string) PriceQueryInterface
HasSortDirection() bool
SortDirection() string
SetSortDirection(sortDirection 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 ¶ added in v0.3.0
AutoMigrateInstruments auto migrates the instrument table
func (*Store) AutoMigratePrices ¶ added in v0.3.0
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) 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 ¶ added in v0.3.0
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)
// 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