Exchange Module structure
Installation
npm install ex-services
Initilization
usage should be like this:
exchangeServices = require('ex-services');
var marketData = exchangeServices.marketData()
new exchangeServices.SERVICE_NAME({apiKey, apiSecret, marketData, onError, onOrderUpdate})'
SERVICE_NAME can be: BinanceService, HitbtcService, HuobiService, IdexService, KucoinService, EthfinexService, LiquiService, LivecoinService, GateService, CoinexService, PoloniexService, bcexService, BiboxService, OkexService, BilaxyService, CoinbeneService, IdaxService, ExratesService, BittrexService, LbankService, DigifinexService,ZbService, BitForexService, BitfinexService, YobitService, HitbtcService, BinanceService
If apikey and apisecret passed, after socket login, module should be automatically subscribe to order updates (new, filled, canceled, partially filled)
marketData
This module will inject into the exchange module and handles exchange data. It contains some methods to handling data which receives from exchange. when you receive new data from exchange, call these functions:
newTicker: function (market, bid, ask, last, volumeQuote)
orderbookSnapshot: function (market, asks, bids)
orderbookUpdate: function (market, asks, bids)
ordersSnapshot: function (orders)
orderUpdate: function (order)
candleSnapshot: function (market, snapshot)
candleUpdate: function (market, candle)
All needed data will store in a variable named data
. For ease of use, inside exchange module assign this.data
to marketData.data
this.data = marketData.data
The data
object structure:
{
tickers: { market: {last, bid, ask, volumeQuote, lastUpdate}, ... },
orderbooks: {
market: { ask:[{Quantity, Rate},...], bid:[{Quantity, Rate},...], lastUpdate }
,...
},
candles: {
market: {lastUpdate,[ {timestamp, open, close, high, low, volumeQuote, volume}, ...]}
...
},
// OrderType: "LIMIT_BUY" / "LIMIT_SELL"
orders: [ {symbol,OrderType, OrderUuid, Price, Opened, Quantity, Closed, ExecutedQuantity}, ...],
filledOrders: [{symbol, OrderType, OrderUuid, Price, Opened, Quantity, Closed, ExecutedQuantity}, ...]
}
Candle patterns
Candles are presented in multiple periods/patterns. Each service might support some or all of the patterns.
- minute :
M1 M3 M5 M15 M30
- hour :
H1 H2 H4 H6 H8 H12
- day :
D1 D7
- month :
1M
- year :
Y1
Functions to implement
- getSymbols (callback)
- getTradeHistory (symbol, maxnumber, callback)
- subscribeTrades (symbols, callback)
- checkBuyVolume (string symbol, number buyVolume,bid, function callback)
- getMinQuantity (symbol, callback)
- roundPrice (market, price, callback)
- roundQuantity (market, quantity, callback)
- subscribeTicker (market, callback)
- subscribeOrderbook (market, callback)
- subscribeCandles (market, callback)
- subscribeToMarket (options)
<
options: {market(required), onNewTicker, onOrderFilled, onOrderbookUpdate}
> - placeOrder (market, side, quantity, price, success, fail, retries = 10)
- updateOrder (clientOrderId, price, quantity, success, fail, order)
- cancelOrder (clientOrderId, success, fail, order)
- orderHistory (success, fail)
- balance (currency, success, fail)
- balances (success, fail)
- openOrders (market, success, fail)