
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:
const Enigma = require('enigma-securities')
var {ENIGMA_USERNAME, ENIGMA_PASSWORD} = process.env;
const prod = new Enigma(ENIGMA_USERNAME, ENIGMA_PASSWORD)
const dev = new Enigma(ENIGMA_USERNAME, ENIGMA_PASSWORD, 'test')
const prod = new Enigma()
const dev = new Enigma('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:
{
"BTC/EUR": "1",
"BTC/USD": "2",
"BTC/CAD": "3"
}
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:
{
"base": "BTC",
"currency": "EUR",
"spot": "4551.29",
"bid": "4528.5336",
"ask": "4574.0465"
}
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
or crypto
.
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)
An interface useful for when the type of operation must be deduced from data. Allows writing
simpler code:
prod.trade(1, bal < 0 ? 'sell' : 'buy', 100)
if (bal < 0)
prod.sell(1, 100)
else
prod.buy(1, 100)
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