Changes between Initial Version and Version 1 of Collector modules


Ignore:
Timestamp:
May 16, 2016, 5:52:56 PM (8 years ago)
Author:
Genuise
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Collector modules

    v1 v1  
     1To the discussion in the [[http://trac.prcn.bitcoin-analytics.com/ceasy/ticket/515]]
     2
     3We discussed list of modules affected.
     4
     5Collector side:
     6* collector/bin/collector.js method {{{nextTick}}}
     7{{{
     8process.nextTick(function ()
     9{
     10...
     11var     exchangeApi = require('../../server/lib/depthAPI')
     12
     13exchangeApi.init(config.tickersToFetch, config.streamAPIModes, config.enabledCurrencies)
     14...
     15}
     16}}}
     17* 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)
     18{{{
     19exports.enabledCurrencies = ['USD', 'EUR', 'CNY',
     20
     21exports.streamAPIModes = {..., coinbaseUSD: 'coinbase1'}
     22}}}
     23* server/lib/depthAPI.js
     24each exchange represented by instance of exchangeAPIObj, collector requests each order book using method {{{getCurrentBook2}}}
     25while published {{{events}}} is global event emitter instance to pass trades events.
     26{{{
     27...
     28
     29exports.events = new (require('events').EventEmitter)() //trade events, orderbook events
     30
     31var exchangeAPIObjs = {}
     32
     33...
     34
     35exports.getCurrentBook2 = function(ticker)
     36{
     37        return exchangeAPIObjs[ticker].currentHashBook
     38}
     39...
     40}}}
     41
     42method {{{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.
     43{{{
     44exports.init = function (tickersToFetch, streamApiModes, currencies)
     45{
     46        exchangeAPIObjs = arr.mapToHash(tickersToFetch, function(ticker)
     47        {
     48                var exObj = apiParams[ticker].exAPIObj ? new apiParams[ticker].exAPIObj() : new api.exAPIDefault()
     49
     50                exObj.init(ticker, apiParams, exports.events, streamApiModes)
     51                return exObj
     52        })
     53...
     54}
     55}}}
     56
     57{{{apiParams}}} is initialize from execution of the method {{{makeApiParams}}}
     58{{{
     59...
     60
     61var apiParams = makeApiParams()
     62exports.apiParams = apiParams
     63}}}
     64
     65where definition of the method {{{makeApiParams}}} is as following
     66{{{
     67function makeApiParams()
     68{
     69        return {
     70...
     71,       mtgoxUSD: makeMtgox('USD')
     72,       btceUSD: {
     73                url: 'https://btc-e.com/api/3/depth/btc_usd?limit=2000',
     74                cur : 'USD',
     75                parse :  fixPriceKeysEx(
     76                        function (x){ return x['btc_usd']},
     77                        'bids', 'asks',
     78                        fn.id),
     79                exAPIObj: api.btcePollingTrades,
     80                trades_url: 'https://btc-e.com/api/3/trades/btc_usd?limit=2000',
     81                trades_key: 'btc_usd',
     82                polling_freq: 3600 / 30,
     83                pollingAliveTimeout: 5 * 60 * 1000,
     84    DoRejectUnauthorized : true
     85        }
     86...
     87
     88}}}
     89
     90where {{{coinbaseUSD}}} is defined as
     91{{{
     92...
     93
     94, coinbaseUSD: {
     95        cur: 'USD',
     96        exAPIObj: api.exAPICoinbase
     97}
     98...
     99}}}
     100
     101where {{{api.exAPICoinbase}}} is included from
     102{{{
     103...
     104, api = require('./exchange-api/apiClasses')
     105...
     106}}}