enigma-securities
v1.0.1
Published
A NodeJs library for the Enigma Securities API
Downloads
4
Maintainers
Readme
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 factory
const Enigma = require('enigma-securities')
// grab credentials from the environment
var {ENIGMA_USERNAME, ENIGMA_PASSWORD} = process.env;
// create a connection object using credentials
const prod = new Enigma(ENIGMA_USERNAME, ENIGMA_PASSWORD)
// to create a connection to the development sandbox
const dev = new Enigma(ENIGMA_USERNAME, ENIGMA_PASSWORD, 'test')
// the constructor will pick up the credentials from the environment
// so you need not specify them
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
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 write
prod.trade(1, bal < 0 ? 'sell' : 'buy', 100)
// instead of
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