If you are looking for the original repo please checkout og
branch.
This repo contains go code for querying Oanda's API for Forex price info. One could also set up a demo account to trade.
WARNING: This is for educational purposes only.
Taken from Oanda's REST V-20 API Introduction page:
The Oanda's REST V-20 API provides programmatic access to Oandas's next generation v20 trading engine. To use this API you must have a v20 trading account, which is available to all divisions except OANDA Global Markets.
What can I do with the OANDA REST-v20 API?
- Get real-time rates for all tradeable pairs 24 hours a day
- Access historical pricing information dating back to 2005
- Place, modify, close orders
- Manage your account settings
- Access your account/trading history
- Requires Go 1.22.5 or greater
- Register demo account from Oanda to obtain an API key
- Modify the
res_edit.json
file in this repo's root directory withID
andToken
obtained in the second step- rename
res_edit.json
tores.json
for go code to work correctly
- rename
Once the above is satisfied you can get the functions in this repo with:
go get github.com/davidhintelmann/Oanda-Go/oanda
Then import in your main.go
(or any go file) with
import "github.com/davidhintelmann/Oanda-Go/oanda"
The following list are the endpoints one can reach using this package.
Account Endpoints for Oanda's REST V-20 API.
-
accounts
Get a list of Orders for an Account -
accountID
Get the full details for a single Account that a client has access to. Full pending Order, open Trade and open Position representations are provided. -
summary
Get a summary for a single Account that a client has access to. -
instruments
Get the list of tradeable instruments for the given Account. The list of tradeable instruments is dependent on the regulatory division that the Account is located in, thus should be the same for all Accounts owned by a single user. -
changes
Endpoint used to poll an Account for its current state and changes since a specified TransactionID.
-
configuration
Set the client-configurable portions of an Account.
Instrument Endpoints for Oanda's REST V-20 API.
-
candles
Fetch candlestick data for an instrument. -
orderBook
Fetch an order book for an instrument. -
positionBook
Fetch a position book for an instrument.
Order Endpoints for Oanda's REST V-20 API.
-
orders
Get a list of Orders for an Account -
pendingOrders
List all pending Orders in an Account -
orders/{orderSpecifier}
Get details for a single Order in an Account
-
orders
Create an Order for an Account
-
orders/{orderSpecifier}
Replace an Order in an Account by simultaneously cancelling it and creating a replacement Order -
orders/{orderSpecifier}/cancel
Cancel a pending Order in an Account -
orders/{orderSpecifier}/clientExtensions
Update the Client Extensions for an Order in an Account. Do not set, modify, or delete clientExtensions if your account is associated with MT4.
Trade Endpoints for Oanda's REST V-20 API.
-
trades
Get a list of Trades for an Account -
openTrades
Get the list of open Trades for an Account -
trades/{tradeSpecifier}
Get the details of a specific Trade in an Account
-
trades/{tradeSpecifier}/close
Close (partially or fully) a specific open Trade in an Account -
trades/{tradeSpecifier}/clientExtensions
Update the Client Extensions for a Trade. Do not add, update, or delete the Client Extensions if your account is associated with MT4. -
trades/{tradeSpecifier}/orders
Create, replace and cancel a Trade’s dependent Orders (Take Profit, Stop Loss and Trailing Stop Loss) through the Trade itself
Position Endpoints for Oanda's REST V-20 API.
-
positions
List all Positions for an Account. The Positions returned are for every instrument that has had a position during the lifetime of an the Account. -
openPositions
List all open Positions for an Account. An open Position is a Position in an Account that currently has a Trade opened for it. -
positions/{instrument}
Get the details of a single Instrument’s Position in an Account. The Position may by open or not.
-
positions/{instrument}/close
Closeout the open Position for a specific instrument in an Account.
Transaction Endpoints for Oanda's REST V-20 API.
-
transactions
Get a list of Transactions pages that satisfy a time-based Transaction query. -
transactions/{transactionID}
Get the details of a single Account Transaction. -
transactions/idrange
Get a range of Transactions for an Account based on the Transaction IDs. -
transactions/sinceid
Get a range of Transactions for an Account starting at (but not including) a provided Transaction ID. -
transactions/stream
Get a stream of Transactions for an Account starting from when the request is made. Note: This endpoint is served by the streaming URLs.
Pricing Endpoints for Oanda's REST V-20 API.
-
candles/latest
Get dancing bears and most recently completed candles within an Account for specified combinations of instrument, granularity, and price component. -
pricing
Get pricing information for a specified list of Instruments within an Account. -
pricing/stream
Get a stream of Account Prices starting from when the request is made. This pricing stream does not include every single price created for the Account, but instead will provide at most 4 prices per second (every 250 milliseconds) for each instrument being requested. If more than one price is created for an instrument during the 250 millisecond window, only the price in effect at the end of the window is sent. This means that during periods of rapid price movement, subscribers to this stream will not be sent every price. Pricing windows for different connections to the price stream are not all aligned in the same way (i.e. they are not all aligned to the top of the second). This means that during periods of rapid price movement, different subscribers may observe different prices depending on their alignment. Note: This endpoint is served by the streaming URLs. -
instruments/{instrument}/candles
Fetch candlestick data for an instrument.