From 8b53816eb2080ceafc4e3906255795da6014bcb9 Mon Sep 17 00:00:00 2001 From: qingwei Date: Mon, 30 May 2016 12:26:16 +0800 Subject: [PATCH 1/3] Make buffer size dynamic --- src/custom.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/custom.js b/src/custom.js index 41bd695..217359a 100644 --- a/src/custom.js +++ b/src/custom.js @@ -94,13 +94,17 @@ export function getDataForContract( const symbol = contract.underlying; if (contract.tick_count) { const start = contract.purchase_time; - const sellT = contract.sell_time; + const sellT = contract.exit_tick_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 bufferSize = 0.05; + const contractStart = contract.purchase_time; + const contractEnd = contract.exit_tick_time; + const buffer = (contractEnd - contractStart) * bufferSize; + const start = Math.round(contractStart - buffer); // add 5 minutes buffer + const sellT = Math.round(contractEnd + buffer); const end = contract.sell_spot ? sellT : nowEpoch(); return autoAdjustGetData(api, symbol, start, end, style, granularity); }); From fa539550c315985b942557bcbbd4fc812d355a54 Mon Sep 17 00:00:00 2001 From: qingwei Date: Mon, 30 May 2016 13:18:10 +0800 Subject: [PATCH 2/3] Fix test --- src/__tests__/custom-test.js | 6 +++--- src/custom.js | 18 +++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) 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 217359a..ac42004 100644 --- a/src/custom.js +++ b/src/custom.js @@ -93,19 +93,23 @@ export function getDataForContract( .then(contract => { const symbol = contract.underlying; if (contract.tick_count) { - const start = contract.purchase_time; - const sellT = contract.exit_tick_time; + const start = +(contract.purchase_time); + const sellT = +(contract.exit_tick_time); const end = contract.sell_spot ? sellT : 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 buffer = (contractEnd - contractStart) * bufferSize; - const start = Math.round(contractStart - buffer); // add 5 minutes buffer - const sellT = Math.round(contractEnd + buffer); + 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 sellT = contractEnd + buffer; const end = contract.sell_spot ? sellT : nowEpoch(); + + console.log('b', buffer); + console.log('s', contractStart); + console.log('e', contractEnd); return autoAdjustGetData(api, symbol, start, end, style, granularity); }); From 2b6fa4eb563cc87a91371d9f2014b48a9c417c39 Mon Sep 17 00:00:00 2001 From: qingwei Date: Mon, 30 May 2016 13:21:26 +0800 Subject: [PATCH 3/3] Better naming, remove log --- src/custom.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/custom.js b/src/custom.js index ac42004..c92d5f5 100644 --- a/src/custom.js +++ b/src/custom.js @@ -94,8 +94,8 @@ export function getDataForContract( const symbol = contract.underlying; if (contract.tick_count) { const start = +(contract.purchase_time); - const sellT = +(contract.exit_tick_time); - const end = contract.sell_spot ? sellT : nowEpoch(); + const exitTime = +(contract.exit_tick_time); + const end = contract.sell_spot ? exitTime : nowEpoch(); return autoAdjustGetData(api, symbol, start, end, style, granularity); } @@ -104,12 +104,9 @@ export function getDataForContract( const contractEnd = +(contract.exit_tick_time); const buffer = Math.round((contractEnd - contractStart) * bufferSize); const start = contractStart - buffer; // add 5 minutes buffer - const sellT = contractEnd + buffer; - const end = contract.sell_spot ? sellT : nowEpoch(); + const bufferedExitTime = contractEnd + buffer; + const end = contract.sell_spot ? bufferedExitTime : nowEpoch(); - console.log('b', buffer); - console.log('s', contractStart); - console.log('e', contractEnd); return autoAdjustGetData(api, symbol, start, end, style, granularity); });