@n1xyz/nord-ts 0.0.18-8121ed05.0 → 0.0.18
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/.local/qa.ts +77 -0
- package/.local/test-atomic.ts +112 -0
- package/check.sh +4 -0
- package/default.nix +47 -0
- package/dist/api/client.d.ts +14 -0
- package/dist/api/client.js +45 -0
- package/dist/gen/nord.d.ts +52 -23
- package/dist/gen/nord.js +322 -170
- package/dist/gen/openapi.d.ts +2244 -0
- package/dist/gen/openapi.js +6 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -9
- package/dist/nord/api/actions.d.ts +30 -1
- package/dist/nord/api/actions.js +60 -3
- package/dist/nord/api/core.d.ts +1 -34
- package/dist/nord/api/core.js +0 -71
- package/dist/nord/client/Nord.d.ts +31 -33
- package/dist/nord/client/Nord.js +100 -60
- package/dist/nord/client/NordUser.d.ts +64 -11
- package/dist/nord/client/NordUser.js +90 -33
- package/dist/nord/index.d.ts +0 -2
- package/dist/nord/index.js +0 -2
- package/dist/nord/models/Subscriber.d.ts +2 -2
- package/dist/types.d.ts +43 -190
- package/dist/utils.d.ts +1 -19
- package/dist/utils.js +5 -39
- package/dist/websocket/NordWebSocketClient.js +18 -13
- package/dist/websocket/index.d.ts +1 -1
- package/package.json +20 -27
- package/src/index.ts +0 -16
- package/src/nord/api/actions.ts +131 -9
- package/src/nord/api/core.ts +0 -71
- package/src/nord/client/Nord.ts +142 -76
- package/src/nord/client/NordUser.ts +171 -50
- package/src/nord/index.ts +0 -2
- package/src/nord/models/Subscriber.ts +2 -2
- package/src/types.ts +55 -216
- package/src/utils.ts +6 -42
- package/src/websocket/NordWebSocketClient.ts +23 -15
- package/src/websocket/index.ts +1 -1
- package/tests/utils.spec.ts +1 -34
- package/dist/idl/bridge.json +0 -1506
- package/jest.config.ts +0 -9
- package/nodemon.json +0 -4
- package/protoc-generate.sh +0 -23
- package/src/idl/bridge.json +0 -1506
- package/src/nord/api/market.ts +0 -122
- package/src/nord/api/queries.ts +0 -135
package/src/nord/api/market.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MarketsStatsResponse,
|
|
3
|
-
OrderbookQuery,
|
|
4
|
-
OrderbookResponse,
|
|
5
|
-
TradesQuery,
|
|
6
|
-
TradesResponse,
|
|
7
|
-
UserAccountIdsQuery,
|
|
8
|
-
UserAccountIdsResponse,
|
|
9
|
-
} from "../../types";
|
|
10
|
-
import { checkedFetch } from "../../utils";
|
|
11
|
-
import { NordError } from "../utils/NordError";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Get market statistics
|
|
15
|
-
*
|
|
16
|
-
* @param webServerUrl - Base URL for the Nord web server
|
|
17
|
-
* @returns Market statistics response
|
|
18
|
-
* @throws {NordError} If the request fails
|
|
19
|
-
*/
|
|
20
|
-
export async function marketsStats(
|
|
21
|
-
webServerUrl: string,
|
|
22
|
-
): Promise<MarketsStatsResponse> {
|
|
23
|
-
try {
|
|
24
|
-
const response = await checkedFetch(`${webServerUrl}/stats`);
|
|
25
|
-
return await response.json();
|
|
26
|
-
} catch (error) {
|
|
27
|
-
throw new NordError("Failed to fetch markets stats", { cause: error });
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Get trades for a market
|
|
33
|
-
*
|
|
34
|
-
* @param webServerUrl - Base URL for the Nord web server
|
|
35
|
-
* @param query - Trades query parameters
|
|
36
|
-
* @returns Trades response
|
|
37
|
-
* @throws {NordError} If the request fails
|
|
38
|
-
*/
|
|
39
|
-
export async function getTrades(
|
|
40
|
-
webServerUrl: string,
|
|
41
|
-
query: TradesQuery,
|
|
42
|
-
): Promise<TradesResponse> {
|
|
43
|
-
try {
|
|
44
|
-
const params = new URLSearchParams();
|
|
45
|
-
params.append("accountId", query.accountId.toString());
|
|
46
|
-
|
|
47
|
-
if (query.since) {
|
|
48
|
-
params.append("since", query.since);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (query.until) {
|
|
52
|
-
params.append("until", query.until);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (query.pageId) {
|
|
56
|
-
params.append("pageId", query.pageId);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const response = await checkedFetch(
|
|
60
|
-
`${webServerUrl}/trades?${params.toString()}`,
|
|
61
|
-
);
|
|
62
|
-
return await response.json();
|
|
63
|
-
} catch (error) {
|
|
64
|
-
throw new NordError("Failed to get trades", { cause: error });
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Get user account IDs
|
|
70
|
-
*
|
|
71
|
-
* @param webServerUrl - Base URL for the Nord web server
|
|
72
|
-
* @param query - User account IDs query parameters
|
|
73
|
-
* @returns User account IDs response
|
|
74
|
-
* @throws {NordError} If the request fails
|
|
75
|
-
*/
|
|
76
|
-
export async function getUserAccountIds(
|
|
77
|
-
webServerUrl: string,
|
|
78
|
-
query: UserAccountIdsQuery,
|
|
79
|
-
): Promise<UserAccountIdsResponse> {
|
|
80
|
-
try {
|
|
81
|
-
const response = await checkedFetch(
|
|
82
|
-
`${webServerUrl}/user/${query.pubkey.toString()}`,
|
|
83
|
-
);
|
|
84
|
-
return await response.json();
|
|
85
|
-
} catch (error) {
|
|
86
|
-
throw new NordError("Failed to get user account IDs", { cause: error });
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Get orderbook for a market
|
|
92
|
-
*
|
|
93
|
-
* @param webServerUrl - Base URL for the Nord web server
|
|
94
|
-
* @param query - Orderbook query parameters
|
|
95
|
-
* @returns Orderbook response
|
|
96
|
-
* @throws {NordError} If the request fails
|
|
97
|
-
*/
|
|
98
|
-
export async function getOrderbook(
|
|
99
|
-
webServerUrl: string,
|
|
100
|
-
query: OrderbookQuery,
|
|
101
|
-
): Promise<OrderbookResponse> {
|
|
102
|
-
try {
|
|
103
|
-
const params = new URLSearchParams();
|
|
104
|
-
|
|
105
|
-
if (query.symbol) {
|
|
106
|
-
params.append("symbol", query.symbol);
|
|
107
|
-
} else if (query.market_id !== undefined) {
|
|
108
|
-
params.append("market_id", query.market_id.toString());
|
|
109
|
-
} else {
|
|
110
|
-
throw new NordError(
|
|
111
|
-
"Either symbol or market_id must be provided for orderbook query",
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const response = await checkedFetch(
|
|
116
|
-
`${webServerUrl}/orderbook?${params.toString()}`,
|
|
117
|
-
);
|
|
118
|
-
return await response.json();
|
|
119
|
-
} catch (error) {
|
|
120
|
-
throw new NordError("Failed to get orderbook", { cause: error });
|
|
121
|
-
}
|
|
122
|
-
}
|
package/src/nord/api/queries.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ActionQuery,
|
|
3
|
-
ActionResponse,
|
|
4
|
-
ActionsResponse,
|
|
5
|
-
RollmanActionResponse,
|
|
6
|
-
RollmanActionsResponse,
|
|
7
|
-
} from "../../types";
|
|
8
|
-
import { checkedFetch } from "../../utils";
|
|
9
|
-
import { NordError } from "../utils/NordError";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Query a specific action
|
|
13
|
-
*
|
|
14
|
-
* @param webServerUrl - Base URL for the Nord web server
|
|
15
|
-
* @param query - Action query parameters
|
|
16
|
-
* @returns Action response
|
|
17
|
-
* @throws {NordError} If the request fails
|
|
18
|
-
*/
|
|
19
|
-
export async function queryAction(
|
|
20
|
-
webServerUrl: string,
|
|
21
|
-
query: ActionQuery,
|
|
22
|
-
): Promise<ActionResponse> {
|
|
23
|
-
try {
|
|
24
|
-
const params = new URLSearchParams();
|
|
25
|
-
if (query.action_id !== undefined) {
|
|
26
|
-
params.append("action_id", query.action_id.toString());
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const response = await checkedFetch(
|
|
30
|
-
`${webServerUrl}/action?${params.toString()}`,
|
|
31
|
-
);
|
|
32
|
-
return await response.json();
|
|
33
|
-
} catch (error) {
|
|
34
|
-
throw new NordError("Failed to query action", { cause: error });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Query recent actions
|
|
40
|
-
*
|
|
41
|
-
* @param webServerUrl - Base URL for the Nord web server
|
|
42
|
-
* @param from - Starting action index
|
|
43
|
-
* @param to - Ending action index
|
|
44
|
-
* @returns Actions response
|
|
45
|
-
* @throws {NordError} If the request fails
|
|
46
|
-
*/
|
|
47
|
-
export async function queryRecentActions(
|
|
48
|
-
webServerUrl: string,
|
|
49
|
-
from: number,
|
|
50
|
-
to: number,
|
|
51
|
-
): Promise<ActionsResponse> {
|
|
52
|
-
try {
|
|
53
|
-
const response = await checkedFetch(
|
|
54
|
-
`${webServerUrl}/actions?from=${from}&to=${to}`,
|
|
55
|
-
);
|
|
56
|
-
return await response.json();
|
|
57
|
-
} catch (error) {
|
|
58
|
-
throw new NordError(
|
|
59
|
-
`Failed to query recent actions (from ${from} to ${to})`,
|
|
60
|
-
{
|
|
61
|
-
cause: error,
|
|
62
|
-
},
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Get the last action ID
|
|
69
|
-
*
|
|
70
|
-
* @param webServerUrl - Base URL for the Nord web server
|
|
71
|
-
* @returns Last action ID
|
|
72
|
-
* @throws {NordError} If the request fails
|
|
73
|
-
*/
|
|
74
|
-
export async function getLastActionId(webServerUrl: string): Promise<number> {
|
|
75
|
-
try {
|
|
76
|
-
const response = await checkedFetch(`${webServerUrl}/actions/last-id`);
|
|
77
|
-
const data = await response.json();
|
|
78
|
-
return data;
|
|
79
|
-
} catch (error) {
|
|
80
|
-
throw new NordError("Failed to get last action ID", {
|
|
81
|
-
cause: error,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Query an action from Rollman
|
|
88
|
-
*
|
|
89
|
-
* @param webServerUrl - Base URL for the Nord web server
|
|
90
|
-
* @param query - Action query parameters
|
|
91
|
-
* @returns Rollman action response
|
|
92
|
-
* @throws {NordError} If the request fails
|
|
93
|
-
*/
|
|
94
|
-
export async function actionQueryRollman(
|
|
95
|
-
webServerUrl: string,
|
|
96
|
-
query: ActionQuery,
|
|
97
|
-
): Promise<RollmanActionResponse> {
|
|
98
|
-
try {
|
|
99
|
-
const params = new URLSearchParams();
|
|
100
|
-
if (query.action_id !== undefined) {
|
|
101
|
-
params.append("action_id", query.action_id.toString());
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const response = await checkedFetch(
|
|
105
|
-
`${webServerUrl}/rollman/action?${params.toString()}`,
|
|
106
|
-
);
|
|
107
|
-
return await response.json();
|
|
108
|
-
} catch (error) {
|
|
109
|
-
throw new NordError("Failed to query Rollman action", { cause: error });
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Query actions from Rollman
|
|
115
|
-
*
|
|
116
|
-
* @param webServerUrl - Base URL for the Nord web server
|
|
117
|
-
* @param last_n - Number of recent actions to query
|
|
118
|
-
* @returns Rollman actions response
|
|
119
|
-
* @throws {NordError} If the request fails
|
|
120
|
-
*/
|
|
121
|
-
export async function actionsQueryRollman(
|
|
122
|
-
webServerUrl: string,
|
|
123
|
-
last_n: number,
|
|
124
|
-
): Promise<RollmanActionsResponse> {
|
|
125
|
-
try {
|
|
126
|
-
const response = await checkedFetch(
|
|
127
|
-
`${webServerUrl}/rollman/actions?last_n=${last_n}`,
|
|
128
|
-
);
|
|
129
|
-
return await response.json();
|
|
130
|
-
} catch (error) {
|
|
131
|
-
throw new NordError(`Failed to query Rollman actions (last ${last_n})`, {
|
|
132
|
-
cause: error,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}
|