@tradejs/connectors 3.1.29-beta.303 → 3.1.29-beta.304
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/index.js +121 -7
- package/dist/index.mjs +121 -7
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -479,6 +479,37 @@ var INTERVAL_TO_MINUTES = {
|
|
|
479
479
|
W: 10080,
|
|
480
480
|
M: 43200
|
|
481
481
|
};
|
|
482
|
+
var definiteOrderRejections = /* @__PURE__ */ new Set([
|
|
483
|
+
10001,
|
|
484
|
+
10002,
|
|
485
|
+
10003,
|
|
486
|
+
10004,
|
|
487
|
+
10005,
|
|
488
|
+
10007,
|
|
489
|
+
10008,
|
|
490
|
+
10009,
|
|
491
|
+
10010,
|
|
492
|
+
10024,
|
|
493
|
+
10027,
|
|
494
|
+
10028,
|
|
495
|
+
10029,
|
|
496
|
+
100028,
|
|
497
|
+
110003,
|
|
498
|
+
110004,
|
|
499
|
+
110006,
|
|
500
|
+
110007,
|
|
501
|
+
110009,
|
|
502
|
+
110012,
|
|
503
|
+
110017,
|
|
504
|
+
110018,
|
|
505
|
+
110019,
|
|
506
|
+
110020,
|
|
507
|
+
110021,
|
|
508
|
+
110023,
|
|
509
|
+
30208,
|
|
510
|
+
30209,
|
|
511
|
+
30228
|
|
512
|
+
]);
|
|
482
513
|
var getLogLevel = (res) => res.retCode === 0 ? "info" : "error";
|
|
483
514
|
var isTradingStopNotModified = (res) => res?.retCode === BYBIT_TRADING_STOP_NOT_MODIFIED_RETCODE;
|
|
484
515
|
var isTradingStopAccepted = (res) => res?.retCode === 0 || isTradingStopNotModified(res);
|
|
@@ -729,7 +760,12 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
729
760
|
const delistings = /* @__PURE__ */ new Map();
|
|
730
761
|
if (!client) return delistings;
|
|
731
762
|
let cursor;
|
|
763
|
+
const seenCursors = /* @__PURE__ */ new Set();
|
|
764
|
+
const deadline = Date.now() + 3e4;
|
|
765
|
+
let pages = 0;
|
|
732
766
|
do {
|
|
767
|
+
if (++pages > 100 || Date.now() >= deadline)
|
|
768
|
+
throw new Error("Bybit delistings exceeded the page or time budget");
|
|
733
769
|
const response = await withTimeout(
|
|
734
770
|
client.getInstrumentsInfo({
|
|
735
771
|
category: BYBIT_CATEGORY2,
|
|
@@ -737,7 +773,7 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
737
773
|
limit: LIMIT,
|
|
738
774
|
cursor
|
|
739
775
|
}),
|
|
740
|
-
1e4,
|
|
776
|
+
Math.min(1e4, Math.max(1, deadline - Date.now())),
|
|
741
777
|
"Bybit delistings"
|
|
742
778
|
);
|
|
743
779
|
if (response.retCode !== 0) {
|
|
@@ -753,9 +789,10 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
753
789
|
}
|
|
754
790
|
}
|
|
755
791
|
const nextCursor = response.result.nextPageCursor;
|
|
756
|
-
if (nextCursor && nextCursor
|
|
792
|
+
if (nextCursor && seenCursors.has(nextCursor)) {
|
|
757
793
|
throw new Error("Bybit delistings pagination did not advance");
|
|
758
794
|
}
|
|
795
|
+
if (nextCursor) seenCursors.add(nextCursor);
|
|
759
796
|
cursor = nextCursor;
|
|
760
797
|
} while (cursor);
|
|
761
798
|
return delistings;
|
|
@@ -1257,18 +1294,83 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
1257
1294
|
}
|
|
1258
1295
|
return positions;
|
|
1259
1296
|
},
|
|
1297
|
+
cancelEntryOrder: async ({ symbol, orderId }) => {
|
|
1298
|
+
const client = await getPrivateClient();
|
|
1299
|
+
if (!client) throw new Error("Bybit private client is unavailable");
|
|
1300
|
+
const result = await withTimeout(
|
|
1301
|
+
client.cancelOrder({
|
|
1302
|
+
category: BYBIT_CATEGORY2,
|
|
1303
|
+
symbol,
|
|
1304
|
+
orderLinkId: orderId
|
|
1305
|
+
}),
|
|
1306
|
+
POSITION_SNAPSHOT_TIMEOUT_MS,
|
|
1307
|
+
`bybit cancel entry ${symbol}`
|
|
1308
|
+
);
|
|
1309
|
+
return result.retCode === 0;
|
|
1310
|
+
},
|
|
1311
|
+
getEntryPositionObservation: async ({ symbol }) => {
|
|
1312
|
+
const client = await getPrivateClient();
|
|
1313
|
+
const marketClient = await getPublicClient();
|
|
1314
|
+
if (!client || !marketClient)
|
|
1315
|
+
throw new Error("Bybit client is unavailable");
|
|
1316
|
+
const result = await withTimeout(
|
|
1317
|
+
client.getPositionInfo({ category: BYBIT_CATEGORY2, symbol }),
|
|
1318
|
+
POSITION_SNAPSHOT_TIMEOUT_MS,
|
|
1319
|
+
`bybit entry position ${symbol}`
|
|
1320
|
+
);
|
|
1321
|
+
if (result.retCode !== 0 || !Array.isArray(result.result?.list) || !result.result.list.length || result.result.nextPageCursor)
|
|
1322
|
+
throw new Error("Bybit entry position observation unavailable");
|
|
1323
|
+
const rows = result.result.list;
|
|
1324
|
+
if (rows.length !== 1 || rows.some(
|
|
1325
|
+
(p2) => p2.symbol !== symbol || p2.positionIdx !== 0 || typeof p2.size !== "string" || !p2.size.trim() || !Number.isFinite(Number(p2.size)) || Number(p2.size) < 0
|
|
1326
|
+
))
|
|
1327
|
+
throw new Error("Invalid Bybit entry position observation");
|
|
1328
|
+
const active = rows.filter((p2) => Number(p2.size) > 0);
|
|
1329
|
+
if (active.length > 1) throw new Error("Ambiguous Bybit entry position");
|
|
1330
|
+
if (!active.length) return null;
|
|
1331
|
+
const p = active[0];
|
|
1332
|
+
const price = Number(p.avgPrice);
|
|
1333
|
+
if (!Number.isFinite(price) || price <= 0 || !["Buy", "Sell"].includes(p.side))
|
|
1334
|
+
throw new Error("Invalid Bybit entry position");
|
|
1335
|
+
const meta = await withTimeout(
|
|
1336
|
+
getSymbolMeta(marketClient, symbol),
|
|
1337
|
+
POSITION_SNAPSHOT_TIMEOUT_MS,
|
|
1338
|
+
`bybit entry metadata ${symbol}`
|
|
1339
|
+
);
|
|
1340
|
+
if (!Number.isFinite(meta.tickSize) || meta.tickSize <= 0)
|
|
1341
|
+
throw new Error("Invalid Bybit entry price tick");
|
|
1342
|
+
const slPrice = p.stopLoss ? Number(p.stopLoss) : void 0;
|
|
1343
|
+
if (slPrice !== void 0 && (!Number.isFinite(slPrice) || slPrice < 0))
|
|
1344
|
+
throw new Error("Invalid Bybit entry stop");
|
|
1345
|
+
return {
|
|
1346
|
+
symbol,
|
|
1347
|
+
qty: Number(p.size),
|
|
1348
|
+
price,
|
|
1349
|
+
direction: p.side === "Buy" ? "LONG" : "SHORT",
|
|
1350
|
+
slPrice,
|
|
1351
|
+
priceTickSize: meta.tickSize
|
|
1352
|
+
};
|
|
1353
|
+
},
|
|
1260
1354
|
getEntryOrderObservation: async ({ symbol, orderId }) => {
|
|
1261
1355
|
const client = await getPrivateClient();
|
|
1262
1356
|
if (!client) throw new Error("Bybit private client is unavailable");
|
|
1263
1357
|
const query = { category: BYBIT_CATEGORY2, symbol, orderLinkId: orderId };
|
|
1264
|
-
const active = await
|
|
1358
|
+
const active = await withTimeout(
|
|
1359
|
+
client.getActiveOrders(query),
|
|
1360
|
+
POSITION_SNAPSHOT_TIMEOUT_MS,
|
|
1361
|
+
`bybit entry orders ${symbol}`
|
|
1362
|
+
);
|
|
1265
1363
|
if (active.retCode !== 0)
|
|
1266
1364
|
throw new Error(`Bybit order observation failed: ${active.retCode}`);
|
|
1267
1365
|
let order = active.result.list.find(
|
|
1268
1366
|
(o) => o.orderLinkId === orderId && o.symbol === symbol
|
|
1269
1367
|
);
|
|
1270
1368
|
if (!order) {
|
|
1271
|
-
const history = await
|
|
1369
|
+
const history = await withTimeout(
|
|
1370
|
+
client.getHistoricOrders(query),
|
|
1371
|
+
POSITION_SNAPSHOT_TIMEOUT_MS,
|
|
1372
|
+
`bybit entry history ${symbol}`
|
|
1373
|
+
);
|
|
1272
1374
|
if (history.retCode !== 0)
|
|
1273
1375
|
throw new Error(`Bybit order history failed: ${history.retCode}`);
|
|
1274
1376
|
order = history.result.list.find(
|
|
@@ -1277,7 +1379,7 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
1277
1379
|
}
|
|
1278
1380
|
if (!order) return null;
|
|
1279
1381
|
const filledQty = Number(order.cumExecQty);
|
|
1280
|
-
if (!Number.isFinite(filledQty) || filledQty < 0)
|
|
1382
|
+
if (typeof order.cumExecQty !== "string" || !order.cumExecQty.trim() || !Number.isFinite(filledQty) || filledQty < 0 || order.orderStatus === "Filled" && filledQty === 0)
|
|
1281
1383
|
throw new Error("Invalid Bybit cumulative execution quantity");
|
|
1282
1384
|
const status = order.orderStatus === "Filled" ? "filled" : order.orderStatus === "Rejected" ? "rejected" : ["Cancelled", "PartiallyFilledCanceled", "Deactivated"].includes(
|
|
1283
1385
|
order.orderStatus
|
|
@@ -1722,6 +1824,11 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
1722
1824
|
if (signal) {
|
|
1723
1825
|
signal.orderFailureReason = typeof orderRes.retMsg === "string" && orderRes.retMsg.trim() ? orderRes.retMsg.trim() : `BYBIT_RETCODE_${orderRes.retCode}`;
|
|
1724
1826
|
}
|
|
1827
|
+
if (!definiteOrderRejections.has(orderRes.retCode)) {
|
|
1828
|
+
throw new Error(
|
|
1829
|
+
`BYBIT_ORDER_SUBMISSION_UNCONFIRMED:${orderRes.retCode}`
|
|
1830
|
+
);
|
|
1831
|
+
}
|
|
1725
1832
|
await onRejected?.();
|
|
1726
1833
|
return false;
|
|
1727
1834
|
}
|
|
@@ -1738,7 +1845,7 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
1738
1845
|
setPositionProtection,
|
|
1739
1846
|
setTakeProfits,
|
|
1740
1847
|
setStopLoss,
|
|
1741
|
-
closePosition: async ({ symbol, direction }) => {
|
|
1848
|
+
closePosition: async ({ symbol, direction, orderId }) => {
|
|
1742
1849
|
invalidatePositionSnapshot(symbol);
|
|
1743
1850
|
const client = await getPrivateClient();
|
|
1744
1851
|
if (!client) {
|
|
@@ -1750,7 +1857,9 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
1750
1857
|
side: direction === "LONG" ? "Sell" : "Buy",
|
|
1751
1858
|
orderType: "Market",
|
|
1752
1859
|
qty: "0",
|
|
1753
|
-
reduceOnly: true
|
|
1860
|
+
reduceOnly: true,
|
|
1861
|
+
closeOnTrigger: true,
|
|
1862
|
+
...orderId ? { orderLinkId: orderId } : {}
|
|
1754
1863
|
});
|
|
1755
1864
|
logger.log(
|
|
1756
1865
|
getLogLevel(closeRes),
|
|
@@ -1760,6 +1869,11 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
1760
1869
|
(0, import_data.toJson)(closeRes, true)
|
|
1761
1870
|
);
|
|
1762
1871
|
if (closeRes.retCode !== 0) {
|
|
1872
|
+
if (!definiteOrderRejections.has(closeRes.retCode)) {
|
|
1873
|
+
throw new Error(
|
|
1874
|
+
`BYBIT_CLOSE_SUBMISSION_UNCONFIRMED:${closeRes.retCode}`
|
|
1875
|
+
);
|
|
1876
|
+
}
|
|
1763
1877
|
return false;
|
|
1764
1878
|
}
|
|
1765
1879
|
invalidatePositionSnapshot(symbol);
|
package/dist/index.mjs
CHANGED
|
@@ -431,6 +431,37 @@ var INTERVAL_TO_MINUTES = {
|
|
|
431
431
|
W: 10080,
|
|
432
432
|
M: 43200
|
|
433
433
|
};
|
|
434
|
+
var definiteOrderRejections = /* @__PURE__ */ new Set([
|
|
435
|
+
10001,
|
|
436
|
+
10002,
|
|
437
|
+
10003,
|
|
438
|
+
10004,
|
|
439
|
+
10005,
|
|
440
|
+
10007,
|
|
441
|
+
10008,
|
|
442
|
+
10009,
|
|
443
|
+
10010,
|
|
444
|
+
10024,
|
|
445
|
+
10027,
|
|
446
|
+
10028,
|
|
447
|
+
10029,
|
|
448
|
+
100028,
|
|
449
|
+
110003,
|
|
450
|
+
110004,
|
|
451
|
+
110006,
|
|
452
|
+
110007,
|
|
453
|
+
110009,
|
|
454
|
+
110012,
|
|
455
|
+
110017,
|
|
456
|
+
110018,
|
|
457
|
+
110019,
|
|
458
|
+
110020,
|
|
459
|
+
110021,
|
|
460
|
+
110023,
|
|
461
|
+
30208,
|
|
462
|
+
30209,
|
|
463
|
+
30228
|
|
464
|
+
]);
|
|
434
465
|
var getLogLevel = (res) => res.retCode === 0 ? "info" : "error";
|
|
435
466
|
var isTradingStopNotModified = (res) => res?.retCode === BYBIT_TRADING_STOP_NOT_MODIFIED_RETCODE;
|
|
436
467
|
var isTradingStopAccepted = (res) => res?.retCode === 0 || isTradingStopNotModified(res);
|
|
@@ -681,7 +712,12 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
681
712
|
const delistings = /* @__PURE__ */ new Map();
|
|
682
713
|
if (!client) return delistings;
|
|
683
714
|
let cursor;
|
|
715
|
+
const seenCursors = /* @__PURE__ */ new Set();
|
|
716
|
+
const deadline = Date.now() + 3e4;
|
|
717
|
+
let pages = 0;
|
|
684
718
|
do {
|
|
719
|
+
if (++pages > 100 || Date.now() >= deadline)
|
|
720
|
+
throw new Error("Bybit delistings exceeded the page or time budget");
|
|
685
721
|
const response = await withTimeout(
|
|
686
722
|
client.getInstrumentsInfo({
|
|
687
723
|
category: BYBIT_CATEGORY2,
|
|
@@ -689,7 +725,7 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
689
725
|
limit: LIMIT,
|
|
690
726
|
cursor
|
|
691
727
|
}),
|
|
692
|
-
1e4,
|
|
728
|
+
Math.min(1e4, Math.max(1, deadline - Date.now())),
|
|
693
729
|
"Bybit delistings"
|
|
694
730
|
);
|
|
695
731
|
if (response.retCode !== 0) {
|
|
@@ -705,9 +741,10 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
705
741
|
}
|
|
706
742
|
}
|
|
707
743
|
const nextCursor = response.result.nextPageCursor;
|
|
708
|
-
if (nextCursor && nextCursor
|
|
744
|
+
if (nextCursor && seenCursors.has(nextCursor)) {
|
|
709
745
|
throw new Error("Bybit delistings pagination did not advance");
|
|
710
746
|
}
|
|
747
|
+
if (nextCursor) seenCursors.add(nextCursor);
|
|
711
748
|
cursor = nextCursor;
|
|
712
749
|
} while (cursor);
|
|
713
750
|
return delistings;
|
|
@@ -1209,18 +1246,83 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
1209
1246
|
}
|
|
1210
1247
|
return positions;
|
|
1211
1248
|
},
|
|
1249
|
+
cancelEntryOrder: async ({ symbol, orderId }) => {
|
|
1250
|
+
const client = await getPrivateClient();
|
|
1251
|
+
if (!client) throw new Error("Bybit private client is unavailable");
|
|
1252
|
+
const result = await withTimeout(
|
|
1253
|
+
client.cancelOrder({
|
|
1254
|
+
category: BYBIT_CATEGORY2,
|
|
1255
|
+
symbol,
|
|
1256
|
+
orderLinkId: orderId
|
|
1257
|
+
}),
|
|
1258
|
+
POSITION_SNAPSHOT_TIMEOUT_MS,
|
|
1259
|
+
`bybit cancel entry ${symbol}`
|
|
1260
|
+
);
|
|
1261
|
+
return result.retCode === 0;
|
|
1262
|
+
},
|
|
1263
|
+
getEntryPositionObservation: async ({ symbol }) => {
|
|
1264
|
+
const client = await getPrivateClient();
|
|
1265
|
+
const marketClient = await getPublicClient();
|
|
1266
|
+
if (!client || !marketClient)
|
|
1267
|
+
throw new Error("Bybit client is unavailable");
|
|
1268
|
+
const result = await withTimeout(
|
|
1269
|
+
client.getPositionInfo({ category: BYBIT_CATEGORY2, symbol }),
|
|
1270
|
+
POSITION_SNAPSHOT_TIMEOUT_MS,
|
|
1271
|
+
`bybit entry position ${symbol}`
|
|
1272
|
+
);
|
|
1273
|
+
if (result.retCode !== 0 || !Array.isArray(result.result?.list) || !result.result.list.length || result.result.nextPageCursor)
|
|
1274
|
+
throw new Error("Bybit entry position observation unavailable");
|
|
1275
|
+
const rows = result.result.list;
|
|
1276
|
+
if (rows.length !== 1 || rows.some(
|
|
1277
|
+
(p2) => p2.symbol !== symbol || p2.positionIdx !== 0 || typeof p2.size !== "string" || !p2.size.trim() || !Number.isFinite(Number(p2.size)) || Number(p2.size) < 0
|
|
1278
|
+
))
|
|
1279
|
+
throw new Error("Invalid Bybit entry position observation");
|
|
1280
|
+
const active = rows.filter((p2) => Number(p2.size) > 0);
|
|
1281
|
+
if (active.length > 1) throw new Error("Ambiguous Bybit entry position");
|
|
1282
|
+
if (!active.length) return null;
|
|
1283
|
+
const p = active[0];
|
|
1284
|
+
const price = Number(p.avgPrice);
|
|
1285
|
+
if (!Number.isFinite(price) || price <= 0 || !["Buy", "Sell"].includes(p.side))
|
|
1286
|
+
throw new Error("Invalid Bybit entry position");
|
|
1287
|
+
const meta = await withTimeout(
|
|
1288
|
+
getSymbolMeta(marketClient, symbol),
|
|
1289
|
+
POSITION_SNAPSHOT_TIMEOUT_MS,
|
|
1290
|
+
`bybit entry metadata ${symbol}`
|
|
1291
|
+
);
|
|
1292
|
+
if (!Number.isFinite(meta.tickSize) || meta.tickSize <= 0)
|
|
1293
|
+
throw new Error("Invalid Bybit entry price tick");
|
|
1294
|
+
const slPrice = p.stopLoss ? Number(p.stopLoss) : void 0;
|
|
1295
|
+
if (slPrice !== void 0 && (!Number.isFinite(slPrice) || slPrice < 0))
|
|
1296
|
+
throw new Error("Invalid Bybit entry stop");
|
|
1297
|
+
return {
|
|
1298
|
+
symbol,
|
|
1299
|
+
qty: Number(p.size),
|
|
1300
|
+
price,
|
|
1301
|
+
direction: p.side === "Buy" ? "LONG" : "SHORT",
|
|
1302
|
+
slPrice,
|
|
1303
|
+
priceTickSize: meta.tickSize
|
|
1304
|
+
};
|
|
1305
|
+
},
|
|
1212
1306
|
getEntryOrderObservation: async ({ symbol, orderId }) => {
|
|
1213
1307
|
const client = await getPrivateClient();
|
|
1214
1308
|
if (!client) throw new Error("Bybit private client is unavailable");
|
|
1215
1309
|
const query = { category: BYBIT_CATEGORY2, symbol, orderLinkId: orderId };
|
|
1216
|
-
const active = await
|
|
1310
|
+
const active = await withTimeout(
|
|
1311
|
+
client.getActiveOrders(query),
|
|
1312
|
+
POSITION_SNAPSHOT_TIMEOUT_MS,
|
|
1313
|
+
`bybit entry orders ${symbol}`
|
|
1314
|
+
);
|
|
1217
1315
|
if (active.retCode !== 0)
|
|
1218
1316
|
throw new Error(`Bybit order observation failed: ${active.retCode}`);
|
|
1219
1317
|
let order = active.result.list.find(
|
|
1220
1318
|
(o) => o.orderLinkId === orderId && o.symbol === symbol
|
|
1221
1319
|
);
|
|
1222
1320
|
if (!order) {
|
|
1223
|
-
const history = await
|
|
1321
|
+
const history = await withTimeout(
|
|
1322
|
+
client.getHistoricOrders(query),
|
|
1323
|
+
POSITION_SNAPSHOT_TIMEOUT_MS,
|
|
1324
|
+
`bybit entry history ${symbol}`
|
|
1325
|
+
);
|
|
1224
1326
|
if (history.retCode !== 0)
|
|
1225
1327
|
throw new Error(`Bybit order history failed: ${history.retCode}`);
|
|
1226
1328
|
order = history.result.list.find(
|
|
@@ -1229,7 +1331,7 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
1229
1331
|
}
|
|
1230
1332
|
if (!order) return null;
|
|
1231
1333
|
const filledQty = Number(order.cumExecQty);
|
|
1232
|
-
if (!Number.isFinite(filledQty) || filledQty < 0)
|
|
1334
|
+
if (typeof order.cumExecQty !== "string" || !order.cumExecQty.trim() || !Number.isFinite(filledQty) || filledQty < 0 || order.orderStatus === "Filled" && filledQty === 0)
|
|
1233
1335
|
throw new Error("Invalid Bybit cumulative execution quantity");
|
|
1234
1336
|
const status = order.orderStatus === "Filled" ? "filled" : order.orderStatus === "Rejected" ? "rejected" : ["Cancelled", "PartiallyFilledCanceled", "Deactivated"].includes(
|
|
1235
1337
|
order.orderStatus
|
|
@@ -1674,6 +1776,11 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
1674
1776
|
if (signal) {
|
|
1675
1777
|
signal.orderFailureReason = typeof orderRes.retMsg === "string" && orderRes.retMsg.trim() ? orderRes.retMsg.trim() : `BYBIT_RETCODE_${orderRes.retCode}`;
|
|
1676
1778
|
}
|
|
1779
|
+
if (!definiteOrderRejections.has(orderRes.retCode)) {
|
|
1780
|
+
throw new Error(
|
|
1781
|
+
`BYBIT_ORDER_SUBMISSION_UNCONFIRMED:${orderRes.retCode}`
|
|
1782
|
+
);
|
|
1783
|
+
}
|
|
1677
1784
|
await onRejected?.();
|
|
1678
1785
|
return false;
|
|
1679
1786
|
}
|
|
@@ -1690,7 +1797,7 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
1690
1797
|
setPositionProtection,
|
|
1691
1798
|
setTakeProfits,
|
|
1692
1799
|
setStopLoss,
|
|
1693
|
-
closePosition: async ({ symbol, direction }) => {
|
|
1800
|
+
closePosition: async ({ symbol, direction, orderId }) => {
|
|
1694
1801
|
invalidatePositionSnapshot(symbol);
|
|
1695
1802
|
const client = await getPrivateClient();
|
|
1696
1803
|
if (!client) {
|
|
@@ -1702,7 +1809,9 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
1702
1809
|
side: direction === "LONG" ? "Sell" : "Buy",
|
|
1703
1810
|
orderType: "Market",
|
|
1704
1811
|
qty: "0",
|
|
1705
|
-
reduceOnly: true
|
|
1812
|
+
reduceOnly: true,
|
|
1813
|
+
closeOnTrigger: true,
|
|
1814
|
+
...orderId ? { orderLinkId: orderId } : {}
|
|
1706
1815
|
});
|
|
1707
1816
|
logger.log(
|
|
1708
1817
|
getLogLevel(closeRes),
|
|
@@ -1712,6 +1821,11 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
1712
1821
|
toJson(closeRes, true)
|
|
1713
1822
|
);
|
|
1714
1823
|
if (closeRes.retCode !== 0) {
|
|
1824
|
+
if (!definiteOrderRejections.has(closeRes.retCode)) {
|
|
1825
|
+
throw new Error(
|
|
1826
|
+
`BYBIT_CLOSE_SUBMISSION_UNCONFIRMED:${closeRes.retCode}`
|
|
1827
|
+
);
|
|
1828
|
+
}
|
|
1715
1829
|
return false;
|
|
1716
1830
|
}
|
|
1717
1831
|
invalidatePositionSnapshot(symbol);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tradejs/connectors",
|
|
3
|
-
"version": "3.1.29-beta.
|
|
3
|
+
"version": "3.1.29-beta.304",
|
|
4
4
|
"description": "MIT-licensed exchange connectors and market data providers for the TradeJS framework.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tradejs",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@tradejs/core": "^3.1.29-beta.
|
|
43
|
-
"@tradejs/types": "^3.1.29-beta.
|
|
42
|
+
"@tradejs/core": "^3.1.29-beta.304",
|
|
43
|
+
"@tradejs/types": "^3.1.29-beta.304",
|
|
44
44
|
"bybit-api": "^4.7.1",
|
|
45
45
|
"chalk": "4.1.2",
|
|
46
46
|
"lodash": "^4.18.1"
|