@barchart/marketdata-api-js
Advanced tools
Comparing version 3.1.51 to 3.2.1
{ | ||
"name": "barchart-marketdata-api", | ||
"version": "3.1.51", | ||
"version": "3.1.49", | ||
"homepage": "https://github.com/barchart/marketdata-api-js", | ||
@@ -5,0 +5,0 @@ "description": "Barchart Market Data API for JavaScript", |
@@ -29,2 +29,3 @@ const version = require('./../../../lib/index').version; | ||
that.connecting = ko.observable(false); | ||
that.paused = ko.observable(false); | ||
@@ -37,2 +38,8 @@ that.canConnect = ko.computed(function() { | ||
}); | ||
that.canPause = ko.computed(function() { | ||
return !that.paused(); | ||
}); | ||
that.canResume = ko.computed(function() { | ||
return that.paused(); | ||
}); | ||
that.canReset = ko.computed(function() { | ||
@@ -58,2 +65,6 @@ var connected = that.connected(); | ||
that.showGrid(); | ||
} else if (event === 'feed paused') { | ||
that.paused(true); | ||
} else if (event === 'feed resumed') { | ||
that.paused(false); | ||
} | ||
@@ -121,2 +132,3 @@ | ||
that.connected(false); | ||
that.paused(false); | ||
@@ -126,2 +138,10 @@ that.activeTemplate('disconnected-template'); | ||
that.pause = function() { | ||
connection.pause(); | ||
}; | ||
that.resume = function() { | ||
connection.resume(); | ||
}; | ||
that.handleLoginKeypress = function(d, e) { | ||
@@ -148,4 +168,2 @@ if (e.keyCode === 13) { | ||
symbols = C3; | ||
} else if (symbol === '#CSTATS') { | ||
symbols = CSTATS; | ||
} else { | ||
@@ -375,3 +393,2 @@ symbols = [ symbol ]; | ||
const C3 = [ 'C3:AL79MRM1', 'C3:BSP9WGQ1', 'C3:RA10BGM1' ]; | ||
const CSTATS = [ 'BLS-LIQUOR-PRICE-USA-12011.CM', 'BLS-BEVALCOHO-PRICE-USA-12010.CM', 'BLS-LIQUOR-PRICE-USA-12012.CM' ]; | ||
@@ -378,0 +395,0 @@ $(document).ready(function() { |
@@ -26,10 +26,2 @@ module.exports = (() => { | ||
/** | ||
* Returns the unique items from an array, where the unique | ||
* key is determined via a strict equality check. | ||
* | ||
* @static | ||
* @param {Array} a | ||
* @returns {Array} | ||
*/ | ||
unique(array) { | ||
@@ -36,0 +28,0 @@ const arrayToFilter = array || [ ]; |
@@ -69,2 +69,36 @@ const MarketState = require('./../marketState/MarketState'); | ||
/** | ||
* Causes the market state to stop updating. All subscriptions are maintained. | ||
* | ||
* @public | ||
*/ | ||
pause() { | ||
this._pause(); | ||
} | ||
/** | ||
* @protected | ||
* @ignore | ||
*/ | ||
_pause() { | ||
return; | ||
} | ||
/** | ||
* Causes the market state to begin updating again (after {@link ConnectionBase#pause} has been called). | ||
* | ||
* @public | ||
*/ | ||
resume() { | ||
this._resume(); | ||
} | ||
/** | ||
* @protected | ||
* @ignore | ||
*/ | ||
_resume() { | ||
return; | ||
} | ||
/** | ||
* Initiates a subscription to an {@link Subscription.EventType} and | ||
@@ -123,2 +157,3 @@ * registers the callback for notifications. | ||
* | ||
* @public | ||
* @return {number|null} | ||
@@ -134,2 +169,3 @@ */ | ||
* | ||
* @public | ||
* @param {number|null} pollingFrequency | ||
@@ -175,2 +211,3 @@ */ | ||
/** | ||
* @public | ||
* @returns {null|string} | ||
@@ -183,2 +220,3 @@ */ | ||
/** | ||
* @public | ||
* @returns {null|string} | ||
@@ -191,2 +229,3 @@ */ | ||
/** | ||
* @public | ||
* @returns {null|string} | ||
@@ -193,0 +232,0 @@ */ |
@@ -55,3 +55,3 @@ const utilities = require('@barchart/marketdata-utilities-js'); | ||
regex.snapshot = /^(BCDS-|BEA-|BLS-|EIA-|CFTC-|USCB-|USDA-)|:/; | ||
regex.snapshot = /^(BCSD-|BEA-|BLS-|EIA-|CFTC-|USCB-|USDA-)|:/; | ||
@@ -64,2 +64,4 @@ function ConnectionInternal(marketState) { | ||
let __paused = false; | ||
let __reconnectAllowed = false; | ||
@@ -118,5 +120,13 @@ let __pollingFrequency = null; | ||
function setPollingFrequency(pollingFrequency) { | ||
if (__paused) { | ||
resume(); | ||
} | ||
if (pollingFrequency === null || pollingFrequency === undefined) { | ||
console.info('Connection: Switching to streaming mode.'); | ||
__pollingFrequency = null; | ||
} else if (typeof(pollingFrequency) === 'number' && !isNaN(pollingFrequency) && !(pollingFrequency < 1000)) { | ||
console.info('Connection: Switching to polling mode.'); | ||
__pollingFrequency = pollingFrequency; | ||
@@ -168,2 +178,4 @@ } | ||
__paused = false; | ||
disconnect(); | ||
@@ -277,2 +289,4 @@ } | ||
console.log(message); | ||
if (message) { | ||
@@ -319,2 +333,35 @@ __inboundMessages.push(message); | ||
function pause() { | ||
if (__paused) { | ||
console.warn('Connection: Unable to pause, feed is already paused.'); | ||
return; | ||
} | ||
if (__pollingFrequency === null) { | ||
enqueueStopTasks(); | ||
enqueueHeartbeat(); | ||
} | ||
__paused = true; | ||
broadcastEvent('events', { event: 'feed paused' }); | ||
} | ||
function resume() { | ||
if (!__paused) { | ||
console.warn('Connection: Unable to resume, feed is not paused.'); | ||
return; | ||
} | ||
__paused = false; | ||
if (__pollingFrequency === null) { | ||
enqueueGoTasks(); | ||
} | ||
broadcastEvent('events', { event: 'feed resumed' }); | ||
} | ||
/** | ||
@@ -436,6 +483,8 @@ * Starts heartbeat connection monitoring. | ||
if (producerListenerExists) { | ||
addTask(snapshotTaskName, producerSymbol); | ||
} else { | ||
addTask(streamingTaskName, producerSymbol); | ||
if (!__paused) { | ||
if (producerListenerExists) { | ||
addTask(snapshotTaskName, producerSymbol); | ||
} else { | ||
addTask(streamingTaskName, producerSymbol); | ||
} | ||
} | ||
@@ -546,4 +595,8 @@ }; | ||
if (previousProducerListenerExists && !currentProducerListenerExists) { | ||
if (previousProducerListenerExists && !currentProducerListenerExists && !__paused) { | ||
addTask(stopTaskName, producerSymbol); | ||
if (getProducerSymbolCount() === 0) { | ||
enqueueHeartbeat(); | ||
} | ||
} | ||
@@ -623,7 +676,7 @@ }; | ||
/** | ||
* Adds a symbol-related task to a queue for asynchronous processing. | ||
* Adds a task to a queue for asynchronous processing. | ||
* | ||
* @private | ||
* @param {String} id | ||
* @param {String} symbol | ||
* @param {String|null} symbol | ||
*/ | ||
@@ -637,3 +690,3 @@ function addTask(id, symbol) { | ||
if (!(lastIndex < 0) && __pendingTasks[lastIndex].id === id) { | ||
if (!(lastIndex < 0) && __pendingTasks[lastIndex].id === id && symbol !== null) { | ||
__pendingTasks[lastIndex].symbols.push(symbol); | ||
@@ -645,2 +698,6 @@ } else { | ||
function enqueueHeartbeat() { | ||
addTask('H_GO', null); | ||
} | ||
/** | ||
@@ -726,5 +783,12 @@ * Schedules symbol subscribe tasks for all symbols with listeners, typically | ||
console.log('Connection: Establishing subscriptions to feed for existing symbols.'); | ||
if (__paused) { | ||
console.log('Connection: Establishing heartbeat only -- feed is paused.'); | ||
enqueueGoTasks(); | ||
enqueueHeartbeat(); | ||
} else { | ||
console.log('Connection: Establishing subscriptions for heartbeat and existing symbols.'); | ||
enqueueHeartbeat(); | ||
enqueueGoTasks(); | ||
} | ||
} else if (firstCharacter === '-') { | ||
@@ -986,3 +1050,3 @@ console.log('Connection: Login failed.'); | ||
function processTasksInPollingMode() { | ||
if (__connectionState !== state.authenticated || __outboundMessages.length !== 0) { | ||
if (__connectionState !== state.authenticated || __outboundMessages.length !== 0 || __paused) { | ||
return; | ||
@@ -1069,5 +1133,9 @@ } | ||
break; | ||
case 'H_GO': | ||
command = 'GO _TIMESTAMP_'; | ||
suffix = null; | ||
break; | ||
} | ||
if (command === null || suffix === null) { | ||
if (command === null) { | ||
console.warn('Pump Tasks: An unsupported task was found in the tasks queue.'); | ||
@@ -1078,26 +1146,30 @@ | ||
let batchSize; | ||
if (task.id === 'MD_GO' || task.id === 'MD_STOP') { | ||
batchSize = 1; | ||
if (suffix === null) { | ||
__outboundMessages.push(command); | ||
} else { | ||
batchSize = 250; | ||
} | ||
let batchSize; | ||
const symbolsUnique = array.unique(task.symbols); | ||
if (task.id === 'MD_GO' || task.id === 'MD_STOP') { | ||
batchSize = 1; | ||
} else { | ||
batchSize = 250; | ||
} | ||
const symbolsStreaming = symbolsUnique.filter(getIsStreamingSymbol); | ||
const symbolsSnapshot = symbolsUnique.filter(getIsSnapshotSymbol); | ||
const symbolsUnique = array.unique(task.symbols); | ||
while (symbolsStreaming.length > 0) { | ||
const batch = symbolsStreaming.splice(0, batchSize); | ||
const symbolsStreaming = symbolsUnique.filter(getIsStreamingSymbol); | ||
const symbolsSnapshot = symbolsUnique.filter(getIsSnapshotSymbol); | ||
__outboundMessages.push(`${command} ${batch.map(s => `${s}=${suffix}`).join(',')}`); | ||
} | ||
while (symbolsStreaming.length > 0) { | ||
const batch = symbolsStreaming.splice(0, batchSize); | ||
if (task.id === 'MU_GO' || task.id === 'MU_REFRESH') { | ||
while (symbolsSnapshot.length > 0) { | ||
const batch = symbolsSnapshot.splice(0, batchSize); | ||
__outboundMessages.push(`${command} ${batch.map(s => `${s}=${suffix}`).join(',')}`); | ||
} | ||
processSnapshots(batch); | ||
if (task.id === 'MU_GO' || task.id === 'MU_REFRESH') { | ||
while (symbolsSnapshot.length > 0) { | ||
const batch = symbolsSnapshot.splice(0, batchSize); | ||
processSnapshots(batch); | ||
} | ||
} | ||
@@ -1124,3 +1196,3 @@ } | ||
if (polling) { | ||
if (polling && !__paused) { | ||
enqueueGoTasks(); | ||
@@ -1207,3 +1279,3 @@ } | ||
}).catch((e) => { | ||
console.log(`Snapshots: Out-of-band snapshot request failed for [ ${symbols.join()} ]`, e); | ||
console.log('Snapshots: Out-of-band snapshot request failed for [ ${symbols.join()} ]', e); | ||
}); | ||
@@ -1398,2 +1470,4 @@ } | ||
disconnect: terminateConnection, | ||
pause: pause, | ||
resume: resume, | ||
off: off, | ||
@@ -1429,2 +1503,10 @@ on: on, | ||
_pause() { | ||
this._internal.pause(); | ||
} | ||
_resume() { | ||
this._internal.resume(); | ||
} | ||
_on() { | ||
@@ -1431,0 +1513,0 @@ this._internal.on.apply(this._internal, arguments); |
@@ -20,4 +20,4 @@ const connection = require('./connection/index'), | ||
version: '3.1.51' | ||
version: '3.2.1' | ||
}; | ||
})(); |
@@ -17,3 +17,3 @@ const xhr = require('xhr'); | ||
regex.cmdty = { }; | ||
regex.cmdty.symbol = /^(BCDS-|BEA-|BLS-|EIA-|CFTC-|USCB-|USDA-)/; | ||
regex.cmdty.symbol = /^(BCSD-|BEA-|BLS-|EIA-|CFTC-|USCB-|USDA-)/; | ||
@@ -203,12 +203,3 @@ regex.c3 = { }; | ||
function retrieveSnapshotsUsingGetCmdtyStats(symbols, username, password) { | ||
return Promise.all(symbols.map((symbol) => { | ||
return retrieveSnapshotUsingGetCmdtyStats(symbol, username, password) | ||
.catch(() => { | ||
console.log(`Snapshots: Out-of-bank request failed for [ ${symbol} ]`); | ||
return null; | ||
}); | ||
})).then((messages) => { | ||
return messages.filter((message) => message !== null); | ||
}); | ||
return Promise.all(symbols.map((symbol) => retrieveSnapshotUsingGetCmdtyStats(symbol, username, password))); | ||
} | ||
@@ -215,0 +206,0 @@ |
{ | ||
"name": "@barchart/marketdata-api-js", | ||
"version": "3.1.51", | ||
"version": "3.2.1", | ||
"description": "Barchart client library for streaming market data from JERQ servers using JavaScript", | ||
@@ -5,0 +5,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
653294
48
19227
7