Javascript wrapper for the OANDA REST API
JavaScript HTML
Switch branches/tags
Nothing to show
Clone or download
Mark Oosterveld
Latest commit 711be08 Jul 27, 2016
Permalink
Failed to load latest commit information.
LICENSE Update LICENSE Jun 13, 2013
README.md made to work with the modern API Jul 27, 2016
oanda.js made to work with the modern API Jul 27, 2016
test.html made to work with the modern API Jul 27, 2016

README.md

oandajs

oanda.js is a javascript wrapper for the OANDA REST API.

Usage

NOTE: We require an AUTH token now.

Include the latest oanda.js in as a script tag:

<script type="text/javascript" src="http://developer.oanda.com/oandajs/oanda.js"></script>

To get current live rates:

OANDA.rate.quote(['EUR_USD'], function(response) {
    if(response && !response.error) {
        var bid = response.prices[0].bid;
        var ask = response.prices[0].ask;
        // Do something with prices
        // ...
    }
});

To open a trade with optional parameters:

OANDA.order.open(accountId, 'EUR_USD', 100, 'buy', 0, 0, 'market', { 'stopLoss' : 0.90, 'takeProfit' : 1.102 }, function(openTradeResponse) {
    if(openTradeResponse && !openTradeResponse.error) {
        var units = openTradeResponse.units;
        var side = openTradeResponse.side;
        var instrument = openTradeResponse.instrument;
        var time = openTradeResponse.time;
        // Do something with open trade result
        // ...
    }
});

To handle errors:

OANDA.order.open(accountId, 'EUR_USD', 100, 'buy', 0, 0, 'market', { 'stopLoss' : 0.90, 'takeProfit' : 1.102 }, function(openTradeResponse) {
    if(openTradeResponse.error) {
        var error = openTradeResponse.error;
        console.log(error.statusCode); //HTTP status code
        console.log(error.code);       //OANDA error code
        console.log(error.message);
    }
});

Examples

Check out these example apps that use oanda.js