wiki:Collector modules

Version 4 (modified by Genuise, 8 years ago) ( diff )

--

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 public method getCurrentBook2 passing exchange tickers of type string as a parameter. Trades on the other hand broadcasted through central event emitter object defined in events module. Trades messages source is every exchange instance. Collector structures register listeners for trades messages.

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')
...
Note: See TracWiki for help on using the wiki.