-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #200 from innovatingdev/fix_encodings
Fixed reqHeadTimestamp and reqHistogramData
- Loading branch information
Showing
3 changed files
with
111 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* This file implement test code for the public API interfaces. | ||
*/ | ||
import { Contract, EventName, IBApi, Stock, WhatToShow } from "../../.."; | ||
import configuration from "../../../common/configuration"; | ||
|
||
describe("IBApi Historical data Tests", () => { | ||
jest.setTimeout(10 * 1000); | ||
|
||
let ib: IBApi; | ||
const clientId = Math.floor(Math.random() * 32766) + 1; // ensure unique client | ||
|
||
beforeEach(() => { | ||
ib = new IBApi({ | ||
host: configuration.ib_host, | ||
port: configuration.ib_port, | ||
clientId, | ||
}); | ||
// logger.info("IBApi created"); | ||
}); | ||
|
||
afterEach(() => { | ||
if (ib) { | ||
ib.disconnect(); | ||
ib = undefined; | ||
} | ||
// logger.info("IBApi disconnected"); | ||
}); | ||
|
||
it("Returns the correct head timestamp", (done) => { | ||
const referenceID = 42; | ||
|
||
ib.once(EventName.connected, () => { | ||
const contract: Contract = new Stock("AAPL"); | ||
|
||
ib.reqHeadTimestamp(referenceID, contract, WhatToShow.TRADES, true, 2) | ||
.on(EventName.headTimestamp, (requestId, headTimestamp) => { | ||
if (requestId === referenceID) { | ||
expect(headTimestamp).toEqual("345479400"); | ||
ib.disconnect(); | ||
} | ||
}) | ||
.on(EventName.disconnected, done) | ||
.on(EventName.error, (err, code, requestId) => { | ||
if (requestId === referenceID) { | ||
done(`[${requestId}] ${err.message} (#${code})`); | ||
} | ||
}); | ||
}); | ||
|
||
ib.connect(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* This file implement test code for the public API interfaces. | ||
*/ | ||
import { Contract, DurationUnit, EventName, IBApi, Stock } from "../../.."; | ||
import configuration from "../../../common/configuration"; | ||
|
||
describe("IBApi Histogram data Tests", () => { | ||
jest.setTimeout(10 * 1000); | ||
|
||
let ib: IBApi; | ||
const clientId = Math.floor(Math.random() * 32766) + 1; // ensure unique client | ||
|
||
beforeEach(() => { | ||
ib = new IBApi({ | ||
host: configuration.ib_host, | ||
port: configuration.ib_port, | ||
clientId, | ||
}); | ||
// logger.info("IBApi created"); | ||
}); | ||
|
||
afterEach(() => { | ||
if (ib) { | ||
ib.disconnect(); | ||
ib = undefined; | ||
} | ||
// logger.info("IBApi disconnected"); | ||
}); | ||
|
||
it("Histogram market data", (done) => { | ||
const referenceID = 46; | ||
|
||
ib.once(EventName.connected, () => { | ||
const contract: Contract = new Stock("AAPL"); | ||
|
||
ib.reqHistogramData(referenceID, contract, true, 1, DurationUnit.WEEK) | ||
.on(EventName.histogramData, (requestID, data) => { | ||
if (requestID === referenceID) { | ||
expect(requestID).toEqual(referenceID); | ||
expect(data.length).toBeGreaterThan(0); | ||
ib.disconnect(); | ||
} | ||
}) | ||
.on(EventName.disconnected, done) | ||
.on(EventName.error, (err, code, requestID) => { | ||
if (requestID == referenceID) { | ||
done(`[${requestID}] ${err.message} (#${code})`); | ||
} | ||
}); | ||
}); | ||
|
||
ib.connect(); | ||
}); | ||
}); |