diff --git a/src/__tests__/custom-test.js b/src/__tests__/custom-test.js index 12b5523..ca0bc68 100644 --- a/src/__tests__/custom-test.js +++ b/src/__tests__/custom-test.js @@ -17,7 +17,9 @@ describe('custom', () => { await liveApi.authorize(token); const nonTickContractID = '8686424368'; const ticks = await liveApi - .getDataForContract(() => liveApi.getContractInfo(nonTickContractID).then(r => r.proposal_open_contract)); + .getDataForContract(() => + liveApi.getContractInfo(nonTickContractID).then(r => r.proposal_open_contract) + ); expect(ticks).to.have.lengthOf(165); }); @@ -26,7 +28,7 @@ describe('custom', () => { const tickContractID = '8818581808'; const ticks = await liveApi .getDataForContract(() => liveApi.getContractInfo(tickContractID).then(r => r.proposal_open_contract)); - expect(ticks).to.have.lengthOf(7); + expect(ticks).to.have.lengthOf(11); }); it('should return candles if user request candles', async () => { @@ -42,6 +44,25 @@ describe('custom', () => { expect(candles).to.have.lengthOf(6); expect(candles[0]).to.have.keys('open', 'close', 'epoch', 'high', 'low'); }); + + it('should return even if contract does not have end time', async () => { + await liveApi.authorize(token); + const nonTickContractID = '8686424368'; + const candles = await liveApi + .getDataForContract( + () => liveApi.getContractInfo(nonTickContractID).then(r => { + const cloned = Object.assign({}, r.proposal_open_contract); + delete cloned.exit_tick_time; + delete cloned.date_expiry; + return cloned; + }), + 1, + 'all', + 'candles', + ); + expect(candles).to.have.length.above(1000); + expect(candles[0]).to.have.keys('open', 'close', 'epoch', 'high', 'low'); + }); }); describe('getDataForSymbol', () => { diff --git a/src/custom.js b/src/custom.js index c92d5f5..a9e0bac 100644 --- a/src/custom.js +++ b/src/custom.js @@ -93,19 +93,19 @@ export function getDataForContract( .then(contract => { const symbol = contract.underlying; if (contract.tick_count) { - const start = +(contract.purchase_time); - const exitTime = +(contract.exit_tick_time); + const start = +(contract.purchase_time) - 5; + const exitTime = +(contract.exit_tick_time) + 5; const end = contract.sell_spot ? exitTime : nowEpoch(); return autoAdjustGetData(api, symbol, start, end, style, granularity); } const bufferSize = 0.05; const contractStart = +(contract.purchase_time); - const contractEnd = +(contract.exit_tick_time); + const contractEnd = +(contract.exit_tick_time) || +(contract.date_expiry); const buffer = Math.round((contractEnd - contractStart) * bufferSize); - const start = contractStart - buffer; // add 5 minutes buffer + const start = buffer ? contractStart - buffer : contractStart; // add 5 minutes buffer const bufferedExitTime = contractEnd + buffer; - const end = contract.sell_spot ? bufferedExitTime : nowEpoch(); + const end = contractEnd ? bufferedExitTime : nowEpoch(); return autoAdjustGetData(api, symbol, start, end, style, granularity); });