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
+22.6k Golang : Set and Get HTTP request headers example
+10.1k Golang : Use regular expression to get all upper case or lower case characters example
+12.4k Golang : Forwarding a local port to a remote server example
+16.4k Golang : Get IP addresses of a domain name
+17.3k Golang : Check if IP address is version 4 or 6
+39k Golang : How to iterate over a []string(array)
+6.5k Golang : Spell checking with ispell example
+10.2k Golang : Detect number of faces or vehicles in a photo
+11k Golang : Roll the dice example
+10.2k Golang : How to check if a website is served via HTTPS
+5.7k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+14.2k Golang : How to shuffle elements in array or slice?