diff --git a/src/__tests__/custom-test.js b/src/__tests__/custom-test.js index 77d10f2..12b5523 100644 --- a/src/__tests__/custom-test.js +++ b/src/__tests__/custom-test.js @@ -18,7 +18,7 @@ describe('custom', () => { const nonTickContractID = '8686424368'; const ticks = await liveApi .getDataForContract(() => liveApi.getContractInfo(nonTickContractID).then(r => r.proposal_open_contract)); - expect(ticks).to.have.lengthOf(451); + expect(ticks).to.have.lengthOf(165); }); it('should get exact number of ticks for tick-contract', async () => { @@ -26,7 +26,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(8); + expect(ticks).to.have.lengthOf(7); }); it('should return candles if user request candles', async () => { @@ -39,7 +39,7 @@ describe('custom', () => { 'all', 'candles', ); - expect(candles).to.have.lengthOf(16); + expect(candles).to.have.lengthOf(6); expect(candles[0]).to.have.keys('open', 'close', 'epoch', 'high', 'low'); }); }); diff --git a/src/custom.js b/src/custom.js index 41bd695..c92d5f5 100644 --- a/src/custom.js +++ b/src/custom.js @@ -93,15 +93,20 @@ export function getDataForContract( .then(contract => { const symbol = contract.underlying; if (contract.tick_count) { - const start = contract.purchase_time; - const sellT = contract.sell_time; - const end = contract.sell_spot ? sellT : nowEpoch(); + const start = +(contract.purchase_time); + const exitTime = +(contract.exit_tick_time); + const end = contract.sell_spot ? exitTime : nowEpoch(); return autoAdjustGetData(api, symbol, start, end, style, granularity); } - const start = contract.purchase_time - (5 * 60); // add 5 minutes buffer - const sellT = contract.sell_time + (5 * 60); - const end = contract.sell_spot ? sellT : nowEpoch(); + const bufferSize = 0.05; + const contractStart = +(contract.purchase_time); + const contractEnd = +(contract.exit_tick_time); + const buffer = Math.round((contractEnd - contractStart) * bufferSize); + const start = contractStart - buffer; // add 5 minutes buffer + const bufferedExitTime = contractEnd + buffer; + const end = contract.sell_spot ? bufferedExitTime : nowEpoch(); + return autoAdjustGetData(api, symbol, start, end, style, granularity); });