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