@n1xyz/nord-ts 0.1.4 → 0.1.5
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/gen/nord_pb.d.ts +286 -3
- package/dist/gen/nord_pb.js +107 -64
- package/dist/gen/openapi.d.ts +165 -1
- package/dist/nord/api/actions.d.ts +9 -0
- package/dist/nord/api/actions.js +16 -0
- package/dist/nord/client/Nord.d.ts +91 -1
- package/dist/nord/client/Nord.js +148 -0
- package/dist/nord/client/NordAdmin.d.ts +179 -13
- package/dist/nord/client/NordAdmin.js +216 -66
- package/dist/nord/client/NordClient.d.ts +0 -9
- package/dist/nord/client/NordClient.js +0 -48
- package/dist/nord/client/NordUser.js +6 -6
- package/dist/nord/index.d.ts +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +5 -0
- package/package.json +2 -2
- package/src/gen/nord_pb.ts +378 -63
- package/src/gen/openapi.ts +165 -1
- package/src/nord/api/actions.ts +26 -1
- package/src/nord/client/Nord.ts +183 -0
- package/src/nord/client/NordAdmin.ts +292 -83
- package/src/nord/client/NordClient.ts +0 -26
- package/src/nord/client/NordUser.ts +7 -6
- package/src/nord/index.ts +0 -1
- package/src/types.ts +6 -0
- package/src/utils.ts +5 -0
package/src/gen/openapi.ts
CHANGED
|
@@ -362,6 +362,14 @@ export interface paths {
|
|
|
362
362
|
"application/json": number;
|
|
363
363
|
};
|
|
364
364
|
};
|
|
365
|
+
404: {
|
|
366
|
+
headers: {
|
|
367
|
+
[name: string]: unknown;
|
|
368
|
+
};
|
|
369
|
+
content: {
|
|
370
|
+
"application/json": components["schemas"]["UserNotFound"];
|
|
371
|
+
};
|
|
372
|
+
};
|
|
365
373
|
};
|
|
366
374
|
};
|
|
367
375
|
put?: never;
|
|
@@ -1103,6 +1111,127 @@ export interface paths {
|
|
|
1103
1111
|
patch?: never;
|
|
1104
1112
|
trace?: never;
|
|
1105
1113
|
};
|
|
1114
|
+
"/fee/brackets/info": {
|
|
1115
|
+
parameters: {
|
|
1116
|
+
query?: never;
|
|
1117
|
+
header?: never;
|
|
1118
|
+
path?: never;
|
|
1119
|
+
cookie?: never;
|
|
1120
|
+
};
|
|
1121
|
+
get: {
|
|
1122
|
+
parameters: {
|
|
1123
|
+
query?: never;
|
|
1124
|
+
header?: never;
|
|
1125
|
+
path?: never;
|
|
1126
|
+
cookie?: never;
|
|
1127
|
+
};
|
|
1128
|
+
requestBody?: never;
|
|
1129
|
+
responses: {
|
|
1130
|
+
200: {
|
|
1131
|
+
headers: {
|
|
1132
|
+
[name: string]: unknown;
|
|
1133
|
+
};
|
|
1134
|
+
content: {
|
|
1135
|
+
"application/json": [
|
|
1136
|
+
components["schemas"]["FeeTierId"],
|
|
1137
|
+
components["schemas"]["FeeTierConfig"]
|
|
1138
|
+
][];
|
|
1139
|
+
};
|
|
1140
|
+
};
|
|
1141
|
+
};
|
|
1142
|
+
};
|
|
1143
|
+
put?: never;
|
|
1144
|
+
post?: never;
|
|
1145
|
+
delete?: never;
|
|
1146
|
+
options?: never;
|
|
1147
|
+
head?: never;
|
|
1148
|
+
patch?: never;
|
|
1149
|
+
trace?: never;
|
|
1150
|
+
};
|
|
1151
|
+
"/account/{account_id}/fee/tier": {
|
|
1152
|
+
parameters: {
|
|
1153
|
+
query?: never;
|
|
1154
|
+
header?: never;
|
|
1155
|
+
path?: never;
|
|
1156
|
+
cookie?: never;
|
|
1157
|
+
};
|
|
1158
|
+
get: {
|
|
1159
|
+
parameters: {
|
|
1160
|
+
query?: never;
|
|
1161
|
+
header?: never;
|
|
1162
|
+
path: {
|
|
1163
|
+
account_id: number;
|
|
1164
|
+
};
|
|
1165
|
+
cookie?: never;
|
|
1166
|
+
};
|
|
1167
|
+
requestBody?: never;
|
|
1168
|
+
responses: {
|
|
1169
|
+
200: {
|
|
1170
|
+
headers: {
|
|
1171
|
+
[name: string]: unknown;
|
|
1172
|
+
};
|
|
1173
|
+
content: {
|
|
1174
|
+
"application/json": components["schemas"]["FeeTierId"];
|
|
1175
|
+
};
|
|
1176
|
+
};
|
|
1177
|
+
404: {
|
|
1178
|
+
headers: {
|
|
1179
|
+
[name: string]: unknown;
|
|
1180
|
+
};
|
|
1181
|
+
content: {
|
|
1182
|
+
"application/json": components["schemas"]["UserNotFound"];
|
|
1183
|
+
};
|
|
1184
|
+
};
|
|
1185
|
+
};
|
|
1186
|
+
};
|
|
1187
|
+
put?: never;
|
|
1188
|
+
post?: never;
|
|
1189
|
+
delete?: never;
|
|
1190
|
+
options?: never;
|
|
1191
|
+
head?: never;
|
|
1192
|
+
patch?: never;
|
|
1193
|
+
trace?: never;
|
|
1194
|
+
};
|
|
1195
|
+
"/accounts/fee-tiers": {
|
|
1196
|
+
parameters: {
|
|
1197
|
+
query?: never;
|
|
1198
|
+
header?: never;
|
|
1199
|
+
path?: never;
|
|
1200
|
+
cookie?: never;
|
|
1201
|
+
};
|
|
1202
|
+
/** @description List fee tiers assigned to accounts. */
|
|
1203
|
+
get: {
|
|
1204
|
+
parameters: {
|
|
1205
|
+
query?: {
|
|
1206
|
+
/** @description fetch results starting with this page; query starts with first entry if page isn't specified */
|
|
1207
|
+
startInclusive?: number | null;
|
|
1208
|
+
/** @description Query returns up to 50 trades in one go. */
|
|
1209
|
+
pageSize?: number | null;
|
|
1210
|
+
};
|
|
1211
|
+
header?: never;
|
|
1212
|
+
path?: never;
|
|
1213
|
+
cookie?: never;
|
|
1214
|
+
};
|
|
1215
|
+
requestBody?: never;
|
|
1216
|
+
responses: {
|
|
1217
|
+
200: {
|
|
1218
|
+
headers: {
|
|
1219
|
+
[name: string]: unknown;
|
|
1220
|
+
};
|
|
1221
|
+
content: {
|
|
1222
|
+
"application/json": components["schemas"]["PageResult_for_uint32_and_AccountFeeTier"];
|
|
1223
|
+
};
|
|
1224
|
+
};
|
|
1225
|
+
};
|
|
1226
|
+
};
|
|
1227
|
+
put?: never;
|
|
1228
|
+
post?: never;
|
|
1229
|
+
delete?: never;
|
|
1230
|
+
options?: never;
|
|
1231
|
+
head?: never;
|
|
1232
|
+
patch?: never;
|
|
1233
|
+
trace?: never;
|
|
1234
|
+
};
|
|
1106
1235
|
"/tv": {
|
|
1107
1236
|
parameters: {
|
|
1108
1237
|
query?: never;
|
|
@@ -2076,6 +2205,7 @@ export interface components {
|
|
|
2076
2205
|
ActionNotFound: null;
|
|
2077
2206
|
/** @description Returns fee parts per market per balance change per action per account. Fee is taken from user without return. Please note that some operations need some deposit which will be returned - these are not part of fees. */
|
|
2078
2207
|
FillRole: "maker" | "taker";
|
|
2208
|
+
UserNotFound: null;
|
|
2079
2209
|
OrderbookInfo: {
|
|
2080
2210
|
/** Format: uint64 */
|
|
2081
2211
|
updateId: number;
|
|
@@ -2153,7 +2283,6 @@ export interface components {
|
|
|
2153
2283
|
pubkey: string;
|
|
2154
2284
|
expiry: string;
|
|
2155
2285
|
};
|
|
2156
|
-
UserNotFound: null;
|
|
2157
2286
|
PageQueryPart_for_String: {
|
|
2158
2287
|
/** @description fetch results starting with this page; query starts with first entry if page isn't specified */
|
|
2159
2288
|
startInclusive?: string | null;
|
|
@@ -2525,6 +2654,41 @@ export interface components {
|
|
|
2525
2654
|
timestamp: number;
|
|
2526
2655
|
paused: boolean;
|
|
2527
2656
|
};
|
|
2657
|
+
/** Format: uint32 */
|
|
2658
|
+
FeeTierId: number;
|
|
2659
|
+
FeeTierConfig: {
|
|
2660
|
+
/** Format: uint16 */
|
|
2661
|
+
maker_fee_bps: number;
|
|
2662
|
+
/** Format: uint16 */
|
|
2663
|
+
taker_fee_bps: number;
|
|
2664
|
+
};
|
|
2665
|
+
PageQueryPart_for_uint32: {
|
|
2666
|
+
/**
|
|
2667
|
+
* Format: uint32
|
|
2668
|
+
* @description fetch results starting with this page; query starts with first entry if page isn't specified
|
|
2669
|
+
*/
|
|
2670
|
+
startInclusive?: number | null;
|
|
2671
|
+
/**
|
|
2672
|
+
* Format: uint8
|
|
2673
|
+
* @description Query returns up to 50 trades in one go.
|
|
2674
|
+
* @default null
|
|
2675
|
+
*/
|
|
2676
|
+
pageSize: number | null;
|
|
2677
|
+
};
|
|
2678
|
+
PageResult_for_uint32_and_AccountFeeTier: {
|
|
2679
|
+
/** @description Set of items for requested by query. */
|
|
2680
|
+
items: components["schemas"]["AccountFeeTier"][];
|
|
2681
|
+
/**
|
|
2682
|
+
* Format: uint32
|
|
2683
|
+
* @description If request contains more data, this is the id is set with which next request should be performed to get next page. If no more data, then it is undefined.
|
|
2684
|
+
*/
|
|
2685
|
+
nextStartInclusive?: number | null;
|
|
2686
|
+
};
|
|
2687
|
+
AccountFeeTier: {
|
|
2688
|
+
/** Format: uint32 */
|
|
2689
|
+
accountId: number;
|
|
2690
|
+
feeTier: components["schemas"]["FeeTierId"];
|
|
2691
|
+
};
|
|
2528
2692
|
/** @description TV config query response https://www.tradingview.com/charting-library-docs/latest/connecting_data/UDF/#data-feed-configuration-data */
|
|
2529
2693
|
TvConfigResponse: {
|
|
2530
2694
|
supported_resolutions: components["schemas"]["Resolution"][];
|
package/src/nord/api/actions.ts
CHANGED
|
@@ -2,7 +2,6 @@ import Decimal from "decimal.js";
|
|
|
2
2
|
import * as proto from "../../gen/nord_pb";
|
|
3
3
|
import { paths } from "../../gen/openapi";
|
|
4
4
|
import createClient from "openapi-fetch";
|
|
5
|
-
|
|
6
5
|
import { create } from "@bufbuild/protobuf";
|
|
7
6
|
import {
|
|
8
7
|
FillMode,
|
|
@@ -21,6 +20,32 @@ import {
|
|
|
21
20
|
toScaledU64,
|
|
22
21
|
} from "../../utils";
|
|
23
22
|
import { sizeDelimitedEncode } from "@bufbuild/protobuf/wire";
|
|
23
|
+
import { NordError } from "../utils/NordError";
|
|
24
|
+
|
|
25
|
+
type ReceiptKind = NonNullable<proto.Receipt["kind"]>;
|
|
26
|
+
type ExtractReceiptKind<K extends ReceiptKind["case"]> = Extract<
|
|
27
|
+
ReceiptKind,
|
|
28
|
+
{ case: K }
|
|
29
|
+
>;
|
|
30
|
+
|
|
31
|
+
export function formatReceiptError(receipt: proto.Receipt): string {
|
|
32
|
+
if (receipt.kind?.case === "err") {
|
|
33
|
+
const err = receipt.kind.value;
|
|
34
|
+
return proto.Error[err] ?? err.toString();
|
|
35
|
+
}
|
|
36
|
+
return receipt.kind?.case ?? "unknown";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function expectReceiptKind<K extends ReceiptKind["case"]>(
|
|
40
|
+
receipt: proto.Receipt,
|
|
41
|
+
expected: K,
|
|
42
|
+
action: string,
|
|
43
|
+
): asserts receipt is proto.Receipt & { kind: ExtractReceiptKind<K> } {
|
|
44
|
+
if (receipt.kind?.case !== expected) {
|
|
45
|
+
const label = formatReceiptError(receipt);
|
|
46
|
+
throw new NordError(`Failed to ${action}: ${label}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
24
49
|
|
|
25
50
|
async function sessionSign(
|
|
26
51
|
signFn: (message: Uint8Array) => Promise<Uint8Array>,
|
package/src/nord/client/Nord.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
NordConfig,
|
|
17
17
|
OrderbookQuery,
|
|
18
18
|
OrderbookResponse,
|
|
19
|
+
FeeTierConfig,
|
|
19
20
|
PeakTpsPeriodUnit,
|
|
20
21
|
SubscriptionPattern,
|
|
21
22
|
Token,
|
|
@@ -24,6 +25,13 @@ import {
|
|
|
24
25
|
AccountTriggerInfo,
|
|
25
26
|
HistoryTriggerQuery,
|
|
26
27
|
TriggerHistoryPage,
|
|
28
|
+
FeeTierId,
|
|
29
|
+
AccountFeeTierPage,
|
|
30
|
+
PageResultStringOrderInfo,
|
|
31
|
+
PageResultStringTrade,
|
|
32
|
+
OrderInfoFromApi,
|
|
33
|
+
TokenStats,
|
|
34
|
+
FillRole,
|
|
27
35
|
} from "../../types";
|
|
28
36
|
import * as utils from "../../utils";
|
|
29
37
|
import { NordWebSocketClient } from "../../websocket/index";
|
|
@@ -617,6 +625,31 @@ export class Nord {
|
|
|
617
625
|
return await this.GET("/info", {});
|
|
618
626
|
}
|
|
619
627
|
|
|
628
|
+
/**
|
|
629
|
+
* Fetch the current fee tier brackets configured on Nord.
|
|
630
|
+
*
|
|
631
|
+
* @returns Array of fee tier identifiers paired with their configuration
|
|
632
|
+
* @throws {NordError} If the request fails
|
|
633
|
+
*/
|
|
634
|
+
public async getFeeBrackets(): Promise<Array<[FeeTierId, FeeTierConfig]>> {
|
|
635
|
+
return await this.GET("/fee/brackets/info", {});
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Retrieve the fee tier assigned to a specific account.
|
|
640
|
+
*
|
|
641
|
+
* @param accountId - Account identifier to query
|
|
642
|
+
* @returns Fee tier details for the requested account
|
|
643
|
+
* @throws {NordError} If the request fails
|
|
644
|
+
*/
|
|
645
|
+
public async getAccountFeeTier(accountId: number): Promise<FeeTierId> {
|
|
646
|
+
return await this.GET("/account/{account_id}/fee/tier", {
|
|
647
|
+
params: {
|
|
648
|
+
path: { account_id: accountId },
|
|
649
|
+
},
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
|
|
620
653
|
/**
|
|
621
654
|
* Get account information
|
|
622
655
|
*
|
|
@@ -632,6 +665,76 @@ export class Nord {
|
|
|
632
665
|
});
|
|
633
666
|
}
|
|
634
667
|
|
|
668
|
+
/**
|
|
669
|
+
* Get the public key associated with an account id.
|
|
670
|
+
*
|
|
671
|
+
* @param accountId - Account id to query
|
|
672
|
+
* @returns Base58-encoded account public key
|
|
673
|
+
* @throws {NordError} If the request fails
|
|
674
|
+
*/
|
|
675
|
+
public async getAccountPubkey(accountId: number): Promise<string> {
|
|
676
|
+
return await this.GET("/account/{account_id}/pubkey", {
|
|
677
|
+
params: {
|
|
678
|
+
path: { account_id: accountId },
|
|
679
|
+
},
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* Get the withdrawal fee charged for an account.
|
|
685
|
+
*
|
|
686
|
+
* @param accountId - Account id to query
|
|
687
|
+
* @returns Withdrawal fee quoted in quote token units
|
|
688
|
+
* @throws {NordError} If the request fails
|
|
689
|
+
*/
|
|
690
|
+
public async getAccountWithdrawalFee(accountId: number): Promise<number> {
|
|
691
|
+
return await this.GET("/account/{account_id}/fees/withdrawal", {
|
|
692
|
+
params: {
|
|
693
|
+
path: { account_id: accountId },
|
|
694
|
+
},
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Get open orders for an account.
|
|
700
|
+
*
|
|
701
|
+
* @param accountId - Account id to query
|
|
702
|
+
* @param query - Optional pagination parameters
|
|
703
|
+
* @returns Page of orders keyed by client order id
|
|
704
|
+
* @throws {NordError} If the request fails
|
|
705
|
+
*/
|
|
706
|
+
public async getAccountOrders(
|
|
707
|
+
accountId: number,
|
|
708
|
+
query?: { startInclusive?: string | null; pageSize?: number | null },
|
|
709
|
+
): Promise<PageResultStringOrderInfo> {
|
|
710
|
+
return await this.GET("/account/{account_id}/orders", {
|
|
711
|
+
params: {
|
|
712
|
+
path: { account_id: accountId },
|
|
713
|
+
query: {
|
|
714
|
+
startInclusive: query?.startInclusive,
|
|
715
|
+
pageSize: query?.pageSize,
|
|
716
|
+
},
|
|
717
|
+
},
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* List account fee tiers with pagination support.
|
|
723
|
+
*/
|
|
724
|
+
public async getAccountsFeeTiers(query?: {
|
|
725
|
+
startInclusive?: number | null;
|
|
726
|
+
pageSize?: number | null;
|
|
727
|
+
}): Promise<AccountFeeTierPage> {
|
|
728
|
+
return await this.GET("/accounts/fee-tiers", {
|
|
729
|
+
params: {
|
|
730
|
+
query: {
|
|
731
|
+
startInclusive: query?.startInclusive ?? undefined,
|
|
732
|
+
pageSize: query?.pageSize ?? undefined,
|
|
733
|
+
},
|
|
734
|
+
},
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
|
|
635
738
|
/**
|
|
636
739
|
* Get profit and loss history for an account
|
|
637
740
|
*
|
|
@@ -674,6 +777,86 @@ export class Nord {
|
|
|
674
777
|
});
|
|
675
778
|
}
|
|
676
779
|
|
|
780
|
+
/**
|
|
781
|
+
* Fetch the per-market fee quote for an account.
|
|
782
|
+
*
|
|
783
|
+
* @param params - Market id, fee kind, and account id to quote
|
|
784
|
+
* @returns Fee in quote token units (negative means fee is charged)
|
|
785
|
+
* @throws {NordError} If the request fails
|
|
786
|
+
*/
|
|
787
|
+
public async getMarketFee({
|
|
788
|
+
marketId,
|
|
789
|
+
feeKind,
|
|
790
|
+
accountId,
|
|
791
|
+
}: {
|
|
792
|
+
marketId: number;
|
|
793
|
+
feeKind: FillRole;
|
|
794
|
+
accountId: number;
|
|
795
|
+
}): Promise<number> {
|
|
796
|
+
return await this.GET("/market/{market_id}/fees/{fee_kind}/{account_id}", {
|
|
797
|
+
params: {
|
|
798
|
+
path: {
|
|
799
|
+
market_id: marketId,
|
|
800
|
+
fee_kind: feeKind,
|
|
801
|
+
account_id: accountId,
|
|
802
|
+
},
|
|
803
|
+
},
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* Fetch token statistics such as index price and oracle metadata.
|
|
809
|
+
*
|
|
810
|
+
* @param tokenId - Token identifier
|
|
811
|
+
* @returns Token stats
|
|
812
|
+
* @throws {NordError} If the request fails
|
|
813
|
+
*/
|
|
814
|
+
public async getTokenStats(tokenId: number): Promise<TokenStats> {
|
|
815
|
+
return await this.GET("/tokens/{token_id}/stats", {
|
|
816
|
+
params: {
|
|
817
|
+
path: { token_id: tokenId },
|
|
818
|
+
},
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Get order summary by order id.
|
|
824
|
+
*
|
|
825
|
+
* @param orderId - Order identifier
|
|
826
|
+
* @returns Order information
|
|
827
|
+
* @throws {NordError} If the request fails
|
|
828
|
+
*/
|
|
829
|
+
public async getOrder(orderId: string): Promise<OrderInfoFromApi> {
|
|
830
|
+
return await this.GET("/order/{order_id}", {
|
|
831
|
+
params: {
|
|
832
|
+
path: { order_id: orderId },
|
|
833
|
+
},
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* Get trade history for a specific order.
|
|
839
|
+
*
|
|
840
|
+
* @param orderId - Order identifier
|
|
841
|
+
* @param query - Optional pagination parameters
|
|
842
|
+
* @returns Page of trades associated with the order
|
|
843
|
+
* @throws {NordError} If the request fails
|
|
844
|
+
*/
|
|
845
|
+
public async getOrderTrades(
|
|
846
|
+
orderId: string,
|
|
847
|
+
query?: { startInclusive?: string | null; pageSize?: number | null },
|
|
848
|
+
): Promise<PageResultStringTrade> {
|
|
849
|
+
return await this.GET("/order/{order_id}/trades", {
|
|
850
|
+
params: {
|
|
851
|
+
path: { order_id: orderId },
|
|
852
|
+
query: {
|
|
853
|
+
startInclusive: query?.startInclusive,
|
|
854
|
+
pageSize: query?.pageSize,
|
|
855
|
+
},
|
|
856
|
+
},
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
|
|
677
860
|
/**
|
|
678
861
|
* Check if an account exists for the given address
|
|
679
862
|
*
|