market

package module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2020 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

Package market implements a simulated forex market.

Index

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

func (m *Market) GetAccountBalance() (balance decimal.Decimal)

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

func (m *Market) GetOrderIDs() (ids []int)

GetOrderIDs returns the IDs of all open orders.

func (*Market) GetQuoteStream

func (m *Market) GetQuoteStream(pairs []forex.CurrencyPair) (ch chan forex.Quote, err error)

GetQuoteStream returns a channel on which price quotes for the given currency pairs are streamed.

func (*Market) GetQuotes

func (m *Market) GetQuotes(pairs []forex.CurrencyPair) (pricing []forex.Quote, err error)

GetQuotes returns the latest price quotes for the given currency pairs.

func (*Market) GetTradeIDs added in v0.3.0

func (m *Market) GetTradeIDs() (ids []int)

GetTradeIDs returns the IDs of all open trades.

func (*Market) GetTradeMargin added in v0.3.0

func (m *Market) GetTradeMargin(tradeID int) (margin decimal.Decimal, err error)

GetTradeMargin returns the required margin of a trade.

func (*Market) GetUnrealisedProfit added in v0.3.0

func (m *Market) GetUnrealisedProfit(tradeID int) (profit decimal.Decimal, err error)

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

func (m *Market) Run() (err error)

Run starts the market simulation. It continues until no more price information is left.

func (*Market) SetAccountBalance added in v0.2.0

func (m *Market) SetAccountBalance(balance decimal.Decimal, currency currency.Unit)

SetAccountBalance sets the account's initial balance.

func (*Market) SetFinishTime added in v0.2.0

func (m *Market) SetFinishTime(finishTime time.Time)

SetFinishTime sets the finish time of the simulation.

func (*Market) SetStartTime added in v0.2.0

func (m *Market) SetStartTime(startTime time.Time)

SetStartTime sets the start time of the simulation.

func (*Market) Step

func (m *Market) Step() (err error)

Step advances the next-in-line pair's quote and notifies subscribers of it.

type Quoter

type Quoter interface {
	NextQuote() (forex.Quote, error)
}

Quoter provides the market with price quotes.

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.

func (*Source) NextQuote added in v0.2.0

func (s *Source) NextQuote() (nextQuote forex.Quote, err error)

NextQuote returns the next quote out of all the aggregated sources.

Directories

Path Synopsis
Package csv implements a type which reads csv quote data and returns quotes one by one.
Package csv implements a type which reads csv quote data and returns quotes one by one.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL