This is a work in progress that I'm making in my spare time. I cant't guarantee that any of it is fast, stable, or even working. There is no OAuth implementation, so you must already have an access token in order to use the API
This library is a NodeJS wrapper for the Oanda REST API. It provides a simple abstraction layer for making requests and retrieving responses from the API.
In the root folder of your project, run the following:
npm install node-oanda --save
If you do not want to add a reference to the library in your package.json file you can omit the
var Oanda = ;
Initializing the API
Before you can make requests to the API, you need to create a new Oanda object with configuration parameters
var Oanda = ;var config =token: 'my_access_token'type: 'practice'dateFormat: 'unix';var api = config;
The access token for the account you want to access the API with. You must have an account with Oanda in order to use the API.
Optional. Defaults to
The type parameter specifies which of the Oanda environments you'd like to use.
'sandbox' 'practice' 'real'
Optional. Defaults to
The date format that you want the API to return. The API supports the following values
Making API requests
With the API configuration initialized, you can now start retrieving and posting data to the API. The
Oanda object is broken down into different endpoints as per the Oanda documentation.
var Oanda = ;var config =token: 'my_access_token'type: 'practice'dateFormat: 'unix';var api = config;// This only creates a request object, the request is not yet sentvar request = apiaccounts;// Here we handle a successful response from the serverrequest;// Here we handle an error returned from the serverrequest;// Execute the request.request;
In the example above, we created a request for
getAccountsForUser which is an endpoint in the
accounts API. What is returned is simply an object containing details of a request. The request has not yet been sent to the server.
We then add callbacks to the request using the
error parameters. When we're finally ready to send the request, we call
go, the request is sent and appropriate callback will be fired when a response is returned, or the request times out.
For complete documentation about each of the endpoints, please see the official Oanda documentation. All parameters from the Oanda documentation that are not explicitly listed should be place inside the