wiki:Collector modules

To the discussion in the http://trac.prcn.bitcoin-analytics.com/ceasy/ticket/515

We discussed list of modules affected.

  • collector/bin/collector.js - entry point for collector process
  • server/lib/config.js - constants enabledCurrencies, streamAPIModes the latter intended to be used in exchangeAPIObj.init method
  • server/lib/depthAPI.js - all actual configuration of exchange objects defined here. Every exchange is represented by its exchange object instance. Module is responsible for creating instances and provides central storage for them in the form of collection(hash object). Orderbooks accessed from collector structures through exported method getCurrentBook2 passing exchange tickers of type string as a parameter. While state of the orderbooks has to be requested outside, trades on the other hand are broadcasted from inside. For this module exports events field of instance require('events').EventEmitter. This event emitter instance is a central point which connects trades publisher - every exchange object - with subscriber(s) on the collector level.

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 in exchangeAPIObj.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')
...
Last modified 8 years ago Last modified on May 16, 2016, 8:40:20 PM
Note: See TracWiki for help on using the wiki.