notbank
Version:
The Notbank for Node.js
143 lines (127 loc) • 4.79 kB
text/typescript
import { WebSocketEndpoint } from "../../constants/endpoints";
import { MessageFrame } from "./messageFrame";
export class SubscriptionIdentifier {
static
Record<WebSocketEndpoint, (eventName: string, payloadStr: string) => string>
> = {
[]: this.
[]: this.
[]: this.
[]: this.
[]: this.
[]: this.
[]: this.
[]: this.
[]: this.
[]:
this.
[]:
this.
[]: this.
[]: this.
[]:
this.
[]:
this.
[]:
this.
[]: this.
};
static get(
eventName: string,
firstIdentifier: number | null = null,
secondIdentifier: number | null = null,
) {
return (
eventName +
SubscriptionIdentifier.
SubscriptionIdentifier.
);
}
static
return firstIdentifier != null ? "_" + firstIdentifier : "";
}
static getFromMessageFrame(message: MessageFrame): string {
return this.
}
static
const instrumentId = SubscriptionIdentifier.
payloadStr,
8,
);
if (instrumentId == null) {
return eventName;
}
return eventName + "_" + instrumentId;
}
static
return (
eventName + "_" + SubscriptionIdentifier.
);
}
static
let instrumentId = SubscriptionIdentifier.
if (instrumentId == null) {
return eventName;
}
return eventName + "_" + instrumentId;
}
static
const instrumentId = SubscriptionIdentifier.
payloadStr,
1,
);
if (instrumentId == null) {
return eventName;
}
return eventName + "_" + instrumentId;
}
static
let accountId = SubscriptionIdentifier.
if (accountId != null) {
return eventName + "_" + accountId;
}
accountId = this.
if (accountId != null) {
return eventName + "_" + accountId;
}
return eventName;
}
static
const data: { InstrumentId?: string; AccountId: number } =
JSON.parse(payloadStr);
let identifier = eventName + "_" + data.AccountId;
if (data.InstrumentId) {
return identifier + "_" + data.InstrumentId;
}
}
static
payloadStr: string,
index: number,
): string | number | null {
const data: any[][] = JSON.parse(payloadStr);
if (data.length == 0) {
return null;
}
if (data[0].length <= index) {
return null;
}
return data[0][index];
}
static
const data: { InstrumentId: string } = JSON.parse(payloadStr);
return data.InstrumentId;
}
static
const data: { Instrument: string } = JSON.parse(payloadStr);
return data.Instrument;
}
static
const data: { AccountId: string } = JSON.parse(payloadStr);
return data.AccountId;
}
static
const data: { Account: string } = JSON.parse(payloadStr);
return data.Account;
}
}