Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit 23b685d

Browse files
committed
Merge pull request #41 from qingweibinary/qingwei/add_buffers_for_contract_data
Add 5 mins extra data for non-tick trade
2 parents e750ddc + 33ec81c commit 23b685d

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/__tests__/custom-test.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,25 @@ import 'babel-polyfill';
55
import LiveApi from '../LiveApi';
66
import ws from 'ws';
77

8-
describe("custom", () => {
8+
describe('custom', () => {
99
let liveApi;
1010
const token = 'qdJ86Avvrsh0Le4';
1111
beforeEach(() => {
1212
liveApi = new LiveApi({ websocket: ws });
1313
});
1414

15-
it("getDataForContract", async () => {
16-
const auth = await liveApi.authorize(token);
17-
const ticks = await liveApi.getDataForContract('8686424368');
18-
expect(ticks).to.have.lengthOf(151);
15+
describe('getDataForContract', () => {
16+
it('should get more extra ticks for non-tick-contract', async () => {
17+
const auth = await liveApi.authorize(token);
18+
const ticks = await liveApi.getDataForContract('8686424368');
19+
expect(ticks).to.have.lengthOf(451);
20+
});
21+
22+
it('should get exact number of ticks for tick-contract', async () => {
23+
const auth = await liveApi.authorize(token);
24+
const ticks = await liveApi.getDataForContract('8818581808');
25+
expect(ticks).to.have.lengthOf(8);
26+
});
1927
});
2028

2129
it('getDataForSymbol', async () => {

src/custom.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,22 @@ export const getDataForContract = (
6666
durationCount,
6767
durationType = 'all',
6868
style = 'ticks',
69-
granularity = 60
69+
granularity = 60,
7070
) => {
7171
const getAllData = () =>
7272
api.subscribeToOpenContract(contractID)
7373
.then(r => {
7474
const contract = r.proposal_open_contract;
7575
const symbol = contract.underlying;
76-
const start = contract.purchase_time;
77-
const sellT = contract.sell_time;
76+
if (contract.tick_count) {
77+
const start = contract.purchase_time;
78+
const sellT = contract.sell_time;
79+
const end = contract.sell_spot ? sellT : nowEpoch();
80+
return autoAdjustGetData(api, symbol, start, end, style, granularity);
81+
}
82+
83+
const start = contract.purchase_time - (5 * 60); // add 5 minutes buffer
84+
const sellT = contract.sell_time + (5 * 60);
7885
const end = contract.sell_spot ? sellT : nowEpoch();
7986
return autoAdjustGetData(api, symbol, start, end, style, granularity);
8087
});

0 commit comments

Comments
 (0)