| | 1 | To the discussion in the [[http://trac.prcn.bitcoin-analytics.com/ceasy/ticket/515]] |
| | 2 | |
| | 3 | We discussed list of modules affected. |
| | 4 | |
| | 5 | Collector side: |
| | 6 | * collector/bin/collector.js method {{{nextTick}}} |
| | 7 | {{{ |
| | 8 | process.nextTick(function () |
| | 9 | { |
| | 10 | ... |
| | 11 | var exchangeApi = require('../../server/lib/depthAPI') |
| | 12 | |
| | 13 | exchangeApi.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 | {{{ |
| | 19 | exports.enabledCurrencies = ['USD', 'EUR', 'CNY', |
| | 20 | |
| | 21 | exports.streamAPIModes = {..., coinbaseUSD: 'coinbase1'} |
| | 22 | }}} |
| | 23 | * server/lib/depthAPI.js |
| | 24 | each exchange represented by instance of exchangeAPIObj, collector requests each order book using method {{{getCurrentBook2}}} |
| | 25 | while published {{{events}}} is global event emitter instance to pass trades events. |
| | 26 | {{{ |
| | 27 | ... |
| | 28 | |
| | 29 | exports.events = new (require('events').EventEmitter)() //trade events, orderbook events |
| | 30 | |
| | 31 | var exchangeAPIObjs = {} |
| | 32 | |
| | 33 | ... |
| | 34 | |
| | 35 | exports.getCurrentBook2 = function(ticker) |
| | 36 | { |
| | 37 | return exchangeAPIObjs[ticker].currentHashBook |
| | 38 | } |
| | 39 | ... |
| | 40 | }}} |
| | 41 | |
| | 42 | 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. |
| | 43 | {{{ |
| | 44 | exports.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 | |
| | 61 | var apiParams = makeApiParams() |
| | 62 | exports.apiParams = apiParams |
| | 63 | }}} |
| | 64 | |
| | 65 | where definition of the method {{{makeApiParams}}} is as following |
| | 66 | {{{ |
| | 67 | function 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 | |
| | 90 | where {{{coinbaseUSD}}} is defined as |
| | 91 | {{{ |
| | 92 | ... |
| | 93 | |
| | 94 | , coinbaseUSD: { |
| | 95 | cur: 'USD', |
| | 96 | exAPIObj: api.exAPICoinbase |
| | 97 | } |
| | 98 | ... |
| | 99 | }}} |
| | 100 | |
| | 101 | where {{{api.exAPICoinbase}}} is included from |
| | 102 | {{{ |
| | 103 | ... |
| | 104 | , api = require('./exchange-api/apiClasses') |
| | 105 | ... |
| | 106 | }}} |