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