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
25 changes: 23 additions & 2 deletions src/__tests__/custom-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -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 () => {
Expand All @@ -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', () => {
Expand Down
10 changes: 5 additions & 5 deletions src/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down