oanda

package module
v0.0.0-...-5f705f7 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2014 License: Apache-2.0 Imports: 11 Imported by: 0

README

OANDA for Go

Build Status

OANDA for Go is a library to access the OANDA REST API from open source programming language Go.

OANDA is a technology company that provides internet based forex trading and currency information. OANDA provide access to their services via a free REST API. OANDA is not affiliated and does not endorse or recommend OANDA for Go.

Please note that this is an alpha release and the code is likely to contain bugs.

Usage

package main

import (
    "fmt"

    "github.com/santegoeds/oanda"
)

func main() {
    client, err := oanda.NewSandboxClient()
    if err != nil {
        panic(err)
    }

    // List available instruments
    instruments, err := client.Instruments(nil, nil)
    if err != nil {
        panic(err)
    }
    fmt.Println(instruments)

    // Buy one unit of EUR/USD with a trailing stop of 10 pips.
    tr, err := client.NewTrade(oanda.Buy, 1, "eur_usd", oanda.TrailingStop(10.0))
    if err != nil {
        panic(err)
    }
    fmt.Println(tr)

    // Create and run a price server.
    priceServer, err := client.NewPriceServer("eur_usd")
    if err != nil {
        panic(err)
    }
    priceServer.ConnectAndHandle(func(instrument string, tick oanda.PriceTick) {
        fmt.Println("Received tick:", instrument, tick)
        priceServer.Stop()
    })
}

License

Oanda for Go is released under the Apache License, Version 2.0

Documentation

Index

Constants

View Source
const (
	Buy  TradeSide = "buy"
	Sell TradeSide = "sell"

	MarketIfTouched OrderType = "marketIfTouched"
	Limit           OrderType = "limit"
	Stop            OrderType = "stop"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	AccountId       int      `json:"accountId"`
	Name            string   `json:"accountName"`
	Balance         float64  `json:"balance"`
	UnrealizedPl    float64  `json:"unrealizedPl"`
	RealizedPl      float64  `json:"realizedPl"`
	MarginUsed      float64  `json:"marginUsed"`
	MarginAvailable float64  `json:"marginAvailable"`
	OpenTrades      int      `json:"openTrades"`
	OpenOrders      int      `json:"openOrders"`
	Currency        string   `json:"accountCurrency"`
	MarginRate      float64  `json:"marginRate"`
	PropertyName    []string `json:"accountPropertyName"`
}

Account represents an Oanda account.

func (*Account) String

func (a *Account) String() string

String implements the fmt.Stringer interface.

type AccountCreateEvent

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

AccountCreateEvent represents an event of type CREATE.

func (*AccountCreateEvent) AccountId

func (t *AccountCreateEvent) AccountId() int

func (*AccountCreateEvent) HomeCurrency

func (t *AccountCreateEvent) HomeCurrency() string

func (*AccountCreateEvent) Reason

func (t *AccountCreateEvent) Reason() string

func (*AccountCreateEvent) String

func (t *AccountCreateEvent) String() string

String implementes the fmt.Stringer interface.

func (*AccountCreateEvent) Time

func (t *AccountCreateEvent) Time() time.Time

func (*AccountCreateEvent) TranId

func (t *AccountCreateEvent) TranId() int

func (*AccountCreateEvent) Type

func (t *AccountCreateEvent) Type() string

func (*AccountCreateEvent) UnmarshalJSON

func (t *AccountCreateEvent) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

type AlignmentTimezone

type AlignmentTimezone time.Location

Optional argument for PollMidpriceCandles and PollBidAskCandles that indicates the timezone to use when aligning candles with DailyAlignment.

See http://developer.oanda.com/docs/v1/rates/#retrieve-instrument-history for further information.

type ApiError

type ApiError struct {
	Code     int    `json:"code"`
	Message  string `json:"message"`
	MoreInfo string `json:"moreInfo"`
}

ApiError holds error details as returned by the Oanda servers.

func (*ApiError) Error

func (ae *ApiError) Error() string

type BidAskCandles

type BidAskCandles struct {
	Instrument  string      `json:"instrument"`
	Granularity Granularity `json:"granularity"`
	Candles     []struct {
		Time     time.Time `json:"time"`
		OpenBid  float64   `json:"openBid"`
		OpenAsk  float64   `json:"openAsk"`
		HighBid  float64   `json:"highBid"`
		HighAsk  float64   `json:"highAsk"`
		LowBid   float64   `json:"lowBid"`
		LowAsk   float64   `json:"lowAsk"`
		CloseBid float64   `json:"closeBid"`
		CloseAsk float64   `json:"closeAsk"`
		Volume   int       `json:"volume"`
		Complete bool      `json:"complete"`
	} `json:"candles"`
}

BidAskCandles represents Bid and Ask instrument history with a specific granularity.

type CalendarEvent

type CalendarEvent struct {
	Title     string    `json:"title"`
	Timestamp time.Time `json:"timestamp"`
	Unit      string    `json:"unit"`
	Currency  string    `json:"currency"`
	Forecast  float64   `json:"forecast,string"`
	Previous  float64   `json:"previous,string"`
	Actual    float64   `json:"actual,string"`
	Market    float64   `json:"market,string"`
}

func (*CalendarEvent) UnmarshalJSON

func (ce *CalendarEvent) UnmarshalJSON(data []byte) error

type CancelOrderResponse

type CancelOrderResponse struct {
	TransactionId int       `json:"id"`
	Instrument    string    `json:"instrument"`
	Units         int       `json:"units"`
	Side          string    `json:"side"`
	Price         float64   `json:"price"`
	Time          time.Time `json:"time"`
}

type CandlesArg

type CandlesArg interface {
	// contains filtered or unexported methods
}

CandlesArg implements optional arguments for MidpointCandles and BidAskCandles.

type Client

type Client struct {
	*http.Client
	// contains filtered or unexported fields
}

func NewFxPracticeClient

func NewFxPracticeClient(token string) (*Client, error)

NewFxPracticeClient returns a client instance that connects to Oanda's fxpractice environment. String token should be set to the generated personal access token.

See http://developer.oanda.com/docs/v1/auth/ for further information.

func NewFxTradeClient

func NewFxTradeClient(token string) (*Client, error)

NewFxTradeClient returns a client instance that connects to Oanda's fxtrade environment. String token should be set to the generated personal access token.

See http://developer.oanda.com/docs/v1/auth/ for further information.

func NewSandboxClient

func NewSandboxClient() (*Client, error)

NewSandboxClient returns a client instance that connects to Oanda's fxsandbox environment. Creating a client will create a user in the sandbox environment with wich all further calls with be authenticated.

See http://developer.oanda.com/docs/v1/auth/ for further information.

func (*Client) Account

func (c *Client) Account(accountId int) (*Account, error)

Account queries the Oanda servers for account information for the specified accountId and returns a new Account instance.

func (*Client) Accounts

func (c *Client) Accounts() ([]Account, error)

Accounts returns a list with all the know accounts.

func (*Client) Calendar

func (c *Client) Calendar(instrument string, period Period) ([]CalendarEvent, error)

func (*Client) CancelOrder

func (c *Client) CancelOrder(orderId int) (*CancelOrderResponse, error)

CancelOrder closes an open order.

func (*Client) CancelRequest

func (c *Client) CancelRequest(req *http.Request)

CancelRequest aborts an in-progress http request.

func (*Client) ClosePosition

func (c *Client) ClosePosition(instrument string) (*PositionCloseResponse, error)

ClosePosition closes an existing position.

func (*Client) CloseTrade

func (c *Client) CloseTrade(tradeId int) (*CloseTradeResponse, error)

CloseTrade closes an open trade.

func (*Client) FullEventHistory

func (c *Client) FullEventHistory() (*url.URL, error)

FullEventHistory returns a url from which a file containing the full transaction history for the account can be downloaded.

func (*Client) Instruments

func (c *Client) Instruments(instruments []string, fields []InstrumentField) (map[string]InstrumentInfo, error)

Instruments returns instrument information. Only the specified instruments are returned if instruments is not nil. If fields is not nil additional information fields is included.

See http://developer.oanda.com/docs/v1/rates/#get-an-instrument-list for further information.

func (*Client) ModifyOrder

func (c *Client) ModifyOrder(orderId int, arg ModifyOrderArg, args ...ModifyOrderArg) (*Order, error)

ModifyOrder updates an open order. Supported arguments are Units(), Price(), Expiry(), UpperBound(), StopLoss(), TakeProfit() and TrailingStop().

func (*Client) ModifyTrade

func (c *Client) ModifyTrade(tradeId int, arg ModifyTradeArg, args ...ModifyTradeArg) (*Trade, error)

ModifyTrade modifies an open trade. Supported optional arguments are StopLoss(), TakeProfit(), TrailingStop()

func (*Client) NewEventServer

func (c *Client) NewEventServer(accountId ...int) (*EventServer, error)

NewEventServer returns an server instance for receiving events for the specified accountId(s). If no accountId is specified events for all accountIds are received. Note that the sandbox environment requires that at least one accountId is provided.

See http://developer.oanda.com/docs/v1/stream/#events-streaming for further information.

func (*Client) NewOrder

func (c *Client) NewOrder(orderType OrderType, side TradeSide, units int, instrument string,
	price float64, expiry time.Time, args ...NewOrderArg) (*Order, error)

NewOrder creates and submits a new order.

func (*Client) NewPricePoller

func (c *Client) NewPricePoller(since time.Time, instr string, instrs ...string) (*PricePoller, error)

NewPricePoller returns a poller to repeatedly poll Oanda for updates of the same set of instruments.

func (*Client) NewPriceServer

func (c *Client) NewPriceServer(instr string, instrs ...string) (*PriceServer, error)

NewPriceServer returns a PriceServer instance for receiving and handling Ticks.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body io.Reader) (*http.Request, error)

NewRequest creates a new http request.

func (*Client) NewTrade

func (c *Client) NewTrade(side TradeSide, units int, instrument string,
	args ...NewTradeArg) (*Trade, error)

NewTrade submits a MarketOrder request to the Oanda servers. Supported OptionalArgs are UpperBound(), LowerBound(), StopLoss(), TakeProfit() and TrailingStop().

func (*Client) Order

func (c *Client) Order(orderId int) (*Order, error)

Order returns information about an existing order.

func (*Client) Orders

func (c *Client) Orders(args ...OrdersArg) ([]Order, error)

Orders returns an array with all orders that match the optional arguments (if any). Supported OrdersArg are MaxId, Count and Instrument.

func (*Client) PollBidAskCandles

func (c *Client) PollBidAskCandles(instrument string, granularity Granularity,
	args ...CandlesArg) (*BidAskCandles, error)

PollBidAskCandles returns historic bid- and ask prices for an instrument.

func (*Client) PollEvent

func (c *Client) PollEvent(tranId int) (Event, error)

PollEvent returns data for a single event.

func (*Client) PollEvents

func (c *Client) PollEvents(args ...EventsArg) ([]Event, error)

PollEvents returns an array of events. Supported optional arguments are MaxId, MinId, Count, Instrument and Ids.

See http://developer.oanda.com/docs/v1/transactions/#get-transaction-history for further information.

func (*Client) PollMidpointCandles

func (c *Client) PollMidpointCandles(instrument string, granularity Granularity,
	args ...CandlesArg) (*MidpointCandles, error)

PollMidpointCandles returns historic midpoint prices for an instrument.

func (*Client) PollPrices

func (c *Client) PollPrices(instrument string, instruments ...string) (Prices, error)

PollPrices returns the latest PriceTick for the specified instruments.

func (*Client) PollPricesSince

func (c *Client) PollPricesSince(since time.Time, instr string, instrs ...string) (Prices, error)

PollPricesSince returns the PriceTicks for instruments. If since is not the zero time instruments whose prices were not updated since the requested time.Time are excluded from the result.

func (*Client) Position

func (c *Client) Position(instrument string) (*Position, error)

Position returns the position for the selected account and instrument.

func (*Client) Positions

func (c *Client) Positions() (Positions, error)

Positions returns all positions for the selected account.

func (*Client) SelectAccount

func (c *Client) SelectAccount(accountId int)

SelectAccount configures the account for which subsequent trades and orders are. Use AccountId 0 to disable account selection.

func (*Client) Trade

func (c *Client) Trade(tradeId int) (*Trade, error)

Trade returns an open trade.

func (*Client) Trades

func (c *Client) Trades(args ...TradesArg) (Trades, error)

Trades returns a list of open trades that match the optional arguments. Supported optional arguments are MaxId(), Count(), Instrument() and Ids().

type CloseTradeResponse

type CloseTradeResponse struct {
	TransactionId int       `json:"id"`
	Price         float64   `json:"price"`
	Instrument    string    `json:"instrument"`
	Profit        float64   `json:"profit"`
	Side          string    `json:"side"`
	Time          time.Time `json:"time"`
}

type ContentType

type ContentType string

type Count

type Count int

Count is an optional argument for Client methods Events(), Orders(), /MidpriceCandles(), BidAskCandles() and Trades().

type DailyAlignment

type DailyAlignment int

Optional argument for PollMidpriceCandles and PollBidAskCandles to indicate the hour at which candles hould be aligned. Only relevant for hourly or greater granularities.

See http://developer.oanda.com/docs/v1/rates/#retrieve-instrument-history for further information.

type DailyInterestEvent

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

DailyInterestEvent represents an event of type DAILY_INTEREST.

func (*DailyInterestEvent) AccountId

func (t *DailyInterestEvent) AccountId() int

func (*DailyInterestEvent) Interest

func (t *DailyInterestEvent) Interest() float64

func (*DailyInterestEvent) String

func (t *DailyInterestEvent) String() string

String implementes the fmt.Stringer interface.

func (*DailyInterestEvent) Time

func (t *DailyInterestEvent) Time() time.Time

func (*DailyInterestEvent) TranId

func (t *DailyInterestEvent) TranId() int

func (*DailyInterestEvent) Type

func (t *DailyInterestEvent) Type() string

func (*DailyInterestEvent) UnmarshalJSON

func (t *DailyInterestEvent) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

type DateFormat

type DateFormat string

type EndTime

type EndTime time.Time

Optional argument for PollMidpriceCandles and PollBidAskCandles to specify the end time of until which instrument history should be included.

See http://developer.oanda.com/docs/v1/rates/#retrieve-instrument-history for further information.

type Environment

type Environment string

type Event

type Event interface {
	TranId() int
	AccountId() int
	Time() time.Time
	Type() string
}

type EventHandlerFunc

type EventHandlerFunc func(int, Event)

type EventServer

type EventServer struct {
	// If HeartbeatFunc is not nil it is invoked once for every heartbeat message that the
	// EventServer receives.
	HeartbeatFunc HeartbeatHandlerFunc
	// contains filtered or unexported fields
}

An EventServer receives events (aka transactions) for one or more accountId(s).

func (*EventServer) ConnectAndHandle

func (es *EventServer) ConnectAndHandle(handleFn EventHandlerFunc) (err error)

ConnectAndDispatch starts the event server and blocks until Stop() is called. Function handleFn is called for each event that is received.

See http://developer.oanda.com/docs/v1/stream/ and http://developer.oanda.com/docs/v1/transactions/ for further information.

func (*EventServer) Stop

func (es *EventServer) Stop()

Stop terminates the events server and causes ConnectAndHandle() to return.

type EventsArg

type EventsArg interface {
	// contains filtered or unexported methods
}

EventsArg is an optional argument for method PollEvents.

type Expiry

type Expiry time.Time

Expiry is an optional argument for Client method ModifyOrder().

type FeeEvent

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

FeeEvent represents an event of type FEE

func (*FeeEvent) AccountBalance

func (t *FeeEvent) AccountBalance() float64

func (*FeeEvent) AccountId

func (t *FeeEvent) AccountId() int

func (*FeeEvent) Amount

func (t *FeeEvent) Amount() float64

func (*FeeEvent) Reason

func (t *FeeEvent) Reason() string

func (*FeeEvent) String

func (t *FeeEvent) String() string

String implementes the fmt.Stringer interface.

func (*FeeEvent) Time

func (t *FeeEvent) Time() time.Time

func (*FeeEvent) TranId

func (t *FeeEvent) TranId() int

func (*FeeEvent) Type

func (t *FeeEvent) Type() string

func (*FeeEvent) UnmarshalJSON

func (t *FeeEvent) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

type Granularity

type Granularity string

Granularity determines the interval at which historic instrument prices are converted into candles.

const (
	S5  Granularity = "S5"
	S10 Granularity = "S10"
	S15 Granularity = "S15"
	S30 Granularity = "S30"
	M1  Granularity = "M1"
	M2  Granularity = "M2"
	M3  Granularity = "M3"
	M5  Granularity = "M5"
	M10 Granularity = "M10"
	M15 Granularity = "M15"
	M30 Granularity = "M30"
	H1  Granularity = "H1"
	H2  Granularity = "H2"
	H3  Granularity = "H3"
	H4  Granularity = "H4"
	H6  Granularity = "H6"
	H8  Granularity = "H8"
	H12 Granularity = "H12"
	D   Granularity = "D"
	W   Granularity = "W"
	M   Granularity = "M"
)

type HeartbeatHandlerFunc

type HeartbeatHandlerFunc func(time.Time)

type Ids

type Ids []int

type IncludeFirst

type IncludeFirst bool

Optional argument for PollMidpriceCandles and PollBidAskCandles to indicate whether the candle that starts at StartTime should be included.

See http://developer.oanda.com/docs/v1/rates/#retrieve-instrument-history for further information.

type Instrument

type Instrument string

Instrument is an optional argument for Client methods Events(), Orders() and Trades().

type InstrumentField

type InstrumentField string
const (
	DisplayNameField     InstrumentField = "displayName"
	PipField             InstrumentField = "pip"
	MaxTradeUnitsField   InstrumentField = "maxTradeUnits"
	PrecisionField       InstrumentField = "precision"
	MaxTrailingStopField InstrumentField = "maxTrailingStop"
	MinTrailingStopField InstrumentField = "minTrailingStop"
	MarginRateField      InstrumentField = "marginRate"
	HaltedField          InstrumentField = "halted"
	InterestRateField    InstrumentField = "interestRate"
)

type InstrumentInfo

type InstrumentInfo struct {
	DisplayName     string  `json:"displayName"`
	Pip             float64 `json:"pip,string"`
	MaxTradeUnits   int     `json:"maxTradeUnits"`
	Precision       float64 `json:"precision"`
	MaxTrailingStop float64 `json:"maxTrailingStop"`
	MinTrailingStop float64 `json:"minTrailingStop"`
	MarginRate      float64 `json:"marginRate"`
	Halted          bool    `json:"halted"`
	InterestRate    map[string]struct {
		Bid float64 `json:"bid"`
		Ask float64 `json:"ask"`
	} `json:"interestRate"`
}

func (*InstrumentInfo) String

func (ii *InstrumentInfo) String() string

type LowerBound

type LowerBound float64

LowerBound is an optional argument for Client methods NewOrder(), ModifyOrder() and NewTrade().

type MaxId

type MaxId int

MaxId is an optional argument for Client methods Events(), Orders() and Trades().

type MidpointCandles

type MidpointCandles struct {
	Instrument  string      `json:"instrument"`
	Granularity Granularity `json:"granularity"`
	Candles     []struct {
		Time     time.Time `json:"time"`
		OpenMid  float64   `json:"openMid"`
		HighMid  float64   `json:"highMid"`
		LowMid   float64   `json:"lowMid"`
		CloseMid float64   `json:"closeMid"`
		Volume   int       `json:"volume"`
		Complete bool      `json:"complete"`
	} `json:"candles"`
}

MidpointCandles represents instrument history with a specific granularity.

type MigrateTradeOpenEvent

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

MigrateTradeOpenEvent represents an event of type MIGRATE_TRADE_OPEN

func (*MigrateTradeOpenEvent) AccountId

func (t *MigrateTradeOpenEvent) AccountId() int

func (*MigrateTradeOpenEvent) Instrument

func (t *MigrateTradeOpenEvent) Instrument() string

func (*MigrateTradeOpenEvent) Price

func (t *MigrateTradeOpenEvent) Price() float64

func (*MigrateTradeOpenEvent) Side

func (t *MigrateTradeOpenEvent) Side() string

func (*MigrateTradeOpenEvent) StopLossPrice

func (t *MigrateTradeOpenEvent) StopLossPrice() float64

func (*MigrateTradeOpenEvent) String

func (t *MigrateTradeOpenEvent) String() string

String implementes the fmt.Stringer interface.

func (*MigrateTradeOpenEvent) TakeProfitPrice

func (t *MigrateTradeOpenEvent) TakeProfitPrice() float64

func (*MigrateTradeOpenEvent) Time

func (t *MigrateTradeOpenEvent) Time() time.Time

func (*MigrateTradeOpenEvent) TradeOpened

func (t *MigrateTradeOpenEvent) TradeOpened() *evtTradeDetail

func (*MigrateTradeOpenEvent) TrailingStopLossDistance

func (t *MigrateTradeOpenEvent) TrailingStopLossDistance() float64

func (*MigrateTradeOpenEvent) TranId

func (t *MigrateTradeOpenEvent) TranId() int

func (*MigrateTradeOpenEvent) Type

func (t *MigrateTradeOpenEvent) Type() string

func (*MigrateTradeOpenEvent) Units

func (t *MigrateTradeOpenEvent) Units() int

func (*MigrateTradeOpenEvent) UnmarshalJSON

func (t *MigrateTradeOpenEvent) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

type MinId

type MinId int

type ModifyOrderArg

type ModifyOrderArg interface {
	// contains filtered or unexported methods
}

ModifyOrderArg represents an opional argument for method ModifyOrder. Types that implement the interface are Units, Price, Expiry, LowerBound, UpperBound, StopLoss, TakeProfit and TrailingStop.

type ModifyTradeArg

type ModifyTradeArg interface {
	// contains filtered or unexported methods
}

type NewOrderArg

type NewOrderArg interface {
	// contains filtered or unexported methods
}

NewOrderArg represents an optional argument for method NewOrder. Types that implement the interface are LowerBound, UpperBound, StopLoss, TakeProfit and TrailingStop.

type NewTradeArg

type NewTradeArg interface {
	// contains filtered or unexported methods
}

type Order

type Order struct {
	OrderId        int       `json:"id"`
	Units          int       `json:"units"`
	Instrument     string    `json:"instrument"`
	Side           string    `json:"side"`
	Price          float64   `json:"price"`
	Time           time.Time `json:"time"`
	StopLoss       float64   `json:"stopLoss"`
	TakeProfit     float64   `json:"takeProfit"`
	TrailingStop   float64   `json:"trailingStop"`
	TrailingAmount float64   `json:"trailingAmount"`
	OrderType      string    `json:"type"`
	Expiry         time.Time `json:"expiry"`
	UpperBound     float64   `json:"upperBound"`
	LowerBound     float64   `json:"lowerBound"`
}

func (*Order) String

func (o *Order) String() string

String implements the fmt.Stringer interface.

type OrderCancelEvent

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

OrderCancelEvent represents and event of type ORDER_CANCEL.

func (*OrderCancelEvent) AccountId

func (t *OrderCancelEvent) AccountId() int

func (*OrderCancelEvent) OrderId

func (t *OrderCancelEvent) OrderId() int

func (*OrderCancelEvent) Reason

func (t *OrderCancelEvent) Reason() string

func (*OrderCancelEvent) String

func (t *OrderCancelEvent) String() string

String implementes the fmt.Stringer interface.

func (*OrderCancelEvent) Time

func (t *OrderCancelEvent) Time() time.Time

func (*OrderCancelEvent) TranId

func (t *OrderCancelEvent) TranId() int

func (*OrderCancelEvent) Type

func (t *OrderCancelEvent) Type() string

func (*OrderCancelEvent) UnmarshalJSON

func (t *OrderCancelEvent) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

type OrderCreateEvent

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

OrderCreateEvent represents an event of type LIMIT_ORDER_CREATE, STOP_ORDER_CREATE or MARKET_IF_TOUCHED_CREATE

func (*OrderCreateEvent) AccountId

func (t *OrderCreateEvent) AccountId() int

func (*OrderCreateEvent) Expiry

func (t *OrderCreateEvent) Expiry() time.Time

func (*OrderCreateEvent) Instrument

func (t *OrderCreateEvent) Instrument() string

func (*OrderCreateEvent) LowerBound

func (t *OrderCreateEvent) LowerBound() float64

func (*OrderCreateEvent) Price

func (t *OrderCreateEvent) Price() float64

func (*OrderCreateEvent) Reason

func (t *OrderCreateEvent) Reason() string

func (*OrderCreateEvent) Side

func (t *OrderCreateEvent) Side() string

func (*OrderCreateEvent) StopLossPrice

func (t *OrderCreateEvent) StopLossPrice() float64

func (*OrderCreateEvent) String

func (t *OrderCreateEvent) String() string

String implementes the fmt.Stringer interface.

func (*OrderCreateEvent) TakeProfitPrice

func (t *OrderCreateEvent) TakeProfitPrice() float64

func (*OrderCreateEvent) Time

func (t *OrderCreateEvent) Time() time.Time

func (*OrderCreateEvent) TrailingStopLossDistance

func (t *OrderCreateEvent) TrailingStopLossDistance() float64

func (*OrderCreateEvent) TranId

func (t *OrderCreateEvent) TranId() int

func (*OrderCreateEvent) Type

func (t *OrderCreateEvent) Type() string

func (*OrderCreateEvent) Units

func (t *OrderCreateEvent) Units() int

func (*OrderCreateEvent) UnmarshalJSON

func (t *OrderCreateEvent) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

func (*OrderCreateEvent) UpperBound

func (t *OrderCreateEvent) UpperBound() float64

type OrderFilledEvent

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

OrderFilledEvent represents an event of type ORDER_FILLED.

func (*OrderFilledEvent) AccountId

func (t *OrderFilledEvent) AccountId() int

func (*OrderFilledEvent) OrderId

func (t *OrderFilledEvent) OrderId() int

func (*OrderFilledEvent) String

func (t *OrderFilledEvent) String() string

String implementes the fmt.Stringer interface.

func (*OrderFilledEvent) Time

func (t *OrderFilledEvent) Time() time.Time

func (*OrderFilledEvent) TranId

func (t *OrderFilledEvent) TranId() int

func (*OrderFilledEvent) Type

func (t *OrderFilledEvent) Type() string

func (*OrderFilledEvent) UnmarshalJSON

func (t *OrderFilledEvent) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

type OrderType

type OrderType string

type OrderUpdateEvent

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

OrderUpdateEvent represents an event of type ORDER_UPDATE

func (*OrderUpdateEvent) AccountId

func (t *OrderUpdateEvent) AccountId() int

func (*OrderUpdateEvent) Instrument

func (t *OrderUpdateEvent) Instrument() string

func (*OrderUpdateEvent) LowerBound

func (t *OrderUpdateEvent) LowerBound() float64

func (*OrderUpdateEvent) Reason

func (t *OrderUpdateEvent) Reason() string

func (*OrderUpdateEvent) Side

func (t *OrderUpdateEvent) Side() string

func (*OrderUpdateEvent) StopLossPrice

func (t *OrderUpdateEvent) StopLossPrice() float64

func (*OrderUpdateEvent) String

func (t *OrderUpdateEvent) String() string

String implementes the fmt.Stringer interface.

func (*OrderUpdateEvent) TakeProfitPrice

func (t *OrderUpdateEvent) TakeProfitPrice() float64

func (*OrderUpdateEvent) Time

func (t *OrderUpdateEvent) Time() time.Time

func (*OrderUpdateEvent) TrailingStopLossDistance

func (t *OrderUpdateEvent) TrailingStopLossDistance() float64

func (*OrderUpdateEvent) TranId

func (t *OrderUpdateEvent) TranId() int

func (*OrderUpdateEvent) Type

func (t *OrderUpdateEvent) Type() string

func (*OrderUpdateEvent) Units

func (t *OrderUpdateEvent) Units() int

func (*OrderUpdateEvent) UnmarshalJSON

func (t *OrderUpdateEvent) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

func (*OrderUpdateEvent) UpperBound

func (t *OrderUpdateEvent) UpperBound() float64

type OrdersArg

type OrdersArg interface {
	// contains filtered or unexported methods
}

OrderArgs represents an optional argument for method Orders. Types that implement the interface are MaxId, Count and Instrument.

type Period

type Period int
const (
	Hour  Period = Period(time.Hour)
	Day   Period = 24 * Hour
	Week  Period = 7 * Day
	Month Period = 2592000
	Year  Period = 31536000
)

type PollRequest

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

PollRequest represents an http request that is executed repeatedly.

func (*PollRequest) Poll

func (pr *PollRequest) Poll() (*http.Response, error)

Poll repeats the http request with which PollRequest was created.

type Position

type Position struct {
	Side       string  `json:"side"`
	Instrument string  `json:"instrument"`
	Units      int     `json:"units"`
	AvgPrice   float64 `json:"avgPrice"`
}

func (*Position) String

func (p *Position) String() string

String implements the fmt.Stringer interface.

type PositionCloseResponse

type PositionCloseResponse struct {
	// Ids are the transaction ids that are created as a result of closing the position.
	TranIds    Ids    `json:"ids"`
	Instrument string `json:"instrument"`
	TotalUnits int    `json:"totalUnits"`
}

type Positions

type Positions []Position

type Price

type Price float64

Price is an optional argument for Client method ModifyOrder().

type PricePoller

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

func (*PricePoller) Poll

func (pp *PricePoller) Poll() (Prices, error)

Poll returns the most recent set of prices for the instruments with which the PricePoller was configured.

type PriceServer

type PriceServer struct {
	// If HeartbeatFunc is not nil it is invoked once for every heartbeat message that the
	// PriceServer receives.
	HeartbeatFunc HeartbeatHandlerFunc
	// contains filtered or unexported fields
}

A PriceServer receives PriceTicks for one or more instrument(s).

func (*PriceServer) ConnectAndHandle

func (ps *PriceServer) ConnectAndHandle(handleFn TickHandlerFunc) error

ConnectAndHandle connects to the Oanda server and invokes handleFn for every Tick received.

func (*PriceServer) Stop

func (ps *PriceServer) Stop()

Stop terminates the Price server.

type PriceTick

type PriceTick struct {
	Time   time.Time `json:"time"`
	Bid    float64   `json:"bid"`
	Ask    float64   `json:"ask"`
	Status string    `json:"status"`
}

PriceTick holds the Bid price, Ask price and status for an instrument at a given point in time

func (*PriceTick) Spread

func (p *PriceTick) Spread() float64

Spread returns the difference between Ask and Bid prices.

type Prices

type Prices map[string]PriceTick

type SetMarginRateEvent

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

SetMarginRateEvent represent and event of type SET_MARGIN_RATE.

func (*SetMarginRateEvent) AccountId

func (t *SetMarginRateEvent) AccountId() int

func (*SetMarginRateEvent) Rate

func (t *SetMarginRateEvent) Rate() float64

func (*SetMarginRateEvent) String

func (t *SetMarginRateEvent) String() string

String implementes the fmt.Stringer interface.

func (*SetMarginRateEvent) Time

func (t *SetMarginRateEvent) Time() time.Time

func (*SetMarginRateEvent) TranId

func (t *SetMarginRateEvent) TranId() int

func (*SetMarginRateEvent) Type

func (t *SetMarginRateEvent) Type() string

func (*SetMarginRateEvent) UnmarshalJSON

func (t *SetMarginRateEvent) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

type StartTime

type StartTime time.Time

Optional argument for PollMidpriceCandles and PollBidAskCandles to specify the start time from which instrument history should be included.

See http://developer.oanda.com/docs/v1/rates/#retrieve-instrument-history for further information.

type StopLoss

type StopLoss float64

StopLoss is an optional argument for Client methods NewOrder(), ModifyOrder(), NewTrade() and ModifyTrade().

type StreamHandler

type StreamHandler interface {
	HandleHeartbeats(<-chan time.Time)
	HandleMessages(<-chan StreamMessage)
}

type StreamMessage

type StreamMessage struct {
	Type       string
	RawMessage json.RawMessage
}

func (*StreamMessage) String

func (msg *StreamMessage) String() string

func (*StreamMessage) UnmarshalJSON

func (msg *StreamMessage) UnmarshalJSON(data []byte) error

type StreamServer

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

func (StreamServer) HandleHeartbeats

func (ss StreamServer) HandleHeartbeats(hbC <-chan time.Time)

func (StreamServer) HandleMessages

func (ss StreamServer) HandleMessages(msgC <-chan StreamMessage)

type TakeProfit

type TakeProfit float64

TakeProfit is an optional argument for Client methods NewOrder(), ModifyOrder(), NewTrade(), and ModifyTrade().

type TickHandlerFunc

type TickHandlerFunc func(instr string, pp PriceTick)

type TimedReader

type TimedReader struct {
	Timeout time.Duration
	io.ReadCloser
	// contains filtered or unexported fields
}

func NewTimedReader

func NewTimedReader(r io.ReadCloser, timeout time.Duration) *TimedReader

NewTimedReader returns an instance of TimedReader where Read operations time out.

func (*TimedReader) Read

func (r *TimedReader) Read(p []byte) (int, error)

type TokenAuthenticator

type TokenAuthenticator string

type Trade

type Trade struct {
	TradeId        int       `json:"id"`
	Units          int       `json:"units"`
	Instrument     string    `json:"instrument"`
	Side           string    `json:"side"`
	Price          float64   `json:"price"`
	Time           time.Time `json:"time"`
	StopLoss       float64   `json:"stopLoss"`
	TakeProfit     float64   `json:"takeProfit"`
	TrailingStop   float64   `json:"trailingStop"`
	TrailingAmount float64   `json:"trailingAmount"`
}

Trade represents an open Oanda trade.

func (*Trade) String

func (t *Trade) String() string

String implements the Stringer interface.

type TradeCloseEvent

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

TradeCloseEvent represents an event of type TRADE_CLOSE, MIGRATE_TRADE_CLOSE, TAKE_PROFIT_FILLED, STOP_LOSS_FILLED, TRAILING_STOP_FILLED or MARGIN_CLOSEOUT.

func (*TradeCloseEvent) AccountBalance

func (t *TradeCloseEvent) AccountBalance() float64

func (*TradeCloseEvent) AccountId

func (t *TradeCloseEvent) AccountId() int

func (*TradeCloseEvent) Instrument

func (t *TradeCloseEvent) Instrument() string

func (*TradeCloseEvent) Interest

func (t *TradeCloseEvent) Interest() float64

func (*TradeCloseEvent) Pl

func (t *TradeCloseEvent) Pl() float64

func (*TradeCloseEvent) Price

func (t *TradeCloseEvent) Price() float64

func (*TradeCloseEvent) Side

func (t *TradeCloseEvent) Side() string

func (*TradeCloseEvent) String

func (t *TradeCloseEvent) String() string

String implementes the fmt.Stringer interface.

func (*TradeCloseEvent) Time

func (t *TradeCloseEvent) Time() time.Time

func (*TradeCloseEvent) TradeId

func (t *TradeCloseEvent) TradeId() int

func (*TradeCloseEvent) TranId

func (t *TradeCloseEvent) TranId() int

func (*TradeCloseEvent) Type

func (t *TradeCloseEvent) Type() string

func (*TradeCloseEvent) Units

func (t *TradeCloseEvent) Units() int

func (*TradeCloseEvent) UnmarshalJSON

func (t *TradeCloseEvent) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

type TradeCreateEvent

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

TradeCreateEvent represents an event of type MARKET_ORDER_CREATE

func (*TradeCreateEvent) AccountBalance

func (t *TradeCreateEvent) AccountBalance() float64

func (*TradeCreateEvent) AccountId

func (t *TradeCreateEvent) AccountId() int

func (*TradeCreateEvent) Instrument

func (t *TradeCreateEvent) Instrument() string

func (*TradeCreateEvent) Interest

func (t *TradeCreateEvent) Interest() float64

func (*TradeCreateEvent) LowerBound

func (t *TradeCreateEvent) LowerBound() float64

func (*TradeCreateEvent) Pl

func (t *TradeCreateEvent) Pl() float64

func (*TradeCreateEvent) Price

func (t *TradeCreateEvent) Price() float64

func (*TradeCreateEvent) Side

func (t *TradeCreateEvent) Side() string

func (*TradeCreateEvent) StopLossPrice

func (t *TradeCreateEvent) StopLossPrice() float64

func (*TradeCreateEvent) String

func (t *TradeCreateEvent) String() string

String implementes the fmt.Stringer interface.

func (*TradeCreateEvent) TakeProfitPrice

func (t *TradeCreateEvent) TakeProfitPrice() float64

func (*TradeCreateEvent) Time

func (t *TradeCreateEvent) Time() time.Time

func (*TradeCreateEvent) TradeOpened

func (t *TradeCreateEvent) TradeOpened() *evtTradeDetail

func (*TradeCreateEvent) TradeReduced

func (t *TradeCreateEvent) TradeReduced() *evtTradeDetail

func (*TradeCreateEvent) TrailingStopLossDistance

func (t *TradeCreateEvent) TrailingStopLossDistance() float64

func (*TradeCreateEvent) TranId

func (t *TradeCreateEvent) TranId() int

func (*TradeCreateEvent) Type

func (t *TradeCreateEvent) Type() string

func (*TradeCreateEvent) Units

func (t *TradeCreateEvent) Units() int

func (*TradeCreateEvent) UnmarshalJSON

func (t *TradeCreateEvent) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

func (*TradeCreateEvent) UpperBound

func (t *TradeCreateEvent) UpperBound() float64

type TradeSide

type TradeSide string

type TradeUpdateEvent

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

TradeUpdateEvent represents an event of type TRADE_UPDATE

func (*TradeUpdateEvent) AccountId

func (t *TradeUpdateEvent) AccountId() int

func (*TradeUpdateEvent) Instrument

func (t *TradeUpdateEvent) Instrument() string

func (*TradeUpdateEvent) Side

func (t *TradeUpdateEvent) Side() string

func (*TradeUpdateEvent) StopLossPrice

func (t *TradeUpdateEvent) StopLossPrice() float64

func (*TradeUpdateEvent) String

func (t *TradeUpdateEvent) String() string

String implementes the fmt.Stringer interface.

func (*TradeUpdateEvent) TailingStopLossDistance

func (t *TradeUpdateEvent) TailingStopLossDistance() float64

func (*TradeUpdateEvent) TakeProfitPrice

func (t *TradeUpdateEvent) TakeProfitPrice() float64

func (*TradeUpdateEvent) Time

func (t *TradeUpdateEvent) Time() time.Time

func (*TradeUpdateEvent) TradeId

func (t *TradeUpdateEvent) TradeId() int

func (*TradeUpdateEvent) TranId

func (t *TradeUpdateEvent) TranId() int

func (*TradeUpdateEvent) Type

func (t *TradeUpdateEvent) Type() string

func (*TradeUpdateEvent) Units

func (t *TradeUpdateEvent) Units() int

func (*TradeUpdateEvent) UnmarshalJSON

func (t *TradeUpdateEvent) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

type Trades

type Trades []Trade

type TradesArg

type TradesArg interface {
	// contains filtered or unexported methods
}

type TrailingStop

type TrailingStop float64

TrailingStop is an optional argument for Client methods NewOrder(), ModifyOrder(), NewTrade() and ModifyTrade().

type TransferFundsEvent

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

TransferFundsEvent represents an event of type TRANSFER_FUNDS.

func (*TransferFundsEvent) AccountId

func (t *TransferFundsEvent) AccountId() int

func (*TransferFundsEvent) Amount

func (t *TransferFundsEvent) Amount() float64

func (*TransferFundsEvent) String

func (t *TransferFundsEvent) String() string

String implementes the fmt.Stringer interface.

func (*TransferFundsEvent) Time

func (t *TransferFundsEvent) Time() time.Time

func (*TransferFundsEvent) TranId

func (t *TransferFundsEvent) TranId() int

func (*TransferFundsEvent) Type

func (t *TransferFundsEvent) Type() string

func (*TransferFundsEvent) UnmarshalJSON

func (t *TransferFundsEvent) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

type Units

type Units int

Units is an optional argument for Client method ModifyOrder().

type UpperBound

type UpperBound float64

UpperBound is an optional argument for Client methods NewOrder(), ModifyOrder() and NewTrade().

type UsernameAuthenticator

type UsernameAuthenticator string

type WeeklyAlignment

type WeeklyAlignment time.Weekday

Optional argument for PollMidpriceCandles and PollBidAskCandles to indicate the weekday at which candles should be aligned. Only relevant for weekly granularity.

See http://developer.oanda.com/docs/v1/rates/#retrieve-instrument-history for further information.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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