Version 2 (modified by 9 years ago) ( diff ) | ,
---|
To the discussion in the http://trac.prcn.bitcoin-analytics.com/ceasy/ticket/515
We discussed list of modules affected.
Collector side:
- collector/bin/collector.js method
nextTick
process.nextTick(function () { ... var exchangeApi = require('../../server/lib/depthAPI') exchangeApi.init(config.tickersToFetch, config.streamAPIModes, config.enabledCurrencies) ... }
- server/lib/config.js constants
enabledCurrencies
,streamAPIModes
the latter intended to be used inexchangeAPIObj.init
method to select specific version of internal adapter implementation (REST or Websocket real time synchronized)exports.enabledCurrencies = ['USD', 'EUR', 'CNY', exports.streamAPIModes = {..., coinbaseUSD: 'coinbase1'}
- server/lib/depthAPI.js
each exchange represented by instance of exchangeAPIObj, collector requests each order book using method getCurrentBook2
while published events
is global event emitter instance to pass trades events.
... exports.events = new (require('events').EventEmitter)() //trade events, orderbook events var exchangeAPIObjs = {} ... exports.getCurrentBook2 = function(ticker) { return exchangeAPIObjs[ticker].currentHashBook } ...
method init
takes list of exchanges specific for current server to instantiate and initialize exchange objects which is returned as hash(key=ticker,value=exObj) and stored in exchangeAPIObjs
in the module scope.
exports.init = function (tickersToFetch, streamApiModes, currencies) { exchangeAPIObjs = arr.mapToHash(tickersToFetch, function(ticker) { var exObj = apiParams[ticker].exAPIObj ? new apiParams[ticker].exAPIObj() : new api.exAPIDefault() exObj.init(ticker, apiParams, exports.events, streamApiModes) return exObj }) ... }
apiParams
is initialize from execution of the method makeApiParams
... var apiParams = makeApiParams() exports.apiParams = apiParams
where definition of the method makeApiParams
is as following
function makeApiParams() { return { ... , mtgoxUSD: makeMtgox('USD') , btceUSD: { url: 'https://btc-e.com/api/3/depth/btc_usd?limit=2000', cur : 'USD', parse : fixPriceKeysEx( function (x){ return x['btc_usd']}, 'bids', 'asks', fn.id), exAPIObj: api.btcePollingTrades, trades_url: 'https://btc-e.com/api/3/trades/btc_usd?limit=2000', trades_key: 'btc_usd', polling_freq: 3600 / 30, pollingAliveTimeout: 5 * 60 * 1000, DoRejectUnauthorized : true } ...
where coinbaseUSD
is defined as
... , coinbaseUSD: { cur: 'USD', exAPIObj: require('./exchange-api/coinbaseAPIClass').exAPICoinbase } ...
where api.exAPICoinbase
is included from
... , api = require('./exchange-api/apiClasses') ...