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 🙏

© 2026 – Pkg Stats / Ryan Hefner

oandav20

v0.6.1

Published

Oanda V20 functions

Readme

OandaV20

npm license

OandaV20 is a wrapper class utilizing the Oanda V20 API

npm i oandav20

const OandaV20=require('oandav20.js');

import OandaV20 from 'oandav20.mjs';

<script src="oandav20.js"></script>
window.OandaV20

const oanda=new OandaV20(api,datetime,host);

To generate an api token, log in to the Account Management Portal and select Manage Api Access:

By default the host is set for live accounts, 'api-fxtrade.oanda.com', and can be omitted For practice accounts, input 'api-fxpractice.oanda.com' as the host.

Datetime can either be 'RFC3339' or 'UNIX'; by default the datetime is set as 'RFC3339'. Please see the Oanda reference: AcceptDatetimeFormat.


  • The request backend now uses fetch, requiring Node.js version 0.18+
  • All methods are now dual purpose callback & async, and reference the same result:
    (async()=>{
    	let resultCB;
    	let resultAsync=await oanda.getAccounts((result)=>{resultCB=result;});
    	console.log(resultCB===resultAsync); //true
    })();

  • The returned result for both modes is a class object:
    const result=new OandaV20.result();
    /*
    	result {
    		error:undefined
    		,data:undefined
    	};
    */
  • Exposed the writable defaults instance object oanda.defaults
  • Exposed the defaults class OandaV20.DEFAULTS
  • Exposed api, datetime, host as writable properties of the instance
    • oanda.api
    • oanda.datetime
    • oanda.host
  • Relaxed type restrictions on passed values

oanda.'method'(arg1,arg2,arg3,callback,arg4)

Any arguments before the callback argument are required:

oanda.'method'(arg1,arg2,callback,options) //arg1, arg2 required

oanda.'method'(arg1,arg2,arg3,callback,body) //arg1, arg2, arg3 required

Any arguments options or body, while optional, if passed are required to be objects {}:

  • If not passed, then values copied from the defaults found in oanda.defaults
  • These will be stringified before sending the request.


Oanda reference: Account Endpoints

  • Get list of accounts
  • getAccounts(callback)
  • result.data : [] array
  • Get full details of a single account
  • getAccount(account,callback)
  • result.data : {} object
  • Get summary details of a single account
  • getAccountSummary(account,callback)
  • result.data : {} object
  • Get a list of tradeable instruments
  • getAccountInstruments(account,callback,options)
  • options = ACCOUNT_INSTRUMENTS
  • result.data : [] array
  • Get changes to account since a specific transaction id
  • getAccountChangesSinceTransaction(account,transactionID,callback)
  • result.data : {} object
  • Set the client-configurable portions on an account
  • setAccountConfiguration(account,callback,body)
  • body = CONFIG
  • result.data : {} object

Oanda reference: Instrument Endpoints

(Documentation is now 404, however, the REST API is still functioning. Caution future changes)

  • Get candlestick data for an instrument
  • getInstrument(instrument,callback,options)
  • options = INSTRUMENT
  • result.data : [] array
  • Get order book data for an instrument
  • getOrderBook(instrument,callback,options)
  • options = TIME
  • result.data : {} object
  • Get position book data for an instrument
  • getPositionBook(instrument,callback,options)
  • options = TIME
  • result.data : {} object

Oanda reference: Position Endpoints

  • List positions for the lifetime of an account
  • getPositions(account,callback)
  • result.data : [] array
  • Get details of an instrument position
  • getPosition(account,instrument,callback)
  • result.data : {} object
  • List positions with open trades
  • getOpenPositions(account,callback)
  • result.data : [] array
  • Fully or partially close an open position
  • closePosition(account,instrument,callback,body)
  • body = CLOSE_POSITION
  • result.data : {} object

Oanda reference: Transaction Endpoints

  • Get a list of transaction pages
  • getTransactions(account,callback,options)
  • options = TRANSACTIONS
  • result.data : {} object
  • Get details of a single transaction
  • getTransaction(account,transactionID,callback)
  • result.data : {} object
  • Get a list of transactions by transaction id range
  • getTransactionsByIdRange(account,from,to,callback,options)
  • options = TYPE
  • result.data : [] array
  • Get a list of transactions starting after a specified transaction id
  • getTransactionsSinceId(account,id,callback,options)
  • options = TYPE
  • result.data : [] array

Oanda reference: Pricing Endpoints

  • Get pricing details for a list of instruments
  • getInstrumentsPricing(account,instruments,callback,options)
  • options = INSTRUMENTS_PRICING
  • result.data : [] array

Oanda reference: Trade Endpoints

  • Get a list of trades by account
  • getTrades(account,callback,options)
  • options = TRADES
  • result.data : [] array
  • Get a list of open trades by account
  • getOpenTrades(account,callback,options)
  • options = TRADES
  • result.data : [] array
  • Get a list of closed trades by account
  • getClosedTrades(account,callback,options)
  • options = TRADES
  • result.data : [] array
  • Get a list of Close-when-tradeable trades by account
  • getCloseWhenTradeableTrades(account,callback,options)
  • options = TRADES
  • result.data : [] array
  • Get a list of all trades by account
  • getAllTrades(account,callback,options)
  • options = TRADES
  • result.data : [] array
  • Get a list of all open trades by account
  • getAllOpenTrades(account,callback)
  • result.data : [] array
  • Get details of a single trade
  • getTrade(account,tradeSpecifier,callback)
  • result.data : {} object
  • Fully or partially close an open trade
  • closeTrade(account,tradeSpecifier,callback,body)
  • body = UNITS
  • result.data : {} object
  • Set the client extensions for a trade
  • setTradeClientExtensions(account,tradeSpecifier,callback,body)
  • body = CLIENT_EXTENSIONS
  • result.data : {} object
  • Do not set, modify, or delete client extensions if your account is associated with MT4
  • Oanda reference:

Oanda reference: Order Endpoints

  • Get a list of orders
  • getOrders(account,callback,options)
  • options = ORDERS
  • result.data : [] array
  • Get a list of pending orders
  • getPendingOrders(account,callback,options)
  • options = ORDERS
  • result.data : [] array
  • Get a list of filled orders
  • getFilledOrders(account,callback,options)
  • options = ORDERS
  • result.data : [] array
  • Get a list of triggered orders
  • getTriggeredOrders(account,callback,options)
  • options = ORDERS
  • result.data : [] array
  • Get a list of cancelled orders
  • getCancelledOrders(account,callback,options)
  • options = ORDERS
  • result.data : [] array
  • Get a list of all pending orders
  • getAllPendingOrders(account,callback)
  • result.data : [] array
  • Get a list of all orders
  • getAllOrders(account,callback,options)
  • options = ORDERS
  • result.data : [] array
  • Get details of a single order
  • getOrder(account,orderSpecifier,callback)
  • result.data : {} object
  • Cancel a pending order
  • cancelOrder(account,orderSpecifier,callback)
  • result.data : {} object
  • Set the client extensions for an order
  • Set the client extensions for a trade when the order is filled
  • setOrderClientExtensions(account,orderSpecifier,callback,body)
  • body = ORDER_EXTENSIONS
  • result.data : {} object
  • Do not set, modify, or delete client extensions if your account is associated with MT4
  • Oanda reference: Client Extensions
  • Create a market order
  • createMarketOrder(account,callback,body)
  • body = MARKET
  • result.data : {} object
  • Do not set, modify, or delete client extensions if your account is associated with MT4
  • Oanda reference: Market Order Request
  • Create a limit order
  • createLimitOrder(account,callback,body)
  • body = LIMIT
  • result.data : {} object
  • Do not set, modify, or delete client extensions if your account is associated with MT4
  • Oanda reference: Limit Order Request
  • Create a stop order
  • createStopOrder(account,callback,body)
  • body = STOP
  • result.data : {} object
  • Do not set, modify, or delete client extensions if your account is associated with MT4
  • Oanda reference: Stop Order Request
  • Create a market-if-touched order
  • createMarketIfTouchedOrder(account,callback,body)
  • body = MARKET_IF_TOUCHED
  • result.data : {} object
  • Do not set, modify, or delete client extensions if your account is associated with MT4
  • Oanda reference: Market If Touched Order Request
  • Create a take profit order
  • createTakeProfitOrder(account,callback,body)
  • body = TAKE_PROFIT
  • result.data : {} object
  • Do not set, modify, or delete client extensions if your account is associated with MT4
  • Oanda reference: Take Profit Order Request
  • Create a stop loss order
  • createStopLossOrder(account,callback,body)
  • body = STOP_LOSS
  • result.data : {} object
  • Do not set, modify, or delete client extensions if your account is associated with MT4
  • Oanda reference: Stop Loss Order Request
  • Create a guaranteed stop loss order
  • createGuaranteedStopLossOrder(account,callback,body)
  • body = GUARANTEED_STOP_LOSS
  • result.data : {} object
  • Do not set, modify, or delete client extensions if your account is associated with MT4
  • Oanda reference: Guaranteed Stop Loss Order Request
  • Create a trailing stop loss order
  • createTrailingStopLossOrder(account,callback,body)
  • body = TRAILING_STOP_LOSS
  • result.data : {} object
  • Do not set, modify, or delete client extensions if your account is associated with MT4
  • Oanda reference: Trailing Stop Loss Order Request
  • Cancel an order and replace with a market order
  • replaceWithMarketOrder(account,orderSpecifier,callback,body)
  • body = MARKET
  • result.data : {} object
  • Do not set, modify, or delete client extensions if your account is associated with MT4
  • Oanda reference: Market Order Request
  • Cancel an order and replace with a limit order
  • replaceWithLimitOrder(account,orderSpecifier,callback,body)
  • body = LIMIT
  • result.data : {} object
  • Do not set, modify, or delete client extensions if your account is associated with MT4
  • Oanda reference: Market Order Request
  • Cancel an order and replace with a stop order
  • replaceWithStopOrder(account,orderSpecifier,callback,body)
  • body = STOP
  • result.data : {} object
  • Do not set, modify, or delete client extensions if your account is associated with MT4
  • Oanda reference: Market Order Request
  • Cancel an order and replace with a market-if-touched order
  • replaceWithMarketIfTouchedOrder(account,orderSpecifier,callback,body)
  • body = MARKET_IF_TOUCHED
  • result.data : {} object
  • Do not set, modify, or delete client extensions if your account is associated with MT4
  • Oanda reference: Market Order Request
  • Cancel an order and replace with a take profit order
  • replaceWithTakeProfitOrder(account,orderSpecifier,callback,body)
  • body = TAKE_PROFIT
  • result.data : {} object
  • Do not set, modify, or delete client extensions if your account is associated with MT4
  • Oanda reference: Market Order Request
  • Cancel an order and replace with a stop loss order
  • replaceWithStopLossOrder(account,orderSpecifier,callback,body)
  • body = STOP_LOSS
  • result.data : {} object
  • Do not set, modify, or delete client extensions if your account is associated with MT4
  • Oanda reference: Market Order Request
  • Cancel an order and replace with a guaranteed stop loss order
  • replaceWithGuaranteedStopLossOrder(account,orderSpecifier,callback,body)
  • body = GUARANTEED_STOP_LOSS
  • result.data : {} object
  • Do not set, modify, or delete client extensions if your account is associated with MT4
  • Oanda reference: Market Order Request
  • Cancel an order and replace with a trailing stop loss order
  • replaceWithTrailingStopLossOrder(account,orderSpecifier,callback,body)
  • body = TRAILING_STOP_LOSS
  • result.data : {} object
  • Do not set, modify, or delete client extensions if your account is associated with MT4
  • Oanda reference: Market Order Request


oanda.defaults

The location for default shapes & values per instance

  • Freely edit primitive values, applied to all relevant method calls per instance
  • The existing PROPERTY_NAMES and NESTED.STRUCTURE in the defaults object should NOT be changed
(result)=>{}
ACCOUNT_INSTRUMENTS={
	instruments:''
};
CONFIG={
	alias:''
	,marginRate:''
};
TIME={
	time:''
};
TYPE={
	type:''
};
UNITS={
	units:''
};
INSTRUMENT={
	price:''
	,count:''
	,smooth:''
	,granularity:''
	,dailyAlignment:''
	,alignmentTimezone:''
	,weeklyAlignment:''
	,from:''
	,includeFirst:''
	,to:''
};
ORDERS={
	state:''
	,instrument:''
	,count:''
	,beforeID:''
	,ids:''
};
TRADES={
	count:''
	,state:''
	,beforeID:''
	,instrument:''
	,ids:''
};
TRANSACTIONS={
	from:''
	,to:''
	,pageSize:''
	,type:''
};
INSTRUMENTS_PRICING={
	since:''
	,includeHomeConversions:''
};
CLOSE_POSITION={
	longClientExtensions:new OandaV20.DEFAULTS.CLIENT_EXTENSIONS()
	,shortClientExtensions:new OandaV20.DEFAULTS.CLIENT_EXTENSIONS()
	,longUnits:''
	,shortUnits:''
};
CLIENT_EXTENSIONS=new OandaV20.DEFAULTS.CLIENT_EXTENSIONS();
ORDER_EXTENSIONS={
	clientExtensions:new OandaV20.DEFAULTS.CLIENT_EXTENSIONS()
	,tradeClientExtensions:new OandaV20.DEFAULTS.CLIENT_EXTENSIONS()
};
TAKE_PROFIT=new OandaV20.DEFAULTS.TAKE_PROFIT();
STOP_LOSS=new OandaV20.DEFAULTS.STOP_LOSS();
GUARANTEED_STOP_LOSS=new OandaV20.DEFAULTS.GUARANTEED_STOP_LOSS();
TRAILING_STOP_LOSS=new OandaV20.DEFAULTS.TRAILING_STOP_LOSS();
TRADE_ORDERS={
	takeProfit:new OandaV20.DEFAULTS.TAKE_PROFIT()
	,stopLoss:new OandaV20.DEFAULTS.STOP_LOSS()
	,guaranteedStopLoss:new OandaV20.DEFAULTS.GUARANTEED_STOP_LOSS()
	,trailingStopLoss:new OandaV20.DEFAULTS.TRAILING_STOP_LOSS()
}
ORDER_CREATE.MARKET={
	type:'MARKET'
	,instrument:''
	,units:''
	,timeInForce:''
	,priceBound:''
	,positionFill:''
	,clientExtensions:new OandaV20.DEFAULTS.CLIENT_EXTENSIONS()
	,takeProfitOnFill:new OandaV20.DEFAULTS.TAKE_PROFIT()
	,stopLossOnFill:new OandaV20.DEFAULTS.STOP_LOSS()
	,guaranteedStopLossOnFill:new OandaV20.DEFAULTS.GUARANTEED_STOP_LOSS()
	,trailingStopLossOnFill:new OandaV20.DEFAULTS.TRAILING_STOP_LOSS()
	,tradeClientExtensions:new OandaV20.DEFAULTS.CLIENT_EXTENSIONS()
};
ORDER_CREATE.LIMIT={
	type:'LIMIT'
	,instrument:''
	,units:''
	,price:''
	,timeInForce:''
	,gtdTime:''
	,positionFill:''
	,triggerCondition:''
	,clientExtensions:new OandaV20.DEFAULTS.CLIENT_EXTENSIONS()
	,takeProfitOnFill:new OandaV20.DEFAULTS.TAKE_PROFIT()
	,stopLossOnFill:new OandaV20.DEFAULTS.STOP_LOSS()
	,guaranteedStopLossOnFill:new OandaV20.DEFAULTS.GUARANTEED_STOP_LOSS()
	,trailingStopLossOnFill:new OandaV20.DEFAULTS.TRAILING_STOP_LOSS()
	,tradeClientExtensions:new OandaV20.DEFAULTS.CLIENT_EXTENSIONS()
};
ORDER_CREATE.STOP={
	type:'STOP'
	,instrument:''
	,units:''
	,price:''
	,priceBound:''
	,timeInForce:''
	,gtdTime:''
	,positionFill:''
	,triggerCondition:''
	,clientExtensions:new OandaV20.DEFAULTS.CLIENT_EXTENSIONS()
	,takeProfitOnFill:new OandaV20.DEFAULTS.TAKE_PROFIT()
	,stopLossOnFill:new OandaV20.DEFAULTS.STOP_LOSS()
	,guaranteedStopLossOnFill:new OandaV20.DEFAULTS.GUARANTEED_STOP_LOSS()
	,trailingStopLossOnFill:new OandaV20.DEFAULTS.TRAILING_STOP_LOSS()
	,tradeClientExtensions:new OandaV20.DEFAULTS.CLIENT_EXTENSIONS()
};
ORDER_CREATE.MARKET_IF_TOUCHED={
	type:'MARKET_IF_TOUCHED'
	,instrument:''
	,units:''
	,price:''
	,priceBound:''
	,timeInForce:''
	,gtdTime:''
	,positionFill:''
	,triggerCondition:''
	,clientExtensions:new OandaV20.DEFAULTS.CLIENT_EXTENSIONS()
	,takeProfitOnFill:new OandaV20.DEFAULTS.TAKE_PROFIT()
	,stopLossOnFill:new OandaV20.DEFAULTS.STOP_LOSS()
	,guaranteedStopLossOnFill:new OandaV20.DEFAULTS.GUARANTEED_STOP_LOSS()
	,trailingStopLossOnFill:new OandaV20.DEFAULTS.TRAILING_STOP_LOSS()
	,tradeClientExtensions:new OandaV20.DEFAULTS.CLIENT_EXTENSIONS()
};
ORDER_CREATE.TAKE_PROFIT={
	type:'TAKE_PROFIT'
	,tradeID:''
	,clientTradeID:''
	,price:''
	,timeInForce:''
	,gtdTime:''
	,triggerCondition:''
	,clientExtensions:new OandaV20.DEFAULTS.CLIENT_EXTENSIONS()
};
ORDER_CREATE.STOP_LOSS={
	type:'STOP_LOSS'
	,tradeID:''
	,clientTradeID:''
	,price:''
	,distance:''
	,timeInForce:''
	,gtdTime:''
	,triggerCondition:''
	,clientExtensions:new OandaV20.DEFAULTS.CLIENT_EXTENSIONS()
};
ORDER_CREATE.GUARANTEED_STOP_LOSS={
	type:'GUARANTEED_STOP_LOSS'
	,tradeID:''
	,clientTradeID:''
	,price:''
	,distance:''
	,timeInForce:''
	,gtdTime:''
	,triggerCondition:''
	,clientExtensions:new OandaV20.DEFAULTS.CLIENT_EXTENSIONS()
};
ORDER_CREATE.TRAILING_STOP_LOSS={
	type:'TRAILING_STOP_LOSS'
	,tradeID:''
	,clientTradeID:''
	,distance:''
	,timeInForce:''
	,gtdTime:''
	,triggerCondition:''
	,clientExtensions:new OandaV20.DEFAULTS.CLIENT_EXTENSIONS()
};