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
+11.4k Golang : Post data with url.Values{}
+8k Javascript : Put image into Chrome browser's console
+8.3k Golang : HttpRouter multiplexer routing example
+5.1k Golang : Check if a word is countable or not
+13.4k Golang : Linear algebra and matrix calculation example
+24.1k Golang : Find biggest/largest number in array
+8.1k Golang : What fmt.Println() can do and println() cannot do
+22.4k Golang : Convert seconds to minutes and remainder seconds
+8.9k Golang : On lambda, anonymous, inline functions and function literals
+22.3k Golang : How to run Golang application such as web server in the background or as daemon?
+14.3k Golang : Fix image: unknown format error
+6.3k Golang & Javascript : How to save cropped image to file on server