Documentation ¶
Overview ¶
Package market implements a simulated forex market.
Index ¶
- type Market
- func (m *Market) AddInstrument(pair forex.CurrencyPair, quoter Quoter, rate decimal.Decimal) (err error)
- func (m *Market) GetAccountBalance() (balance decimal.Decimal)
- func (m *Market) GetCurrencyPairs() (pairs []forex.CurrencyPair, err error)
- func (m *Market) GetOrderIDs() (ids []int)
- func (m *Market) GetQuoteStream(pairs []forex.CurrencyPair) (ch chan forex.Quote, err error)
- func (m *Market) GetQuotes(pairs []forex.CurrencyPair) (pricing []forex.Quote, err error)
- func (m *Market) GetTradeIDs() (ids []int)
- func (m *Market) GetTradeMargin(tradeID int) (margin decimal.Decimal, err error)
- func (m *Market) GetUnrealisedProfit(tradeID int) (profit decimal.Decimal, err error)
- func (m *Market) PlaceOrder(pair forex.CurrencyPair, units decimal.Decimal) (orderID int, err error)
- func (m *Market) Run() (err error)
- func (m *Market) SetAccountBalance(balance decimal.Decimal, currency currency.Unit)
- func (m *Market) SetFinishTime(finishTime time.Time)
- func (m *Market) SetStartTime(startTime time.Time)
- func (m *Market) Step() (err error)
- type Quoter
- type Source
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Market ¶
type Market struct {
// contains filtered or unexported fields
}
Market is a simulation of a foreign exchange market. It handles orders, trades, latest quotes etc. It only deals with one account at a time.
func NewMarket ¶
func NewMarket() (m *Market)
NewMarket returns a new forex market simulation, initially without any orders/trades.
func (*Market) AddInstrument ¶ added in v0.2.0
func (m *Market) AddInstrument(pair forex.CurrencyPair, quoter Quoter, rate decimal.Decimal) (err error)
AddInstrument adds a new instrument to the market.
func (*Market) GetAccountBalance ¶ added in v0.3.0
GetAccountBalance returns the account's balance.
func (*Market) GetCurrencyPairs ¶
func (m *Market) GetCurrencyPairs() (pairs []forex.CurrencyPair, err error)
GetCurrencyPairs returns an overview of all currency pairs which can be traded.
func (*Market) GetOrderIDs ¶ added in v0.3.0
GetOrderIDs returns the IDs of all open orders.
func (*Market) GetQuoteStream ¶
GetQuoteStream returns a channel on which price quotes for the given currency pairs are streamed.
func (*Market) GetTradeIDs ¶ added in v0.3.0
GetTradeIDs returns the IDs of all open trades.
func (*Market) GetTradeMargin ¶ added in v0.3.0
GetTradeMargin returns the required margin of a trade.
func (*Market) GetUnrealisedProfit ¶ added in v0.3.0
GetUnrealisedProfit returns the unrealised profit of a trade.
func (*Market) PlaceOrder ¶ added in v0.1.0
func (m *Market) PlaceOrder(pair forex.CurrencyPair, units decimal.Decimal) (orderID int, err error)
PlaceOrder places an order for the given number of units of the given currency pair at the current market price.
func (*Market) Run ¶
Run starts the market simulation. It continues until no more price information is left.
func (*Market) SetAccountBalance ¶ added in v0.2.0
SetAccountBalance sets the account's initial balance.
func (*Market) SetFinishTime ¶ added in v0.2.0
SetFinishTime sets the finish time of the simulation.
func (*Market) SetStartTime ¶ added in v0.2.0
SetStartTime sets the start time of the simulation.
type Source ¶ added in v0.2.0
type Source struct {
// contains filtered or unexported fields
}
Source combines multiple quoters together into one.
func (*Source) AddQuoter ¶ added in v0.2.0
func (s *Source) AddQuoter(pair forex.CurrencyPair, quoter Quoter) (err error)
AddQuoter adds a new Quoter to the source. Only one quoter can be added per currency pair.
func (*Source) GetCurrencyPairs ¶ added in v0.2.0
func (s *Source) GetCurrencyPairs() (pairs []forex.CurrencyPair)
GetCurrencyPairs returns a list of all currency pairs which can be traded.