Skip to content

Instantly share code, notes, and snippets.

@risacher
Created February 15, 2017 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save risacher/f261c9928c9442607275abf1a97319d3 to your computer and use it in GitHub Desktop.
Save risacher/f261c9928c9442607275abf1a97319d3 to your computer and use it in GitHub Desktop.
example of how to invoke OANDA V20 API from node.js
"use strict";
const oandaV20 = require('@oanda/v20/context');
const fs = require('fs');
var ctx = new oandaV20.Context('api-fxpractice.oanda.com', 443, true, "demo");
var key = fs.readFileSync('api.key', {encoding: 'utf8'});
//remove any bad chars (e.g. the trailing newline)
key = key.replace(/[^0-9a-fA-F-]/g, "");
console.log(key);
ctx.setToken(key);
ctx.account.list(function(res) {
var accounts = res.body;
console.log(accounts);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment