Golang : Get a list of crosses(instruments) available to trade from Oanda account
Below is a simple program to get a list of available crosses for trading from Oanda.com. My original purpose of writing this code is for developing my own trading bot and from what I discovered is that ..... not all crosses are available to trade in Oanda. Therefore, it is good to limit the trading bot to the crosses available.
Here you go!
package main
import (
"fmt"
"github.com/awoldes/goanda"
)
func main() {
oandaAccountID := ""
oandaAPIKey := ""
fmt.Println("Get list of tradeable instruments for this account id : " + oandaAccountID)
UsingLIVEAccount := false // set false to use https://api-fxpractice.oanda.com
oanda := goanda.NewConnection(oandaAccountID, oandaAPIKey, UsingLIVEAccount)
// list out all the available instruments under this account
crossesAvailableToTrade := oanda.GetAccountInstruments(oandaAccountID)
for k, v := range crossesAvailableToTrade.Instruments {
fmt.Println(k, v.Name)
}
// list only CURRENCY
fmt.Println("================================================================")
for _, v := range crossesAvailableToTrade.Instruments {
// only print those with type CURRENCY
if v.Type == "CURRENCY" {
//fmt.Println(k, v.Name)
fmt.Println(v.Name, ",")
}
}
}
See also : Golang : Oanda bot with Telegram and RSI example
By Adam Ng(黃武俊)
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+14.2k Golang : Reset buffer example
+19.4k Golang : Archive directory with tar and gzip
+25.5k Golang : Convert IP address string to long ( unsigned 32-bit integer )
+47.6k Golang : How to convert JSON string to map and slice
+4.6k HTTP common errors and their meaning explained
+6.4k Golang : Check if password length meet the requirement
+3.4k Golang : Switch Redis database redis.NewClient
+7.2k Golang : Gorrila set route name and get the current route name
+35k Golang : Integer is between a range
+5.4k Fix fatal error: evacuation not done in time problem
+20.9k Golang : Create and resolve(read) symbolic links
+14.9k Golang : Accurate and reliable decimal calculations