goanda

package module
v0.5.0 Latest Latest
Warning

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

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

README

Goanda

Goanda is a client for the OANDA REST-v20 API.

Branches

This project uses the github flow branching model.

Commits

Commits in this project should conform to the conventional variety of Conventional Commits.

Commits must be of the form prefix(scope): message with an optional ! after the prefix to indicate a breaking change.

Valid prefixes include build, ci, chore, docs, feat, fix, perf, refactor, revert, style, and test.

Versions

This project adheres to Semantic Versioning. Every merge to master should correspond to a version bump of the appropriate type. Versions are represented by tags of the form v1.2.3.

Completion

Not much of the API is implemented. You probably can't do much with this library yet.

Documentation

Overview

Package goanda implements a stateless client for the oanda REST-v20 API.

Index

Constants

View Source
const (
	// HostURL is the host url of most routes of the REST-v20 API.
	HostURL = "https://api-fxpractice.oanda.com/v3"

	// HostURLStream is the host url of the specialised streaming routes of the REST-v20 API.
	HostURLStream = "https://stream-fxpractice.oanda.com/v3"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID       string
	Alias    string
	Currency string

	OpenTradeCount    int
	OpenPositionCount int
	PendingOrderCount int

	HedgingEnabled bool

	MarginRate                 decimal.Decimal
	UnrealizedPL               decimal.Decimal
	NAV                        decimal.Decimal
	MarginUsed                 decimal.Decimal
	MarginAvailable            decimal.Decimal
	PositionValue              decimal.Decimal
	MarginCloseoutUnrealizedPL decimal.Decimal
	MarginCloseoutNAV          decimal.Decimal
	MarginCloseoutMarginUsed   decimal.Decimal
	MarginCloseoutPercent      decimal.Decimal
	WithdrawalLimit            decimal.Decimal
	Balance                    decimal.Decimal
	PL                         decimal.Decimal
	ResettablePL               decimal.Decimal

	Trades    []Trade
	Positions []Position
}

Account holds complete account information.

type AccountProperties

type AccountProperties struct {
	ID   string
	Tags []string
}

AccountProperties holds properties related to an account.

type Client

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

Client is a stateless client for the oanda REST-v20 API.

func NewClient added in v0.1.0

func NewClient(key string) (c *Client)

New returns a new client configured with the necessary auth and address etc.

func (*Client) GetAccount

func (c *Client) GetAccount(accountID string) (acc Account, err error)

GetAccount returns the IDs of all accounts registered with the broker.

func (*Client) GetAccountInstruments added in v0.4.0

func (c *Client) GetAccountInstruments(accountID string) (instruments []Instrument, err error)

GetAccountInstruments returns the instruments that an account can trade.

func (*Client) GetAccounts

func (c *Client) GetAccounts() (ids []string, err error)

GetAccounts returns the IDs of all accounts registered with the broker.

func (*Client) GetHTTPClient

func (c *Client) GetHTTPClient() *http.Client

GetHTTPClient returns the underlying http client used by the resty client.

func (*Client) GetOpenTrades

func (c *Client) GetOpenTrades(accountID string) (trades []Trade, err error)

GetOpenTrades returns all open trades of an account.

func (*Client) GetPositions

func (c *Client) GetPositions(accountID string) (positions []Position, err error)

GetPositions returns positions for all instruments that have had a position during the account's lifetime.

func (*Client) GetPricing

func (c *Client) GetPricing(accountID string, instruments []string) (prices []Pricing, err error)

GetPricing returns pricing for the given instruments.

func (*Client) GetPricingStream

func (c *Client) GetPricingStream(accountID string, instruments []string) (ch chan Pricing, err error)

GetPricingStream returns pricing for the given instruments.

func (*Client) PlaceOrder

func (c *Client) PlaceOrder(accountID string, order interface{}) (orderID int, err error)

PlaceOrder places the given order.

type DayOfWeek added in v0.4.0

type DayOfWeek string
const (
	Sunday    DayOfWeek = "SUNDAY"
	Monday    DayOfWeek = "MONDAY"
	Tuesday   DayOfWeek = "TUESDAY"
	Wednesday DayOfWeek = "WEDNESDAY"
	Thursday  DayOfWeek = "THURSDAY"
	Friday    DayOfWeek = "FRIDAY"
	Saturday  DayOfWeek = "SATURDAY"
)

type Instrument added in v0.4.0

type Instrument struct {
	Name                        string
	DisplayName                 string
	Type                        InstrumentType
	PipLocation                 int
	DisplayPrecision            int
	TradeUnitsPrecision         int
	MinimumTradeSize            decimal.Decimal
	MaximumTrailingStopDistance decimal.Decimal
	MinimumTrailingStopDistance decimal.Decimal
	MaximumPositionSize         decimal.Decimal
	MaximumOrderUnits           decimal.Decimal
	MarginRate                  decimal.Decimal
	Commission                  InstrumentCommission
	Financing                   InstrumentFinancing
}

Instrument represents an instrument that can be traded by an account.

type InstrumentCommission added in v0.4.0

type InstrumentCommission struct {
	Commission        decimal.Decimal
	UnitsTraded       decimal.Decimal
	MinimumCommission decimal.Decimal
}

InstrumentCommission represents instrument-specific commission information.

type InstrumentFinancing added in v0.4.0

type InstrumentFinancing struct {
	LongRate            decimal.Decimal
	ShortRate           decimal.Decimal
	FinancingDaysOfWeek []struct {
		DayOfWeek   DayOfWeek
		DaysCharged int
	}
}

InstrumentFinancing represents instrument-specific commission information.

type InstrumentType added in v0.4.0

type InstrumentType string

InstrumentType represents what type of instrument it is.

const (
	CurrencyType InstrumentType = "CURRENCY"
	CFDType      InstrumentType = "CFD"
	MetalType    InstrumentType = "METAL"
)

type LimitOrderRequest

type LimitOrderRequest struct {
	OrderRequest
}

TODO: Fill this with its fields.

type MarketIfTouchedOrderRequest

type MarketIfTouchedOrderRequest struct {
	OrderRequest
}

TODO: Fill this with its fields.

type MarketOrderRequest

type MarketOrderRequest struct {
	OrderRequest
}

TODO: Fill this with its fields.

type OrderPositionFill

type OrderPositionFill string

OrderPositionFill specifies how positions in the account are to be modified when an order is filled.

const (
	OpenOnly    OrderPositionFill = "OPEN_ONLY"
	ReduceFirst OrderPositionFill = "REDUCE_FIRST"
	ReduceOnly  OrderPositionFill = "REDUCE_ONLY"
	Default     OrderPositionFill = "DEFAULT"
)

type OrderRequest added in v0.4.1

type OrderRequest struct {
	Type         OrderType         `json:"type"`
	Instrument   string            `json:"instrument"`
	Units        decimal.Decimal   `json:"units,string"`
	TimeInForce  TimeInForce       `json:"timeInForce"`
	PositionFill OrderPositionFill `json:"positionFill"`
}

type OrderType

type OrderType string

OrderType represents the type of order to create.

const (
	Market           OrderType = "MARKET"
	Limit            OrderType = "LIMIT"
	Stop             OrderType = "STOP"
	MarketIfTouched  OrderType = "MARKET_IF_TOUCHED"
	TakeProfit       OrderType = "TAKE_PROFIT"
	StopLoss         OrderType = "STOP_LOSS"
	TrailingStopLoss OrderType = "TRAILING_STOP_LOSS"
	FixedPrice       OrderType = "FIXED_PRICE"
)

type Position

type Position struct {
	Instrument string

	PL           decimal.Decimal
	UnrealizedPL decimal.Decimal
	MarginUsed   decimal.Decimal
	ResettablePL decimal.Decimal

	Long  PositionSide
	Short PositionSide
}

Position holds information about a market position.

type PositionSide

type PositionSide struct {
	TradeIDs []string

	Units        decimal.Decimal
	AveragePrice decimal.Decimal
	PL           decimal.Decimal
	UnrealizedPL decimal.Decimal
	ResettablePL decimal.Decimal
}

PositionSide holds information either a long or short side of a position.

type PriceBucket

type PriceBucket struct {
	Price     decimal.Decimal
	Liquidity int
}

PriceBucket represents a price available for an amount of liquidity.

type Pricing added in v0.3.0

type Pricing struct {
	Instrument string
	Tradeable  bool
	Bids       []PriceBucket
	Asks       []PriceBucket
	Time       time.Time
}

Pricing represents an account-specific price of an instrument.

func (*Pricing) UnmarshalJSON added in v0.3.0

func (p *Pricing) UnmarshalJSON(b []byte) (err error)

type StopLossOrderRequest

type StopLossOrderRequest struct {
	OrderRequest
}

TODO: Fill this with its fields.

type StopOrderRequest

type StopOrderRequest struct {
	OrderRequest
}

TODO: Fill this with its fields.

type TakeProfitOrderRequest

type TakeProfitOrderRequest struct {
	OrderRequest
}

TODO: Fill this with its fields.

type TimeInForce

type TimeInForce string

TimeInForce represents how long an order should remain pending before being automatically cancelled.

const (
	GTC TimeInForce = "GTC"
	GTD TimeInForce = "GTD"
	GFD TimeInForce = "GFD"
	FOK TimeInForce = "FOK"
	IOC TimeInForce = "IOC"
)

type Trade

type Trade struct {
	ID         string
	Instrument string

	State TradeState

	Price                 decimal.Decimal
	InitialUnits          decimal.Decimal
	InitialMarginRequired decimal.Decimal
	CurrentUnits          decimal.Decimal
	RealizedPL            decimal.Decimal
	UnrealizedPL          decimal.Decimal
	MarginUsed            decimal.Decimal
	AverageClosePrice     decimal.Decimal

	OpenTime  time.Time
	CloseTime time.Time

	ClosingTransactionIDs []string
}

Trade represents a trade of an account.

func (*Trade) UnmarshalJSON added in v0.2.0

func (t *Trade) UnmarshalJSON(b []byte) (err error)

type TradeState

type TradeState string

TradeState represents the current state of a trade.

const (
	Open               TradeState = "OPEN"
	Closed             TradeState = "CLOSED"
	CloseWhenTradeable TradeState = "CLOSE_WHEN_TRADEABLE"
)

type TrailingStopLossOrderRequest

type TrailingStopLossOrderRequest struct {
	OrderRequest
}

TODO: Fill this with its fields.

Jump to

Keyboard shortcuts

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