Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/__tests__/custom-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ 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 () => {
await liveApi.authorize(token);
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 () => {
Expand All @@ -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');
});
});
Expand Down
17 changes: 11 additions & 6 deletions src/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down