Enigma Securities API
A NodeJs library for trading with the Enigma Securities platform
For more information on the firm, please see: https://enigma-securities.io
Install
The library is available from npmjs.com and can be installed in the usual manner:
$ npm install enigma-securities
Use
The module exports a factory so that multiple connections can be managed and thus connection objects must be created:
// fetch factoryconst Enigma = // grab credentials from the environment var ENIGMA_USERNAME ENIGMA_PASSWORD = processenv; // create a connection object using credentials const prod = ENIGMA_USERNAME ENIGMA_PASSWORD // to create a connection to the development sandbox const dev = ENIGMA_USERNAME ENIGMA_PASSWORD 'test' // the constructor will pick up the credentials from the environment// so you need not specify them const prod = const dev = 'test'
API
The following methods are supported:
products
Lists the products available in the platform. The return value is an object with crosses for keys and product ids for values. It will generally look like this:
price(id)
- id: the product id returned from the
products()
method
The method returns the spot, bid and ask prices for the product. The returned object looks more or less like this:
buy(id, qty, type)
sell(id, qty, type)
- id: the product id received from
products
- type: specifies the metric of the quantity. can be one of:
fiat
orcrypto
. if left unspecified, defaults to fiat - qty: the amount for the trade
Use these methods to buy or sell a given asset
trade(id, op, qty, type)
- op: one of:
buy
orsell
An interface useful for when the type of operation must be deduced from data. Allows writing simpler code:
// you can writeprod // instead ofif bal < 0 prodelse prod
trades [intraday]
Returns an array of trades performed for the account. If a true value is passed to the method, only intraday trades are returned. The output looks like this:
Notes
If credentials are neither provided via the environment, nor explicitly, the factory constructor will throw an exception on load:
Testing
A test suite is available and comprises primarily integration tests, so you can use it to make sure you can reach the platform. To run, first set the environment variables shown below with your credentials and then run the tests:
$ export ENIGMA_USER=xxxx
$ export ENIGMA_PASS=xxxx
$ npm test
Licence
MIT
Support
For support post an issue on Github or reach out to me on Telegram. My username is @ekkis