Oanda for Go
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
analytics Make start of an analytics sub package Nov 11, 2014
cmd/example Actually add the example program. Aug 16, 2016
status Refactor SetUpSuite & TearDownSuite. Nov 23, 2015
.travis.yml Add support for 64bit Ids on 32bit architectures. Feb 22, 2016
LICENSE.txt Initial checkin Sep 11, 2014
README.md Correct example in README and add executable example program. Aug 16, 2016
TODO.md Update TODO.md Nov 11, 2014
accounts.go Fix Id type for Account API. Mar 14, 2016
accounts_test.go Additional tests for Account. Mar 14, 2016
client.go Add logging and improve debugging support. Mar 26, 2016
debug.go Add logging and improve debugging support. Mar 26, 2016
events.go Adds EventFromJSON public method allowing for Event mocks Aug 10, 2016
events_test.go Add support for 64bit Ids on 32bit architectures. Feb 22, 2016
labs.go Fix for Period type. Feb 23, 2016
labs_test.go Refactor SetUpSuite & TearDownSuite. Nov 23, 2015
oanda_test.go Add support for 64bit Ids on 32bit architectures. Feb 22, 2016
orders.go Add support for 64bit Ids on 32bit architectures. Feb 22, 2016
orders_test.go Refactor SetUpSuite & TearDownSuite. Nov 23, 2015
positions.go Add support for 64bit Ids on 32bit architectures. Feb 22, 2016
positions_test.go Refactor SetUpSuite & TearDownSuite. Nov 23, 2015
prices.go Add logging and improve debugging support. Mar 26, 2016
prices_test.go Refactor SetUpSuite & TearDownSuite. Nov 23, 2015
rates.go Add support for 64bit Ids on 32bit architectures. Feb 22, 2016
rates_test.go Refactor SetUpSuite & TearDownSuite. Nov 23, 2015
release.go Add logging and improve debugging support. Mar 26, 2016
streaming.go Add logging and improve debugging support. Mar 26, 2016
trades.go Add support for 64bit Ids on 32bit architectures. Feb 22, 2016
trades_test.go Refactor SetUpSuite & TearDownSuite. Nov 23, 2015
util.go Add support for 64bit Ids on 32bit architectures. Feb 22, 2016
util_test.go Fix bugs in oanda.Time type and add tests. Aug 14, 2015

README.md

OANDA for Go

Build Status Coverage Status

OANDA for Go is a library to access the OANDA REST API from open source programming language Go.

OANDA is a technology company that provides internet based forex trading and currency information. OANDA provide access to their services via a free REST API. OANDA is not affiliated and does not endorse or recommend OANDA for Go.

Please note that this is an alpha release and the code is likely to contain bugs.

Usage

package main

import (
	"flag"
	"fmt"

	"github.com/santegoeds/oanda"
)

var (
	token   = flag.String("token", "", "Oanda authorization token.")
	account = flag.Int64("account", 0, "Oanda account.")
)

func main() {
	flag.Parse()

	if *token == "" {
		panic("An Oanda authorization token is required")
	}

	if *account == 0 {
		panic("An Oanda account is required")
	}

	client, err := oanda.NewFxPracticeClient(*token)
	if err != nil {
		panic(err)
	}

	client.SelectAccount(oanda.Id(*account))

	// List available instruments
	instruments, err := client.Instruments(nil, nil)
	if err != nil {
		panic(err)
	}
	fmt.Println(instruments)

	// Buy one unit of EUR/USD with a trailing stop of 10 pips.
	tradeInfo, err := client.NewTrade(oanda.Buy, 1, "eur_usd", oanda.TrailingStop(10.0))
	if err != nil {
		panic(err)
	}
	fmt.Println(tradeInfo)

	// Create and run a price server.
	priceServer, err := client.NewPriceServer("eur_usd")
	if err != nil {
		panic(err)
	}
	priceServer.ConnectAndHandle(func(instrument string, tick oanda.PriceTick) {
		fmt.Println("Received tick:", instrument, tick)
		priceServer.Stop()
	})

	// Close the previously opened trade.
	tradeCloseInfo, err := client.CloseTrade(tradeInfo.TradeId)
	if err != nil {
		panic(err)
	}
	fmt.Println(tradeCloseInfo)
}

License

Oanda for Go is released under the Apache License, Version 2.0