diff --git a/src/__tests__/custom-test.js b/src/__tests__/custom-test.js index ac15874..5b88009 100644 --- a/src/__tests__/custom-test.js +++ b/src/__tests__/custom-test.js @@ -5,17 +5,25 @@ import 'babel-polyfill'; import LiveApi from '../LiveApi'; import ws from 'ws'; -describe("custom", () => { +describe('custom', () => { let liveApi; const token = 'qdJ86Avvrsh0Le4'; beforeEach(() => { liveApi = new LiveApi({ websocket: ws }); }); - it("getDataForContract", async () => { - const auth = await liveApi.authorize(token); - const ticks = await liveApi.getDataForContract('8686424368'); - expect(ticks).to.have.lengthOf(151); + describe('getDataForContract', () => { + it('should get more extra ticks for non-tick-contract', async () => { + const auth = await liveApi.authorize(token); + const ticks = await liveApi.getDataForContract('8686424368'); + expect(ticks).to.have.lengthOf(451); + }); + + it('should get exact number of ticks for tick-contract', async () => { + const auth = await liveApi.authorize(token); + const ticks = await liveApi.getDataForContract('8818581808'); + expect(ticks).to.have.lengthOf(8); + }); }); it('getDataForSymbol', async () => { diff --git a/src/custom.js b/src/custom.js index 2e428d6..4c980ed 100644 --- a/src/custom.js +++ b/src/custom.js @@ -66,15 +66,22 @@ export const getDataForContract = ( durationCount, durationType = 'all', style = 'ticks', - granularity = 60 + granularity = 60, ) => { const getAllData = () => api.subscribeToOpenContract(contractID) .then(r => { const contract = r.proposal_open_contract; const symbol = contract.underlying; - const start = contract.purchase_time; - const sellT = contract.sell_time; + if (contract.tick_count) { + const start = contract.purchase_time; + const sellT = contract.sell_time; + const end = contract.sell_spot ? sellT : 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(); return autoAdjustGetData(api, symbol, start, end, style, granularity); });