nsekit 0.1.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/dist/brokers/dhan/DhanBroker.d.ts +51 -0
- package/dist/brokers/dhan/DhanBroker.d.ts.map +1 -0
- package/dist/brokers/dhan/dhan-auth.d.ts +28 -0
- package/dist/brokers/dhan/dhan-auth.d.ts.map +1 -0
- package/dist/brokers/dhan/dhan-constants.d.ts +21 -0
- package/dist/brokers/dhan/dhan-constants.d.ts.map +1 -0
- package/dist/brokers/dhan/dhan-instruments.d.ts +45 -0
- package/dist/brokers/dhan/dhan-instruments.d.ts.map +1 -0
- package/dist/brokers/dhan/dhan-mapper.d.ts +128 -0
- package/dist/brokers/dhan/dhan-mapper.d.ts.map +1 -0
- package/dist/brokers/dhan/dhan-socket.d.ts +46 -0
- package/dist/brokers/dhan/dhan-socket.d.ts.map +1 -0
- package/dist/brokers/dhan/index.d.ts +8 -0
- package/dist/brokers/dhan/index.d.ts.map +1 -0
- package/dist/brokers/finvasia/FinvasiaBroker.d.ts +50 -0
- package/dist/brokers/finvasia/FinvasiaBroker.d.ts.map +1 -0
- package/dist/brokers/finvasia/finvasia-auth.d.ts +28 -0
- package/dist/brokers/finvasia/finvasia-auth.d.ts.map +1 -0
- package/dist/brokers/finvasia/finvasia-constants.d.ts +22 -0
- package/dist/brokers/finvasia/finvasia-constants.d.ts.map +1 -0
- package/dist/brokers/finvasia/finvasia-instruments.d.ts +44 -0
- package/dist/brokers/finvasia/finvasia-instruments.d.ts.map +1 -0
- package/dist/brokers/finvasia/finvasia-mapper.d.ts +120 -0
- package/dist/brokers/finvasia/finvasia-mapper.d.ts.map +1 -0
- package/dist/brokers/finvasia/finvasia-socket.d.ts +42 -0
- package/dist/brokers/finvasia/finvasia-socket.d.ts.map +1 -0
- package/dist/brokers/finvasia/index.d.ts +8 -0
- package/dist/brokers/finvasia/index.d.ts.map +1 -0
- package/dist/brokers/paper/PaperBroker.d.ts +76 -0
- package/dist/brokers/paper/PaperBroker.d.ts.map +1 -0
- package/dist/brokers/paper/index.d.ts +4 -0
- package/dist/brokers/paper/index.d.ts.map +1 -0
- package/dist/brokers/paper/paper-fill-engine.d.ts +105 -0
- package/dist/brokers/paper/paper-fill-engine.d.ts.map +1 -0
- package/dist/brokers/zerodha/ZerodhaBroker.d.ts +52 -0
- package/dist/brokers/zerodha/ZerodhaBroker.d.ts.map +1 -0
- package/dist/brokers/zerodha/index.d.ts +8 -0
- package/dist/brokers/zerodha/index.d.ts.map +1 -0
- package/dist/brokers/zerodha/zerodha-auth.d.ts +28 -0
- package/dist/brokers/zerodha/zerodha-auth.d.ts.map +1 -0
- package/dist/brokers/zerodha/zerodha-constants.d.ts +21 -0
- package/dist/brokers/zerodha/zerodha-constants.d.ts.map +1 -0
- package/dist/brokers/zerodha/zerodha-instruments.d.ts +36 -0
- package/dist/brokers/zerodha/zerodha-instruments.d.ts.map +1 -0
- package/dist/brokers/zerodha/zerodha-mapper.d.ts +136 -0
- package/dist/brokers/zerodha/zerodha-mapper.d.ts.map +1 -0
- package/dist/brokers/zerodha/zerodha-socket.d.ts +33 -0
- package/dist/brokers/zerodha/zerodha-socket.d.ts.map +1 -0
- package/dist/errors/broker-error.d.ts +22 -0
- package/dist/errors/broker-error.d.ts.map +1 -0
- package/dist/errors/index.d.ts +5 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/nsekit-error.d.ts +13 -0
- package/dist/errors/nsekit-error.d.ts.map +1 -0
- package/dist/errors/result.d.ts +19 -0
- package/dist/errors/result.d.ts.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23806 -0
- package/dist/instruments/instrument-master.d.ts +134 -0
- package/dist/instruments/instrument-master.d.ts.map +1 -0
- package/dist/interfaces/broker.interface.d.ts +33 -0
- package/dist/interfaces/broker.interface.d.ts.map +1 -0
- package/dist/session/session-manager.d.ts +128 -0
- package/dist/session/session-manager.d.ts.map +1 -0
- package/dist/types/broker.d.ts +222 -0
- package/dist/types/broker.d.ts.map +1 -0
- package/dist/types/common.d.ts +10 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/instruments.d.ts +59 -0
- package/dist/types/instruments.d.ts.map +1 -0
- package/dist/websocket/ws-manager.d.ts +101 -0
- package/dist/websocket/ws-manager.d.ts.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WSManager — Coordinates WebSocket connections across multiple brokers.
|
|
3
|
+
*
|
|
4
|
+
* Provides a single subscription interface that fans out to the appropriate
|
|
5
|
+
* broker's tick stream based on token resolution via InstrumentMaster.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Multi-broker tick aggregation
|
|
9
|
+
* - Token resolution via InstrumentMaster
|
|
10
|
+
* - Auto-reconnect tracking
|
|
11
|
+
* - Clean subscription lifecycle
|
|
12
|
+
*/
|
|
13
|
+
import type { BrokerId, WSConnectionState } from '../types/common';
|
|
14
|
+
import type { TickCallback } from '../types/broker';
|
|
15
|
+
import type { IBroker } from '../interfaces/broker.interface';
|
|
16
|
+
import type { InstrumentMaster } from '../instruments/instrument-master';
|
|
17
|
+
export interface WSRedisClient {
|
|
18
|
+
publish(channel: string, message: string): Promise<number>;
|
|
19
|
+
set(key: string, value: string, ...args: (string | number)[]): Promise<unknown>;
|
|
20
|
+
}
|
|
21
|
+
interface AggregatedState {
|
|
22
|
+
brokers: Record<string, WSConnectionState>;
|
|
23
|
+
totalSubscriptions: number;
|
|
24
|
+
totalSymbols: number;
|
|
25
|
+
}
|
|
26
|
+
export interface WSManagerOptions {
|
|
27
|
+
/** Optional Redis client for tick publishing. */
|
|
28
|
+
redis?: WSRedisClient;
|
|
29
|
+
}
|
|
30
|
+
export declare class WSManager {
|
|
31
|
+
private brokers;
|
|
32
|
+
private subscriptions;
|
|
33
|
+
private instrumentMaster;
|
|
34
|
+
private readonly redis;
|
|
35
|
+
constructor(options?: WSManagerOptions);
|
|
36
|
+
/**
|
|
37
|
+
* Optionally provide an InstrumentMaster for symbol-to-token resolution.
|
|
38
|
+
* Without it, symbols are passed directly to brokers as tokens.
|
|
39
|
+
*/
|
|
40
|
+
setInstrumentMaster(master: InstrumentMaster): void;
|
|
41
|
+
/**
|
|
42
|
+
* Register a broker for WebSocket tick management.
|
|
43
|
+
*/
|
|
44
|
+
addBroker(brokerId: BrokerId, broker: IBroker): void;
|
|
45
|
+
/**
|
|
46
|
+
* Remove a broker and clean up its subscriptions.
|
|
47
|
+
*/
|
|
48
|
+
removeBroker(brokerId: BrokerId): void;
|
|
49
|
+
/**
|
|
50
|
+
* Subscribe to tick data for the given symbols.
|
|
51
|
+
*
|
|
52
|
+
* Symbols can be in the format `{exchange}:{tradingSymbol}` (e.g. "NSE:RELIANCE")
|
|
53
|
+
* or just a trading symbol. The manager resolves the appropriate broker tokens
|
|
54
|
+
* using InstrumentMaster when available.
|
|
55
|
+
*
|
|
56
|
+
* @returns The subscription ID for later unsubscription
|
|
57
|
+
*/
|
|
58
|
+
subscribe(symbols: string[], callback: TickCallback): string;
|
|
59
|
+
/**
|
|
60
|
+
* Remove a subscription and clean up broker-level subscriptions.
|
|
61
|
+
*/
|
|
62
|
+
unsubscribe(subId: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* Unsubscribe all active subscriptions and clean up.
|
|
65
|
+
*/
|
|
66
|
+
unsubscribeAll(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Get an aggregated view of all broker connection states.
|
|
69
|
+
*/
|
|
70
|
+
getState(): AggregatedState;
|
|
71
|
+
/**
|
|
72
|
+
* Get the connection state for a specific broker.
|
|
73
|
+
*/
|
|
74
|
+
getBrokerState(brokerId: BrokerId): WSConnectionState;
|
|
75
|
+
/**
|
|
76
|
+
* Get reconnect statistics for a broker.
|
|
77
|
+
*/
|
|
78
|
+
getReconnectInfo(brokerId: BrokerId): {
|
|
79
|
+
count: number;
|
|
80
|
+
lastAt: number | null;
|
|
81
|
+
} | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Record a reconnect event for tracking purposes.
|
|
84
|
+
* Call this from an external health monitor or broker event handler.
|
|
85
|
+
*/
|
|
86
|
+
recordReconnect(brokerId: BrokerId): void;
|
|
87
|
+
/** List all registered broker IDs. */
|
|
88
|
+
getBrokerIds(): BrokerId[];
|
|
89
|
+
/** Number of active subscriptions. */
|
|
90
|
+
get subscriptionCount(): number;
|
|
91
|
+
/**
|
|
92
|
+
* Resolve an array of symbols into per-broker token groups.
|
|
93
|
+
*
|
|
94
|
+
* If InstrumentMaster is available, look up each symbol to find which
|
|
95
|
+
* brokers have a token for it and what that token is. Otherwise, send
|
|
96
|
+
* the raw symbols to all registered brokers.
|
|
97
|
+
*/
|
|
98
|
+
private resolveSymbolsToBrokers;
|
|
99
|
+
}
|
|
100
|
+
export {};
|
|
101
|
+
//# sourceMappingURL=ws-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ws-manager.d.ts","sourceRoot":"","sources":["../../src/websocket/ws-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,KAAK,EAAe,YAAY,EAAgB,MAAM,iBAAiB,CAAC;AAC/E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAIzE,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3D,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,MAAM,GAAG,MA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,sCAAsC;IACtC,YAAY,IAAI,QAAQ,EAAE;IAI1B,sCAAsC;IACtC,IAAI,iBAAiB,IAAI,MAAM,CAE9B;IAID;;;;;;OAMG;IACH,OAAO,CAAC,uBAAuB;CAiDhC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nsekit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Unified broker abstraction for Indian stock markets - CCXT-like interface for NSE/BSE brokers",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"package.json",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "bun run clean && bun run build:types && bun run build:js",
|
|
23
|
+
"build:types": "bunx tsc --emitDeclarationOnly --declaration --declarationMap --outDir dist",
|
|
24
|
+
"build:js": "bun build src/index.ts --outdir dist --target bun --format esm",
|
|
25
|
+
"dev": "bun --watch src/index.ts",
|
|
26
|
+
"test": "bun test",
|
|
27
|
+
"test:manual": "bun run test-manual.ts",
|
|
28
|
+
"lint": "tsc --noEmit",
|
|
29
|
+
"clean": "rm -rf dist",
|
|
30
|
+
"prepublishOnly": "bun run build"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"kiteconnect": "^5.0.0",
|
|
34
|
+
"ws": "^8.16.0",
|
|
35
|
+
"ioredis": "^5.3.2",
|
|
36
|
+
"zod": "^3.22.4",
|
|
37
|
+
"date-fns": "^3.3.1",
|
|
38
|
+
"otplib": "^12.0.1",
|
|
39
|
+
"pino": "^8.17.2"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/ws": "^8.5.10",
|
|
43
|
+
"typescript": "^5.3.3",
|
|
44
|
+
"bun-types": "latest"
|
|
45
|
+
},
|
|
46
|
+
"keywords": ["nse", "bse", "trading", "broker", "zerodha", "finvasia", "dhan", "options"],
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/ilampirai/nsekit.git"
|
|
51
|
+
}
|
|
52
|
+
}
|