npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-oanda

v1.1.21

Published

A NodeJS wrapper for the Oanda REST API

Downloads

15

Readme

node-oanda

Build Status

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.

Getting started

To install the library, you will need to have NodeJS and the Node Package Manager (npm) setup on your machine.

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 --save parameter.

Requiring

Once you've installed the package you should be able to require it in your own code. To require the package, add the following line to a javascript file that you would like to use the API in:

var Oanda = require('node-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 = require('node-oanda');

var config = {
  token: 'my_access_token',
  type: 'practice',
  dateFormat: 'unix'
};

var api = new Oanda(config);

Configuration options

token (string)

Required

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.

type (string)

Optional. Defaults to 'real'

The type parameter specifies which of the Oanda environments you'd like to use.

'sandbox'
'practice'
'real'

dateFormat (string)

Optional. Defaults to 'RFC3339'

The date format that you want the API to return. The API supports the following values

'unix'
'RFC3339'

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.

Example request

var Oanda = require('node-oanda');

var config = {
  token: 'my_access_token',
  type: 'practice',
  dateFormat: 'unix'
};

var api = new Oanda(config);

// This only creates a request object, the request is not yet sent
var request = api.accounts.getAccountsForUser();

// Here we handle a successful response from the server
request.success(function(data) {
  console.log('Yay! My data: ', data);
});

// Here we handle an error returned from the server
request.error(function(err) {
  console.log('Damn, something went wrong: ', err);
});

// Execute the request.
request.go();

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 success and 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.

API endpoints

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 options parameter.

Rates

api.rates.getInstrumentList( account_id, options )
api.rates.getCurrentPrices( instruments, options )
api.rates.retrieveInstrumentHistory( instrument, options )

Accounts

api.accounts.getAccountsForUser( username )
api.accounts.getAccountInformation( account_id )

Orders

api.orders.getOrdersForAccount( account_id, options )
api.orders.createNewOrder( account_id, instrument, units, side, type, expiry, price, options )  
api.orders.getInformationForOrder( account_id, order_id )
api.orders.modifyExistingOrder( account_id, order_id, options )
api.orders.closeOrder( account_id, order_id )

Trades

api.trades.getListOfOpenTrades( account_id, options )
api.trades.getInformationOnSpecificTrade( account_id, trade_id )
api.trades.modifyExistingTrade( account_id, trade_id, options )
api.trades.closeOpenTrade( account_id, trade_id )

Positions

api.positions.getListOfOpenPositions( account_id )
api.positions.getPositionForInstrument( account_id, instrument )
api.positions.closeExistingPosition( account_id, instrument )

History

api.history.getTransactionHistory( account_id, options )
api.history.getInformationForTransaction( account_id, transation_id )
api.history.getFullAccountHistory( account_id )