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
+13.9k Golang : Get current time
+9.9k Golang : ffmpeg with os/exec.Command() returns non-zero status
+32.2k Golang : Convert []string to []byte examples
+19.6k Golang : Set or Add HTTP Request Headers
+11.7k Golang : How to detect a server/machine network interface capabilities?
+7.8k Golang : Reverse a string with unicode
+7.9k Javascript : How to check a browser's Do Not Track status?
+12.3k Golang : How to display image file or expose CSS, JS files from localhost?
+28k Golang : Move file to another directory
+6.2k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+19.2k Golang : Check if directory exist and create if does not exist
+21.8k Golang : Convert string slice to struct and access with reflect example