oandav20

Oanda V20 functions

Usage no npm install needed!

<script type="module">
  import oandav20 from 'https://cdn.skypack.dev/oandav20';
</script>

README

OandaV20

Oanda npm license Made with linux

OandaV20 is a collection of functions utilizing the Oanda V20 API


npm i oandav20

Oanda=require('oandav20')(api,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.



Common

  • All functions use the calling format func(arguments={},callback=function(data){})

  • Omit arguments: func(callback)

    • If the arguments object is not provided, the functions will be supplied with the default arguments
    • Default arguments are attached to each function and may be accessed using func.defaults()
      • If an object is provided to .defaults(obj={}), the object properties will be added to the function defaults
      • Add any required properties: account, id, etc, to the defaults to fully omit the arguments object
      • Omitting the parameter has no effect
      • Returns the default object

  • Omit callback: func(arguments)
    • If a callback is not provided, the function response will print to the console

  • Datetime argument: arguments.datetime = datetime
    • All function arguments may include a datetime property to set the response datetime format
    • .datetime = 'RFC3339' || 'UNIX'

  • Repeat argument: arguments.repeat = number
    • All function arguments may include a repeat property to cause the function to be repeatedly called with a given frequency
    • If the repeat argument is provided, the function will return an object obj=func({repeat:1000}) with the properties:
      • obj.repeat = [given repeat argument number] //modifiable repeat interval
      • obj.end = function() //end the repeatable interval

  • Debug argument: arguments.debug = boolean
    • All function arguments may include a debug property, equal to true, to instruct the function to print the https head and body if applicable
    • The https request will not be sent

  • Requests limit & queue
    • Requests are limited to 100/second
    • Please see Best Practices
    • If the request limit is reached:
      • GET requests with paths, including queries, matching queued requests will be discarded
      • All other requests will be queued
      • The queue will be emptied up to the request limit once a new second is calculated


Functions

  • api oanda.api(key)
    • Get & Set system api key
    • Omitting key has no effect
    • Returns: current key string

  • host oanda.host(hostname)
    • Get & Set system host name
    • Omitting hostname has no effect
    • Returns: current host name string

  • getAccounts oanda.getAccounts(args,cb)
    • Get list of accounts
    • Requires arguments: none
    • Callback data: array []

  • getAccount oanda.getAccount(args,cb)
    • Get details of a single account
    • Requires arguments: account = string
    • Callback data: object {}

  • getAccountChangesSinceTransaction oanda.getAccountChangesSinceTransaction(args,cb)
    • Get changes to account since a specific transaction id
    • Requires arguments:
      • account = string
      • transaction = string || number
    • Callback data: object {}

  • getAccountInstruments oanda.getAccountInstruments(args,cb)
    • Get list of tradeable instruments for an account
    • Requires arguments: account = string
    • Optional arguments: instruments = csv string
    • Callback data: array []

  • setAccountConfiguration oanda.setAccountConfiguration(args,cb)
    • Set the client-configurable portions on an account
    • Requires arguments: account = string
    • Optional arguments:
      • alias = string
      • marginRate = number
    • Callback data: object {}

  • getInstrument oanda.getInstrument(args,cb)
    • Get candlestick data for an instrument
    • Requires arguments: instrument = string
    • Optional arguments:
      • price = string
      • count = number
      • smooth = boolean
      • granularity = string
      • dailyAlignment = number
      • alignmentTimezone = string
      • weeklyAlignment = string
      • from = datetime
      • includeFirst = boolean
      • to = datetime
    • Callback data: array []

  • getOrderBook oanda.getOrderBook(args,cb)
    • Get order book data for an instrument
    • Requires arguments: instrument = string
    • Optional arguments: time = datetime
    • Callback data: object {}

  • getPositionBook oanda.getPositionBook(args,cb)
    • Get position book data for an instrument
    • Requires arguments: instrument = string
    • Optional arguments: time = datetime
    • Callback data: object {}

  • getOrders oanda.getOrders(args,cb)
    • Get a list of orders for an account
    • Requires arguments: account = string
    • Optional arguments:
      • state = string
      • count = number
      • instrument = string
      • beforeID = string || number
      • ids = csv string list
    • Callback data: array []

  • getOrder oanda.getOrder(args,cb)
    • Get details of a single order for an account
    • Requires arguments:
      • account = string
      • id = number || string
    • Callback data: object {}

  • getPendingOrders oanda.getPendingOrders(args,cb)
    • Get a list of pending orders for an account
    • Requires arguments: account = string
    • Callback data: array []

  • createOrder oanda.createOrder(args,cb)
    • Create an order for an account
    • Requires arguments: account = string
    • Optional arguments:
      • order = object
      • Do not set, modify, or delete client extensions if your account is associated with MT4
      • Please see Order Request
    • Callback data: object {}

  • replaceOrder oanda.replaceOrder(args,cb)
    • Replace an order by cancelling and creating a new order
    • Requires arguments:
      • account = string
      • id = number || string
    • Optional arguments:
      • order = object
      • Do not set, modify, or delete client extensions if your account is associated with MT4
      • Please see Order Request
    • Callback data: object {}

  • cancelOrder oanda.cancelOrder(args,cb)
    • Cancel a pending order for an account
    • Requires arguments:
      • account = string
      • id = number || string
    • Callback data: object {}

  • setOrderClientExtensions oanda.setOrderClientExtensions(args,cb)
    • Set the client extensions for an order
    • Set the client extensions for a trade when the order is filled
    • Requires arguments:
      • account = string
      • id = number || string
    • Optional arguments:
      • clientExtensions = object
      • tradeClientExtensions = object
      • Do not set, modify, or delete client extensions if your account is associated with MT4
      • Please see Client Extensions
    • Callback data: object {}

  • getPositions oanda.getPositions(args,cb)
    • List positions for the lifetime of an account
    • Requires arguments: account = string
    • Callback data: array []

  • getPosition oanda.getPosition(args,cb)
    • Get details of a position taken during the lifetime of an account
    • Requires arguments:
      • account = string
      • instrument = string
    • Callback data: object {}

  • getOpenPositions oanda.getOpenPositions(args,cb)
    • List positions with open trades for an account
    • Requires arguments: account = string
    • Callback data: array []

  • closePosition oanda.closePosition(args,cb)
    • Fully or partially close an open position for an account
    • Requires arguments:
      • account = string
      • instrument = string
    • Optional arguments:
      • longUnits = number || string
      • shortUnits = number || string
      • longClientExtensions = object
      • shortClientExtensions = object
      • Do not set, modify, or delete client extensions if your account is associated with MT4
      • Please see Client Extensions
    • Callback data: object {}

  • getInstrumentsPricing oanda.getInstrumentsPricing(args,cb)
    • Get pricing details for a list of instruments
    • Requires arguments: account = string
    • Optional arguments:
      • instruments = csv string
      • since = datetime
      • includeHomeConversions = boolean
    • Callback data: array []

  • getTrades oanda.getTrades(args,cb)
    • Get a list of trades by account
    • Requires arguments: account = string
    • Optional arguments:
      • count = number
      • state = string
      • instrument = string
      • beforeID = number || string
      • ids = csv string
    • Callback data: array []

  • getTrade oanda.getTrade(args,cb)
    • Get details of a single trade for an account
    • Requires arguments:
      • account = string
      • id = number || string
    • Callback data: object {}

  • getOpenTrades oanda.getOpenTrades(args,cb)
    • Get a list of open trades by account
    • Requires arguments: account = string
    • Callback data: array []

  • closeTrade oanda.closeTrade(args,cb)
    • Fully or partially close an open trade
    • Requires arguments:
      • account = string
      • id = number || string
    • Optional arguments: units = number || string
    • Callback data: object {}

  • setTradeClientExtensions oanda.setTradeClientExtensions(args,cb)
    • Set the client extensions for a trade
    • Requires arguments:
      • account = string
      • id = number || string
    • Optional arguments:
      • clientExtensions = object
      • Do not set, modify, or delete client extensions if your account is associated with MT4
      • Please see Client Extensions
    • Callback data: object {}

  • setTradeOrders oanda.setTradeOrders(args,cb)
    • Create, replace and cancel the orders for a trade
    • Requires arguments:
      • account = string
      • id = number || string
    • Optional arguments:
    • Callback data: object {}

  • getTransactions oanda.getTransactions(args,cb)
    • Get a list of transaction pages
    • Requires arguments: account = string
    • Optional arguments:
      • from = datetime
      • to = datetime
      • pageSize = number
      • type = csv string
    • Callback data: object {}

  • getTransaction oanda.getTransaction(args,cb)
    • Get details of a single transaction
    • Requires arguments:
      • account = string
      • id = number
    • Callback data: object {}

  • getTransactionsByIdRange oanda.getTransactionsByIdRange(args,cb)
    • Get a list of transactions by transaction id range
    • Requires arguments:
      • account = string
      • from = number
      • to = number
    • Optional arguments: type = csv string
    • Callback data: array []

  • getTransactionsSinceId oanda.getTransactionsSinceId(args,cb)
    • Get a list of transactions starting after a specified transaction id
    • Requires arguments:
      • account = string
      • id = number
    • Optional arguments: type = csv string
    • Callback data: array []