@openfeed/sdk-js 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DOCUMENTATION.md +217 -0
- package/LICENSE +28 -0
- package/README.md +29 -0
- package/SUBSCRIPTION_TYPES.md +200 -0
- package/SYMBOLS_EXCHANGES.md +17 -0
- package/dist/empty-411f875a.js +4 -0
- package/dist/generated/index.d.ts +6 -0
- package/dist/generated/openfeed.d.ts +1314 -0
- package/dist/generated/openfeed_api.d.ts +305 -0
- package/dist/generated/openfeed_instrument.d.ts +343 -0
- package/dist/generated/version.d.ts +1 -0
- package/dist/index.js +8676 -0
- package/dist/node.js +12325 -0
- package/dist/scripts/process.d.ts +1 -0
- package/dist/src/connection/connection.d.ts +61 -0
- package/dist/src/connection/connection_interfaces.d.ts +26 -0
- package/dist/src/connection/listeners.d.ts +14 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/test.d.ts +1 -0
- package/dist/src/utilities/async.d.ts +16 -0
- package/dist/src/utilities/empty.d.ts +2 -0
- package/dist/src/utilities/messages.d.ts +8 -0
- package/package.json +60 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import WebSocket from "isomorphic-ws";
|
|
2
|
+
import Long from "long";
|
|
3
|
+
import type { ExchangeResponse_Exchange, InstrumentReferenceResponse, SubscriptionType } from "@gen/openfeed_api";
|
|
4
|
+
import type { InstrumentDefinition } from "@gen/openfeed_instrument";
|
|
5
|
+
import type { Service } from "@gen/openfeed";
|
|
6
|
+
import { IOpenFeedClient, IOpenFeedConnection, IOpenFeedLogger, OpenFeedInstrumentReferenceRequest, OpenFeedInstrumentRequest } from "./connection_interfaces";
|
|
7
|
+
import { OpenFeedListeners } from "./listeners";
|
|
8
|
+
declare class OpenFeedConnection implements IOpenFeedConnection {
|
|
9
|
+
private readonly connectionToken;
|
|
10
|
+
private readonly socket;
|
|
11
|
+
private readonly listeners;
|
|
12
|
+
private readonly logger?;
|
|
13
|
+
private readonly subscriptions;
|
|
14
|
+
private readonly exchangeRequests;
|
|
15
|
+
private readonly instrumentRequests;
|
|
16
|
+
private readonly definitionsInFlight;
|
|
17
|
+
private readonly instrumentReferenceRequests;
|
|
18
|
+
private readonly whenDisconnectedSource;
|
|
19
|
+
constructor(connectionToken: string, socket: WebSocket, listeners: OpenFeedListeners, logger?: IOpenFeedLogger | undefined);
|
|
20
|
+
private messageTriggered;
|
|
21
|
+
private runConnectionWatchLoop;
|
|
22
|
+
private onMessage;
|
|
23
|
+
private disconnect;
|
|
24
|
+
private onError;
|
|
25
|
+
private onClose;
|
|
26
|
+
subscribe: (service: Service, subscriptionType: SubscriptionType, snapshotIntervalSeconds: number, symbols?: string[] | null, marketIds?: Long[] | null, exchanges?: string[] | null, channels?: number[] | null) => Long;
|
|
27
|
+
unsubscribe: (subscriptionId: Long) => void;
|
|
28
|
+
getExchanges: () => Promise<ExchangeResponse_Exchange[]>;
|
|
29
|
+
getInstrument: (request: OpenFeedInstrumentRequest) => Promise<InstrumentDefinition[]>;
|
|
30
|
+
getInstrumentReference: (request: OpenFeedInstrumentReferenceRequest) => Promise<InstrumentReferenceResponse>;
|
|
31
|
+
whenDisconnected: () => Promise<void>;
|
|
32
|
+
dispose: () => void;
|
|
33
|
+
}
|
|
34
|
+
export declare class OpenFeedClient implements IOpenFeedClient {
|
|
35
|
+
private readonly url;
|
|
36
|
+
private readonly username;
|
|
37
|
+
private readonly password;
|
|
38
|
+
private readonly listeners;
|
|
39
|
+
private readonly logger?;
|
|
40
|
+
private readonly clientId?;
|
|
41
|
+
private socket;
|
|
42
|
+
private _connection;
|
|
43
|
+
private whenConnectedInternalSource;
|
|
44
|
+
private whenConnectedSource;
|
|
45
|
+
private loopResetSource;
|
|
46
|
+
private subscribeResetSource;
|
|
47
|
+
private readonly subscriptions;
|
|
48
|
+
constructor(url: string, username: string, password: string, listeners: OpenFeedListeners, logger?: IOpenFeedLogger | undefined, clientId?: string | undefined);
|
|
49
|
+
private onOpen;
|
|
50
|
+
private onMessage;
|
|
51
|
+
private onError;
|
|
52
|
+
private onClose;
|
|
53
|
+
private runConnectLoop;
|
|
54
|
+
private cleanUp;
|
|
55
|
+
private runSubscribeLoop;
|
|
56
|
+
subscribe: (service: Service, subscriptionType: SubscriptionType, snapshotIntervalSeconds: number, symbols?: string[] | null, marketIds?: Long[] | null, exchanges?: string[] | null, channels?: number[] | null) => Long;
|
|
57
|
+
unsubscribe: (subscriptionId: Long) => void;
|
|
58
|
+
get connection(): Promise<OpenFeedConnection>;
|
|
59
|
+
dispose: () => void;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Long from "long";
|
|
2
|
+
import type { Service } from "@gen/openfeed";
|
|
3
|
+
import type { ExchangeResponse_Exchange, InstrumentReferenceRequest, InstrumentReferenceResponse, InstrumentRequest, SubscriptionType } from "@gen/openfeed_api";
|
|
4
|
+
import { OptionalUndefined } from "@src/utilities/messages";
|
|
5
|
+
import type { InstrumentDefinition } from "@gen/openfeed_instrument";
|
|
6
|
+
export type OpenFeedInstrumentRequest = Omit<OptionalUndefined<InstrumentRequest>, "correlationId" | "token" | "version">;
|
|
7
|
+
export type OpenFeedInstrumentReferenceRequest = Omit<OptionalUndefined<InstrumentReferenceRequest>, "correlationId" | "token">;
|
|
8
|
+
export interface IOpenFeedConnection {
|
|
9
|
+
subscribe: (service: Service, subscriptionType: SubscriptionType, snapshotIntervalSeconds: number, symbols: string[] | null, marketIds: Long[] | null, exchanges: string[] | null, channels: number[] | null) => Long;
|
|
10
|
+
unsubscribe: (subscriptionId: Long) => void;
|
|
11
|
+
whenDisconnected: () => Promise<void>;
|
|
12
|
+
getExchanges: () => Promise<ExchangeResponse_Exchange[]>;
|
|
13
|
+
getInstrument: (request: OpenFeedInstrumentRequest) => Promise<InstrumentDefinition[]>;
|
|
14
|
+
getInstrumentReference: (request: OpenFeedInstrumentReferenceRequest) => Promise<InstrumentReferenceResponse>;
|
|
15
|
+
}
|
|
16
|
+
export interface IOpenFeedClient {
|
|
17
|
+
get connection(): Promise<IOpenFeedConnection>;
|
|
18
|
+
subscribe: (service: Service, subscriptionType: SubscriptionType, snapshotIntervalSeconds: number, symbols: string[] | null, marketIds: Long[] | null, exchanges: string[] | null, channels: number[] | null) => Long;
|
|
19
|
+
unsubscribe: (subscriptionId: Long) => void;
|
|
20
|
+
dispose: () => void;
|
|
21
|
+
}
|
|
22
|
+
export interface IOpenFeedLogger {
|
|
23
|
+
log: (...data: any[]) => void;
|
|
24
|
+
warn: (...data: any[]) => void;
|
|
25
|
+
error: (...data: any[]) => void;
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OpenfeedGatewayMessage } from "@gen/openfeed_api";
|
|
2
|
+
import { InstrumentDefinition } from "@gen/openfeed_instrument";
|
|
3
|
+
import { IOpenFeedConnection } from "./connection_interfaces";
|
|
4
|
+
export declare class OpenFeedListeners {
|
|
5
|
+
private readonly instrumentBySymbol;
|
|
6
|
+
private readonly instrumentByMarketId;
|
|
7
|
+
constructor();
|
|
8
|
+
private addDetails;
|
|
9
|
+
onConnected: (connection: IOpenFeedConnection) => void | Promise<void>;
|
|
10
|
+
onCredentialsRejected: () => void | Promise<void>;
|
|
11
|
+
onDisconnected: () => void | Promise<void>;
|
|
12
|
+
onMessage: (message: OpenfeedGatewayMessage) => void | Promise<void>;
|
|
13
|
+
onMessageWithMetadata: (message: OpenfeedGatewayMessage, symbolNames: string[], instrument?: InstrumentDefinition) => void | Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class that provides promise that can be resolved using a handler
|
|
3
|
+
*/
|
|
4
|
+
export declare class ResolutionSource<T> {
|
|
5
|
+
private readonly _whenCompleted;
|
|
6
|
+
private _resolve;
|
|
7
|
+
private _reject;
|
|
8
|
+
private _completed;
|
|
9
|
+
constructor();
|
|
10
|
+
private onResolve;
|
|
11
|
+
private onError;
|
|
12
|
+
get completed(): boolean;
|
|
13
|
+
get whenCompleted(): Promise<T>;
|
|
14
|
+
get resolve(): (result: T) => void;
|
|
15
|
+
get reject(): (error: Error) => void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type KeysOfType<T, SelectedType> = {
|
|
2
|
+
[key in keyof T]: SelectedType extends T[key] ? key : never;
|
|
3
|
+
}[keyof T];
|
|
4
|
+
type Optional<T> = Partial<Pick<T, KeysOfType<T, undefined>>>;
|
|
5
|
+
type Required<T> = Omit<T, KeysOfType<T, undefined>>;
|
|
6
|
+
export type OptionalUndefined<T> = Optional<T> & Required<T>;
|
|
7
|
+
export declare const toT: <T>(obj: OptionalUndefined<T>) => T;
|
|
8
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openfeed/sdk-js",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "JavaScript SDK for Barchart OpenFeed",
|
|
5
|
+
"main": "dist/node.js",
|
|
6
|
+
"browser": "dist/index.js",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"types": "dist/src/index.d.ts",
|
|
9
|
+
"repository": "https://github.com/openfeed-org/sdk-js",
|
|
10
|
+
"author": "Dejan Maksimovic <maximovic.d@gmail.com>",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"generate:proto": "cd node_modules\\proto && ..\\..\\protoc --plugin=..\\..\\node_modules\\.bin\\protoc-gen-ts_proto --ts_proto_opt=outputJsonMethods=false --ts_proto_opt=outputPartialMethods=false --ts_proto_opt=exportCommonSymbols=false --ts_proto_opt=esModuleInterop=true --ts_proto_opt=forceLong=long --ts_proto_opt=useExactTypes=false --ts_proto_out=../../generated *.proto",
|
|
14
|
+
"generate:version": "genversion --es6 -s -d ./generated/version.ts",
|
|
15
|
+
"generate:process": "tsx ./scripts/process.ts",
|
|
16
|
+
"generate": "yarn generate:proto && yarn generate:process",
|
|
17
|
+
"build:clear": "rimraf dist",
|
|
18
|
+
"build:node": "esbuild --bundle --outfile=dist/node.js --platform=node --target=node16 --format=esm --banner:js=\"import { createRequire } from 'module';const require = createRequire(import.meta.url);\" src/index.ts",
|
|
19
|
+
"build:ts": "yarn generate:version && vite build",
|
|
20
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
21
|
+
"run:browser": "yarn generate:version && vite dev",
|
|
22
|
+
"run:node": "yarn generate:version && tsx ./src/test.ts"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/jest": "^29.5.4",
|
|
26
|
+
"@types/node": "^20.5.6",
|
|
27
|
+
"@types/ws": "^8.5.5",
|
|
28
|
+
"@typescript-eslint/eslint-plugin": "^6.4.1",
|
|
29
|
+
"@typescript-eslint/parser": "^6.4.1",
|
|
30
|
+
"eslint": "^8.47.0",
|
|
31
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
32
|
+
"eslint-config-airbnb-typescript": "^17.1.0",
|
|
33
|
+
"eslint-config-prettier": "^9.0.0",
|
|
34
|
+
"eslint-plugin-import": "^2.28.1",
|
|
35
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
36
|
+
"genversion": "^3.1.1",
|
|
37
|
+
"google-protobuf": "^3.21.2",
|
|
38
|
+
"jest": "^29.6.4",
|
|
39
|
+
"prettier": "^3.0.2",
|
|
40
|
+
"proto": "git+ssh://git@github.com/openfeed-org/proto.git#master",
|
|
41
|
+
"ts-jest": "^29.1.1",
|
|
42
|
+
"ts-proto": "^1.156.7",
|
|
43
|
+
"tsx": "^3.12.7",
|
|
44
|
+
"typescript": "^5.2.2",
|
|
45
|
+
"vite": "^4.4.9"
|
|
46
|
+
},
|
|
47
|
+
"packageManager": "yarn@1.22.19",
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"isomorphic-ws": "^5.0.0",
|
|
50
|
+
"long": "^5.2.3",
|
|
51
|
+
"ws": "^8.13.0"
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"dist",
|
|
55
|
+
"package.json",
|
|
56
|
+
"*.md",
|
|
57
|
+
"LICENSE",
|
|
58
|
+
"tsconfig.json"
|
|
59
|
+
]
|
|
60
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": "./",
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"useDefineForClassFields": true,
|
|
6
|
+
"module": "CommonJS",
|
|
7
|
+
"moduleResolution": "Node",
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"noUnusedLocals": true,
|
|
14
|
+
"noUnusedParameters": false,
|
|
15
|
+
"noImplicitReturns": true,
|
|
16
|
+
"rootDir": "./",
|
|
17
|
+
"types": ["jest"],
|
|
18
|
+
"paths": {
|
|
19
|
+
"@src/*": ["./src/*"],
|
|
20
|
+
"@gen/*": ["./generated/*"]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"include": ["./src", "./generated", "./scripts/"]
|
|
24
|
+
}
|