Documentation ¶
Index ¶
- type Account
- func (a *Account) Balance() float64
- func (a *Account) ChargedFees() float64
- func (a *Account) Equity() float64
- func (a *Account) HomeCurrency() string
- func (a *Account) ID() string
- func (a *Account) Instrument(instrument string) *Instrument
- func (a *Account) Instruments() map[string]*Instrument
- func (a *Account) MarginFree() float64
- func (a *Account) MarginUsed() float64
- func (a *Account) Time() time.Time
- func (a *Account) UnrealizedEffectiveProfit() float64
- func (a *Account) UnrealizedNetProfit() float64
- type AccountStatus
- type BrokerClient
- type Engine
- type FundsTransfer
- type FundsTransferHandler
- type Hedge
- type Instrument
- func (i *Instrument) Ask() float64
- func (i *Instrument) BaseCurrency() string
- func (i *Instrument) Bid() float64
- func (i *Instrument) ChargedFees() float64
- func (i *Instrument) Leverage() float64
- func (i *Instrument) LongPosition() *Position
- func (i *Instrument) MarginUsed() float64
- func (i *Instrument) Name() string
- func (i *Instrument) PipLocation() int
- func (i *Instrument) QuoteCurrency() string
- func (i *Instrument) ShortPosition() *Position
- func (i *Instrument) Spread() float64
- func (i *Instrument) Trade(id string) *Trade
- func (i *Instrument) TradeByOrder(index int) *Trade
- func (i *Instrument) Trades() <-chan *Trade
- func (i *Instrument) TradesByAscendingOrder(tradesNumber int) <-chan *Trade
- func (i *Instrument) TradesByDescendingOrder(tradesNumber int) <-chan *Trade
- func (i *Instrument) TradesNumber() int32
- func (i *Instrument) UnrealizedEffectiveProfit() float64
- func (i *Instrument) UnrealizedNetProfit() float64
- type InstrumentDetails
- type Logger
- type Option
- type OrderFill
- type OrderFillHandler
- type Position
- func (p *Position) AveragePrice() float64
- func (p *Position) ChargedFees() float64
- func (p *Position) MarginUsed() float64
- func (p *Position) Side() Side
- func (p *Position) Trade(id string) *Trade
- func (p *Position) TradeByOrder(index int) *Trade
- func (p *Position) Trades() <-chan *Trade
- func (p *Position) TradesByAscendingOrder(tradesNumber int) <-chan *Trade
- func (p *Position) TradesByDescendingOrder(tradesNumber int) <-chan *Trade
- func (p *Position) TradesNumber() int32
- func (p *Position) Units() int32
- func (p *Position) UnrealizedEffectiveProfit() float64
- func (p *Position) UnrealizedNetProfit() float64
- type Side
- type Strategy
- type SwapCharge
- type SwapChargeHandler
- type Tick
- type TickHandler
- type Trade
- func (t *Trade) ChargedFees() float64
- func (t *Trade) CurrentPrice() float64
- func (t *Trade) ID() string
- func (t *Trade) InstrumentName() string
- func (t *Trade) MarginUsed() float64
- func (t *Trade) OpenPrice() float64
- func (t *Trade) OpenTime() time.Time
- func (t *Trade) Side() Side
- func (t *Trade) Units() int32
- func (t *Trade) UnrealizedEffectiveProfit() float64
- func (t *Trade) UnrealizedNetProfit() float64
- type TradeDetails
- type TradeSwapCharge
- type TradingSession
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct {
// contains filtered or unexported fields
}
Account represent the current account status. Mirrors the broker status.
func (*Account) ChargedFees ¶
func (*Account) HomeCurrency ¶
func (*Account) Instrument ¶
func (a *Account) Instrument(instrument string) *Instrument
func (*Account) Instruments ¶
func (a *Account) Instruments() map[string]*Instrument
func (*Account) MarginFree ¶
func (*Account) MarginUsed ¶
func (*Account) UnrealizedEffectiveProfit ¶
func (*Account) UnrealizedNetProfit ¶
type AccountStatus ¶
type BrokerClient ¶
type BrokerClient interface { GetAccountStatus(accountID string) (AccountStatus, error) GetAvailableInstruments(accountID string) ([]InstrumentDetails, error) OpenMarketOrder(accountID, instrument string, units int32, side string) error CloseTrade(accountID, id string) error GetOpenTrades(accountID string) ([]TradeDetails, error) SubscribePrices(accountID string, instruments []InstrumentDetails, callback TickHandler) error SubscribeOrderFillNotifications(accountID string, orderFIllCallback OrderFillHandler) error SubscribeSwapChargeNotifications(accountID string, swapChargeCallback SwapChargeHandler) error SubscribeFundsTransferNotifications(accountID string, fundsTransferCallback FundsTransferHandler) error }
type Engine ¶
type Engine interface { Account() *Account Buy(instrument string, units int32) Sell(instrument string, units int32) CloseTrade(instrument string, id string) StopSession() // Gracefully stops trading session from strategy }
Engine is the interface used for interaction from strategy. Is used to check the state of the account, open or close trades and to stop the session.
type FundsTransfer ¶
type FundsTransferHandler ¶
type FundsTransferHandler func(funds *FundsTransfer)
type Instrument ¶
type Instrument struct {
// contains filtered or unexported fields
}
func (*Instrument) Ask ¶
func (i *Instrument) Ask() float64
func (*Instrument) BaseCurrency ¶
func (i *Instrument) BaseCurrency() string
func (*Instrument) Bid ¶
func (i *Instrument) Bid() float64
func (*Instrument) ChargedFees ¶
func (i *Instrument) ChargedFees() float64
func (*Instrument) Leverage ¶
func (i *Instrument) Leverage() float64
func (*Instrument) LongPosition ¶
func (i *Instrument) LongPosition() *Position
func (*Instrument) MarginUsed ¶
func (i *Instrument) MarginUsed() float64
func (*Instrument) Name ¶
func (i *Instrument) Name() string
func (*Instrument) PipLocation ¶
func (i *Instrument) PipLocation() int
func (*Instrument) QuoteCurrency ¶
func (i *Instrument) QuoteCurrency() string
func (*Instrument) ShortPosition ¶
func (i *Instrument) ShortPosition() *Position
func (*Instrument) Spread ¶
func (i *Instrument) Spread() float64
func (*Instrument) Trade ¶
func (i *Instrument) Trade(id string) *Trade
func (*Instrument) TradeByOrder ¶
func (i *Instrument) TradeByOrder(index int) *Trade
func (*Instrument) Trades ¶
func (i *Instrument) Trades() <-chan *Trade
func (*Instrument) TradesByAscendingOrder ¶
func (i *Instrument) TradesByAscendingOrder(tradesNumber int) <-chan *Trade
func (*Instrument) TradesByDescendingOrder ¶
func (i *Instrument) TradesByDescendingOrder(tradesNumber int) <-chan *Trade
func (*Instrument) TradesNumber ¶
func (i *Instrument) TradesNumber() int32
func (*Instrument) UnrealizedEffectiveProfit ¶
func (i *Instrument) UnrealizedEffectiveProfit() float64
func (*Instrument) UnrealizedNetProfit ¶
func (i *Instrument) UnrealizedNetProfit() float64
type InstrumentDetails ¶
type Logger ¶
type Logger interface { Fatal(args ...interface{}) Fatalf(format string, args ...interface{}) Error(args ...interface{}) Errorf(format string, args ...interface{}) Warn(args ...interface{}) Warnf(format string, args ...interface{}) Info(args ...interface{}) Infof(format string, args ...interface{}) Debug(args ...interface{}) Debugf(format string, args ...interface{}) }
Logger is an interface of a logger behaviour used by gotrader, with it the user will be able to configure logging level and message format at free will. The idea is to have a generic interface already implemented by a by some logging packages, without importing them directly.
type Option ¶
type Option func(p *sessionParameters)
Option represents trading session functional option
func AccountID ¶
AccountID is the functional option to define the account where the session will operate
func HedgeType ¶
HedgeType is the functional option to choose how hedge is calculated in the backtest engine.
func HomeCurrency ¶
HomeCurrency is the functional option to define home currency in the backtest engine.
func InitialBalance ¶
InitialBalance is the functional option to define the initial balance in the backtest engine.
func Instruments ¶
Instruments is the functional option to define the instruments to trade
type OrderFillHandler ¶
type OrderFillHandler func(order *OrderFill)
type Position ¶
type Position struct {
// contains filtered or unexported fields
}
Position represents the total exposure in a single side of an instrument. Is the aggregation of all the trades of that side.
func (*Position) AveragePrice ¶
func (*Position) ChargedFees ¶
func (*Position) MarginUsed ¶
func (*Position) TradeByOrder ¶
func (*Position) TradesByAscendingOrder ¶
func (*Position) TradesByDescendingOrder ¶
func (*Position) TradesNumber ¶
func (*Position) UnrealizedEffectiveProfit ¶
func (*Position) UnrealizedNetProfit ¶
type Strategy ¶
type Strategy interface { Initialize() SetEngine(engine Engine) OnOrderFill(orderFill *OrderFill) OnTick(tick *Tick) OnStop() }
Strategy is the interface that a strategy must implement in order to be used by this engine.
type SwapCharge ¶
type SwapCharge struct { Charges []*TradeSwapCharge Time time.Time }
type SwapChargeHandler ¶
type SwapChargeHandler func(charges *SwapCharge)
type TickHandler ¶
type TickHandler func(tick *Tick)
type Trade ¶
type Trade struct {
// contains filtered or unexported fields
}
Trade represents a transaction in a broker (execution of an order). Not all brokers have the possibility to operate over single trades, making impossible to use this engine in the current state.
func (*Trade) ChargedFees ¶
ChargedFees returns the total charged fees, like rollovers.
func (*Trade) CurrentPrice ¶
CurrentPrice returns the current price of the trade/instrument.
func (*Trade) InstrumentName ¶
InstrumentName return the instrument name.
func (*Trade) MarginUsed ¶
MarginUsed return the margin that the trade is using
func (*Trade) UnrealizedEffectiveProfit ¶
UnrealizedEffectiveProfit returns the unrealized profit plus the charged fees.
func (*Trade) UnrealizedNetProfit ¶
UnrealizedNetProfit returns the unrealized profit.
type TradeDetails ¶
type TradeSwapCharge ¶
type TradeSwapCharge struct { ID string Ammount float64 Instrument InstrumentDetails }
type TradingSession ¶
type TradingSession struct {
// contains filtered or unexported fields
}
TradingSession represents the entrypoint struct of the gotrader package, representing a trading session.
func NewTradingSession ¶
func NewTradingSession(opts ...Option) *TradingSession
NewTradingSession is the TradingSession constructor.
func (*TradingSession) Backtest ¶
func (s *TradingSession) Backtest() *TradingSession
Backtest defines that this is a backtesting session.
func (*TradingSession) Live ¶
func (s *TradingSession) Live() *TradingSession
Live defines that this is a live session.
func (*TradingSession) SetClient ¶
func (s *TradingSession) SetClient(client BrokerClient) *TradingSession
SetClient sets the client that will be used for comunication with the broker.
func (*TradingSession) SetStrategy ¶
func (s *TradingSession) SetStrategy(strategy Strategy) *TradingSession
SetStrategy sets the strategy to trade.