goanda

package module
v0.0.0-...-f64b6fc Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2020 License: MIT Imports: 11 Imported by: 0

README

forked from https://github.com/AwolDes/goanda

goanda

A Golang wrapper for the OANDA v20 API. Currently OANDA has wrappers for Python, Javascript and Java. Goanda exists to extend upon those languages because of the increasing popularity of Go and for a side prject I'm working on.

Features

Goanda can perform the following actions on your OANDA brokerage accounts:

  • Get candlesticks of all instruments
  • Create and update orders
  • Get data on current and past trades on OANDA
  • Close/scale out of trades you have open
  • Close positions (not just trades)
  • Get data on your account
    • NAV
    • Current % of used margin
    • Balance
    • And more!
  • Get data on all your transactions
  • Get all pricing data (bid/ask spread) on specific instruments

Requirements

  • Go v1.9+

Note: This package was created by a third party, and was not created by anyone affiliated with OANDA

Usage

To use this package run go get github.com/AwolDes/goanda then import it into your program and set it up following the snippets below.

Basic Example

I suggest creating a .env file for your project to keep your secrets safe! Make sure you add a .gitignore file.

~/project/.env

OANDA_API_KEY=
OANDA_ACCOUNT=

~/project/main.go

package main

import (
	"log"
	"os"

	"github.com/AwolDes/goanda"
	"github.com/davecgh/go-spew/spew"
	"github.com/joho/godotenv"
)

func main() {
	err := godotenv.Load()
	if err != nil {
		log.Fatal("Error loading .env file")
	}
	key := os.Getenv("OANDA_API_KEY")
	accountID := os.Getenv("OANDA_ACCOUNT_ID")
	oanda := goanda.NewConnection(accountID, key, false)
	history := oanda.GetCandles("EUR_USD")
	spew.Dump(history)
}

Look at the /examples directory for more!

Contributing

For now if you'd like to contribute create an Issue and/or submit a PR!

TODO

API (in order of priority)
  • Instrument endpoints (to get prices and the order book)
  • Order endpoints (to create, get or update orders for an account)
  • Trade enpoints (to get information on current trades)
  • Position endpoints (to get information on current positions)
  • Account endpoints (to get information on the account)
  • Transaction endpoints (to get information on account transactions)
  • Pricing endpoints (to get pricing of instruments)
  • Streaming endpoints for Pricing & Transactions
Docs
  • Write docs on how to use goanda
  • Write example programs for goanda
  • Write tests for goanda

Supporting Projects

Thank you to the following projects, they really helped me while I was developing this API

License

This project was created under the MIT license

Documentation

Index

Constants

View Source
const OANDA_AGENT string = "v20-golang/0.0.1"

Variables

This section is empty.

Functions

func DPanicf

func DPanicf(template string, args ...interface{})

func Debugf

func Debugf(template string, args ...interface{})

func Errorf

func Errorf(template string, args ...interface{})

func Fatalf

func Fatalf(template string, args ...interface{})

func Infof

func Infof(template string, args ...interface{})

func Panicf

func Panicf(template string, args ...interface{})

func Warnf

func Warnf(template string, args ...interface{})

Types

type AccountChanges

type AccountChanges struct {
	Changes struct {
		OrdersCancelled []interface{} `json:"ordersCancelled"`
		OrdersCreated   []interface{} `json:"ordersCreated"`
		OrdersFilled    []struct {
			CreateTime           time.Time `json:"createTime"`
			FilledTime           time.Time `json:"filledTime"`
			FillingTransactionID string    `json:"fillingTransactionID"`
			ID                   string    `json:"id"`
			Instrument           string    `json:"instrument"`
			PositionFill         string    `json:"positionFill"`
			State                string    `json:"state"`
			TimeInForce          string    `json:"timeInForce"`
			TradeOpenedID        string    `json:"tradeOpenedID"`
			Type                 string    `json:"type"`
			Units                string    `json:"units"`
		} `json:"ordersFilled"`
		OrdersTriggered []interface{} `json:"ordersTriggered"`
		Positions       []struct {
			Instrument string `json:"instrument"`
			Long       struct {
				Pl           string `json:"pl"`
				ResettablePL string `json:"resettablePL"`
				Units        string `json:"units"`
			} `json:"long"`
			Pl           string `json:"pl"`
			ResettablePL string `json:"resettablePL"`
			Short        struct {
				AveragePrice string   `json:"averagePrice"`
				Pl           string   `json:"pl"`
				ResettablePL string   `json:"resettablePL"`
				TradeIDs     []string `json:"tradeIDs"`
				Units        string   `json:"units"`
			} `json:"short"`
		} `json:"positions"`
		TradesClosed []interface{} `json:"tradesClosed"`
		TradesOpened []struct {
			CurrentUnits string    `json:"currentUnits"`
			Financing    string    `json:"financing"`
			ID           string    `json:"id"`
			InitialUnits string    `json:"initialUnits"`
			Instrument   string    `json:"instrument"`
			OpenTime     time.Time `json:"openTime"`
			Price        string    `json:"price"`
			RealizedPL   string    `json:"realizedPL"`
			State        string    `json:"state"`
		} `json:"tradesOpened"`
		TradesReduced []interface{} `json:"tradesReduced"`
		Transactions  []struct {
			AccountID      string    `json:"accountID"`
			BatchID        string    `json:"batchID"`
			ID             string    `json:"id"`
			Instrument     string    `json:"instrument"`
			PositionFill   string    `json:"positionFill,omitempty"`
			Reason         string    `json:"reason"`
			Time           time.Time `json:"time"`
			TimeInForce    string    `json:"timeInForce,omitempty"`
			Type           string    `json:"type"`
			Units          string    `json:"units"`
			UserID         int       `json:"userID"`
			AccountBalance string    `json:"accountBalance,omitempty"`
			Financing      string    `json:"financing,omitempty"`
			OrderID        string    `json:"orderID,omitempty"`
			Pl             string    `json:"pl,omitempty"`
			Price          string    `json:"price,omitempty"`
			TradeOpened    struct {
				TradeID string `json:"tradeID"`
				Units   string `json:"units"`
			} `json:"tradeOpened,omitempty"`
		} `json:"transactions"`
	} `json:"changes"`
	LastTransactionID string `json:"lastTransactionID"`
	State             struct {
		NAV                        string        `json:"NAV"`
		MarginAvailable            string        `json:"marginAvailable"`
		MarginCloseoutMarginUsed   string        `json:"marginCloseoutMarginUsed"`
		MarginCloseoutNAV          string        `json:"marginCloseoutNAV"`
		MarginCloseoutPercent      string        `json:"marginCloseoutPercent"`
		MarginCloseoutUnrealizedPL string        `json:"marginCloseoutUnrealizedPL"`
		MarginUsed                 string        `json:"marginUsed"`
		Orders                     []interface{} `json:"orders"`
		PositionValue              string        `json:"positionValue"`
		Positions                  []struct {
			Instrument        string `json:"instrument"`
			LongUnrealizedPL  string `json:"longUnrealizedPL"`
			NetUnrealizedPL   string `json:"netUnrealizedPL"`
			ShortUnrealizedPL string `json:"shortUnrealizedPL"`
		} `json:"positions"`
		Trades []struct {
			ID           string `json:"id"`
			UnrealizedPL string `json:"unrealizedPL"`
		} `json:"trades"`
		UnrealizedPL    string `json:"unrealizedPL"`
		WithdrawalLimit string `json:"withdrawalLimit"`
	} `json:"state"`
	ErrorMessage string `json:"errorMessage"`
}

type AccountInfo

type AccountInfo struct {
	Account struct {
		NAV                         string        `json:"NAV"`
		Alias                       string        `json:"alias"`
		Balance                     string        `json:"balance"`
		CreatedByUserID             int           `json:"createdByUserID"`
		CreatedTime                 time.Time     `json:"createdTime"`
		Currency                    string        `json:"currency"`
		HedgingEnabled              bool          `json:"hedgingEnabled"`
		ID                          string        `json:"id"`
		LastTransactionID           string        `json:"lastTransactionID"`
		MarginAvailable             string        `json:"marginAvailable"`
		MarginCloseoutMarginUsed    string        `json:"marginCloseoutMarginUsed"`
		MarginCloseoutNAV           string        `json:"marginCloseoutNAV"`
		MarginCloseoutPercent       string        `json:"marginCloseoutPercent"`
		MarginCloseoutPositionValue string        `json:"marginCloseoutPositionValue"`
		MarginCloseoutUnrealizedPL  string        `json:"marginCloseoutUnrealizedPL"`
		MarginRate                  string        `json:"marginRate"`
		MarginUsed                  string        `json:"marginUsed"`
		OpenPositionCount           int           `json:"openPositionCount"`
		OpenTradeCount              int           `json:"openTradeCount"`
		Orders                      []interface{} `json:"orders"`
		PendingOrderCount           int           `json:"pendingOrderCount"`
		Pl                          string        `json:"pl"`
		PositionValue               string        `json:"positionValue"`
		Positions                   []struct {
			Instrument string `json:"instrument"`
			Long       struct {
				Pl           string `json:"pl"`
				ResettablePL string `json:"resettablePL"`
				Units        string `json:"units"`
				UnrealizedPL string `json:"unrealizedPL"`
			} `json:"long"`
			Pl           string `json:"pl"`
			ResettablePL string `json:"resettablePL"`
			Short        struct {
				Pl           string `json:"pl"`
				ResettablePL string `json:"resettablePL"`
				Units        string `json:"units"`
				UnrealizedPL string `json:"unrealizedPL"`
			} `json:"short"`
			UnrealizedPL string `json:"unrealizedPL"`
		} `json:"positions"`
		ResettablePL    string        `json:"resettablePL"`
		Trades          []interface{} `json:"trades"`
		UnrealizedPL    string        `json:"unrealizedPL"`
		WithdrawalLimit string        `json:"withdrawalLimit"`
	} `json:"account"`
	LastTransactionID string `json:"lastTransactionID"`
	ErrorMessage      string `json:"errorMessage"`
}

type AccountInstruments

type AccountInstruments struct {
	Instruments []struct {
		DisplayName                 string `json:"displayName"`
		DisplayPrecision            int    `json:"displayPrecision"`
		MarginRate                  string `json:"marginRate"`
		MaximumOrderUnits           string `json:"maximumOrderUnits"`
		MaximumPositionSize         string `json:"maximumPositionSize"`
		MaximumTrailingStopDistance string `json:"maximumTrailingStopDistance"`
		MinimumTradeSize            string `json:"minimumTradeSize"`
		MinimumTrailingStopDistance string `json:"minimumTrailingStopDistance"`
		Name                        string `json:"name"`
		PipLocation                 int    `json:"pipLocation"`
		TradeUnitsPrecision         int    `json:"tradeUnitsPrecision"`
		Type                        string `json:"type"`
	} `json:"instruments"`
	ErrorMessage string `json:"errorMessage"`
}

type AccountProperties

type AccountProperties struct {
	Accounts []struct {
		ID           string `json:"id"`
		Mt4AccountID int    `json:"mt4AccountID"`
		Tags         []string
	}
}

type AccountSummary

type AccountSummary struct {
	Account struct {
		NAV                         string    `json:"NAV"`
		Alias                       string    `json:"alias"`
		Balance                     float64   `json:"balance,string"`
		CreatedByUserID             int       `json:"createdByUserID"`
		CreatedTime                 time.Time `json:"createdTime"`
		Currency                    string    `json:"currency"`
		HedgingEnabled              bool      `json:"hedgingEnabled"`
		ID                          string    `json:"id"`
		LastTransactionID           string    `json:"lastTransactionID"`
		MarginAvailable             float64   `json:"marginAvailable,string"`
		MarginCloseoutMarginUsed    string    `json:"marginCloseoutMarginUsed"`
		MarginCloseoutNAV           string    `json:"marginCloseoutNAV"`
		MarginCloseoutPercent       string    `json:"marginCloseoutPercent"`
		MarginCloseoutPositionValue string    `json:"marginCloseoutPositionValue"`
		MarginCloseoutUnrealizedPL  string    `json:"marginCloseoutUnrealizedPL"`
		MarginRate                  string    `json:"marginRate"`
		MarginUsed                  string    `json:"marginUsed"`
		OpenPositionCount           int       `json:"openPositionCount"`
		OpenTradeCount              int       `json:"openTradeCount"`
		PendingOrderCount           int       `json:"pendingOrderCount"`
		Pl                          string    `json:"pl"`
		PositionValue               string    `json:"positionValue"`
		ResettablePL                string    `json:"resettablePL"`
		UnrealizedPL                string    `json:"unrealizedPL"`
		WithdrawalLimit             string    `json:"withdrawalLimit"`
	} `json:"account"`
	LastTransactionID string `json:"lastTransactionID"`
	ErrorMessage      string `json:"errorMessage"`
}

type BidAskCandles

type BidAskCandles struct {
	Candles []struct {
		Ask struct {
			C float64 `json:"c,string"`
			H float64 `json:"h,string"`
			L float64 `json:"l,string"`
			O float64 `json:"o,string"`
		} `json:"ask"`
		Bid struct {
			C float64 `json:"c,string"`
			H float64 `json:"h,string"`
			L float64 `json:"l,string"`
			O float64 `json:"o,string"`
		} `json:"bid"`
		Complete bool      `json:"complete"`
		Time     time.Time `json:"time"`
		Volume   int       `json:"volume"`
	} `json:"candles"`
	ErrorMessage string `json:"errorMessage"`
}

type BrokerBook

type BrokerBook struct {
	Instrument   string    `json:"instrument"`
	Time         time.Time `json:"time"`
	Price        string    `json:"price"`
	BucketWidth  string    `json:"bucketWidth"`
	Buckets      []Bucket  `json:"buckets"`
	ErrorMessage string    `json:"errorMessage"`
}

type Bucket

type Bucket struct {
	Price             string `json:"price"`
	LongCountPercent  string `json:"longCountPercent"`
	ShortCountPercent string `json:"shortCountPercent"`
	ErrorMessage      string `json:"errorMessage"`
}

type CancelledOrder

type CancelledOrder struct {
	OrderCancelTransaction struct {
		ID                string    `json:"id"`
		Time              time.Time `json:"time"`
		UserID            int       `json:"userID"`
		AccountID         string    `json:"accountID"`
		BatchID           string    `json:"batchID"`
		RequestID         string    `json:"requestID"`
		Type              string    `json:"type"`
		OrderID           string    `json:"orderID"`
		ClientOrderID     string    `json:"clientOrderID"`
		Reason            string    `json:"reason"`
		ReplacedByOrderID string    `json:"replacedByOrderID"`
	} `json:"orderCancelTransaction"`
	RelatedTransactionIDs []string `json:"relatedTransactionIDs"`
	LastTransactionID     string   `json:"lastTransactionID"`
	ErrorMessage          string   `json:"errorMessage"`
}

type Candle

type Candle struct {
	Open         float64 `json:"o,string"`
	Close        float64 `json:"c,string"`
	Low          float64 `json:"l,string"`
	High         float64 `json:"h,string"`
	ErrorMessage string  `json:"errorMessage"`
}

type Candles

type Candles struct {
	Complete     bool      `json:"complete"`
	Volume       int       `json:"volume"`
	Time         time.Time `json:"time"`
	Mid          Candle    `json:"mid"`
	ErrorMessage string    `json:"errorMessage"`
}

type ClosePositionPayload

type ClosePositionPayload struct {
	LongUnits  string `json:"longUnits"`
	ShortUnits string `json:"shortUnits"`
}

type CloseTradePayload

type CloseTradePayload struct {
	Units string
}

type Connection

type Connection interface {
	Request(endpoint string) []byte
	Send(endpoint string, data []byte) []byte
	Update(endpoint string, data []byte) []byte
	GetOrderDetails(instrument string, units string) OrderDetails
	GetAccountSummary() (AccountSummary, error)
	CreateOrder(body OrderPayload) OrderResponse
}

type Headers

type Headers struct {
	DatetimeFormat string
	// contains filtered or unexported fields
}

type InstrumentHistory

type InstrumentHistory struct {
	Instrument   string    `json:"instrument"`
	Granularity  string    `json:"granularity"`
	Candles      []Candles `json:"candles"`
	ErrorMessage string    `json:"errorMessage"`
}

type InstrumentPricing

type InstrumentPricing struct {
	Time   time.Time `json:"time"`
	Prices []struct {
		Type string    `json:"type"`
		Time time.Time `json:"time"`
		Bids []struct {
			Price     float64 `json:"price,string"`
			Liquidity int     `json:"liquidity"`
		} `json:"bids"`
		Asks []struct {
			Price     float64 `json:"price,string"`
			Liquidity int     `json:"liquidity"`
		} `json:"asks"`
		CloseoutBid    float64 `json:"closeoutBid,string"`
		CloseoutAsk    float64 `json:"closeoutAsk,string"`
		Status         string  `json:"status"`
		Tradeable      bool    `json:"tradeable"`
		UnitsAvailable struct {
			Default struct {
				Long  string `json:"long"`
				Short string `json:"short"`
			} `json:"default"`
			OpenOnly struct {
				Long  string `json:"long"`
				Short string `json:"short"`
			} `json:"openOnly"`
			ReduceFirst struct {
				Long  string `json:"long"`
				Short string `json:"short"`
			} `json:"reduceFirst"`
			ReduceOnly struct {
				Long  string `json:"long"`
				Short string `json:"short"`
			} `json:"reduceOnly"`
		} `json:"unitsAvailable"`
		QuoteHomeConversionFactors struct {
			PositiveUnits string `json:"positiveUnits"`
			NegativeUnits string `json:"negativeUnits"`
		} `json:"quoteHomeConversionFactors"`
		Instrument string `json:"instrument"`
	} `json:"prices"`
	ErrorMessage string `json:"errorMessage"`
}

type ModifiedTrade

type ModifiedTrade struct {
	OrderCreateTransaction struct {
		Type         string `json:"type"`
		Instrument   string `json:"instrument"`
		Units        string `json:"units"`
		TimeInForce  string `json:"timeInForce"`
		PositionFill string `json:"positionFill"`
		Reason       string `json:"reason"`
		TradeClose   struct {
			Units   string `json:"units"`
			TradeID string `json:"tradeID"`
		} `json:"tradeClose"`
		ID        string    `json:"id"`
		UserID    int       `json:"userID"`
		AccountID string    `json:"accountID"`
		BatchID   string    `json:"batchID"`
		RequestID string    `json:"requestID"`
		Time      time.Time `json:"time"`
	} `json:"orderCreateTransaction"`
	OrderFillTransaction struct {
		Type           string `json:"type"`
		Instrument     string `json:"instrument"`
		Units          string `json:"units"`
		Price          string `json:"price"`
		FullPrice      string `json:"fullPrice"`
		PL             string `json:"pl"`
		Financing      string `json:"financing"`
		Commission     string `json:"commission"`
		AccountBalance string `json:"accountBalance"`
		TradeOpened    string `json:"tradeOpened"`
		TimeInForce    string `json:"timeInForce"`
		PositionFill   string `json:"positionFill"`
		Reason         string `json:"reason"`
		TradesClosed   []struct {
			TradeID    string `json:"tradeID"`
			Units      string `json:"units"`
			RealizedPL string `json:"realizedPL"`
			Financing  string `json:"financing"`
		} `json:"tradesClosed"`
		TradeReduced struct {
			TradeID    string `json:"tradeID"`
			Units      string `json:"units"`
			RealizedPL string `json:"realizedPL"`
			Financing  string `json:"financing"`
		} `json:"tradeReduced"`
		ID            string    `json:"id"`
		UserID        int       `json:"userID"`
		AccountID     string    `json:"accountID"`
		BatchID       string    `json:"batchID"`
		RequestID     string    `json:"requestID"`
		OrderID       string    `json:"orderId"`
		ClientOrderID string    `json:"clientOrderId"`
		Time          time.Time `json:"time"`
	} `json:"orderFillTransaction"`
	OrderCancelTransaction struct {
		Type      string    `json:"type"`
		OrderID   string    `json:"orderID"`
		Reason    string    `json:"reason"`
		ID        string    `json:"id"`
		UserID    int       `json:"userID"`
		AccountID string    `json:"accountID"`
		BatchID   string    `json:"batchID"`
		RequestID string    `json:"requestID"`
		Time      time.Time `json:"time"`
	} `json:"orderCancelTransaction"`
	RelatedTransactionIDs []string `json:"relatedTransactionIDs"`
	LastTransactionID     string   `json:"lastTransactionID"`
	ErrorMessage          string   `json:"errorMessage"`
}

type OandaConnection

type OandaConnection struct {
	DatetimeFormat string
	// contains filtered or unexported fields
}

func NewConnection

func NewConnection(accountID string, token string, live bool) *OandaConnection

func (*OandaConnection) CancelOrder

func (c *OandaConnection) CancelOrder(orderSpecifier string) (CancelledOrder, error)

func (*OandaConnection) ClosePosition

func (c *OandaConnection) ClosePosition(instrument string, body ClosePositionPayload) (ModifiedTrade, error)

func (*OandaConnection) CloseTrade

func (c *OandaConnection) CloseTrade(tradeId string) (ModifiedTrade, error)

func (*OandaConnection) CreateOrder

func (c *OandaConnection) CreateOrder(body OrderPayload) (OrderResponse, error)

func (*OandaConnection) GetAccount

func (c *OandaConnection) GetAccount(id string) (AccountInfo, error)

func (*OandaConnection) GetAccountChanges

func (c *OandaConnection) GetAccountChanges(id string, transactionId string) (AccountChanges, error)

func (*OandaConnection) GetAccountInstruments

func (c *OandaConnection) GetAccountInstruments(id string) (AccountInstruments, error)

func (*OandaConnection) GetAccountSummary

func (c *OandaConnection) GetAccountSummary() (AccountSummary, error)

func (*OandaConnection) GetAccounts

func (c *OandaConnection) GetAccounts() (AccountProperties, error)

func (*OandaConnection) GetBidAskCandles

func (c *OandaConnection) GetBidAskCandles(instrument string, count string, granularity string) (BidAskCandles, error)

func (*OandaConnection) GetCandles

func (c *OandaConnection) GetCandles(instrument string, count string, granularity string) (InstrumentHistory, error)

func (*OandaConnection) GetInstrumentPrice

func (c *OandaConnection) GetInstrumentPrice(instrument string) (InstrumentPricing, error)

func (*OandaConnection) GetOpenPositions

func (c *OandaConnection) GetOpenPositions() (OpenPositions, error)

func (*OandaConnection) GetOpenTrades

func (c *OandaConnection) GetOpenTrades() (ReceivedTrades, error)

func (*OandaConnection) GetOrder

func (c *OandaConnection) GetOrder(orderSpecifier string) (RetrievedOrder, error)

func (*OandaConnection) GetOrderDetails

func (c *OandaConnection) GetOrderDetails(instrument string, units string) (OrderDetails, error)

func (*OandaConnection) GetOrders

func (c *OandaConnection) GetOrders(instrument string) (RetrievedOrders, error)

func (*OandaConnection) GetPendingOrders

func (c *OandaConnection) GetPendingOrders() (RetrievedOrders, error)

func (*OandaConnection) GetPricingForInstruments

func (c *OandaConnection) GetPricingForInstruments(instruments []string) (Pricings, error)

func (*OandaConnection) GetTrade

func (c *OandaConnection) GetTrade(ticket string) (ReceivedTrade, error)

func (*OandaConnection) GetTradesForInstrument

func (c *OandaConnection) GetTradesForInstrument(instrument string) (ReceivedTrades, error)

func (*OandaConnection) GetTransaction

func (c *OandaConnection) GetTransaction(ticket string) (Transaction, error)

func (*OandaConnection) GetTransactions

func (c *OandaConnection) GetTransactions(from time.Time, to time.Time) (TransactionPages, error)

https://golang.org/pkg/time/#Time.AddDate https://play.golang.org/p/Dw7D4JJ7EC

func (*OandaConnection) GetTransactionsSinceId

func (c *OandaConnection) GetTransactionsSinceId(id string) (Transactions, error)

func (*OandaConnection) OrderBook

func (c *OandaConnection) OrderBook(instrument string) (BrokerBook, error)

func (*OandaConnection) OrderReplace

func (c *OandaConnection) OrderReplace(orderId string, body OrderPayload) (RetrievedOrder, error)

func (*OandaConnection) PositionBook

func (c *OandaConnection) PositionBook(instrument string) (BrokerBook, error)

func (*OandaConnection) ReduceTradeSize

func (c *OandaConnection) ReduceTradeSize(ticket string, body CloseTradePayload) (ModifiedTrade, error)

Default is close the whole position using the string "ALL" in body.units

func (*OandaConnection) Request

func (c *OandaConnection) Request(endpoint string) ([]byte, error)

TODO: include params as a second option

func (*OandaConnection) Send

func (c *OandaConnection) Send(endpoint string, data []byte) ([]byte, error)

func (*OandaConnection) Update

func (c *OandaConnection) Update(endpoint string, data []byte) ([]byte, error)

func (*OandaConnection) UpdateOrder

func (c *OandaConnection) UpdateOrder(orderSpecifier string, body OrderPayload) (RetrievedOrder, error)

type OandaPricingStreamMessage

type OandaPricingStreamMessage struct {
	Type        StreamMsgType
	Time        time.Time
	Instrument  string
	Bids        []PriceBucket
	Asks        []PriceBucket
	CloseoutBid decimal.Decimal
	CloseoutAsk decimal.Decimal
}

type OandaTransactionStreamMessage

type OandaTransactionStreamMessage struct {
	Type                    StreamMsgType
	Instrument              string
	Units                   string
	Price                   string
	TimeInForce             string
	TriggerCondition        string
	PartialFill             string
	PositionFill            string
	RejectReason            string
	Reason                  string
	Id                      string `json:"id"`
	AccountID               string
	UserID                  int64
	BatchID                 string
	RequestID               string
	TradeID                 string
	ReplacesOrderID         string `json:"replacesOrderID"`
	ReplacedByOrderID       string `json:"replacedByOrderID"`
	OrderID                 string
	CancellingTransactionID string
	Commission              string
	Financing               string
	TradesClosed            *[]TradesClosed
	TradeOpened             *TradeOpened
	Guaranteed              bool
	Time                    time.Time
	IntendedReplacesOrderID string
}

type OnFill

type OnFill struct {
	TimeInForce string `json:"timeInForce,omitempty"`
	Price       string `json:"price,omitempty"` // must be a string for float precision
}

type OpenPositions

type OpenPositions struct {
	LastTransactionID string `json:"lastTransactionID"`
	Positions         []struct {
		Instrument string `json:"instrument"`
		Long       struct {
			AveragePrice string   `json:"averagePrice"`
			Pl           string   `json:"pl"`
			ResettablePL string   `json:"resettablePL"`
			TradeIDs     []string `json:"tradeIDs"`
			Units        string   `json:"units"`
			UnrealizedPL string   `json:"unrealizedPL"`
		} `json:"long"`
		Pl           string `json:"pl"`
		ResettablePL string `json:"resettablePL"`
		Short        struct {
			Pl           string `json:"pl"`
			ResettablePL string `json:"resettablePL"`
			Units        string `json:"units"`
			UnrealizedPL string `json:"unrealizedPL"`
		} `json:"short"`
		UnrealizedPL string `json:"unrealizedPL"`
	} `json:"positions"`
}

type OrderBody

type OrderBody struct {
	Units            int              `json:"units"`
	Instrument       string           `json:"instrument"`
	TimeInForce      string           `json:"timeInForce"`
	Type             string           `json:"type"`
	PositionFill     string           `json:"positionFill,omitempty"`
	Price            string           `json:"price,omitempty"`
	StopLossOnFill   *OnFill          `json:"stopLossOnFill,omitempty"`
	ClientExtensions *OrderExtensions `json:"clientExtensions,omitempty"`
	TradeID          string           `json:"tradeID,omitempty"`
}

type OrderDetails

type OrderDetails struct {
	GainPerPipPerMillionUnits float64 `json:"gainPerPipPerMillionUnits,string"`
	LossPerPipPerMillionUnits float64 `json:"lossPerPipPerMillionUnits,string"`
	UnitsAvailable            struct {
		Default struct {
			Long  float64 `json:"long,string"`
			Short float64 `json:"short,string"`
		} `json:"default"`
		OpenOnly struct {
			Long  float64 `json:"long,string"`
			Short float64 `json:"short,string"`
		} `json:"openOnly"`
		ReduceFirst struct {
			Long  float64 `json:"long,string"`
			Short float64 `json:"short,string"`
		} `json:"reduceFirst"`
		ReduceOnly struct {
			Long  float64 `json:"long,string"`
			Short float64 `json:"short,string"`
		} `json:"reduceOnly"`
	} `json:"unitsAvailable"`
	UnitValues struct {
		Isolation struct {
			Units               float64 `json:"units,string"`
			Commission          float64 `json:"commission,string"`
			PositionValueChange float64 `json:"positionValueChange,string"`
			PositionValue       float64 `json:"positionValue,string"`
			MarginRequired      float64 `json:"marginRequired,string"`
			MarginUsed          float64 `json:"marginUsed,string"`
		} `json:"isolation"`
		PositionDefault struct {
			Units               float64 `json:"units,string"`
			Commission          float64 `json:"commission,string"`
			PositionValueChange float64 `json:"positionValueChange,string"`
			PositionValue       float64 `json:"positionValue,string"`
			MarginRequired      float64 `json:"marginRequired,string"`
			MarginUsed          float64 `json:"marginUsed,string"`
		} `json:"positionDefault"`
		PositionOpenOnly struct {
			Units               float64 `json:"units,string"`
			Commission          float64 `json:"commission,string"`
			PositionValueChange float64 `json:"positionValueChange,string"`
			PositionValue       float64 `json:"positionValue,string"`
			MarginRequired      float64 `json:"marginRequired,string"`
			MarginUsed          float64 `json:"marginUsed,string"`
		} `json:"positionOpenOnly"`
		PositionReduceFirst struct {
			Units               float64 `json:"units,string"`
			Commission          float64 `json:"commission,string"`
			PositionValueChange float64 `json:"positionValueChange,string"`
			PositionValue       float64 `json:"positionValue,string"`
			MarginRequired      float64 `json:"marginRequired,string"`
			MarginUsed          float64 `json:"marginUsed,string"`
		} `json:"positionReduceFirst"`
		PositionReduceOnly struct {
			Units               float64 `json:"units,string"`
			Commission          float64 `json:"commission,string"`
			PositionValueChange float64 `json:"positionValueChange,string"`
			PositionValue       float64 `json:"positionValue,string"`
			MarginRequired      float64 `json:"marginRequired,string"`
			MarginUsed          float64 `json:"marginUsed,string"`
		} `json:"positionReduceOnly"`
	} `json:"unitValues"`
	ValueTables struct {
		CommissionTable []struct {
			Units string `json:"units"`
			Value string `json:"value"`
		} `json:"commissionTable"`
	} `json:"valueTables"`
	LastTransactionID string `json:"lastTransactionID"`
	ErrorMessage      string `json:"errorMessage"`
}

type OrderExtensions

type OrderExtensions struct {
	Comment string `json:"comment,omitempty"`
	ID      string `json:"id,omitempty"`
	Tag     string `json:"tag,omitempty"`
}

type OrderInfo

type OrderInfo struct {
	ClientExtensions struct {
		Comment string `json:"comment,omitempty"`
		ID      string `json:"id,omitempty"`
		Tag     string `json:"tag,omitempty"`
	} `json:"clientExtensions,omitempty"`
	CreateTime       time.Time `json:"createTime"`
	ID               string    `json:"id"`
	Instrument       string    `json:"instrument,omitempty"`
	PartialFill      string    `json:"partialFill"`
	PositionFill     string    `json:"positionFill"`
	Price            string    `json:"price"`
	ReplacesOrderID  string    `json:"replacesOrderID,omitempty"`
	State            string    `json:"state"`
	TimeInForce      string    `json:"timeInForce"`
	TriggerCondition string    `json:"triggerCondition"`
	Type             string    `json:"type"`
	Units            string    `json:"units,omitempty"`
	TradeID          string    `json:"tradeID,omitempty"`
	ErrorMessage     string    `json:"errorMessage"`
}

type OrderPayload

type OrderPayload struct {
	Order OrderBody `json:"order"`
}

type OrderReplace

type OrderReplace struct {
	OrderCancelTransaction struct {
		ID                string    `json:"id"`
		Time              time.Time `json:"time"`
		UserID            int       `json:"userID"`
		AccountID         string    `json:"accountID"`
		BatchID           string    `json:"batchID"`
		RequestID         string    `json:"requestID"`
		Type              string    `json:"type"`
		OrderID           string    `json:"orderID"`
		ClientOrderID     string    `json:"clientOrderID"`
		Reason            string    `json:"reason"`
		ReplacedByOrderID string    `json:"replacedByOrderID"`
	} `json:"orderCancelTransaction"`
	RelatedTransactionIDs []string `json:"relatedTransactionIDs"`
	LastTransactionID     string   `json:"lastTransactionID"`
	ErrorMessage          string   `json:"errorMessage"`
}

type OrderResponse

type OrderResponse struct {
	LastTransactionID      string `json:"lastTransactionID"`
	OrderCreateTransaction struct {
		AccountID    string    `json:"accountID"`
		BatchID      string    `json:"batchID"`
		ID           string    `json:"id"`
		Instrument   string    `json:"instrument"`
		PositionFill string    `json:"positionFill"`
		Reason       string    `json:"reason"`
		Time         time.Time `json:"time"`
		TimeInForce  string    `json:"timeInForce"`
		Type         string    `json:"type"`
		Units        string    `json:"units"`
		UserID       int       `json:"userID"`
	} `json:"orderCreateTransaction"`
	OrderFillTransaction struct {
		AccountBalance string    `json:"accountBalance"`
		AccountID      string    `json:"accountID"`
		BatchID        string    `json:"batchID"`
		Financing      string    `json:"financing"`
		ID             string    `json:"id"`
		Instrument     string    `json:"instrument"`
		OrderID        string    `json:"orderID"`
		Pl             string    `json:"pl"`
		Price          string    `json:"price"`
		Reason         string    `json:"reason"`
		Time           time.Time `json:"time"`
		TradeOpened    struct {
			TradeID string `json:"tradeID"`
			Units   string `json:"units"`
		} `json:"tradeOpened"`
		Type   string `json:"type"`
		Units  string `json:"units"`
		UserID int    `json:"userID"`
	} `json:"orderFillTransaction"`
	RelatedTransactionIDs []string `json:"relatedTransactionIDs"`
	ErrorMessage          string   `json:"errorMessage"`
}

type PriceBucket

type PriceBucket struct {
	Price     decimal.Decimal
	Liquidity int64
}

type Pricings

type Pricings struct {
	Prices []struct {
		Asks []struct {
			Liquidity int    `json:"liquidity"`
			Price     string `json:"price"`
		} `json:"asks"`
		Bids []struct {
			Liquidity int    `json:"liquidity"`
			Price     string `json:"price"`
		} `json:"bids"`
		CloseoutAsk                string `json:"closeoutAsk"`
		CloseoutBid                string `json:"closeoutBid"`
		Instrument                 string `json:"instrument"`
		QuoteHomeConversionFactors struct {
			NegativeUnits string `json:"negativeUnits"`
			PositiveUnits string `json:"positiveUnits"`
		} `json:"quoteHomeConversionFactors"`
		Status         string    `json:"status"`
		Time           time.Time `json:"time"`
		UnitsAvailable struct {
			Default struct {
				Long  string `json:"long"`
				Short string `json:"short"`
			} `json:"default"`
			OpenOnly struct {
				Long  string `json:"long"`
				Short string `json:"short"`
			} `json:"openOnly"`
			ReduceFirst struct {
				Long  string `json:"long"`
				Short string `json:"short"`
			} `json:"reduceFirst"`
			ReduceOnly struct {
				Long  string `json:"long"`
				Short string `json:"short"`
			} `json:"reduceOnly"`
		} `json:"unitsAvailable"`
	} `json:"prices"`
}

type ReceivedTrade

type ReceivedTrade struct {
	LastTransactionID string `json:"lastTransactionID"`
	Trades            struct {
		CurrentUnits string    `json:"currentUnits"`
		Financing    string    `json:"financing"`
		ID           string    `json:"id"`
		InitialUnits string    `json:"initialUnits"`
		Instrument   string    `json:"instrument"`
		OpenTime     time.Time `json:"openTime"`
		Price        string    `json:"price"`
		RealizedPL   string    `json:"realizedPL"`
		State        string    `json:"state"`
		UnrealizedPL string    `json:"unrealizedPL"`
	} `json:"trade"`
}

type ReceivedTrades

type ReceivedTrades struct {
	LastTransactionID string `json:"lastTransactionID"`
	Trades            []struct {
		CurrentUnits    string         `json:"currentUnits"`
		Financing       string         `json:"financing"`
		ID              string         `json:"id"`
		InitialUnits    string         `json:"initialUnits"`
		Instrument      string         `json:"instrument"`
		OpenTime        time.Time      `json:"openTime"`
		Price           string         `json:"price"`
		RealizedPL      string         `json:"realizedPL"`
		State           string         `json:"state"`
		UnrealizedPL    string         `json:"unrealizedPL"`
		StopLossOrder   *StopLossOrder `json:"stopLossOrder,omitempty"`
		TakeProfitOrder *StopLossOrder `json:"takeProfitOrder,omitempty"`
	} `json:"trades"`
	ErrorMessage string `json:"errorMessage"`
}

type RetrievedOrder

type RetrievedOrder struct {
	Order        OrderInfo `json:"order"`
	ErrorMessage string    `json:"errorMessage"`
}

type RetrievedOrders

type RetrievedOrders struct {
	LastTransactionID string      `json:"lastTransactionID"`
	Orders            []OrderInfo `json:"orders,omitempty"`
	ErrorMessage      string      `json:"errorMessage"`
}

type StopLossOrder

type StopLossOrder struct {
	ID    string `json:"id"`
	Price string `json:"price"`
}

type StreamMsgType

type StreamMsgType string
const (
	HeartbeatType                         StreamMsgType = "HEARTBEAT"
	CreateType                            StreamMsgType = "CREATE"
	CloseType                             StreamMsgType = "CLOSE"
	ReopenType                            StreamMsgType = "REOPEN"
	ClientConfigureType                   StreamMsgType = "CLIENT_CONFIGURE"
	ClientConfigureRejectType             StreamMsgType = "CLIENT_CONFIGURE_REJECT"
	TransferFundsType                     StreamMsgType = "TRANSFER_FUNDS"
	TransferFundsRejectType               StreamMsgType = "TRANSFER_FUNDS_REJECT"
	MarketOrderType                       StreamMsgType = "MARKET_ORDER"
	MarketOrderRejectType                 StreamMsgType = "MARKET_ORDER_REJECT"
	FixedPriceOrderType                   StreamMsgType = "FIXED_PRICE_ORDER"
	LimitOrderType                        StreamMsgType = "LIMIT_ORDER"
	LimitOrderRejectType                  StreamMsgType = "LIMIT_ORDER_REJECT"
	StopOrderType                         StreamMsgType = "STOP_ORDER"
	StopOrderRejectType                   StreamMsgType = "STOP_ORDER_REJECT"
	MarketIfTouchedOrderType              StreamMsgType = "MARKET_IF_TOUCHED_ORDER"
	MarketIfTouchedOrderRejectType        StreamMsgType = "MARKET_IF_TOUCHED_ORDER_REJECT"
	TakeProfitOrderType                   StreamMsgType = "TAKE_PROFIT_ORDER"
	TakeProfitOrderRejectType             StreamMsgType = "TAKE_PROFIT_ORDER_REJECT"
	StopLossOrderType                     StreamMsgType = "STOP_LOSS_ORDER"
	StopLossOrderRejectType               StreamMsgType = "STOP_LOSS_ORDER_REJECT"
	TrailingStopLossOrderType             StreamMsgType = "TRAILING_STOP_LOSS_ORDER"
	TrailingStopLossOrderRejectType       StreamMsgType = "TRAILING_STOP_LOSS_ORDER_REJECT"
	OrderFillType                         StreamMsgType = "ORDER_FILL"
	OrderCancelType                       StreamMsgType = "ORDER_CANCEL"
	OrderCancelRejectType                 StreamMsgType = "ORDER_CANCEL_REJECT"
	OrderClientExtensionsModifyType       StreamMsgType = "ORDER_CLIENT_EXTENSIONS_MODIFY"
	OrderClientExtensionsModifyRejectType StreamMsgType = "ORDER_CLIENT_EXTENSIONS_MODIFY_REJECT"
	TradeClientExtensionsModifyType       StreamMsgType = "TRADE_CLIENT_EXTENSIONS_MODIFY"
	TradeClientExtensionsModifyRejectType StreamMsgType = "TRADE_CLIENT_EXTENSIONS_MODIFY_REJECT"
	MarginCallEnterType                   StreamMsgType = "MARGIN_CALL_ENTER"
	MarginCallExtendType                  StreamMsgType = "MARGIN_CALL_EXTEND"
	MarginCallExitType                    StreamMsgType = "MARGIN_CALL_EXIT"
	DelayedTradeClosureType               StreamMsgType = "DELAYED_TRADE_CLOSURE"
	DailyFinancingType                    StreamMsgType = "DAILY_FINANCING"
	DividendType                          StreamMsgType = "DIVIDEND"
	ResetResettablePlType                 StreamMsgType = "RESET_RESETTABLE_PL"

	PriceType StreamMsgType = "PRICE"
)

type TakeProfitOrder

type TakeProfitOrder struct {
	ID    string `json:"id"`
	Price string `json:"price"`
}

type TradeOpened

type TradeOpened struct {
	TradeID string
	Price   string
}

type TradesClosed

type TradesClosed struct {
	TradeID   string
	Price     string
	Financing string
}

type Transaction

type Transaction struct {
	LastTransactionID string `json:"lastTransactionID"`
	Transaction       struct {
		AccountBalance string    `json:"accountBalance"`
		AccountID      string    `json:"accountID"`
		BatchID        string    `json:"batchID"`
		Financing      string    `json:"financing"`
		ID             string    `json:"id"`
		Instrument     string    `json:"instrument"`
		OrderID        string    `json:"orderID"`
		Pl             string    `json:"pl"`
		Price          string    `json:"price"`
		Reason         string    `json:"reason"`
		Time           time.Time `json:"time"`
		TradeOpened    struct {
			TradeID string `json:"tradeID"`
			Units   string `json:"units"`
		} `json:"tradeOpened"`
		Type   string `json:"type"`
		Units  string `json:"units"`
		UserID int    `json:"userID"`
	} `json:"transaction"`
}

type TransactionPages

type TransactionPages struct {
	Count             int       `json:"count"`
	From              time.Time `json:"from"`
	LastTransactionID string    `json:"lastTransactionID"`
	PageSize          int       `json:"pageSize"`
	Pages             []string  `json:"pages"`
	To                time.Time `json:"to"`
}

type Transactions

type Transactions struct {
	LastTransactionID string `json:"lastTransactionID"`
	Transactions      []struct {
		AccountBalance string    `json:"accountBalance"`
		AccountID      string    `json:"accountID"`
		BatchID        string    `json:"batchID"`
		Financing      string    `json:"financing"`
		ID             string    `json:"id"`
		Instrument     string    `json:"instrument"`
		OrderID        string    `json:"orderID"`
		Pl             string    `json:"pl"`
		Price          string    `json:"price"`
		Reason         string    `json:"reason"`
		Time           time.Time `json:"time"`
		TradeOpened    struct {
			TradeID string `json:"tradeID"`
			Units   string `json:"units"`
		} `json:"tradeOpened"`
		Type   string `json:"type"`
		Units  string `json:"units"`
		UserID int    `json:"userID"`
	} `json:"transactions"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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