@aicoin/opendata-mcp 1.0.11 → 1.0.13
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/build/index.js +61 -15
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -162,6 +162,34 @@ function truncArr(arr, max) {
|
|
|
162
162
|
data: arr.slice(0, max)
|
|
163
163
|
};
|
|
164
164
|
}
|
|
165
|
+
function okDepth(data, max = 50) {
|
|
166
|
+
if (data && typeof data === "object") {
|
|
167
|
+
const obj = data;
|
|
168
|
+
const inner = obj.data;
|
|
169
|
+
if (inner && typeof inner === "object") {
|
|
170
|
+
const d = inner;
|
|
171
|
+
const bids = d.bids;
|
|
172
|
+
const asks = d.asks;
|
|
173
|
+
const bTotal = Array.isArray(bids) ? bids.length : 0;
|
|
174
|
+
const aTotal = Array.isArray(asks) ? asks.length : 0;
|
|
175
|
+
if (bTotal > max || aTotal > max) {
|
|
176
|
+
return ok({
|
|
177
|
+
...obj,
|
|
178
|
+
data: {
|
|
179
|
+
...d,
|
|
180
|
+
bids: Array.isArray(bids) ? bids.slice(0, max) : bids,
|
|
181
|
+
asks: Array.isArray(asks) ? asks.slice(0, max) : asks
|
|
182
|
+
},
|
|
183
|
+
_truncated: {
|
|
184
|
+
bids: { total: bTotal, showing: Math.min(bTotal, max) },
|
|
185
|
+
asks: { total: aTotal, showing: Math.min(aTotal, max) }
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return ok(data);
|
|
192
|
+
}
|
|
165
193
|
function err(e) {
|
|
166
194
|
const msg = e instanceof Error ? e.message : String(e);
|
|
167
195
|
return {
|
|
@@ -1123,17 +1151,28 @@ function registerMarketTools(server2) {
|
|
|
1123
1151
|
);
|
|
1124
1152
|
server2.tool(
|
|
1125
1153
|
"get_latest_depth",
|
|
1126
|
-
"Get latest order book depth
|
|
1154
|
+
"Get latest order book depth snapshot from Redis",
|
|
1127
1155
|
{
|
|
1128
|
-
|
|
1156
|
+
dbKey: z4.string().describe(
|
|
1157
|
+
"Trading pair key, e.g. btcusdt:binance, ethusdt:okex"
|
|
1158
|
+
),
|
|
1159
|
+
size: z4.string().optional().describe(
|
|
1160
|
+
"Number of depth levels, 1-500, default 50"
|
|
1161
|
+
),
|
|
1162
|
+
...maxItemsParam
|
|
1129
1163
|
},
|
|
1130
|
-
async ({
|
|
1164
|
+
async ({ dbKey, size, _max_items }) => {
|
|
1131
1165
|
try {
|
|
1132
|
-
|
|
1166
|
+
const params = {
|
|
1167
|
+
dbKey
|
|
1168
|
+
};
|
|
1169
|
+
if (size) params.size = size;
|
|
1170
|
+
return okDepth(
|
|
1133
1171
|
await apiGet(
|
|
1134
1172
|
"/api/upgrade/v2/futures/latest-depth",
|
|
1135
|
-
|
|
1136
|
-
)
|
|
1173
|
+
params
|
|
1174
|
+
),
|
|
1175
|
+
parseMax(_max_items, 50)
|
|
1137
1176
|
);
|
|
1138
1177
|
} catch (e) {
|
|
1139
1178
|
return err(e);
|
|
@@ -1144,15 +1183,17 @@ function registerMarketTools(server2) {
|
|
|
1144
1183
|
"get_full_depth",
|
|
1145
1184
|
"Get full order book depth data for futures",
|
|
1146
1185
|
{
|
|
1147
|
-
|
|
1186
|
+
dbKey: z4.string().describe(
|
|
1187
|
+
"Trading pair key, e.g. btcswapusd:hbdm, btcswapusdt:binance"
|
|
1188
|
+
),
|
|
1148
1189
|
...maxItemsParam
|
|
1149
1190
|
},
|
|
1150
|
-
async ({
|
|
1191
|
+
async ({ dbKey, _max_items }) => {
|
|
1151
1192
|
try {
|
|
1152
|
-
return
|
|
1193
|
+
return okDepth(
|
|
1153
1194
|
await apiGet(
|
|
1154
1195
|
"/api/upgrade/v2/futures/full-depth",
|
|
1155
|
-
{
|
|
1196
|
+
{ dbKey }
|
|
1156
1197
|
),
|
|
1157
1198
|
parseMax(_max_items, 50)
|
|
1158
1199
|
);
|
|
@@ -1163,17 +1204,22 @@ function registerMarketTools(server2) {
|
|
|
1163
1204
|
);
|
|
1164
1205
|
server2.tool(
|
|
1165
1206
|
"get_full_depth_grouped",
|
|
1166
|
-
"Get full depth data grouped by price
|
|
1207
|
+
"Get full depth data grouped by price interval",
|
|
1167
1208
|
{
|
|
1168
|
-
|
|
1209
|
+
dbKey: z4.string().describe(
|
|
1210
|
+
"Trading pair key, e.g. btcswapusd:hbdm, btcswapusdt:binance"
|
|
1211
|
+
),
|
|
1212
|
+
groupSize: z4.string().describe(
|
|
1213
|
+
"Price grouping interval, e.g. 100, 500, 1000"
|
|
1214
|
+
),
|
|
1169
1215
|
...maxItemsParam
|
|
1170
1216
|
},
|
|
1171
|
-
async ({
|
|
1217
|
+
async ({ dbKey, groupSize, _max_items }) => {
|
|
1172
1218
|
try {
|
|
1173
|
-
return
|
|
1219
|
+
return okDepth(
|
|
1174
1220
|
await apiGet(
|
|
1175
1221
|
"/api/upgrade/v2/futures/full-depth/grouped",
|
|
1176
|
-
{
|
|
1222
|
+
{ dbKey, groupSize }
|
|
1177
1223
|
),
|
|
1178
1224
|
parseMax(_max_items, 50)
|
|
1179
1225
|
);
|