Skip to content

Commit

Permalink
Merge pull request #214 from stoqey/ryl20240315
Browse files Browse the repository at this point in the history
Ryl20240315
  • Loading branch information
rylorin authored May 9, 2024
2 parents 10ddecd + 29cc284 commit 5e61fb3
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 73 deletions.
14 changes: 7 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
version: 2.1

jobs:
build-dependencies:
environment:
NODE_ENV: development
docker:
- image: node:18.17.1
- image: node:18.19.1
working_directory: ~/repo
steps:
- restore_cache:
Expand Down Expand Up @@ -66,7 +67,7 @@ jobs:
- JAVA_PATH=/opt/i4j_jres/1.8.0_152/bin # JRE is bundled starting with TWS 952
- APP=GATEWAY
docker:
- image: node:18.17.1
- image: node:18.19.1
working_directory: ~/repo
steps:
- restore_cache:
Expand Down Expand Up @@ -99,14 +100,12 @@ jobs:
# CC_TEST_REPORTER_ID: <insert id>
NODE_ENV: development
docker:
- image: node:18.17.1
- image: node:18.19.1
- image: industrialninja/ib_gateway:latest
environment:
- TZ=America/NewYork
- APP=GATEWAY
- TRADING_MODE=paper
ports:
- 4003:4003
working_directory: ~/repo
steps:
- restore_cache:
Expand Down Expand Up @@ -160,7 +159,8 @@ jobs:
environment:
CC_TEST_REPORTER_ID: <insert id>
docker:
- image: circleci/node:12.18.4
# - image: circleci/node:16.13.1
- image: node:18.19.1
working_directory: ~/repo
steps:
- attach_workspace:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
uses: "actions/setup-node@v4"
with:
node-version: 18.19.1
cache: "yarn" # caches the yarn cache folder not node_modules

# Automated Version Bump
- name: "Automated Version Bump"
Expand All @@ -35,7 +36,7 @@ jobs:
run: yarn install --frozen-lockfile

# Publish the package
- name: npm publish
- name: "Publishing to Npm registry"
run: |
npm config set //registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN
npm publish
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.16.1
v18.19.1
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@
},
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^18.19.22",
"@types/node": "^18.19.33",
"@types/source-map-support": "^0.5.10",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"ajv": "^8.12.0",
"ajv": "^8.13.0",
"eslint": "^8.57.0",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-rxjs": "^5.0.3",
"jest": "^29.7.0",
"jest-environment-node": "^29.7.0",
"jest-junit": "^16.0.0",
"ts-jest": "^29.1.2",
"typedoc": "^0.25.11",
"typescript": "^5.4.2"
"typedoc": "^0.25.13",
"typescript": "^5.4.5"
},
"engines": {
"node": ">=18.0.0"
Expand Down
16 changes: 8 additions & 8 deletions src/api-next/api-next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,7 @@ export class IBApiNext {
* - OPTION_IMPLIED_VOLATILITY
* - FEE_RATE
* - REBATE_RATE
* @param useRTH Set to 0 to obtain the data which was also generated outside of the Regular Trading Hours, set to 1 to obtain only the RTH data
* @param useRTH Set to false to obtain the data which was also generated outside of the Regular Trading Hours, set to true to obtain only the RTH data
* @param formatDate Set to 1 to obtain the bars' time as yyyyMMdd HH:mm:ss, set to 2 to obtain it like system time format in seconds
*/
getHistoricalData(
Expand All @@ -1757,7 +1757,7 @@ export class IBApiNext {
durationStr: string,
barSizeSetting: BarSizeSetting,
whatToShow: WhatToShow,
useRTH: number,
useRTH: number | boolean,
formatDate: number,
): Promise<Bar[]> {
return lastValueFrom(
Expand Down Expand Up @@ -1927,14 +1927,14 @@ export class IBApiNext {
* @param startDateTime "20170701 12:01:00". Uses TWS timezone specified at login.
* @param endDateTime "20170701 13:01:00". In TWS timezone. Exactly one of start time and end time has to be defined.
* @param numberOfTicks Number of distinct data points. Max currently 1000 per request.
* @param useRTH Data from regular trading hours (1), or all available hours (0)
* @param useRTH Data from regular trading hours (true), or all available hours (false)
*/
getHistoricalTicksMid(
contract: Contract,
startDateTime: string,
endDateTime: string,
numberOfTicks: number,
useRTH: number,
useRTH: number | boolean,
): Observable<HistoricalTick[]> {
return this.subscriptions
.register<HistoricalTick[]>(
Expand Down Expand Up @@ -1995,15 +1995,15 @@ export class IBApiNext {
* @param startDateTime "20170701 12:01:00". Uses TWS timezone specified at login.
* @param endDateTime "20170701 13:01:00". In TWS timezone. Exactly one of start time and end time has to be defined.
* @param numberOfTicks Number of distinct data points. Max currently 1000 per request.
* @param useRTH Data from regular trading hours (1), or all available hours (0)
* @param useRTH Data from regular trading hours (true), or all available hours (false)
* @param ignoreSize A filter only used when the source price is Bid_Ask
*/
getHistoricalTicksBidAsk(
contract: Contract,
startDateTime: string,
endDateTime: string,
numberOfTicks: number,
useRTH: number,
useRTH: number | boolean,
ignoreSize: boolean,
): Observable<HistoricalTickBidAsk[]> {
return this.subscriptions
Expand Down Expand Up @@ -2063,14 +2063,14 @@ export class IBApiNext {
* @param startDateTime "20170701 12:01:00". Uses TWS timezone specified at login.
* @param endDateTime "20170701 13:01:00". In TWS timezone. Exactly one of start time and end time has to be defined.
* @param numberOfTicks Number of distinct data points. Max 1000 per request.
* @param useRTH Data from regular trading hours (1), or all available hours (0)
* @param useRTH Data from regular trading hours (true), or all available hours (false)
*/
getHistoricalTicksLast(
contract: Contract,
startDateTime: string,
endDateTime: string,
numberOfTicks: number,
useRTH: number,
useRTH: number | boolean,
): Observable<HistoricalTickLast[]> {
return this.subscriptions
.register<HistoricalTickLast[]>(
Expand Down
22 changes: 14 additions & 8 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ import OptionExerciseAction from "./data/enum/option-exercise-action";
import { BarSizeSetting } from "./historical/bar-size-setting";
import { HistogramEntry } from "./historical/histogramEntry";
import { HistoricalTick } from "./historical/historicalTick";
import { HistoricalTickBidAsk } from "./historical/historicalTickBidAsk";
import { HistoricalTickLast } from "./historical/historicalTickLast";
import {
HistoricalTickBidAsk,
TickAttribBidAsk,
} from "./historical/historicalTickBidAsk";
import {
HistoricalTickLast,
TickAttribLast,
} from "./historical/historicalTickLast";
import { ScannerSubscription } from "./market/scannerSubscription";
import { TickByTickDataType } from "./market/tickByTickDataType";
import { TickType } from "./market/tickType";
Expand Down Expand Up @@ -959,7 +965,7 @@ export class IBApi extends EventEmitter {
* - OPTION_IMPLIED_VOLATILITY
* - FEE_RATE
* - REBATE_RATE
* @param useRTH Set to 0 to obtain the data which was also generated outside of the Regular Trading Hours, set to 1
* @param useRTH Set to `false` to obtain the data which was also generated outside of the Regular Trading Hours, set to `true`
* to obtain only the RTH data
* @param formatDate Set to 1 to obtain the bars' time as yyyyMMdd HH:mm:ss, set to 2 to obtain it like system time
* format in seconds
Expand All @@ -973,7 +979,7 @@ export class IBApi extends EventEmitter {
durationStr: string,
barSizeSetting: BarSizeSetting,
whatToShow: WhatToShow,
useRTH: number,
useRTH: number | boolean,
formatDate: number,
keepUpToDate: boolean,
): IBApi {
Expand Down Expand Up @@ -1045,7 +1051,7 @@ export class IBApi extends EventEmitter {
endDateTime: string,
numberOfTicks: number,
whatToShow: WhatToShow,
useRTH: number,
useRTH: number | boolean,
ignoreSize: boolean,
): IBApi {
this.controller.schedule(() =>
Expand Down Expand Up @@ -2994,8 +3000,8 @@ export declare interface IBApi {
time: number,
price: number,
size: number,
tickAttribLast: unknown, /* TODO: replace with TickAttribLast type as soon as available. */
exchange: string,
tickAttribLast: TickAttribLast,
exchange: string,
specialConditions: string,
) => void,
): this;
Expand Down Expand Up @@ -3029,7 +3035,7 @@ export declare interface IBApi {
askPrice: number,
bidSize: number,
askSize: number,
tickAttribBidAsk: unknown /* TODO: replace with TickAttribBidAsk type as soon as available. */,
tickAttribBidAsk: TickAttribBidAsk,
) => void,
): this;

Expand Down
4 changes: 2 additions & 2 deletions src/api/historical/historicalTickLast.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Attributes of a [[HistoricalTickBidAsk]].
*/
export interface TickAttribBidAsk {
export interface TickAttribLast {
/** TODO document */
pastLimit?: boolean;

Expand All @@ -19,7 +19,7 @@ export interface HistoricalTickLast {
time?: number;

/** Tick attribs of historical last tick. */
tickAttribBidAsk?: TickAttribBidAsk;
tickAttribLast?: TickAttribLast;

/** The last price of the historical tick. */
price?: number;
Expand Down
2 changes: 1 addition & 1 deletion src/core/io/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2405,7 +2405,7 @@ export class Decoder {
const specialConditions = this.readStr();
ticks[i] = {
time: time,
tickAttribBidAsk: {
tickAttribLast: {
pastLimit: (mask & (1 << 0)) !== 0,
unreported: (mask & (1 << 1)) !== 0,
},
Expand Down
4 changes: 2 additions & 2 deletions src/core/io/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2101,7 +2101,7 @@ function tagValuesToTokens(tagValues: TagValue[]): unknown[] {
durationStr: string,
barSizeSetting: BarSizeSetting,
whatToShow: WhatToShow,
useRTH: number,
useRTH: number | boolean,
formatDate: number,
keepUpToDate: boolean,
chartOptions?: TagValue[],
Expand Down Expand Up @@ -2219,7 +2219,7 @@ function tagValuesToTokens(tagValues: TagValue[]): unknown[] {
endDateTime: string,
numberOfTicks: number,
whatToShow: WhatToShow,
useRth: number,
useRth: number | boolean,
ignoreSize: boolean,
miscOptions?: TagValue[],
): void {
Expand Down
99 changes: 99 additions & 0 deletions src/tests/unit/api-next-live/get-historical-ticks.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* This file implements tests for the [[IBApiNext.getContractDetails]] function.
*/

import { Subscription } from "rxjs";
import { IBApiNext } from "../../..";
import { sample_etf } from "../sample-data/contracts";

describe("ApiNext: getContractDetails()", () => {
jest.setTimeout(10 * 1000);

const clientId = Math.floor(Math.random() * 32766) + 1; // ensure unique client

let api: IBApiNext;
let error$: Subscription;

beforeEach(() => {
api = new IBApiNext();

if (!error$) {
error$ = api.errorSubject.subscribe((error) => {
if (error.reqId === -1) {
console.warn(`${error.error.message} (Error #${error.code})`);
} else {
console.error(
`${error.error.message} (Error #${error.code}) ${
error.advancedOrderReject ? error.advancedOrderReject : ""
}`,
);
}
});
}

try {
api.connect(clientId);
} catch (error) {
console.error(error.message);
}
});

afterEach(() => {
if (api) {
api.disconnect();
api = undefined;
}
});

test("ETF historical ticks last", (done) => {
api
.getHistoricalTicksLast(sample_etf, "20240508-17:00:00", null, 1, true)
// eslint-disable-next-line rxjs/no-ignored-subscription
.subscribe({
next: (ticks) => {
// console.log(ticks.length, ticks);
expect(ticks.length).toEqual(17);
expect(ticks[0].time).toEqual(1715187600);
expect(ticks[0].price).toEqual(516.635);
expect(ticks[0].size).toEqual(1);
expect(ticks[0].exchange).toEqual("FINRA");
},
complete: () => {
done();
},
error: () => {
done("Some error occured!");
},
});
});

test("ETF historical bid/ask ticks", (done) => {
api
.getHistoricalTicksBidAsk(
sample_etf,
"20240508-17:00:00",
null,
1,
true,
true,
)
// eslint-disable-next-line rxjs/no-ignored-subscription
.subscribe({
next: (ticks) => {
// console.log(ticks.length, ticks);
expect(ticks.length).toEqual(34);
expect(ticks[0].time).toEqual(1715187599);
expect(ticks[0].priceBid).toEqual(516.62);
expect(ticks[0].priceAsk).toEqual(516.63);
expect(ticks[0].sizeBid).toEqual(1100);
expect(ticks[0].sizeAsk).toEqual(1400);
},
complete: () => {
done();
},
error: () => {
done("Some error occured!");
},
});
});
});
Loading

0 comments on commit 5e61fb3

Please sign in to comment.