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
+8.9k Golang : How to join strings?
+15.6k Golang : Get all local users and print out their home directory, description and group id
+6.5k PHP : How to handle URI or URL with non-ASCII characters such as Chinese/Japanese/Korean(CJK) ?
+12.6k Golang : Search and extract certain XML data example
+4.9k Facebook : How to place save to Facebook button on your website
+11.2k Golang : Web routing/multiplex example
+5.6k Golang : fmt.Println prints out empty data from struct
+13.5k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+34.4k Golang : Create x509 certificate, private and public keys
+10.5k Golang : Embed secret text string into binary(executable) file
+8.3k Golang : Variadic function arguments sanity check example
+19.6k Golang : Fix cannot download, $GOPATH not set error