Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ryl20240309 #211

Merged
merged 4 commits into from
Mar 9, 2024
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
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
exclude_patterns:
- "ref/"
- "src/tests"
- "src/tests/"
8 changes: 6 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ jobs:
timeout-minutes: 3
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18.17.1

- name: Prepare
run: yarn install --frozen-lockfile

- name: Type Check
run: yarn type-check

- name: Lint Check
run: yarn lint
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ jobs:

steps:
- name: "Checkout source code"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"
with:
ref: ${{ github.ref }}

# Setup Node.js
- name: "Setup Node.js"
uses: "actions/setup-node@v3"
uses: "actions/setup-node@v4"
with:
node-version: 18.17.1

Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,26 @@
"dependencies": {
"colors": "^1.4.0",
"command-buffer": "^0.1.0",
"dotenv": "^16.3.1",
"dotenv": "^16.4.4",
"eventemitter3": "^5.0.1",
"function-rate-limit": "^1.1.0",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@types/jest": "^29.5.11",
"@types/node": "^18.17.15",
"@types/jest": "^29.5.12",
"@types/node": "^18.19.15",
"@types/source-map-support": "^0.5.10",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"ajv": "^8.12.0",
"eslint": "^8.56.0",
"eslint-plugin-jest": "^27.6.2",
"eslint-plugin-jest": "^27.8.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.1",
"typedoc": "^0.25.7",
"ts-jest": "^29.1.2",
"typedoc": "^0.25.8",
"typescript": "^5.2.2"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion src/api/data/enum/sec-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export enum SecType {
ICS = "ICS",

/** Cryptocurrency. */
CRYPTO = "CRYPTO ",
CRYPTO = "CRYPTO",
}

export default SecType;
38 changes: 18 additions & 20 deletions src/core/api-next/subscription-registry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Observable } from "rxjs";
import { EventName } from "../..";
import { IBApiNextError, IBApiNext, ItemListUpdate } from "../../api-next";
import { IBApiNext, IBApiNextError, ItemListUpdate } from "../../api-next";
import { IBApiAutoConnection } from "./auto-connection";
import { IBApiNextMap } from "./map";
import { IBApiNextSubscription } from "./subscription";
Expand Down Expand Up @@ -31,7 +31,7 @@ class RegistryEntry {
public readonly callback: (
subscriptions: Map<number, IBApiNextSubscription<unknown>>,
...eventArgs: unknown[]
) => void
) => void,
) {
this.listener = (...eventArgs) => {
this.callback(this.subscriptions, ...eventArgs);
Expand All @@ -42,10 +42,8 @@ class RegistryEntry {
public readonly listener: (...eventArgs: unknown[]) => void;

/** Map of all active subscriptions, with reqId as key. */
public readonly subscriptions: Map<
number,
IBApiNextSubscription<unknown>
> = new Map();
public readonly subscriptions: Map<number, IBApiNextSubscription<unknown>> =
new Map();
}

/**
Expand All @@ -67,8 +65,8 @@ export class IBApiNextSubscriptionRegistry {
*/
constructor(
private readonly api: IBApiAutoConnection,
private readonly apiNext: IBApiNext
) { }
private readonly apiNext: IBApiNext,
) {}

/** A Map containing the subscription registry, with event name as key. */
private readonly entires = new IBApiNextMap<EventName, RegistryEntry>();
Expand All @@ -94,33 +92,33 @@ export class IBApiNextSubscriptionRegistry {
(
subscriptions: Map<number, IBApiNextSubscription<T>>,
...eventArgs: unknown[]
) => void
) => void,
][],
instanceId?: string
instanceId?: string,
): Observable<ItemListUpdate<T>> {
// get the existing registry entries, or add if not existing yet

const entires: RegistryEntry[] = [];
const entries: RegistryEntry[] = [];
eventHandler.forEach((handler) => {
const eventName = handler[0];
const callback = handler[1];
const entry = this.entires.getOrAdd(eventName, () => {
const entry = new RegistryEntry(eventName, callback);
this.apiNext.logger.debug(
LOG_TAG,
`Add RegistryEntry for EventName.${eventName}`
`Add RegistryEntry for EventName.${eventName}`,
);
this.api.addListener(eventName, entry.listener);
return entry;
});
entires.push(entry);
entries.push(entry);
});

// lookup subscription by instance id

let subscription: IBApiNextSubscription<T>;
if (instanceId) {
entires.forEach((entry) => {
entries.forEach((entry) => {
const values = entry.subscriptions.values();
while (!subscription) {
const it = values.next();
Expand Down Expand Up @@ -150,30 +148,30 @@ export class IBApiNextSubscriptionRegistry {
}
},
() => {
entires.forEach((entry) => {
entries.forEach((entry) => {
entry.subscriptions.delete(subscription.reqId);
if (!entry.subscriptions.size) {
this.api.removeListener(entry.eventName, entry.listener);
this.apiNext.logger.debug(
LOG_TAG,
`Remove RegistryEntry for EventName.${entry.eventName}.`
`Remove RegistryEntry for EventName.${entry.eventName}.`,
);
this.entires.delete(entry.eventName);
}
});

this.apiNext.logger.debug(
LOG_TAG,
`Deleted IBApiNextSubscription for ${subscription.reqId}.`
`Deleted IBApiNextSubscription for ${subscription.reqId}.`,
);
},
instanceId
instanceId,
);

entires.forEach((entry) => {
entries.forEach((entry) => {
this.apiNext.logger.debug(
LOG_TAG,
`Add IBApiNextSubscription on EventName.${entry.eventName} for ${subscription.reqId}.`
`Add IBApiNextSubscription on EventName.${entry.eventName} for ${subscription.reqId}.`,
);
entry.subscriptions.set(subscription.reqId, subscription);
});
Expand Down
13 changes: 7 additions & 6 deletions src/core/io/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ export class Decoder {
*/
readDoubleOrUndefined(): number | undefined {
const token = this.readStr();
if (!token || token === "") {
if (!token) {
return undefined;
}
const val = parseFloat(token);
Expand All @@ -525,6 +525,7 @@ export class Decoder {
* Read a token from queue and return it as integer value.
*
* Returns Number.MAX_VALUE if the token is empty.
* @deprecated readIntOrUndefined is probably what you are looking for
*/
readIntMax(): number {
const token = this.readStr();
Expand Down Expand Up @@ -3066,7 +3067,7 @@ class OrderDecoder {

readDisplaySize(): void {
if (this.version >= 9) {
this.order.displaySize = this.decoder.readInt();
this.order.displaySize = this.decoder.readIntOrUndefined();
}
}

Expand Down Expand Up @@ -3417,7 +3418,7 @@ class OrderDecoder {

if (nConditions > 0) {
this.order.conditions = new Array(nConditions);

for (let i = 0; i < nConditions; i++) {
const orderConditionType = this.decoder.readInt();

Expand Down Expand Up @@ -3645,14 +3646,14 @@ class OrderDecoder {

readPostToAts(): void {
if (this.serverVersion >= MIN_SERVER_VER.POST_TO_ATS) {
this.order.postToAts = this.decoder.readIntMax();
this.order.postToAts = this.decoder.readIntOrUndefined();
}
}

readPegBestPegMidOrderAttributes() {
if (this.serverVersion >= MIN_SERVER_VER.PEGBEST_PEGMID_OFFSETS) {
this.order.minTradeQty = this.decoder.readIntMax();
this.order.minCompeteSize = this.decoder.readIntMax();
this.order.minTradeQty = this.decoder.readIntOrUndefined();
this.order.minCompeteSize = this.decoder.readIntOrUndefined();
this.order.competeAgainstBestOffset =
this.decoder.readDoubleOrUndefined();
this.order.midOffsetAtWhole = this.decoder.readDoubleOrUndefined();
Expand Down
1 change: 0 additions & 1 deletion src/tests/unit/api-next-live/get-contract-details.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ describe("ApiNext: getContractDetails()", () => {

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

let subscription$: Subscription;
let api: IBApiNext;
let error$: Subscription;

Expand Down
Loading
Loading