trader

package module
v0.4.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: 0

Documentation

Overview

Package trader defines a trader using a moving average strategy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Currency currency.Unit   // the account's home currency.
	Balance  decimal.Decimal // the account balance in the account's home currency.
}

Account represents the current state of a standard trading account with a broker.

type Client

type Client interface {
	// GetAccounts returns the IDs of all accounts registered with the broker.
	GetAccounts() (accountIDs []string, err error)

	// GetCurrencyPairs returns an overview of all currency pairs which can be traded.
	GetCurrencyPairs(accountID string) (pairs []forex.CurrencyPair, err error)

	// GetQuotes returns the latest price quotes for the given currency pairs.
	GetQuotes(accountID string, pairs []forex.CurrencyPair) (pricing []forex.Quote, err error)

	// GetQuoteStream returns a channel on which price quotes for the given currency pairs are streamed.
	GetQuoteStream(accountID string, pairs []forex.CurrencyPair) (ch chan forex.Quote, err error)

	// PlaceOrder places a (market) order for the given amount of units of the given currency pair.
	PlaceOrder(accountID string, pair forex.CurrencyPair, units decimal.Decimal) (orderID int, err error)
}

Client is an interface to a generic broker which the trader can use to get price information and place trades.

type MarketOrder added in v0.2.0

type MarketOrder struct {
	Units decimal.Decimal
	Pair  forex.CurrencyPair
}

type Trader

type Trader struct {
	// contains filtered or unexported fields
}

Trader is a trader that uses moving averages (MA) to decide when to buy and sell.

func NewTrader

func NewTrader(client Client) (t *Trader)

New returns a new Trader which uses the given orderer to place orders and the given retriever to retrieve prices.

func (*Trader) SetWindowSize added in v0.3.0

func (t *Trader) SetWindowSize(window time.Duration)

SetWindowSize sets the trading window size. Window size is 0 by default -- every quote is counted.

func (*Trader) Trade

func (t *Trader) Trade(accountID string) (err error)

Trade trades automatically on the given account. This cannot be done in parallel.

type Triplet added in v0.3.0

type Triplet struct {
	Short, Medium, Long *movavg.MovingAvg
}

Triplet keeps track of three MAs.

func NewTriplet added in v0.3.0

func NewTriplet(short, medium, long int) (t *Triplet)

NewTriplet creates a new Triplet with moving averages of the given lengths.

func (*Triplet) Put added in v0.3.0

func (t *Triplet) Put(val decimal.Decimal)

Put includes a price in the moving average.

func (*Triplet) String added in v0.3.0

func (t *Triplet) String() string

String returns a string representation of the triplet.

Directories

Path Synopsis
Package movavg implements a type `MovingAvg` that allows the efficient maintaining of a moving average of numbers.
Package movavg implements a type `MovingAvg` that allows the efficient maintaining of a moving average of numbers.

Jump to

Keyboard shortcuts

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