Skip to content
oandaPublic

About

Javascript wrapper for the OANDA REST API

Resources

Stars

30 stars

Watchers

57 watching

Forks

Latest commit

 

History

61 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Javascript wrapper for the OANDA REST API

Resources

Stars

30 stars

Watchers

57 watching

Forks

Releases

Packages

Contributors

Languages