@n1xyz/nord-ts 0.1.7 → 0.1.9
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/actions.js +39 -82
- package/dist/bundle.js +79181 -0
- package/dist/client/Nord.d.ts +13 -2
- package/dist/client/Nord.js +68 -78
- package/dist/client/NordAdmin.d.ts +2 -2
- package/dist/client/NordAdmin.js +57 -89
- package/dist/client/NordUser.js +118 -147
- package/dist/const.js +5 -8
- package/dist/error.js +7 -5
- package/dist/gen/nord_pb.js +88 -92
- package/dist/gen/openapi.d.ts +83 -6
- package/dist/gen/openapi.js +1 -2
- package/dist/index.js +10 -49
- package/dist/types.d.ts +3 -0
- package/dist/types.js +21 -60
- package/dist/utils.js +38 -86
- package/dist/websocket/NordWebSocketClient.js +12 -17
- package/dist/websocket/Subscriber.js +6 -7
- package/dist/websocket/events.js +1 -2
- package/dist/websocket/index.js +10 -15
- package/package.json +3 -4
- package/dist/api/client.d.ts +0 -14
- package/dist/api/client.js +0 -45
- package/dist/bridge/client.d.ts +0 -151
- package/dist/bridge/client.js +0 -434
- package/dist/bridge/const.d.ts +0 -23
- package/dist/bridge/const.js +0 -47
- package/dist/bridge/index.d.ts +0 -4
- package/dist/bridge/index.js +0 -23
- package/dist/bridge/types.d.ts +0 -120
- package/dist/bridge/types.js +0 -18
- package/dist/bridge/utils.d.ts +0 -64
- package/dist/bridge/utils.js +0 -131
- package/dist/gen/common.d.ts +0 -68
- package/dist/gen/common.js +0 -215
- package/dist/gen/nord.d.ts +0 -882
- package/dist/gen/nord.js +0 -6520
- package/dist/idl/bridge.d.ts +0 -569
- package/dist/idl/bridge.js +0 -8
- package/dist/idl/bridge.json +0 -1506
- package/dist/idl/index.d.ts +0 -607
- package/dist/idl/index.js +0 -8
- package/dist/nord/api/actions.d.ts +0 -126
- package/dist/nord/api/actions.js +0 -397
- package/dist/nord/api/core.d.ts +0 -16
- package/dist/nord/api/core.js +0 -81
- package/dist/nord/api/market.d.ts +0 -36
- package/dist/nord/api/market.js +0 -96
- package/dist/nord/api/metrics.d.ts +0 -67
- package/dist/nord/api/metrics.js +0 -229
- package/dist/nord/api/queries.d.ts +0 -46
- package/dist/nord/api/queries.js +0 -109
- package/dist/nord/api/triggers.d.ts +0 -7
- package/dist/nord/api/triggers.js +0 -38
- package/dist/nord/client/Nord.d.ts +0 -396
- package/dist/nord/client/Nord.js +0 -747
- package/dist/nord/client/NordAdmin.d.ts +0 -259
- package/dist/nord/client/NordAdmin.js +0 -395
- package/dist/nord/client/NordClient.d.ts +0 -33
- package/dist/nord/client/NordClient.js +0 -45
- package/dist/nord/client/NordUser.d.ts +0 -362
- package/dist/nord/client/NordUser.js +0 -781
- package/dist/nord/index.d.ts +0 -11
- package/dist/nord/index.js +0 -36
- package/dist/nord/models/Subscriber.d.ts +0 -37
- package/dist/nord/models/Subscriber.js +0 -25
- package/dist/nord/utils/NordError.d.ts +0 -35
- package/dist/nord/utils/NordError.js +0 -49
- package/src/actions.ts +0 -333
- package/src/client/Nord.ts +0 -934
- package/src/client/NordAdmin.ts +0 -484
- package/src/client/NordUser.ts +0 -1122
- package/src/const.ts +0 -34
- package/src/error.ts +0 -76
- package/src/gen/.gitkeep +0 -0
- package/src/gen/nord_pb.ts +0 -5053
- package/src/gen/openapi.ts +0 -2904
- package/src/index.ts +0 -11
- package/src/types.ts +0 -327
- package/src/utils.ts +0 -266
- package/src/websocket/NordWebSocketClient.ts +0 -316
- package/src/websocket/Subscriber.ts +0 -56
- package/src/websocket/events.ts +0 -31
- package/src/websocket/index.ts +0 -105
package/dist/gen/openapi.d.ts
CHANGED
|
@@ -1253,10 +1253,61 @@ export interface paths {
|
|
|
1253
1253
|
[name: string]: unknown;
|
|
1254
1254
|
};
|
|
1255
1255
|
content: {
|
|
1256
|
-
"application/json": [
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1256
|
+
"application/json": components["schemas"]["AdminInfo"][];
|
|
1257
|
+
};
|
|
1258
|
+
};
|
|
1259
|
+
};
|
|
1260
|
+
};
|
|
1261
|
+
put?: never;
|
|
1262
|
+
post?: never;
|
|
1263
|
+
delete?: never;
|
|
1264
|
+
options?: never;
|
|
1265
|
+
head?: never;
|
|
1266
|
+
patch?: never;
|
|
1267
|
+
trace?: never;
|
|
1268
|
+
};
|
|
1269
|
+
"/account/volume": {
|
|
1270
|
+
parameters: {
|
|
1271
|
+
query?: never;
|
|
1272
|
+
header?: never;
|
|
1273
|
+
path?: never;
|
|
1274
|
+
cookie?: never;
|
|
1275
|
+
};
|
|
1276
|
+
/** @description Get trading volume for an account
|
|
1277
|
+
*
|
|
1278
|
+
* Optionally, you can specify a market to get volume for. If not specified, array of (MarketId, Volume) is returned.
|
|
1279
|
+
*
|
|
1280
|
+
* Returns raw values, caller must rescale to base token decimals */
|
|
1281
|
+
get: {
|
|
1282
|
+
parameters: {
|
|
1283
|
+
query: {
|
|
1284
|
+
accountId: number;
|
|
1285
|
+
marketId?: number | null;
|
|
1286
|
+
/** @description start with this timestamp (RFC3339); defaults to UNIX epoch start */
|
|
1287
|
+
since?: string;
|
|
1288
|
+
/** @description end with this timestamp (RFC3339); defaults to current date-time */
|
|
1289
|
+
until?: string;
|
|
1290
|
+
};
|
|
1291
|
+
header?: never;
|
|
1292
|
+
path?: never;
|
|
1293
|
+
cookie?: never;
|
|
1294
|
+
};
|
|
1295
|
+
requestBody?: never;
|
|
1296
|
+
responses: {
|
|
1297
|
+
200: {
|
|
1298
|
+
headers: {
|
|
1299
|
+
[name: string]: unknown;
|
|
1300
|
+
};
|
|
1301
|
+
content: {
|
|
1302
|
+
"application/json": components["schemas"]["AccountVolumeInfo"][];
|
|
1303
|
+
};
|
|
1304
|
+
};
|
|
1305
|
+
404: {
|
|
1306
|
+
headers: {
|
|
1307
|
+
[name: string]: unknown;
|
|
1308
|
+
};
|
|
1309
|
+
content: {
|
|
1310
|
+
"application/json": components["schemas"]["UserNotFound"];
|
|
1260
1311
|
};
|
|
1261
1312
|
};
|
|
1262
1313
|
};
|
|
@@ -2279,6 +2330,8 @@ export interface components {
|
|
|
2279
2330
|
high24h: number;
|
|
2280
2331
|
/** Format: double */
|
|
2281
2332
|
low24h: number;
|
|
2333
|
+
/** Format: double */
|
|
2334
|
+
closePrice24h: number;
|
|
2282
2335
|
perpStats?: components["schemas"]["PerpMarketStats"] | null;
|
|
2283
2336
|
};
|
|
2284
2337
|
PerpMarketStats: {
|
|
@@ -2726,8 +2779,32 @@ export interface components {
|
|
|
2726
2779
|
accountId: number;
|
|
2727
2780
|
feeTier: components["schemas"]["FeeTierId"];
|
|
2728
2781
|
};
|
|
2729
|
-
|
|
2730
|
-
|
|
2782
|
+
AdminInfo: {
|
|
2783
|
+
key: string;
|
|
2784
|
+
roles: string[];
|
|
2785
|
+
};
|
|
2786
|
+
GetAccountVolumeQuery: {
|
|
2787
|
+
/** Format: uint32 */
|
|
2788
|
+
accountId: number;
|
|
2789
|
+
/** Format: uint32 */
|
|
2790
|
+
marketId?: number | null;
|
|
2791
|
+
/**
|
|
2792
|
+
* @description start with this timestamp (RFC3339); defaults to UNIX epoch start
|
|
2793
|
+
* @default null
|
|
2794
|
+
*/
|
|
2795
|
+
since: string;
|
|
2796
|
+
/**
|
|
2797
|
+
* @description end with this timestamp (RFC3339); defaults to current date-time
|
|
2798
|
+
* @default null
|
|
2799
|
+
*/
|
|
2800
|
+
until: string;
|
|
2801
|
+
};
|
|
2802
|
+
AccountVolumeInfo: {
|
|
2803
|
+
/** Format: uint32 */
|
|
2804
|
+
marketId: number;
|
|
2805
|
+
/** Format: double */
|
|
2806
|
+
volume: number;
|
|
2807
|
+
};
|
|
2731
2808
|
/** @description TV config query response https://www.tradingview.com/charting-library-docs/latest/connecting_data/UDF/#data-feed-configuration-data */
|
|
2732
2809
|
TvConfigResponse: {
|
|
2733
2810
|
supported_resolutions: components["schemas"]["Resolution"][];
|
package/dist/gen/openapi.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,49 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
-
};
|
|
21
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
-
var ownKeys = function(o) {
|
|
23
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
-
var ar = [];
|
|
25
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
-
return ar;
|
|
27
|
-
};
|
|
28
|
-
return ownKeys(o);
|
|
29
|
-
};
|
|
30
|
-
return function (mod) {
|
|
31
|
-
if (mod && mod.__esModule) return mod;
|
|
32
|
-
var result = {};
|
|
33
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
-
__setModuleDefault(result, mod);
|
|
35
|
-
return result;
|
|
36
|
-
};
|
|
37
|
-
})();
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.openapi = exports.proto = void 0;
|
|
40
|
-
__exportStar(require("./types"), exports);
|
|
41
|
-
__exportStar(require("./utils"), exports);
|
|
42
|
-
__exportStar(require("./const"), exports);
|
|
43
|
-
__exportStar(require("./error"), exports);
|
|
44
|
-
__exportStar(require("./websocket/index"), exports);
|
|
45
|
-
__exportStar(require("./client/Nord"), exports);
|
|
46
|
-
__exportStar(require("./client/NordUser"), exports);
|
|
47
|
-
__exportStar(require("./client/NordAdmin"), exports);
|
|
48
|
-
exports.proto = __importStar(require("./gen/nord_pb"));
|
|
49
|
-
exports.openapi = __importStar(require("./gen/openapi"));
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export * from "./utils";
|
|
3
|
+
export * from "./const";
|
|
4
|
+
export * from "./error";
|
|
5
|
+
export * from "./websocket/index";
|
|
6
|
+
export * from "./client/Nord";
|
|
7
|
+
export * from "./client/NordUser";
|
|
8
|
+
export * from "./client/NordAdmin";
|
|
9
|
+
export * as proto from "./gen/nord_pb";
|
|
10
|
+
export * as openapi from "./gen/openapi";
|
package/dist/types.d.ts
CHANGED
|
@@ -70,6 +70,9 @@ export type FeeTierId = components["schemas"]["FeeTierId"];
|
|
|
70
70
|
export type TokenStats = components["schemas"]["TokenStats"];
|
|
71
71
|
export type AccountFeeTier = components["schemas"]["AccountFeeTier"];
|
|
72
72
|
export type AccountFeeTierPage = components["schemas"]["PageResult_for_uint32_and_AccountFeeTier"];
|
|
73
|
+
export type AdminInfo = components["schemas"]["AdminInfo"];
|
|
74
|
+
export type GetAccountVolumeQuery = components["schemas"]["GetAccountVolumeQuery"];
|
|
75
|
+
export type AccountVolumeInfo = components["schemas"]["AccountVolumeInfo"];
|
|
73
76
|
/**
|
|
74
77
|
* Configuration options for the Nord client
|
|
75
78
|
*/
|
package/dist/types.js
CHANGED
|
@@ -1,70 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.QuoteSize = exports.WebSocketMessageType = exports.TriggerStatus = exports.TriggerKind = exports.FillMode = exports.Side = void 0;
|
|
40
|
-
exports.fillModeToProtoFillMode = fillModeToProtoFillMode;
|
|
41
|
-
const proto = __importStar(require("./gen/nord_pb"));
|
|
42
|
-
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
43
|
-
const utils_1 = require("./utils");
|
|
44
|
-
var Side;
|
|
1
|
+
import * as proto from "./gen/nord_pb";
|
|
2
|
+
import Decimal from "decimal.js";
|
|
3
|
+
import { toScaledU64 } from "./utils";
|
|
4
|
+
export var Side;
|
|
45
5
|
(function (Side) {
|
|
46
6
|
Side["Ask"] = "ask";
|
|
47
7
|
Side["Bid"] = "bid";
|
|
48
|
-
})(Side || (
|
|
49
|
-
var FillMode;
|
|
8
|
+
})(Side || (Side = {}));
|
|
9
|
+
export var FillMode;
|
|
50
10
|
(function (FillMode) {
|
|
51
11
|
FillMode[FillMode["Limit"] = 0] = "Limit";
|
|
52
12
|
FillMode[FillMode["PostOnly"] = 1] = "PostOnly";
|
|
53
13
|
FillMode[FillMode["ImmediateOrCancel"] = 2] = "ImmediateOrCancel";
|
|
54
14
|
FillMode[FillMode["FillOrKill"] = 3] = "FillOrKill";
|
|
55
|
-
})(FillMode || (
|
|
56
|
-
var TriggerKind;
|
|
15
|
+
})(FillMode || (FillMode = {}));
|
|
16
|
+
export var TriggerKind;
|
|
57
17
|
(function (TriggerKind) {
|
|
58
18
|
TriggerKind[TriggerKind["StopLoss"] = 0] = "StopLoss";
|
|
59
19
|
TriggerKind[TriggerKind["TakeProfit"] = 1] = "TakeProfit";
|
|
60
|
-
})(TriggerKind || (
|
|
61
|
-
var TriggerStatus;
|
|
20
|
+
})(TriggerKind || (TriggerKind = {}));
|
|
21
|
+
export var TriggerStatus;
|
|
62
22
|
(function (TriggerStatus) {
|
|
63
23
|
TriggerStatus[TriggerStatus["Active"] = 0] = "Active";
|
|
64
24
|
TriggerStatus[TriggerStatus["Success"] = 1] = "Success";
|
|
65
25
|
TriggerStatus[TriggerStatus["Cancel"] = 2] = "Cancel";
|
|
66
26
|
TriggerStatus[TriggerStatus["Remove"] = 4] = "Remove";
|
|
67
|
-
})(TriggerStatus || (
|
|
27
|
+
})(TriggerStatus || (TriggerStatus = {}));
|
|
68
28
|
/**
|
|
69
29
|
* Converts a `FillMode` enum to its corresponding protobuf representation.
|
|
70
30
|
*
|
|
@@ -72,7 +32,7 @@ var TriggerStatus;
|
|
|
72
32
|
* @returns The corresponding protobuf fill mode.
|
|
73
33
|
* @throws Will throw an error if provided with an invalid fill mode.
|
|
74
34
|
*/
|
|
75
|
-
function fillModeToProtoFillMode(x) {
|
|
35
|
+
export function fillModeToProtoFillMode(x) {
|
|
76
36
|
if (x === FillMode.Limit)
|
|
77
37
|
return proto.FillMode.LIMIT;
|
|
78
38
|
if (x === FillMode.PostOnly)
|
|
@@ -87,12 +47,12 @@ function fillModeToProtoFillMode(x) {
|
|
|
87
47
|
/**
|
|
88
48
|
* WebSocket message types
|
|
89
49
|
*/
|
|
90
|
-
var WebSocketMessageType;
|
|
50
|
+
export var WebSocketMessageType;
|
|
91
51
|
(function (WebSocketMessageType) {
|
|
92
52
|
WebSocketMessageType["TradeUpdate"] = "trades";
|
|
93
53
|
WebSocketMessageType["DeltaUpdate"] = "delta";
|
|
94
54
|
WebSocketMessageType["AccountUpdate"] = "account";
|
|
95
|
-
})(WebSocketMessageType || (
|
|
55
|
+
})(WebSocketMessageType || (WebSocketMessageType = {}));
|
|
96
56
|
// Positive decimal price and size.
|
|
97
57
|
// Example:
|
|
98
58
|
// ```
|
|
@@ -105,11 +65,13 @@ var WebSocketMessageType;
|
|
|
105
65
|
// If you want to get smaller tick on client (on server it will not change),
|
|
106
66
|
// do `new QuoteSize(new Decimal(114000/2), new Decimal(0.00070))`.
|
|
107
67
|
// It will be 40$ limit, but may help if BTC suddently moves fast.
|
|
108
|
-
class QuoteSize {
|
|
68
|
+
export class QuoteSize {
|
|
69
|
+
price;
|
|
70
|
+
size;
|
|
109
71
|
/// Input can be only positive values.
|
|
110
72
|
constructor(quotePrice, quoteSize) {
|
|
111
|
-
const p = new
|
|
112
|
-
const s = new
|
|
73
|
+
const p = new Decimal(quotePrice);
|
|
74
|
+
const s = new Decimal(quoteSize);
|
|
113
75
|
if (!p.isPositive() || !s.isPositive()) {
|
|
114
76
|
throw new Error("quotePrice and quoteSize must be positive");
|
|
115
77
|
}
|
|
@@ -123,9 +85,8 @@ class QuoteSize {
|
|
|
123
85
|
// Converts to wire format to be send to server, scaling price and size according to market decimals.
|
|
124
86
|
toWire(marketPriceDecimals, marketSizeDecimals) {
|
|
125
87
|
return {
|
|
126
|
-
price:
|
|
127
|
-
size:
|
|
88
|
+
price: toScaledU64(this.price, marketPriceDecimals),
|
|
89
|
+
size: toScaledU64(this.size, marketSizeDecimals),
|
|
128
90
|
};
|
|
129
91
|
}
|
|
130
92
|
}
|
|
131
|
-
exports.QuoteSize = QuoteSize;
|
package/dist/utils.js
CHANGED
|
@@ -1,75 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.toScaledU128 = exports.toScaledU64 = exports.MAX_BUFFER_LEN = exports.ZERO_DECIMAL = exports.SESSION_TTL = void 0;
|
|
40
|
-
exports.panic = panic;
|
|
41
|
-
exports.isRfc3339 = isRfc3339;
|
|
42
|
-
exports.assert = assert;
|
|
43
|
-
exports.optExpect = optExpect;
|
|
44
|
-
exports.checkedFetch = checkedFetch;
|
|
45
|
-
exports.makeWalletSignFn = makeWalletSignFn;
|
|
46
|
-
exports.decodeLengthDelimited = decodeLengthDelimited;
|
|
47
|
-
exports.decodeHex = decodeHex;
|
|
48
|
-
exports.findMarket = findMarket;
|
|
49
|
-
exports.findToken = findToken;
|
|
50
|
-
exports.keypairFromPrivateKey = keypairFromPrivateKey;
|
|
51
|
-
exports.signUserPayload = signUserPayload;
|
|
52
|
-
const decimal_js_1 = require("decimal.js");
|
|
53
|
-
const wire_1 = require("@bufbuild/protobuf/wire");
|
|
54
|
-
const protobuf_1 = require("@bufbuild/protobuf");
|
|
55
|
-
const ethers_1 = require("ethers");
|
|
56
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
57
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
58
|
-
const bs58_1 = __importDefault(require("bs58"));
|
|
59
|
-
const solana = __importStar(require("@solana/web3.js"));
|
|
60
|
-
exports.SESSION_TTL = 60n * 60n * 24n * 30n;
|
|
61
|
-
exports.ZERO_DECIMAL = new decimal_js_1.Decimal(0);
|
|
62
|
-
exports.MAX_BUFFER_LEN = 10000;
|
|
1
|
+
import { Decimal } from "decimal.js";
|
|
2
|
+
import { sizeDelimitedPeek } from "@bufbuild/protobuf/wire";
|
|
3
|
+
import { fromBinary } from "@bufbuild/protobuf";
|
|
4
|
+
import { ethers } from "ethers";
|
|
5
|
+
import fetch from "node-fetch";
|
|
6
|
+
import { Keypair } from "@solana/web3.js";
|
|
7
|
+
import bs58 from "bs58";
|
|
8
|
+
import * as solana from "@solana/web3.js";
|
|
9
|
+
import { Buffer } from "buffer";
|
|
10
|
+
export const SESSION_TTL = 60n * 60n * 24n * 30n;
|
|
11
|
+
export const ZERO_DECIMAL = new Decimal(0);
|
|
12
|
+
export const MAX_BUFFER_LEN = 10_000;
|
|
63
13
|
// Max size of data returned from Nord endpoints
|
|
64
14
|
const MAX_PAYLOAD_SIZE = 100 * 1024; // 100 kB
|
|
65
|
-
function panic(message) {
|
|
15
|
+
export function panic(message) {
|
|
66
16
|
throw new Error(message);
|
|
67
17
|
}
|
|
68
|
-
function isRfc3339(s) {
|
|
18
|
+
export function isRfc3339(s) {
|
|
69
19
|
const REGEX = /^((?:(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2}(?:\.\d+)?))(Z|[\+-]\d{2}:\d{2})?)$/;
|
|
70
20
|
return REGEX.test(s);
|
|
71
21
|
}
|
|
72
|
-
function assert(predicate, message) {
|
|
22
|
+
export function assert(predicate, message) {
|
|
73
23
|
if (!predicate)
|
|
74
24
|
panic(message ?? "Assertion violated");
|
|
75
25
|
}
|
|
@@ -79,7 +29,7 @@ function assert(predicate, message) {
|
|
|
79
29
|
* @param message Error message
|
|
80
30
|
* @returns Unwrapped value
|
|
81
31
|
*/
|
|
82
|
-
function optExpect(value, message) {
|
|
32
|
+
export function optExpect(value, message) {
|
|
83
33
|
if (value === undefined)
|
|
84
34
|
throw new Error(message);
|
|
85
35
|
return value;
|
|
@@ -91,8 +41,8 @@ function optExpect(value, message) {
|
|
|
91
41
|
* @returns Raw response if fetch succeeded
|
|
92
42
|
* @throws If response wasn't Ok
|
|
93
43
|
*/
|
|
94
|
-
async function checkedFetch(url, init) {
|
|
95
|
-
const resp = await (
|
|
44
|
+
export async function checkedFetch(url, init) {
|
|
45
|
+
const resp = await fetch(url, init);
|
|
96
46
|
assert(resp.ok, `Request failed with ${resp.status}: ${resp.statusText}`);
|
|
97
47
|
return resp;
|
|
98
48
|
}
|
|
@@ -104,13 +54,13 @@ async function checkedFetch(url, init) {
|
|
|
104
54
|
* then signs it with provided user wallet key and returns signature
|
|
105
55
|
* as hex string prefixed with `"0x"`
|
|
106
56
|
*/
|
|
107
|
-
function makeWalletSignFn(walletKey) {
|
|
108
|
-
const signingKey = new
|
|
109
|
-
return async (message) => signingKey.sign(
|
|
57
|
+
export function makeWalletSignFn(walletKey) {
|
|
58
|
+
const signingKey = new ethers.SigningKey(walletKey);
|
|
59
|
+
return async (message) => signingKey.sign(ethers.hashMessage(message)).serialized;
|
|
110
60
|
}
|
|
111
61
|
// Returned numbers do fit into specified bits range, or error is thrown.
|
|
112
62
|
function makeToScaledBigUint(params) {
|
|
113
|
-
const Dec =
|
|
63
|
+
const Dec = Decimal.clone({
|
|
114
64
|
precision: params.precision,
|
|
115
65
|
toExpPos: params.exponent,
|
|
116
66
|
toExpNeg: -params.exponent,
|
|
@@ -146,7 +96,7 @@ function makeToScaledBigUint(params) {
|
|
|
146
96
|
* @param decimals Number of decimal digits
|
|
147
97
|
* @returns Rescaled unsigned integer
|
|
148
98
|
*/
|
|
149
|
-
|
|
99
|
+
export const toScaledU64 = makeToScaledBigUint({
|
|
150
100
|
bits: 64,
|
|
151
101
|
precision: 20,
|
|
152
102
|
exponent: 28,
|
|
@@ -162,7 +112,7 @@ exports.toScaledU64 = makeToScaledBigUint({
|
|
|
162
112
|
* @param decimals Number of decimal digits
|
|
163
113
|
* @returns Rescaled unsigned integer
|
|
164
114
|
*/
|
|
165
|
-
|
|
115
|
+
export const toScaledU128 = makeToScaledBigUint({
|
|
166
116
|
bits: 128,
|
|
167
117
|
precision: 40,
|
|
168
118
|
exponent: 56,
|
|
@@ -175,9 +125,9 @@ exports.toScaledU128 = makeToScaledBigUint({
|
|
|
175
125
|
* @param schema Message schema for decoding
|
|
176
126
|
* @returns Decoded message
|
|
177
127
|
*/
|
|
178
|
-
function decodeLengthDelimited(bytes, schema) {
|
|
128
|
+
export function decodeLengthDelimited(bytes, schema) {
|
|
179
129
|
// use sizeDelimitedPeek to extract the message length and offset
|
|
180
|
-
const peekResult =
|
|
130
|
+
const peekResult = sizeDelimitedPeek(bytes);
|
|
181
131
|
if (peekResult.size === null || peekResult.offset === null) {
|
|
182
132
|
throw new Error("Failed to parse size-delimited message");
|
|
183
133
|
}
|
|
@@ -188,38 +138,38 @@ function decodeLengthDelimited(bytes, schema) {
|
|
|
188
138
|
throw new Error(`Encoded message size (${peekResult.size} bytes) is greater than remaining buffer size (${bytes.length - peekResult.offset} bytes).`);
|
|
189
139
|
}
|
|
190
140
|
// decode the message using the offset and size from peek
|
|
191
|
-
return
|
|
141
|
+
return fromBinary(schema, bytes.slice(peekResult.offset, peekResult.offset + peekResult.size));
|
|
192
142
|
}
|
|
193
|
-
function decodeHex(value) {
|
|
143
|
+
export function decodeHex(value) {
|
|
194
144
|
const hex = value.startsWith("0x") ? value.slice(2) : value;
|
|
195
145
|
return Uint8Array.from(Buffer.from(hex, "hex"));
|
|
196
146
|
}
|
|
197
|
-
function findMarket(markets, marketId) {
|
|
147
|
+
export function findMarket(markets, marketId) {
|
|
198
148
|
if (marketId < 0 || markets.length - 1 < marketId) {
|
|
199
149
|
throw new Error(`The market with marketId=${marketId} not found`);
|
|
200
150
|
}
|
|
201
151
|
return markets[marketId];
|
|
202
152
|
}
|
|
203
|
-
function findToken(tokens, tokenId) {
|
|
153
|
+
export function findToken(tokens, tokenId) {
|
|
204
154
|
if (tokenId < 0 || tokens.length - 1 < tokenId) {
|
|
205
155
|
throw new Error(`The token with tokenId=${tokenId} not found`);
|
|
206
156
|
}
|
|
207
157
|
return tokens[tokenId];
|
|
208
158
|
}
|
|
209
|
-
function keypairFromPrivateKey(privateKey) {
|
|
159
|
+
export function keypairFromPrivateKey(privateKey) {
|
|
210
160
|
if (typeof privateKey === "string") {
|
|
211
161
|
if (!privateKey.startsWith("0x")) {
|
|
212
|
-
return
|
|
162
|
+
return Keypair.fromSecretKey(bs58.decode(privateKey));
|
|
213
163
|
}
|
|
214
164
|
const hex = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
|
|
215
165
|
const bytes = new Uint8Array(hex.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
|
|
216
|
-
return
|
|
166
|
+
return Keypair.fromSecretKey(bytes);
|
|
217
167
|
}
|
|
218
|
-
return
|
|
168
|
+
return Keypair.fromSecretKey(privateKey);
|
|
219
169
|
}
|
|
220
|
-
async function signUserPayload({ payload, user, signTransaction, }) {
|
|
170
|
+
export async function signUserPayload({ payload, user, signTransaction, }) {
|
|
221
171
|
const tx = new solana.Transaction({
|
|
222
|
-
blockhash:
|
|
172
|
+
blockhash: bs58.encode(new Uint8Array(32)),
|
|
223
173
|
lastValidBlockHeight: 0,
|
|
224
174
|
feePayer: user,
|
|
225
175
|
});
|
|
@@ -230,6 +180,8 @@ async function signUserPayload({ payload, user, signTransaction, }) {
|
|
|
230
180
|
}));
|
|
231
181
|
const signedTx = await signTransaction(tx);
|
|
232
182
|
const sig = signedTx.signatures[0];
|
|
183
|
+
assert(sig !== undefined, //.
|
|
184
|
+
"signed transaction must have a signature");
|
|
233
185
|
assert(sig.signature !== null, "signature must be non-null; check your signTransaction function");
|
|
234
186
|
assert(sig.signature.length === 64, //.
|
|
235
187
|
"signature must be 64 bytes");
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.NordWebSocketClient = void 0;
|
|
7
|
-
const events_1 = require("events");
|
|
8
|
-
const ws_1 = __importDefault(require("ws"));
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import WebSocket from "ws";
|
|
9
3
|
const VALID_STREAM_TYPES = ["trades", "delta", "account"];
|
|
10
4
|
/**
|
|
11
5
|
* WebSocket client for Nord exchange
|
|
@@ -16,19 +10,21 @@ const VALID_STREAM_TYPES = ["trades", "delta", "account"];
|
|
|
16
10
|
* the endpoint type (e.g., only 'trades@BTCUSDC' subscriptions are valid on
|
|
17
11
|
* the /ws/trades endpoint).
|
|
18
12
|
*/
|
|
19
|
-
class NordWebSocketClient extends
|
|
13
|
+
export class NordWebSocketClient extends EventEmitter {
|
|
14
|
+
ws = null;
|
|
15
|
+
url;
|
|
16
|
+
reconnectAttempts = 0;
|
|
17
|
+
maxReconnectAttempts = 5;
|
|
18
|
+
reconnectDelay = 1000;
|
|
19
|
+
pingInterval = null;
|
|
20
|
+
pingTimeout = null;
|
|
21
|
+
isBrowser;
|
|
20
22
|
/**
|
|
21
23
|
* Create a new NordWebSocketClient
|
|
22
24
|
* @param url WebSocket server URL
|
|
23
25
|
*/
|
|
24
26
|
constructor(url) {
|
|
25
27
|
super();
|
|
26
|
-
this.ws = null;
|
|
27
|
-
this.reconnectAttempts = 0;
|
|
28
|
-
this.maxReconnectAttempts = 5;
|
|
29
|
-
this.reconnectDelay = 1000;
|
|
30
|
-
this.pingInterval = null;
|
|
31
|
-
this.pingTimeout = null;
|
|
32
28
|
this.url = url;
|
|
33
29
|
// Check if we're in a browser environment
|
|
34
30
|
// The most reliable way is to check for Node.js process
|
|
@@ -101,7 +97,7 @@ class NordWebSocketClient extends events_1.EventEmitter {
|
|
|
101
97
|
}
|
|
102
98
|
else {
|
|
103
99
|
// In Node.js
|
|
104
|
-
return
|
|
100
|
+
return WebSocket;
|
|
105
101
|
}
|
|
106
102
|
}
|
|
107
103
|
/**
|
|
@@ -244,4 +240,3 @@ class NordWebSocketClient extends events_1.EventEmitter {
|
|
|
244
240
|
}, this.reconnectDelay);
|
|
245
241
|
}
|
|
246
242
|
}
|
|
247
|
-
exports.NordWebSocketClient = NordWebSocketClient;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Subscriber = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
1
|
+
import { MAX_BUFFER_LEN } from "../utils";
|
|
5
2
|
/**
|
|
6
3
|
* Subscriber class for handling WebSocket subscriptions
|
|
7
4
|
*/
|
|
8
|
-
class Subscriber {
|
|
5
|
+
export class Subscriber {
|
|
6
|
+
streamURL;
|
|
7
|
+
buffer;
|
|
8
|
+
maxBufferLen;
|
|
9
9
|
/**
|
|
10
10
|
* Create a new Subscriber instance
|
|
11
11
|
* @param config Subscriber configuration
|
|
@@ -13,7 +13,7 @@ class Subscriber {
|
|
|
13
13
|
constructor(config) {
|
|
14
14
|
this.streamURL = config.streamURL;
|
|
15
15
|
this.buffer = [];
|
|
16
|
-
this.maxBufferLen = config.maxBufferLen ??
|
|
16
|
+
this.maxBufferLen = config.maxBufferLen ?? MAX_BUFFER_LEN;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Subscribe to WebSocket events
|
|
@@ -22,4 +22,3 @@ class Subscriber {
|
|
|
22
22
|
// TODO: Implement subscription logic
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
exports.Subscriber = Subscriber;
|
package/dist/websocket/events.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|