@n1xyz/nord-ts 0.1.12 → 0.3.1
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/client/Nord.d.ts +2 -2
- package/dist/client/Nord.js +2 -2
- package/dist/client/NordUser.d.ts +14 -0
- package/dist/client/NordUser.js +23 -6
- package/dist/gen/nord_pb.d.ts +20 -5
- package/dist/gen/nord_pb.js +20 -5
- package/dist/gen/openapi.d.ts +184 -57
- package/dist/nord/api/actions.d.ts +128 -0
- package/dist/nord/api/actions.js +396 -0
- package/dist/nord/api/core.d.ts +16 -0
- package/dist/nord/api/core.js +81 -0
- package/dist/nord/api/metrics.d.ts +67 -0
- package/dist/nord/api/metrics.js +229 -0
- package/dist/nord/api/triggers.d.ts +7 -0
- package/dist/nord/api/triggers.js +38 -0
- package/dist/nord/client/Nord.d.ts +387 -0
- package/dist/nord/client/Nord.js +747 -0
- package/dist/nord/client/NordAdmin.d.ts +226 -0
- package/dist/nord/client/NordAdmin.js +410 -0
- package/dist/nord/client/NordClient.d.ts +16 -0
- package/dist/nord/client/NordClient.js +28 -0
- package/dist/nord/client/NordUser.d.ts +379 -0
- package/dist/nord/client/NordUser.js +787 -0
- package/dist/nord/index.d.ts +8 -0
- package/dist/nord/index.js +34 -0
- package/dist/nord/models/Subscriber.d.ts +37 -0
- package/dist/nord/models/Subscriber.js +25 -0
- package/dist/nord/utils/NordError.d.ts +35 -0
- package/dist/nord/utils/NordError.js +49 -0
- package/dist/types.d.ts +42 -20
- package/dist/websocket/NordWebSocketClient.js +3 -3
- package/dist/websocket/Subscriber.d.ts +3 -3
- package/package.json +2 -2
- package/dist/bundle.js +0 -79181
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Nord } from "./client/Nord";
|
|
2
|
+
export { NordUser } from "./client/NordUser";
|
|
3
|
+
export { NordAdmin, AclRole } from "./client/NordAdmin";
|
|
4
|
+
export { NordError } from "./utils/NordError";
|
|
5
|
+
export * from "./api/core";
|
|
6
|
+
export * from "./api/metrics";
|
|
7
|
+
export * from "./api/actions";
|
|
8
|
+
export * from "./models/Subscriber";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.NordError = exports.AclRole = exports.NordAdmin = exports.NordUser = exports.Nord = void 0;
|
|
18
|
+
// Export main client classes
|
|
19
|
+
var Nord_1 = require("./client/Nord");
|
|
20
|
+
Object.defineProperty(exports, "Nord", { enumerable: true, get: function () { return Nord_1.Nord; } });
|
|
21
|
+
var NordUser_1 = require("./client/NordUser");
|
|
22
|
+
Object.defineProperty(exports, "NordUser", { enumerable: true, get: function () { return NordUser_1.NordUser; } });
|
|
23
|
+
var NordAdmin_1 = require("./client/NordAdmin");
|
|
24
|
+
Object.defineProperty(exports, "NordAdmin", { enumerable: true, get: function () { return NordAdmin_1.NordAdmin; } });
|
|
25
|
+
Object.defineProperty(exports, "AclRole", { enumerable: true, get: function () { return NordAdmin_1.AclRole; } });
|
|
26
|
+
// Export utility classes
|
|
27
|
+
var NordError_1 = require("./utils/NordError");
|
|
28
|
+
Object.defineProperty(exports, "NordError", { enumerable: true, get: function () { return NordError_1.NordError; } });
|
|
29
|
+
// Export API modules
|
|
30
|
+
__exportStar(require("./api/core"), exports);
|
|
31
|
+
__exportStar(require("./api/metrics"), exports);
|
|
32
|
+
__exportStar(require("./api/actions"), exports);
|
|
33
|
+
// Export models
|
|
34
|
+
__exportStar(require("./models/Subscriber"), exports);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import { Account, DeltaEvent, OrderbookResponse, SubscriberConfig, StreamTrade, Trades } from "../../types";
|
|
3
|
+
/**
|
|
4
|
+
* Subscriber class for handling WebSocket subscriptions
|
|
5
|
+
*/
|
|
6
|
+
export declare class Subscriber {
|
|
7
|
+
streamURL: string;
|
|
8
|
+
buffer: (DeltaEvent | Trades | Account)[];
|
|
9
|
+
maxBufferLen: number;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new Subscriber instance
|
|
12
|
+
* @param config Subscriber configuration
|
|
13
|
+
*/
|
|
14
|
+
constructor(config: SubscriberConfig);
|
|
15
|
+
/**
|
|
16
|
+
* Subscribe to WebSocket events
|
|
17
|
+
*/
|
|
18
|
+
subscribe(): void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Interface for orderbook subscription
|
|
22
|
+
*/
|
|
23
|
+
export interface OrderbookSubscription extends EventEmitter {
|
|
24
|
+
on(event: "message", listener: (data: OrderbookResponse) => void): this;
|
|
25
|
+
on(event: "error", listener: (error: Error) => void): this;
|
|
26
|
+
close(): void;
|
|
27
|
+
removeAllListeners(event?: string): this;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Interface for trade subscription
|
|
31
|
+
*/
|
|
32
|
+
export interface TradeSubscription extends EventEmitter {
|
|
33
|
+
on(event: "message", listener: (data: StreamTrade[]) => void): this;
|
|
34
|
+
on(event: "error", listener: (error: Error) => void): this;
|
|
35
|
+
close(): void;
|
|
36
|
+
removeAllListeners(event?: string): this;
|
|
37
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Subscriber = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
/**
|
|
6
|
+
* Subscriber class for handling WebSocket subscriptions
|
|
7
|
+
*/
|
|
8
|
+
class Subscriber {
|
|
9
|
+
/**
|
|
10
|
+
* Create a new Subscriber instance
|
|
11
|
+
* @param config Subscriber configuration
|
|
12
|
+
*/
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.streamURL = config.streamURL;
|
|
15
|
+
this.buffer = [];
|
|
16
|
+
this.maxBufferLen = config.maxBufferLen ?? utils_1.MAX_BUFFER_LEN;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Subscribe to WebSocket events
|
|
20
|
+
*/
|
|
21
|
+
subscribe() {
|
|
22
|
+
// TODO: Implement subscription logic
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.Subscriber = Subscriber;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for creating a NordError
|
|
3
|
+
*/
|
|
4
|
+
export interface NordErrorOptions {
|
|
5
|
+
/** The original error that caused this error */
|
|
6
|
+
cause?: unknown;
|
|
7
|
+
/** HTTP status code (if applicable) */
|
|
8
|
+
statusCode?: number;
|
|
9
|
+
/** Additional error details */
|
|
10
|
+
details?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Custom error class for Nord-related errors
|
|
14
|
+
*/
|
|
15
|
+
export declare class NordError extends Error {
|
|
16
|
+
/** The original error that caused this error */
|
|
17
|
+
readonly cause?: unknown;
|
|
18
|
+
/** HTTP status code (if applicable) */
|
|
19
|
+
readonly statusCode?: number;
|
|
20
|
+
/** Additional error details */
|
|
21
|
+
readonly details?: Record<string, unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* Create a new NordError
|
|
24
|
+
*
|
|
25
|
+
* @param message - Error message
|
|
26
|
+
* @param options - Error options
|
|
27
|
+
*/
|
|
28
|
+
constructor(message: string, options?: NordErrorOptions);
|
|
29
|
+
/**
|
|
30
|
+
* Convert the error to a string representation
|
|
31
|
+
*
|
|
32
|
+
* @returns String representation of the error
|
|
33
|
+
*/
|
|
34
|
+
toString(): string;
|
|
35
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NordError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Custom error class for Nord-related errors
|
|
6
|
+
*/
|
|
7
|
+
class NordError extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Create a new NordError
|
|
10
|
+
*
|
|
11
|
+
* @param message - Error message
|
|
12
|
+
* @param options - Error options
|
|
13
|
+
*/
|
|
14
|
+
constructor(message, options = {}) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "NordError";
|
|
17
|
+
this.cause = options.cause;
|
|
18
|
+
this.statusCode = options.statusCode;
|
|
19
|
+
this.details = options.details;
|
|
20
|
+
// Capture stack trace
|
|
21
|
+
if (Error.captureStackTrace) {
|
|
22
|
+
Error.captureStackTrace(this, NordError);
|
|
23
|
+
}
|
|
24
|
+
// Handle nested errors
|
|
25
|
+
if (this.cause instanceof Error) {
|
|
26
|
+
this.stack =
|
|
27
|
+
this.stack + "\nCaused by: " + (this.cause.stack || this.cause.message);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Convert the error to a string representation
|
|
32
|
+
*
|
|
33
|
+
* @returns String representation of the error
|
|
34
|
+
*/
|
|
35
|
+
toString() {
|
|
36
|
+
let result = `${this.name}: ${this.message}`;
|
|
37
|
+
if (this.statusCode) {
|
|
38
|
+
result += ` \nstatus: ${this.statusCode}`;
|
|
39
|
+
}
|
|
40
|
+
if (this.details && Object.keys(this.details).length > 0) {
|
|
41
|
+
result += ` \ndetails: ${JSON.stringify(this.details, null, 2)}`;
|
|
42
|
+
}
|
|
43
|
+
if (this.cause) {
|
|
44
|
+
result += ` \ncause: ${this.cause.toString()}`;
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.NordError = NordError;
|
package/dist/types.d.ts
CHANGED
|
@@ -60,11 +60,11 @@ export type FillModeFromApi = components["schemas"]["FillMode"];
|
|
|
60
60
|
export type PlacementOrigin = components["schemas"]["PlacementOrigin"];
|
|
61
61
|
export type FinalizationReason = components["schemas"]["FinalizationReason"];
|
|
62
62
|
export type PagedQuery = components["schemas"]["PagedQuery"];
|
|
63
|
-
export type
|
|
64
|
-
export type
|
|
65
|
-
export type AccountTriggerInfo = components["schemas"]["
|
|
66
|
-
export type TriggerHistoryPage = components["schemas"]["
|
|
67
|
-
export type WithdrawalHistoryPage = components["schemas"]["
|
|
63
|
+
export type AccountPnlInfo = components["schemas"]["AccountPnlInfo"];
|
|
64
|
+
export type AccountPnlInfoPage = components["schemas"]["PageResult_for_String_and_AccountPnlInfo"];
|
|
65
|
+
export type AccountTriggerInfo = components["schemas"]["TriggerInfo"];
|
|
66
|
+
export type TriggerHistoryPage = components["schemas"]["PageResult_for_String_and_Trigger"];
|
|
67
|
+
export type WithdrawalHistoryPage = components["schemas"]["PageResult_for_String_and_Withdrawal"];
|
|
68
68
|
export type FeeTierConfig = components["schemas"]["FeeTierConfig"];
|
|
69
69
|
export type FeeTierId = components["schemas"]["FeeTierId"];
|
|
70
70
|
export type TokenStats = components["schemas"]["TokenStats"];
|
|
@@ -127,7 +127,7 @@ export interface StreamTrade {
|
|
|
127
127
|
side: Side;
|
|
128
128
|
price: number;
|
|
129
129
|
size: number;
|
|
130
|
-
order_id:
|
|
130
|
+
order_id: string;
|
|
131
131
|
}
|
|
132
132
|
export interface Trades {
|
|
133
133
|
last_update_id: number;
|
|
@@ -199,12 +199,7 @@ export declare enum WebSocketMessageType {
|
|
|
199
199
|
/**
|
|
200
200
|
* WebSocket trade update message
|
|
201
201
|
*/
|
|
202
|
-
export
|
|
203
|
-
e: WebSocketMessageType.TradeUpdate;
|
|
204
|
-
symbol: string;
|
|
205
|
-
trades: StreamTrade[];
|
|
206
|
-
timestamp: number;
|
|
207
|
-
}
|
|
202
|
+
export type WebSocketTradeUpdate = Trades;
|
|
208
203
|
/**
|
|
209
204
|
* WebSocket delta update message
|
|
210
205
|
*/
|
|
@@ -217,16 +212,43 @@ export interface WebSocketDeltaUpdate {
|
|
|
217
212
|
bids: OrderbookEntry[];
|
|
218
213
|
timestamp: number;
|
|
219
214
|
}
|
|
220
|
-
|
|
221
|
-
* WebSocket user update message
|
|
222
|
-
*/
|
|
215
|
+
export type OrderId = string;
|
|
223
216
|
export interface WebSocketAccountUpdate {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
217
|
+
last_update_id: number;
|
|
218
|
+
update_id: number;
|
|
219
|
+
account_id: number;
|
|
220
|
+
fills: Record<OrderId, {
|
|
221
|
+
side: "bid" | "ask";
|
|
222
|
+
quantity: number;
|
|
223
|
+
remaining: number;
|
|
224
|
+
price: number;
|
|
225
|
+
order_id: string;
|
|
226
|
+
market_id: number;
|
|
227
|
+
maker_id: number;
|
|
228
|
+
taker_id: number;
|
|
229
|
+
sender_tracking_id: number | null;
|
|
230
|
+
}>;
|
|
231
|
+
places: Record<OrderId, {
|
|
232
|
+
side: "bid" | "ask";
|
|
233
|
+
current_size: number;
|
|
234
|
+
price: number;
|
|
235
|
+
market_id: number;
|
|
236
|
+
}>;
|
|
237
|
+
cancels: Record<OrderId, {
|
|
238
|
+
side: "bid" | "ask";
|
|
239
|
+
current_size: number;
|
|
240
|
+
price: number;
|
|
241
|
+
market_id: number;
|
|
242
|
+
}>;
|
|
243
|
+
balances: Record<string, number>;
|
|
228
244
|
}
|
|
229
|
-
export type WebSocketMessage =
|
|
245
|
+
export type WebSocketMessage = {
|
|
246
|
+
trades: WebSocketTradeUpdate;
|
|
247
|
+
} | {
|
|
248
|
+
delta: WebSocketDeltaUpdate;
|
|
249
|
+
} | {
|
|
250
|
+
account: WebSocketAccountUpdate;
|
|
251
|
+
};
|
|
230
252
|
export interface SPLTokenInfo {
|
|
231
253
|
mint: string;
|
|
232
254
|
precision: number;
|
|
@@ -212,15 +212,15 @@ export class NordWebSocketClient extends EventEmitter {
|
|
|
212
212
|
}
|
|
213
213
|
const hasOwn = (k) => Object.prototype.hasOwnProperty.call(message, k);
|
|
214
214
|
if (hasOwn("trades")) {
|
|
215
|
-
this.emit("trades", message);
|
|
215
|
+
this.emit("trades", message.trades);
|
|
216
216
|
return;
|
|
217
217
|
}
|
|
218
218
|
if (hasOwn("delta")) {
|
|
219
|
-
this.emit("delta", message);
|
|
219
|
+
this.emit("delta", message.delta);
|
|
220
220
|
return;
|
|
221
221
|
}
|
|
222
222
|
if (hasOwn("account")) {
|
|
223
|
-
this.emit("account", message);
|
|
223
|
+
this.emit("account", message.account);
|
|
224
224
|
return;
|
|
225
225
|
}
|
|
226
226
|
this.emit("error", new Error(`Unexpected message type: ${message}`));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
|
-
import { Account, DeltaEvent,
|
|
2
|
+
import { Account, DeltaEvent, WebSocketDeltaUpdate, SubscriberConfig, Trades, WebSocketTradeUpdate } from "../types";
|
|
3
3
|
/**
|
|
4
4
|
* Subscriber class for handling WebSocket subscriptions
|
|
5
5
|
*/
|
|
@@ -21,7 +21,7 @@ export declare class Subscriber {
|
|
|
21
21
|
* Interface for orderbook subscription
|
|
22
22
|
*/
|
|
23
23
|
export interface OrderbookSubscription extends EventEmitter {
|
|
24
|
-
on(event: "message", listener: (data:
|
|
24
|
+
on(event: "message", listener: (data: WebSocketDeltaUpdate) => void): this;
|
|
25
25
|
on(event: "error", listener: (error: Error) => void): this;
|
|
26
26
|
close(): void;
|
|
27
27
|
removeAllListeners(event?: string): this;
|
|
@@ -30,7 +30,7 @@ export interface OrderbookSubscription extends EventEmitter {
|
|
|
30
30
|
* Interface for trade subscription
|
|
31
31
|
*/
|
|
32
32
|
export interface TradeSubscription extends EventEmitter {
|
|
33
|
-
on(event: "message", listener: (data:
|
|
33
|
+
on(event: "message", listener: (data: WebSocketTradeUpdate) => void): this;
|
|
34
34
|
on(event: "error", listener: (error: Error) => void): this;
|
|
35
35
|
close(): void;
|
|
36
36
|
removeAllListeners(event?: string): this;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n1xyz/nord-ts",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Typescript for Nord",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@bufbuild/protobuf": "^2.6.3",
|
|
47
|
-
"@n1xyz/proton": "0.0
|
|
47
|
+
"@n1xyz/proton": "0.1.0",
|
|
48
48
|
"@noble/curves": "^1.9.6",
|
|
49
49
|
"@noble/ed25519": "^2.3.0",
|
|
50
50
|
"@noble/hashes": "^1.8.0",
|