Documentation ¶
Index ¶
- Constants
- Variables
- func CalculatePriceWithSlippage(source rand.Source, price, orderSlippage float64) float64
- func CandlestickBucket(t time.Time, tickSizeMinutes int64) time.Time
- func FloatDiff(a, b []float64) []float64
- func PostDataSlackMessage(text string, params ...slack.PostMessageParameters)
- func PostStrategyDataToSlack(strategy StrategyInterface, ts *TradingStrategyModel, ...)
- func PostTradesSlackMessage(text string, params ...slack.PostMessageParameters)
- func SMA(period uint, values []float64, index uint) float64
- func TruncateFloat(f float64, precision uint) float64
- func ValidateCandlesticks(candles []*CandlestickModel, tickSizeMinutes int64) error
- func ValidateIndicatorSets(historyTicks, currentTick int, indicatorSets []*IndicatorSet) error
- type Backend
- type BacktestResults
- type Backtester
- type BacktesterBackend
- func (b *BacktesterBackend) CreateMarketOrder(m *MarketOrderModel) error
- func (b *BacktesterBackend) FindCandlesticks(startTime, endTime time.Time, p Product, tickSizeMinutes int64) ([]*CandlestickModel, error)
- func (b *BacktesterBackend) UpdateTradingStrategy(m *TradingStrategyModel) error
- func (b *BacktesterBackend) UpsertCandlestick(*CandlestickModel) error
- type BacktesterExchange
- func (b *BacktesterExchange) CreateMarketOrder(m *MarketOrder) (*CreateMarketOrderResponse, error)
- func (k *BacktesterExchange) EmitsFullCandlesticks() bool
- func (b *BacktesterExchange) GetCandlesticks(p Product, start time.Time, end time.Time, granularity int) ([]*CandlestickModel, error)
- func (b *BacktesterExchange) GetMessageChan(context.Context, Product) (<-chan *ExchangeMessage, error)
- func (b *BacktesterExchange) NextTick()
- func (b *BacktesterExchange) StreamCandlesticks(ctx context.Context, product Product) (<-chan *CandlestickModel, error)
- type BacktesterGenome
- type BacktesterGenomeFactory
- type Bot
- type CacheingBackend
- type CandlestickBuilder
- type CandlestickDirection
- type CandlestickModel
- type CodeMigrations
- func (c *CodeMigrations) AddMigration(m *Migration)
- func (c *CodeMigrations) Close() error
- func (c *CodeMigrations) First() (version uint, err error)
- func (c *CodeMigrations) Next(version uint) (nextVersion uint, err error)
- func (c *CodeMigrations) Open(url string) (source.Driver, error)
- func (c *CodeMigrations) Prev(version uint) (prevVersion uint, err error)
- func (c *CodeMigrations) ReadDown(version uint) (io.ReadCloser, string, error)
- func (c *CodeMigrations) ReadUp(version uint) (io.ReadCloser, string, error)
- type CreateMarketOrderResponse
- type DBConn
- func (d *DBConn) CreateMarketOrder(m *MarketOrderModel) error
- func (d *DBConn) CreateTradingStrategy(m *TradingStrategyModel) error
- func (d *DBConn) FindActiveTradingStrategies(p Product) ([]*TradingStrategyModel, error)
- func (d *DBConn) FindCandlestickByID(id int64) (*CandlestickModel, error)
- func (d *DBConn) FindCandlesticks(startTime, endTime time.Time, product Product, tickSizeMinutes int64) ([]*CandlestickModel, error)
- func (d *DBConn) FindMarketOrderByID(id int64) (*MarketOrderModel, error)
- func (d *DBConn) FindMostRecentCandlestick(p Product) (*CandlestickModel, error)
- func (d *DBConn) FindTradingStrategyByID(id int64) (*TradingStrategyModel, error)
- func (d *DBConn) UpdateTradingStrategy(m *TradingStrategyModel) error
- func (d *DBConn) UpsertCandlestick(c *CandlestickModel) error
- type DEMAIndicator
- type EMACrossoverStrategy
- func (e *EMACrossoverStrategy) Buy(history []*IndicatorSet, current int) (bool, error)
- func (e *EMACrossoverStrategy) Clone() StrategyGenome
- func (e *EMACrossoverStrategy) Crossover(m StrategyGenome, r *rand.Rand) (StrategyGenome, StrategyGenome)
- func (e *EMACrossoverStrategy) Indicators() []Indicator
- func (e *EMACrossoverStrategy) Mutate(rng *rand.Rand)
- func (e *EMACrossoverStrategy) Rand(rng *rand.Rand)
- func (e *EMACrossoverStrategy) Sell(history []*IndicatorSet, current int) (bool, error)
- func (e *EMACrossoverStrategy) SetTradingStrategy(t *TradingStrategyModel)
- func (e *EMACrossoverStrategy) String() string
- type EMAIndicator
- type Exchange
- type ExchangeMessage
- type ExchangeMessageType
- type ExchangeType
- type FakeGDAXExchange
- type FakeKrakenExchange
- type GDAXClient
- type GDAXExchange
- func (g *GDAXExchange) CreateMarketOrder(args *MarketOrder) (*CreateMarketOrderResponse, error)
- func (k *GDAXExchange) EmitsFullCandlesticks() bool
- func (g *GDAXExchange) GetCandlesticks(product Product, start, end time.Time, granularitySeconds int) ([]*CandlestickModel, error)
- func (g *GDAXExchange) GetMessageChan(ctx context.Context, product Product) (<-chan *ExchangeMessage, error)
- func (g *GDAXExchange) StreamCandlesticks(ctx context.Context, product Product) (<-chan *CandlestickModel, error)
- type HistoricalImporter
- type Indicator
- type IndicatorSet
- type IndicatorValue
- type KrakenClient
- type KrakenExchange
- func (k *KrakenExchange) CreateMarketOrder(*MarketOrder) (*CreateMarketOrderResponse, error)
- func (k *KrakenExchange) EmitsFullCandlesticks() bool
- func (k *KrakenExchange) GetCandlesticks(product Product, start time.Time, end time.Time, granularity int) ([]*CandlestickModel, error)
- func (k *KrakenExchange) GetMessageChan(ctx context.Context, product Product) (<-chan *ExchangeMessage, error)
- func (k *KrakenExchange) StreamCandlesticks(ctx context.Context, product Product) (<-chan *CandlestickModel, error)
- type MACDIndicator
- type MACDWithSignal
- type MarketOrder
- type MarketOrderModel
- type MarketOrderStrategy
- type Migration
- type OrderStrategy
- type PerformOrderArgs
- type PerformOrderResponse
- type Product
- type ProductMetadata
- type RSIIndicator
- type RSIStrategy
- func (e *RSIStrategy) Buy(history []*IndicatorSet, current int) (bool, error)
- func (e *RSIStrategy) Clone() StrategyGenome
- func (e *RSIStrategy) Crossover(m StrategyGenome, r *rand.Rand) (StrategyGenome, StrategyGenome)
- func (e *RSIStrategy) Indicators() []Indicator
- func (e *RSIStrategy) Mutate(rng *rand.Rand)
- func (e *RSIStrategy) Rand(rng *rand.Rand)
- func (e *RSIStrategy) Sell(history []*IndicatorSet, current int) (bool, error)
- func (e *RSIStrategy) SetTradingStrategy(t *TradingStrategyModel)
- func (e *RSIStrategy) String() string
- type RealtimeImporter
- func (i *RealtimeImporter) Flush()
- func (i *RealtimeImporter) ProcessExchangeMessage(msg *ExchangeMessage)
- func (i *RealtimeImporter) Start(flushInterval time.Duration)
- func (i *RealtimeImporter) StartProcessingCandlesticks()
- func (i *RealtimeImporter) StartProcessingMessages(flushInterval time.Duration)
- type Runner
- type S1Strategy
- func (s *S1Strategy) Buy(history []*IndicatorSet, current int) (bool, error)
- func (s *S1Strategy) Clone() StrategyGenome
- func (s *S1Strategy) Crossover(m StrategyGenome, r *rand.Rand) (StrategyGenome, StrategyGenome)
- func (s *S1Strategy) Indicators() []Indicator
- func (s *S1Strategy) Mutate(rng *rand.Rand)
- func (s *S1Strategy) Rand(rng *rand.Rand)
- func (s *S1Strategy) Sell(history []*IndicatorSet, current int) (bool, error)
- func (s *S1Strategy) SetTradingStrategy(t *TradingStrategyModel)
- func (s *S1Strategy) String() string
- type SlackNotifier
- type StrategyGenome
- type StrategyInterface
- type TradingStrategy
- func (t *TradingStrategy) LastCandlestickTime() time.Time
- func (t *TradingStrategy) ProcessTick(m *TradingStrategyModel) error
- func (t *TradingStrategy) SeedIndicators(c *CandlestickModel) error
- func (t *TradingStrategy) TryBuy(m *TradingStrategyModel) error
- func (t *TradingStrategy) TrySell(m *TradingStrategyModel) error
- type TradingStrategyModel
- func (m *TradingStrategyModel) BeforeInsert(db orm.DB) error
- func (m *TradingStrategyModel) BeforeUpdate(db orm.DB) error
- func (t *TradingStrategyModel) Copy() *TradingStrategyModel
- func (t *TradingStrategyModel) SetStrategy(s StrategyInterface) error
- func (t *TradingStrategyModel) Strategy() (StrategyInterface, error)
Constants ¶
const ( ExchangeGDAX ExchangeType = "gdax" ExchangeKraken ExchangeType = "kraken" // ProductBTCUSD refers to a Bitcoin trading product with // units in Dollars. ProductBTCUSD Product = "BTC-USD" // ProductETHUSD refers to an Ethereum trading product with // units in Dollars. ProductETHUSD Product = "ETH-USD" // ProductLTCUSD refers to an Litecoin trading product with // units in Dollars. ProductLTCUSD Product = "LTC-USD" ProductXMRUSD Product = "XMR-USD" ProductBCHUSD Product = "BCH-USD" ProductDashUSD Product = "DASH-USD" ProductZcashUSD Product = "ZEC-USD" ProductXRPUSD Product = "XRP-USD" // CurrencyUSD refers to US dollars. CurrencyUSD = "USD" // CurrencyBTC refers to Bitcoin. CurrencyBTC = "BTC" // CurrencyETH is the Ethereum currency. CurrencyETH = "ETH" // CurrencyLTC is the Litecoin currency. CurrencyLTC = "LTC" // CurrencyXMR is the Monero currency. CurrencyXMR = "XMR" // CurrencyBCH is the Bitcoin Cash currency. CurrencyBCH = "BCH" // CurrencyDash is the Dash currency. CurrencyDash = "DASH" // CurrencyZcash is the Zcash currency. CurrencyZcash = "ZEC" // CurrencyXRP is the Ripple currency. CurrencyXRP = "XRP" // CurrencyETC is the Ethereum Classic currency. CurrencyETC = "ETC" // MessageMatch is an exchange message that refers to a match // between a buy and sell order. MessageMatch ExchangeMessageType = "match" // CandlestickDirectionUp refers to a candlestick that points // up. CandlestickDirectionUp CandlestickDirection = "up" // CandlestickDirectionDown refers to a candlestick that points // down. CandlestickDirectionDown CandlestickDirection = "down" // OrderBuy indicates a buy position on an order. OrderBuy = "buy" // OrderSell indicates a sell position on an order. OrderSell = "sell" )
const ( // StrategyStateTryingToBuy is the state for when the strategy // is trying to find the right price point in order to buy. StrategyStateTryingToBuy = "trying-to-buy" // StrategyStateTryingToSell is the state for when the // strategy is trying to find the right time to sell. StrategyStateTryingToSell = "trying-to-sell" // IndicatorEMA refers to the exponential moving average // indicator. IndicatorEMA = "ema" // IndicatorDEMA refers to the EMA difference indicator. IndicatorDEMA = "dema" // IndicatorRSI refers to the RSI indicator. IndicatorRSI = "rsi" // IndicatorMACD refers to the MACD indicator. IndicatorMACD = "macd" // IndicatorMACDWithSignal refers to the MACD with signal // indicator. IndicatorMACDWithSignal = "macd-with-signal" // TradingStrategyEMACrossover is a trading strategy that buys // and sells using EMA crossovers. TradingStrategyEMACrossover = "ema-crossover" // TradingStrategyRSI is a trading strategy that buys and // sells based on RSI values. TradingStrategyRSI = "rsi" // TradingStrategyS1 is the first proprietary Vespyr trading // strategy. TradingStrategyS1 = "s1" )
Variables ¶
var ( // ErrMissingCandlestick is returned when a candlestick is missing from a set ErrMissingCandlestick = errors.New("error: a candlestick is missing") )
var ( // ErrNotEnoughData is returned when there isn't enough data. ErrNotEnoughData = errors.New("error: not enough data") )
var ProductToMetadata = map[Product]*ProductMetadata{ ProductBTCUSD: &ProductMetadata{ ExchangeType: ExchangeGDAX, MarketOrderBuyCurrency: CurrencyUSD, MarketOrderSellCurrency: CurrencyBTC, MarketOrderFeesCurrency: CurrencyUSD, }, ProductETHUSD: &ProductMetadata{ ExchangeType: ExchangeGDAX, MarketOrderBuyCurrency: CurrencyUSD, MarketOrderSellCurrency: CurrencyETH, MarketOrderFeesCurrency: CurrencyUSD, }, ProductLTCUSD: &ProductMetadata{ ExchangeType: ExchangeGDAX, MarketOrderBuyCurrency: CurrencyUSD, MarketOrderSellCurrency: CurrencyLTC, MarketOrderFeesCurrency: CurrencyUSD, }, ProductXMRUSD: &ProductMetadata{ ExchangeType: ExchangeKraken, MarketOrderBuyCurrency: CurrencyUSD, MarketOrderSellCurrency: CurrencyXMR, MarketOrderFeesCurrency: CurrencyUSD, }, ProductBCHUSD: &ProductMetadata{ ExchangeType: ExchangeKraken, MarketOrderBuyCurrency: CurrencyUSD, MarketOrderSellCurrency: CurrencyBCH, MarketOrderFeesCurrency: CurrencyUSD, }, ProductDashUSD: &ProductMetadata{ ExchangeType: ExchangeKraken, MarketOrderBuyCurrency: CurrencyUSD, MarketOrderSellCurrency: CurrencyDash, MarketOrderFeesCurrency: CurrencyUSD, }, ProductZcashUSD: &ProductMetadata{ ExchangeType: ExchangeKraken, MarketOrderBuyCurrency: CurrencyUSD, MarketOrderSellCurrency: CurrencyZcash, MarketOrderFeesCurrency: CurrencyUSD, }, ProductXRPUSD: &ProductMetadata{ ExchangeType: ExchangeKraken, MarketOrderBuyCurrency: CurrencyUSD, MarketOrderSellCurrency: CurrencyXRP, MarketOrderFeesCurrency: CurrencyUSD, }, }
ProductToMetadata is a singleton with metadata about each product.
var RootCmd = &cobra.Command{ Use: "vespyr", Short: "vespyr is a currency trading engine", Run: func(cmd *cobra.Command, args []string) { fmt.Println("Run `vespyr help` for more information.") }, }
RootCmd is the CLI interface to vespyr.
Functions ¶
func CalculatePriceWithSlippage ¶
CalculatePriceWithSlippage calculates a price taking into account slippage.
func CandlestickBucket ¶
CandlestickBucket returns the candlestick bucket based on the base time.
func PostDataSlackMessage ¶
func PostDataSlackMessage(text string, params ...slack.PostMessageParameters)
PostDataSlackMessage posts a Slack message to the configured channel.
func PostStrategyDataToSlack ¶
func PostStrategyDataToSlack(strategy StrategyInterface, ts *TradingStrategyModel, meta map[string]interface{})
PostStrategyDataToSlack posts information about a strategy's tick to Slack.
func PostTradesSlackMessage ¶
func PostTradesSlackMessage(text string, params ...slack.PostMessageParameters)
PostTradesSlackMessage posts a Slack message to the configured channel.
func TruncateFloat ¶
TruncateFloat truncates the float to the specified number of decimal places.
func ValidateCandlesticks ¶
func ValidateCandlesticks(candles []*CandlestickModel, tickSizeMinutes int64) error
ValidateCandlesticks ensures that the range of candlesticks is valid.
func ValidateIndicatorSets ¶
func ValidateIndicatorSets(historyTicks, currentTick int, indicatorSets []*IndicatorSet) error
ValidateIndicatorSets ensures that the data in the present indicator sets is good enough to process.
Types ¶
type Backend ¶
type Backend interface { // Candlesticks UpsertCandlestick(*CandlestickModel) error FindCandlesticks(time.Time, time.Time, Product, int64) ([]*CandlestickModel, error) FindMostRecentCandlestick(Product) (*CandlestickModel, error) FindCandlestickByID(int64) (*CandlestickModel, error) // Market orders CreateMarketOrder(*MarketOrderModel) error FindMarketOrderByID(int64) (*MarketOrderModel, error) // Trading strategies FindTradingStrategyByID(int64) (*TradingStrategyModel, error) CreateTradingStrategy(*TradingStrategyModel) error UpdateTradingStrategy(*TradingStrategyModel) error FindActiveTradingStrategies(Product) ([]*TradingStrategyModel, error) }
Backend is the interface to the database.
func NewCacheingBackend ¶
type BacktestResults ¶
type BacktestResults struct { BudgetCurrency string InitialBudget float64 FinalBudget float64 TradeCurrency string InitialCurrencyPrice float64 FinalCurrencyPrice float64 GrossProfit float64 GrossLoss float64 ProfitTrades uint LossTrades uint PortfolioValuePerDay []float64 }
BacktestResults contains information about the results of the backtest.
func (*BacktestResults) ExpectedPayoff ¶
func (b *BacktestResults) ExpectedPayoff() float64
func (*BacktestResults) NetProfit ¶
func (b *BacktestResults) NetProfit() float64
func (*BacktestResults) ProfitFactor ¶
func (b *BacktestResults) ProfitFactor() float64
func (*BacktestResults) SharpeRatio ¶
func (b *BacktestResults) SharpeRatio() float64
type Backtester ¶
type Backtester struct {
// contains filtered or unexported fields
}
Backtester backtests a trading algorithm with historical data.
func NewBacktester ¶
func NewBacktester(startTime, endTime time.Time, model *TradingStrategyModel, backend Backend, source rand.Source) (*Backtester, error)
NewBacktester creates a new Backtester.
func (*Backtester) Results ¶
func (b *Backtester) Results() *BacktestResults
Results returns the results of the backtest.
func (*Backtester) ResultsCSV ¶
func (b *Backtester) ResultsCSV() (io.Reader, error)
ResultsCSV returns a CSV with the granular details about the backtest
type BacktesterBackend ¶
type BacktesterBackend struct { Backend // contains filtered or unexported fields }
BacktesterBackend is a custom backend used specifically for backtesting that registers all model updates.
func (*BacktesterBackend) CreateMarketOrder ¶
func (b *BacktesterBackend) CreateMarketOrder(m *MarketOrderModel) error
CreateMarketOrder registers the market order as the current market order.
func (*BacktesterBackend) FindCandlesticks ¶
func (b *BacktesterBackend) FindCandlesticks(startTime, endTime time.Time, p Product, tickSizeMinutes int64) ([]*CandlestickModel, error)
FindCandlesticks passes the call over to the underlying backend.
func (*BacktesterBackend) UpdateTradingStrategy ¶
func (b *BacktesterBackend) UpdateTradingStrategy(m *TradingStrategyModel) error
UpdateTradingStrategy updates the trading strategy metadata.
func (*BacktesterBackend) UpsertCandlestick ¶
func (b *BacktesterBackend) UpsertCandlestick(*CandlestickModel) error
UpsertCandlestick is a noop.
type BacktesterExchange ¶
type BacktesterExchange struct {
// contains filtered or unexported fields
}
BacktesterExchange is a mock exchange that can perform mock trades.
func NewBacktesterExchange ¶
func NewBacktesterExchange(candles []*CandlestickModel, marketOrderSlippage float64, randSource rand.Source) *BacktesterExchange
NewBacktesterExchange instantiates a new backtester exchange.
func (*BacktesterExchange) CreateMarketOrder ¶
func (b *BacktesterExchange) CreateMarketOrder(m *MarketOrder) (*CreateMarketOrderResponse, error)
CreateMarketOrder creates a mock market order taking into account a slippage percentage.
func (*BacktesterExchange) EmitsFullCandlesticks ¶
func (k *BacktesterExchange) EmitsFullCandlesticks() bool
func (*BacktesterExchange) GetCandlesticks ¶
func (b *BacktesterExchange) GetCandlesticks(p Product, start time.Time, end time.Time, granularity int) ([]*CandlestickModel, error)
GetCandlesticks is a noop.
func (*BacktesterExchange) GetMessageChan ¶
func (b *BacktesterExchange) GetMessageChan(context.Context, Product) (<-chan *ExchangeMessage, error)
GetMessageChan is a noop.
func (*BacktesterExchange) NextTick ¶
func (b *BacktesterExchange) NextTick()
NextTick advances the exchange to the next candle.
func (*BacktesterExchange) StreamCandlesticks ¶
func (b *BacktesterExchange) StreamCandlesticks(ctx context.Context, product Product) (<-chan *CandlestickModel, error)
type BacktesterGenome ¶
type BacktesterGenome struct {
// contains filtered or unexported fields
}
BacktesterGenome wraps a StrategyGenome. BacktesterGenome evaluates a StrategyGenome in a backtest when it's evaluated.
func (*BacktesterGenome) Clone ¶
func (b *BacktesterGenome) Clone() gago.Genome
Clone clones the BacktesterGenome.
func (*BacktesterGenome) Crossover ¶
Crossover crosses over the underlying strategy with the passed in genomes.
func (*BacktesterGenome) Evaluate ¶
func (b *BacktesterGenome) Evaluate() float64
Evaluate runs a backtest and returns the score.
func (*BacktesterGenome) Mutate ¶
func (b *BacktesterGenome) Mutate(rng *rand.Rand)
Mutate mutates the underlying strategy.
type BacktesterGenomeFactory ¶
type BacktesterGenomeFactory struct {
// contains filtered or unexported fields
}
BacktesterGenomeFactory generates strategy genomes to be tested by gago.
func NewBacktesterGenomeFactory ¶
func NewBacktesterGenomeFactory(startTime, endTime time.Time, model *TradingStrategyModel, backend Backend) (*BacktesterGenomeFactory, error)
NewBacktesterGenomeFactory creates a new NewBacktesterGenomeFactory.
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
Bot is a type that runs automated trading strategies at each tick.
func NewBot ¶
func NewBot(tickCheckInterval time.Duration, clock clockwork.Clock, backend Backend, exchange Exchange, product Product) *Bot
NewBot returns a new instance of Bot.
func (*Bot) ProcessTick ¶
ProcessTick a tick, calling all strategies that have to run.
func (*Bot) ProcessTickForNewCandlestick ¶
ProcessTickForNewCandlestick processes the current tick is there's a new candlestick available.
type CacheingBackend ¶
func (*CacheingBackend) FindCandlesticks ¶
func (c *CacheingBackend) FindCandlesticks(s time.Time, e time.Time, p Product, t int64) ([]*CandlestickModel, error)
type CandlestickBuilder ¶
type CandlestickBuilder struct {
// contains filtered or unexported fields
}
CandlestickBuilder builds a candlestick from a stream of exchange messages.
func NewCandlestickBuilder ¶
func NewCandlestickBuilder(productType Product, start, end time.Time) *CandlestickBuilder
NewCandlestickBuilder returns a new CandlestickBuilder.
func (*CandlestickBuilder) Build ¶
func (c *CandlestickBuilder) Build() *CandlestickModel
Build returns a complete Candlestick.
func (*CandlestickBuilder) ProcessCandlestickModel ¶
func (c *CandlestickBuilder) ProcessCandlestickModel(e *CandlestickModel)
ProcessCandlestickModel adds a candlestick to the builder. This should be used for reprojecting a set of candlesticks.
func (*CandlestickBuilder) ProcessMessage ¶
func (c *CandlestickBuilder) ProcessMessage(e *ExchangeMessage)
ProcessMessage processes an exchange message.
type CandlestickDirection ¶
type CandlestickDirection string
CandlestickDirection refers to a candlestick direction.
type CandlestickModel ¶
type CandlestickModel struct { ID int64 CreatedAt time.Time UpdatedAt time.Time StartTime time.Time EndTime time.Time Low float64 High float64 Open float64 Close float64 Volume float64 Direction CandlestickDirection Product Product // contains filtered or unexported fields }
CandlestickModel is a candlestick's representation in a database.
func ReprojectCandlesticks ¶
func ReprojectCandlesticks(candles []*CandlestickModel, product Product, tickSizeMinutes int64) ([]*CandlestickModel, error)
ReprojectCandlesticks generates sets of candlesticks using a different period. The candlesticks must be passed with ascending start time.
func (*CandlestickModel) BeforeInsert ¶
func (m *CandlestickModel) BeforeInsert(db orm.DB) error
func (*CandlestickModel) BeforeUpdate ¶
func (m *CandlestickModel) BeforeUpdate(db orm.DB) error
func (*CandlestickModel) MeanPrice ¶
func (m *CandlestickModel) MeanPrice() (float64, error)
MeanPrice returns the mean price for the candlestick period.
type CodeMigrations ¶
type CodeMigrations struct {
// contains filtered or unexported fields
}
CodeMigrations is a type that stores migrations as part of the code.
func (*CodeMigrations) AddMigration ¶
func (c *CodeMigrations) AddMigration(m *Migration)
AddMigration adds a migration to the set of migrations.
func (*CodeMigrations) Close ¶
func (c *CodeMigrations) Close() error
Close closes the migration driver.
func (*CodeMigrations) First ¶
func (c *CodeMigrations) First() (version uint, err error)
First returns the first migration.
func (*CodeMigrations) Next ¶
func (c *CodeMigrations) Next(version uint) (nextVersion uint, err error)
Next returns the next migration.
func (*CodeMigrations) Open ¶
func (c *CodeMigrations) Open(url string) (source.Driver, error)
Open opens the migration driver.
func (*CodeMigrations) Prev ¶
func (c *CodeMigrations) Prev(version uint) (prevVersion uint, err error)
Prev returns the previous migration.
func (*CodeMigrations) ReadDown ¶
func (c *CodeMigrations) ReadDown(version uint) (io.ReadCloser, string, error)
ReadDown returns the Down migration for the version.
func (*CodeMigrations) ReadUp ¶
func (c *CodeMigrations) ReadUp(version uint) (io.ReadCloser, string, error)
ReadUp returns the Up migration for the version.
type CreateMarketOrderResponse ¶
type CreateMarketOrderResponse struct { ExchangeID string FilledSize float64 FilledSizeCurrency string Fees float64 FeesCurrency string }
CreateMarketOrderResponse is the create market order response.
type DBConn ¶
type DBConn struct {
// contains filtered or unexported fields
}
DBConn contains the supported backend operations.
func (*DBConn) CreateMarketOrder ¶
func (d *DBConn) CreateMarketOrder(m *MarketOrderModel) error
func (*DBConn) CreateTradingStrategy ¶
func (d *DBConn) CreateTradingStrategy(m *TradingStrategyModel) error
func (*DBConn) FindActiveTradingStrategies ¶
func (d *DBConn) FindActiveTradingStrategies(p Product) ([]*TradingStrategyModel, error)
func (*DBConn) FindCandlestickByID ¶
func (d *DBConn) FindCandlestickByID(id int64) (*CandlestickModel, error)
func (*DBConn) FindCandlesticks ¶
func (d *DBConn) FindCandlesticks(startTime, endTime time.Time, product Product, tickSizeMinutes int64) ([]*CandlestickModel, error)
FindCandlesticks locates candlesticks within a range and reprojects them.
func (*DBConn) FindMarketOrderByID ¶
func (d *DBConn) FindMarketOrderByID(id int64) (*MarketOrderModel, error)
func (*DBConn) FindMostRecentCandlestick ¶
func (d *DBConn) FindMostRecentCandlestick(p Product) (*CandlestickModel, error)
func (*DBConn) FindTradingStrategyByID ¶
func (d *DBConn) FindTradingStrategyByID(id int64) (*TradingStrategyModel, error)
func (*DBConn) UpdateTradingStrategy ¶
func (d *DBConn) UpdateTradingStrategy(m *TradingStrategyModel) error
func (*DBConn) UpsertCandlestick ¶
func (d *DBConn) UpsertCandlestick(c *CandlestickModel) error
UpsertCandlestick upserts a candlestick.
type DEMAIndicator ¶
type DEMAIndicator struct {
// contains filtered or unexported fields
}
DEMAIndicator is an indicator that tracks the difference in two EMAs.
func NewDEMAIndicator ¶
func NewDEMAIndicator(shortPeriod, longPeriod uint) *DEMAIndicator
NewDEMAIndicator creates a new DEMAIndicator.
func (*DEMAIndicator) AddCandlestick ¶
func (d *DEMAIndicator) AddCandlestick(c *CandlestickModel) error
AddCandlestick processes a candlestick.
func (*DEMAIndicator) Name ¶
func (d *DEMAIndicator) Name() string
Name returns the name of the indicator.
func (*DEMAIndicator) Value ¶
func (d *DEMAIndicator) Value() (*IndicatorValue, error)
Value returns the DEMA value for the last processed candlestick.
type EMACrossoverStrategy ¶
type EMACrossoverStrategy struct { ShortPeriod uint `yaml:"short_period"` LongPeriod uint `yaml:"long_period"` UpThreshold float64 `yaml:"up_threshold"` DownThreshold float64 `yaml:"down_threshold"` // contains filtered or unexported fields }
EMACrossoverStrategy is a strategy for that buys and sells based on EMA crossovers.
func (*EMACrossoverStrategy) Buy ¶
func (e *EMACrossoverStrategy) Buy(history []*IndicatorSet, current int) (bool, error)
Buy determines whether the currency should be bought using the indicator history.
func (*EMACrossoverStrategy) Clone ¶
func (e *EMACrossoverStrategy) Clone() StrategyGenome
Clone returns a clone of the current strategy.
func (*EMACrossoverStrategy) Crossover ¶
func (e *EMACrossoverStrategy) Crossover(m StrategyGenome, r *rand.Rand) (StrategyGenome, StrategyGenome)
Crossover crosses over an EMACrossoverStrategy with a different one.
func (*EMACrossoverStrategy) Indicators ¶
func (e *EMACrossoverStrategy) Indicators() []Indicator
Indicators returns the indicators returned by the strategy.
func (*EMACrossoverStrategy) Mutate ¶
func (e *EMACrossoverStrategy) Mutate(rng *rand.Rand)
Mutate mutates the underlying strategy.
func (*EMACrossoverStrategy) Rand ¶
func (e *EMACrossoverStrategy) Rand(rng *rand.Rand)
Rand creates a random version of the strategy.
func (*EMACrossoverStrategy) Sell ¶
func (e *EMACrossoverStrategy) Sell(history []*IndicatorSet, current int) (bool, error)
Sell determines whether the currency should be sold using the indicator history.
func (*EMACrossoverStrategy) SetTradingStrategy ¶
func (e *EMACrossoverStrategy) SetTradingStrategy(t *TradingStrategyModel)
SetTradingStrategy sets the underlying trading strategy.
func (*EMACrossoverStrategy) String ¶
func (e *EMACrossoverStrategy) String() string
String returns the string representation of the strategy.
type EMAIndicator ¶
type EMAIndicator struct {
// contains filtered or unexported fields
}
EMAIndicator computes a running value for an exponential moving average.
func NewEMAIndicator ¶
func NewEMAIndicator(period uint) *EMAIndicator
NewEMAIndicator creates a new EMAIndicator.
func (*EMAIndicator) AddCandlestick ¶
func (e *EMAIndicator) AddCandlestick(c *CandlestickModel) error
AddCandlestick adds a candlestick to the indicator.
func (*EMAIndicator) Name ¶
func (e *EMAIndicator) Name() string
Name returns the name of the indicator.
func (*EMAIndicator) Value ¶
func (e *EMAIndicator) Value() (*IndicatorValue, error)
Value returns the last calculated EMA value.
type Exchange ¶
type Exchange interface { GetMessageChan(context.Context, Product) (<-chan *ExchangeMessage, error) GetCandlesticks(product Product, start, end time.Time, granularity int) ([]*CandlestickModel, error) CreateMarketOrder(*MarketOrder) (*CreateMarketOrderResponse, error) StreamCandlesticks(ctx context.Context, product Product) (<-chan *CandlestickModel, error) EmitsFullCandlesticks() bool }
Exchange represents a connection to a trading exchange.
type ExchangeMessage ¶
type ExchangeMessage struct { Price float64 ProductType string Size float64 Type string Time time.Time }
ExchangeMessage is emitted by an exchange representing an action that occurred on the exchange.
type ExchangeMessageType ¶
type ExchangeMessageType string
ExchangeMessageType refers to a message type that's emitted by an exchange.
type FakeGDAXExchange ¶
type FakeGDAXExchange struct {
GDAXExchange
}
FakeGDAXExchange is a GDAX implementation that places mock trades.
func NewFakeGDAXExchange ¶
func NewFakeGDAXExchange(clock clockwork.Clock) *FakeGDAXExchange
NewFakeGDAXExchange returns a new instance of FakeGDAXExchange.
func (*FakeGDAXExchange) CreateMarketOrder ¶
func (f *FakeGDAXExchange) CreateMarketOrder(args *MarketOrder) (*CreateMarketOrderResponse, error)
CreateMarketOrder mocks a market order at the last market price.
type FakeKrakenExchange ¶
type FakeKrakenExchange struct {
KrakenExchange
}
func NewFakeKrakenExchange ¶
func NewFakeKrakenExchange(client KrakenClient, clock clockwork.Clock) *FakeKrakenExchange
type GDAXClient ¶
type GDAXClient interface { GetHistoricRates(product string, p ...coinbase.GetHistoricRatesParams) ([]coinbase.HistoricRate, error) CreateOrder(*coinbase.Order) (coinbase.Order, error) GetOrder(string) (coinbase.Order, error) }
GDAXClient is the interface for an underlying GDAX client.
type GDAXExchange ¶
type GDAXExchange struct {
// contains filtered or unexported fields
}
GDAXExchange is a client to the GDAX cryptocurrency exchange.
func NewGDAXExchange ¶
func NewGDAXExchange(client GDAXClient, clock clockwork.Clock) *GDAXExchange
NewGDAXExchange returns a new instance of GDAXExchange.
func (*GDAXExchange) CreateMarketOrder ¶
func (g *GDAXExchange) CreateMarketOrder(args *MarketOrder) (*CreateMarketOrderResponse, error)
CreateMarketOrder creates a market order on GDAX.
func (*GDAXExchange) EmitsFullCandlesticks ¶
func (k *GDAXExchange) EmitsFullCandlesticks() bool
func (*GDAXExchange) GetCandlesticks ¶
func (g *GDAXExchange) GetCandlesticks(product Product, start, end time.Time, granularitySeconds int) ([]*CandlestickModel, error)
GetCandlesticks returns candlesticks for a specified period and granularity from GDAX.
func (*GDAXExchange) GetMessageChan ¶
func (g *GDAXExchange) GetMessageChan(ctx context.Context, product Product) (<-chan *ExchangeMessage, error)
GetMessageChan returns a channel that emits exchange messages.
func (*GDAXExchange) StreamCandlesticks ¶
func (g *GDAXExchange) StreamCandlesticks(ctx context.Context, product Product) (<-chan *CandlestickModel, error)
type HistoricalImporter ¶
type HistoricalImporter struct {
// contains filtered or unexported fields
}
HistoricalImporter is a type that can import candle stick information into the backend from a specific period of time.
func NewHistoricalImporter ¶
func NewHistoricalImporter(product Product, e Exchange, b Backend, concurrency int) *HistoricalImporter
NewHistoricalImporter creates a new HistoricalImporter.
func (*HistoricalImporter) Import ¶
func (h *HistoricalImporter) Import(start, end time.Time)
Import imports a time range into a backend.
type Indicator ¶
type Indicator interface { AddCandlestick(c *CandlestickModel) error Value() (*IndicatorValue, error) Name() string }
Indicator is an interface to a type that can generate an IndicatorValue for a candlestick.
type IndicatorSet ¶
type IndicatorSet struct { Time time.Time Values []*IndicatorValue }
IndicatorSet describes a collection of indicators for a specific point in time.
type IndicatorValue ¶
IndicatorValue describes the value of an indicator at a specific point in time.
type KrakenClient ¶
KrakenClient is the interface needed out of a Kraken client.
type KrakenExchange ¶
type KrakenExchange struct {
// contains filtered or unexported fields
}
KrakenExchange is a client to the Kraken cryptocurrency exchange.
func NewKrakenExchange ¶
func NewKrakenExchange(client KrakenClient, clock clockwork.Clock) *KrakenExchange
NewKrakenExchange creates a new instance of KrakenExchange.
func (*KrakenExchange) CreateMarketOrder ¶
func (k *KrakenExchange) CreateMarketOrder(*MarketOrder) (*CreateMarketOrderResponse, error)
func (*KrakenExchange) EmitsFullCandlesticks ¶
func (k *KrakenExchange) EmitsFullCandlesticks() bool
EmitsFullCandlesticks returns whether the exchange emits full candlesticks.
func (*KrakenExchange) GetCandlesticks ¶
func (k *KrakenExchange) GetCandlesticks(product Product, start time.Time, end time.Time, granularity int) ([]*CandlestickModel, error)
func (*KrakenExchange) GetMessageChan ¶
func (k *KrakenExchange) GetMessageChan(ctx context.Context, product Product) (<-chan *ExchangeMessage, error)
func (*KrakenExchange) StreamCandlesticks ¶
func (k *KrakenExchange) StreamCandlesticks(ctx context.Context, product Product) (<-chan *CandlestickModel, error)
StreamCandlesticks provides a stream of candlesticks for the product from the exchange.
type MACDIndicator ¶
type MACDIndicator struct {
// contains filtered or unexported fields
}
MACDIndicator implements the MACD indicator.
func NewMACDIndicator ¶
func NewMACDIndicator(shortPeriod, longPeriod uint) *MACDIndicator
NewMACDIndicator creates a new MACD indicator.
func (*MACDIndicator) AddCandlestick ¶
func (m *MACDIndicator) AddCandlestick(c *CandlestickModel) error
AddCandlestick adds a candlestick to the indicator.
func (*MACDIndicator) Name ¶
func (m *MACDIndicator) Name() string
Name return the name of the indicator.
func (*MACDIndicator) Value ¶
func (m *MACDIndicator) Value() (*IndicatorValue, error)
Value value returns the value of the indicator.
type MACDWithSignal ¶
type MACDWithSignal struct {
// contains filtered or unexported fields
}
MACDWithSignal is an indicator that tracks the MACD value minus the signal EMA.
func NewMACDWithSignal ¶
func NewMACDWithSignal(shortPeriod, longPeriod, signalPeriod uint) *MACDWithSignal
NewMACDWithSignal returns a new MACDWithSignal.
func (*MACDWithSignal) AddCandlestick ¶
func (m *MACDWithSignal) AddCandlestick(c *CandlestickModel) error
AddCandlestick adds a candlestick to the indicator.
func (*MACDWithSignal) Name ¶
func (m *MACDWithSignal) Name() string
Name return the name of the indicator.
func (*MACDWithSignal) Value ¶
func (m *MACDWithSignal) Value() (*IndicatorValue, error)
Value value returns the value of the indicator.
type MarketOrder ¶
MarketOrder describes the settings for a MarketOrder.
func NewMarketOrder ¶
func NewMarketOrder(product Product, side string, cost float64) *MarketOrder
NewMarketOrder instantiates a new market order.
type MarketOrderModel ¶
type MarketOrderModel struct { ID int64 CreatedAt time.Time UpdatedAt time.Time TradingStrategyID int64 ExchangeID string Product Product Side string Cost float64 CostCurrency string FilledSize float64 SizeCurrency string Fees float64 FeesCurrency string // contains filtered or unexported fields }
MarketOrderModel contains metadata about market orders that were placed.
func (*MarketOrderModel) BeforeInsert ¶
func (m *MarketOrderModel) BeforeInsert(db orm.DB) error
func (*MarketOrderModel) BeforeUpdate ¶
func (m *MarketOrderModel) BeforeUpdate(db orm.DB) error
type MarketOrderStrategy ¶
type MarketOrderStrategy struct {
// contains filtered or unexported fields
}
MarketOrderStrategy executes a buy/sell order using a single market order.
func NewMarketOrderStrategy ¶
func NewMarketOrderStrategy(exchange Exchange, backend Backend) *MarketOrderStrategy
NewMarketOrderStrategy creates a new market order strategy.
func (*MarketOrderStrategy) PerformOrder ¶
func (o *MarketOrderStrategy) PerformOrder(args *PerformOrderArgs) (*PerformOrderResponse, error)
PerformOrder creates the market order to buy or sell the currency amount.
func (*MarketOrderStrategy) String ¶
func (o *MarketOrderStrategy) String() string
String returns the string representation of the strategy.
type Migration ¶
type Migration struct {
// contains filtered or unexported fields
}
Migration defines a database migration.
type OrderStrategy ¶
type OrderStrategy interface { PerformOrder(*PerformOrderArgs) (*PerformOrderResponse, error) String() string }
OrderStrategy is an interface for buying or selling a currency.
type PerformOrderArgs ¶
type PerformOrderArgs struct { Product Product Side string Cost float64 Timeout time.Duration TradingStrategy *TradingStrategyModel Candlestick *CandlestickModel }
PerformOrderArgs are the arguments to the PerformOrder method.
type PerformOrderResponse ¶
type PerformOrderResponse struct { FilledSize float64 FilledSizeCurrency string Fees float64 FeesCurrency string }
PerformOrderResponse is the response to PerformOrder.
type ProductMetadata ¶
type ProductMetadata struct { ExchangeType ExchangeType MarketOrderBuyCurrency string MarketOrderSellCurrency string MarketOrderFeesCurrency string }
ProductMetadata defines metadata about each product.
type RSIIndicator ¶
type RSIIndicator struct {
// contains filtered or unexported fields
}
RSIIndicator calculates the RSI indicator.
func NewRSIIndicator ¶
func NewRSIIndicator(periods uint) *RSIIndicator
NewRSIIndicator returns a new RSIIndicator.
func (*RSIIndicator) AddCandlestick ¶
func (r *RSIIndicator) AddCandlestick(c *CandlestickModel) error
AddCandlestick adds a candlestick to the indicator.
func (*RSIIndicator) Name ¶
func (r *RSIIndicator) Name() string
Name returns the name of the indicator
func (*RSIIndicator) Value ¶
func (r *RSIIndicator) Value() (*IndicatorValue, error)
Value returns the last calculated RSI value.
type RSIStrategy ¶
type RSIStrategy struct { Period uint `yaml:"period"` BuyThreshold float64 `yaml:"buy_threshold"` SellThreshold float64 `yaml:"sell_threshold"` // contains filtered or unexported fields }
RSIStrategy is a strategy for that buys and sells based on the RSI values.
func (*RSIStrategy) Buy ¶
func (e *RSIStrategy) Buy(history []*IndicatorSet, current int) (bool, error)
Buy determines whether the currency should be bought using the indicator history.
func (*RSIStrategy) Clone ¶
func (e *RSIStrategy) Clone() StrategyGenome
Clone returns a clone of the current strategy.
func (*RSIStrategy) Crossover ¶
func (e *RSIStrategy) Crossover(m StrategyGenome, r *rand.Rand) (StrategyGenome, StrategyGenome)
Crossover crosses over an RSIStrategy with a different one.
func (*RSIStrategy) Indicators ¶
func (e *RSIStrategy) Indicators() []Indicator
Indicators returns the indicators returned by the strategy.
func (*RSIStrategy) Mutate ¶
func (e *RSIStrategy) Mutate(rng *rand.Rand)
Mutate mutates the underlying strategy.
func (*RSIStrategy) Rand ¶
func (e *RSIStrategy) Rand(rng *rand.Rand)
Rand creates a random version of the strategy.
func (*RSIStrategy) Sell ¶
func (e *RSIStrategy) Sell(history []*IndicatorSet, current int) (bool, error)
Sell determines whether the currency should be sold using the indicator history.
func (*RSIStrategy) SetTradingStrategy ¶
func (e *RSIStrategy) SetTradingStrategy(t *TradingStrategyModel)
SetTradingStrategy sets the underlying trading strategy.
func (*RSIStrategy) String ¶
func (e *RSIStrategy) String() string
String returns the string representation of the strategy.
type RealtimeImporter ¶
type RealtimeImporter struct {
// contains filtered or unexported fields
}
RealtimeImporter imports exchange data into a backend.
func NewRealtimeImporter ¶
func NewRealtimeImporter(p Product, b Backend, e Exchange) *RealtimeImporter
NewRealtimeImporter instantiates a new RealtimeImporter.
func (*RealtimeImporter) Flush ¶
func (i *RealtimeImporter) Flush()
Flush flushes all populated candlesticks to the backend.
func (*RealtimeImporter) ProcessExchangeMessage ¶
func (i *RealtimeImporter) ProcessExchangeMessage(msg *ExchangeMessage)
ProcessExchangeMessage processes an exchange message, sending the message to the appropriate candlestick.
func (*RealtimeImporter) Start ¶
func (i *RealtimeImporter) Start(flushInterval time.Duration)
Start begins the import process.
func (*RealtimeImporter) StartProcessingCandlesticks ¶
func (i *RealtimeImporter) StartProcessingCandlesticks()
StartProcessingCandlesticks processes candlesticks as they're emitted by the exchange.
func (*RealtimeImporter) StartProcessingMessages ¶
func (i *RealtimeImporter) StartProcessingMessages(flushInterval time.Duration)
StartProcessingMessages begins the import process with messages.
type Runner ¶
type Runner struct { Backend Backend BTCUSDBot *Bot ETHUSDBot *Bot LTCUSDBot *Bot BTCUSDRealtimeImporter *RealtimeImporter ETHUSDRealtimeImporter *RealtimeImporter LTCUSDRealtimeImporter *RealtimeImporter BTCUSDHistoricalImporter *HistoricalImporter ETHUSDHistoricalImporter *HistoricalImporter LTCUSDHistoricalImporter *HistoricalImporter GDAXExchange Exchange KrakenExchange Exchange }
Runner contains singletons exported by the package.
type S1Strategy ¶
type S1Strategy struct { EMAShortPeriod uint `yaml:"ema_short_period"` EMALongPeriod uint `yaml:"ema_long_period"` EMAUpThreshold float64 `yaml:"ema_up_threshold"` EMADownThreshold float64 `yaml:"ema_down_threshold"` RSIExitThreshold float64 `yaml:"rsi_exit_threshold"` RSIEntranceThreshold float64 `yaml:"rsi_entrance_threshold"` // contains filtered or unexported fields }
S1Strategy is a custom trading strategy.
func (*S1Strategy) Buy ¶
func (s *S1Strategy) Buy(history []*IndicatorSet, current int) (bool, error)
Buy determines whether the currency should be bought using the indicator history.
func (*S1Strategy) Clone ¶
func (s *S1Strategy) Clone() StrategyGenome
Clone returns a clone of the current strategy.
func (*S1Strategy) Crossover ¶
func (s *S1Strategy) Crossover(m StrategyGenome, r *rand.Rand) (StrategyGenome, StrategyGenome)
Crossover crosses over an S1Strategy with a different ons.
func (*S1Strategy) Indicators ¶
func (s *S1Strategy) Indicators() []Indicator
Indicators returns the indicators returned by the strategy.
func (*S1Strategy) Mutate ¶
func (s *S1Strategy) Mutate(rng *rand.Rand)
Mutate mutates the underlying strategy.
func (*S1Strategy) Rand ¶
func (s *S1Strategy) Rand(rng *rand.Rand)
Rand creates a random version of the strategy.
func (*S1Strategy) Sell ¶
func (s *S1Strategy) Sell(history []*IndicatorSet, current int) (bool, error)
Sell determines whether the currency should be sold using the indicator history.
func (*S1Strategy) SetTradingStrategy ¶
func (s *S1Strategy) SetTradingStrategy(t *TradingStrategyModel)
SetTradingStrategy sets the underlying trading strategy.
func (*S1Strategy) String ¶
func (s *S1Strategy) String() string
String returns the string representation of the strategy.
type SlackNotifier ¶
type SlackNotifier struct {
// contains filtered or unexported fields
}
SlackNotifier posts messages to a single Slack client.
func NewSlackNotifier ¶
func NewSlackNotifier(trades, data string, client *slack.Client) *SlackNotifier
NewSlackNotifier creates a new Slack notifier.
type StrategyGenome ¶
type StrategyGenome interface { StrategyInterface Rand(rng *rand.Rand) Clone() StrategyGenome Mutate(rng *rand.Rand) Crossover(m StrategyGenome, r *rand.Rand) (StrategyGenome, StrategyGenome) }
StrategyGenome defines the methods that should be implemented in order for an strategy to be optimized genetically.
type StrategyInterface ¶
type StrategyInterface interface { Indicators() []Indicator Buy(history []*IndicatorSet, current int) (bool, error) Sell(history []*IndicatorSet, current int) (bool, error) String() string SetTradingStrategy(t *TradingStrategyModel) }
StrategyInterface describes the exposed by a trading strategy.
type TradingStrategy ¶
type TradingStrategy struct {
// contains filtered or unexported fields
}
TradingStrategy represents a general trading strategy where the underlying strategy can indicate either buying or selling.
func NewTradingStrategy ¶
func NewTradingStrategy(backend Backend, exchange Exchange, strategy StrategyInterface, clock clockwork.Clock) *TradingStrategy
NewTradingStrategy instantiates a new trading strategy.
func (*TradingStrategy) LastCandlestickTime ¶
func (t *TradingStrategy) LastCandlestickTime() time.Time
LastCandlestickTime returns the ending time of the last candlestick that was processed.
func (*TradingStrategy) ProcessTick ¶
func (t *TradingStrategy) ProcessTick(m *TradingStrategyModel) error
ProcessTick processes a single trading strategy model tick.
func (*TradingStrategy) SeedIndicators ¶
func (t *TradingStrategy) SeedIndicators(c *CandlestickModel) error
SeedIndicators seeds the indicators with the current candle.
func (*TradingStrategy) TryBuy ¶
func (t *TradingStrategy) TryBuy(m *TradingStrategyModel) error
TryBuy tries to buy a currency if the underlying strategy indicates so.
func (*TradingStrategy) TrySell ¶
func (t *TradingStrategy) TrySell(m *TradingStrategyModel) error
TrySell tries to sell a currency if the underlying strategy indicates so.
type TradingStrategyModel ¶
type TradingStrategyModel struct { ID int64 CreatedAt time.Time UpdatedAt time.Time DeactivatedAt time.Time LastTickAt time.Time NextTickAt time.Time Product Product HistoryTicks uint State string InitialBudget float64 Budget float64 BudgetCurrency string Invested float64 InvestedCurrency string TickSizeMinutes uint TradingStrategy string TradingStrategyData []byte // contains filtered or unexported fields }
TradingStrategyModel contains metadata for a trading strategy.
func (*TradingStrategyModel) BeforeInsert ¶
func (m *TradingStrategyModel) BeforeInsert(db orm.DB) error
func (*TradingStrategyModel) BeforeUpdate ¶
func (m *TradingStrategyModel) BeforeUpdate(db orm.DB) error
func (*TradingStrategyModel) Copy ¶
func (t *TradingStrategyModel) Copy() *TradingStrategyModel
Copy returns a copy of the current model.
func (*TradingStrategyModel) SetStrategy ¶
func (t *TradingStrategyModel) SetStrategy(s StrategyInterface) error
SetStrategy sets the underlying trading strategy.
func (*TradingStrategyModel) Strategy ¶
func (t *TradingStrategyModel) Strategy() (StrategyInterface, error)
Strategy returns the underlying trading strategy.
Source Files ¶
- backend.go
- backtesting.go
- bot.go
- cacheing_backend.go
- candlesticks.go
- cli.go
- ema.go
- ema_crossover_strategy.go
- exchange.go
- gdax.go
- historical_importer.go
- kraken.go
- macd.go
- math.go
- migrations.go
- models.go
- optimization.go
- order_strategies.go
- realtime_importer.go
- rsi.go
- rsi_strategy.go
- s1_strategy.go
- slack_notifier.go
- strategy.go