@tradejs/connectors 3.1.29-beta.304 → 3.1.29-beta.306
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 +40 -15
- package/dist/index.mjs +40 -15
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -445,6 +445,7 @@ var LIMIT = 1e3;
|
|
|
445
445
|
var BYBIT_CATEGORY2 = "linear";
|
|
446
446
|
var BYBIT_CAPABILITIES = {
|
|
447
447
|
orderSubmissionValidation: true,
|
|
448
|
+
nativeFullPositionTakeProfit: true,
|
|
448
449
|
supportedUniverses: ["crypto", "tradfi"],
|
|
449
450
|
defaultUniverse: "crypto"
|
|
450
451
|
};
|
|
@@ -506,6 +507,7 @@ var definiteOrderRejections = /* @__PURE__ */ new Set([
|
|
|
506
507
|
110020,
|
|
507
508
|
110021,
|
|
508
509
|
110023,
|
|
510
|
+
110126,
|
|
509
511
|
30208,
|
|
510
512
|
30209,
|
|
511
513
|
30228
|
|
@@ -1313,22 +1315,41 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
1313
1315
|
const marketClient = await getPublicClient();
|
|
1314
1316
|
if (!client || !marketClient)
|
|
1315
1317
|
throw new Error("Bybit client is unavailable");
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1318
|
+
let cursor;
|
|
1319
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1320
|
+
let sawPositionRow = false;
|
|
1321
|
+
let p;
|
|
1322
|
+
do {
|
|
1323
|
+
const result = await withTimeout(
|
|
1324
|
+
client.getPositionInfo({
|
|
1325
|
+
category: BYBIT_CATEGORY2,
|
|
1326
|
+
symbol,
|
|
1327
|
+
...cursor ? { cursor } : {}
|
|
1328
|
+
}),
|
|
1329
|
+
POSITION_SNAPSHOT_TIMEOUT_MS,
|
|
1330
|
+
`bybit entry position ${symbol}`
|
|
1331
|
+
);
|
|
1332
|
+
if (result.retCode !== 0 || !Array.isArray(result.result?.list))
|
|
1333
|
+
throw new Error("Bybit entry position observation unavailable");
|
|
1334
|
+
for (const row of result.result.list) {
|
|
1335
|
+
const qty = Number(row.size);
|
|
1336
|
+
if (row.symbol !== symbol || row.positionIdx !== 0 || typeof row.size !== "string" || !row.size.trim() || !Number.isFinite(qty) || qty < 0)
|
|
1337
|
+
throw new Error("Invalid Bybit entry position observation");
|
|
1338
|
+
sawPositionRow = true;
|
|
1339
|
+
if (qty === 0) continue;
|
|
1340
|
+
if (p) throw new Error("Ambiguous Bybit entry position");
|
|
1341
|
+
p = row;
|
|
1342
|
+
}
|
|
1343
|
+
cursor = result.result.nextPageCursor || void 0;
|
|
1344
|
+
if (cursor) {
|
|
1345
|
+
if (seen.has(cursor) || seen.size >= 19)
|
|
1346
|
+
throw new Error("Incomplete Bybit entry position pagination");
|
|
1347
|
+
seen.add(cursor);
|
|
1348
|
+
}
|
|
1349
|
+
} while (cursor);
|
|
1350
|
+
if (!sawPositionRow)
|
|
1322
1351
|
throw new Error("Bybit entry position observation unavailable");
|
|
1323
|
-
|
|
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];
|
|
1352
|
+
if (!p) return null;
|
|
1332
1353
|
const price = Number(p.avgPrice);
|
|
1333
1354
|
if (!Number.isFinite(price) || price <= 0 || !["Buy", "Sell"].includes(p.side))
|
|
1334
1355
|
throw new Error("Invalid Bybit entry position");
|
|
@@ -1340,14 +1361,18 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
1340
1361
|
if (!Number.isFinite(meta.tickSize) || meta.tickSize <= 0)
|
|
1341
1362
|
throw new Error("Invalid Bybit entry price tick");
|
|
1342
1363
|
const slPrice = p.stopLoss ? Number(p.stopLoss) : void 0;
|
|
1364
|
+
const tpPrice = p.takeProfit ? Number(p.takeProfit) : void 0;
|
|
1343
1365
|
if (slPrice !== void 0 && (!Number.isFinite(slPrice) || slPrice < 0))
|
|
1344
1366
|
throw new Error("Invalid Bybit entry stop");
|
|
1367
|
+
if (tpPrice !== void 0 && (!Number.isFinite(tpPrice) || tpPrice < 0))
|
|
1368
|
+
throw new Error("Invalid Bybit entry take profit");
|
|
1345
1369
|
return {
|
|
1346
1370
|
symbol,
|
|
1347
1371
|
qty: Number(p.size),
|
|
1348
1372
|
price,
|
|
1349
1373
|
direction: p.side === "Buy" ? "LONG" : "SHORT",
|
|
1350
1374
|
slPrice,
|
|
1375
|
+
tpPrice,
|
|
1351
1376
|
priceTickSize: meta.tickSize
|
|
1352
1377
|
};
|
|
1353
1378
|
},
|
package/dist/index.mjs
CHANGED
|
@@ -397,6 +397,7 @@ var LIMIT = 1e3;
|
|
|
397
397
|
var BYBIT_CATEGORY2 = "linear";
|
|
398
398
|
var BYBIT_CAPABILITIES = {
|
|
399
399
|
orderSubmissionValidation: true,
|
|
400
|
+
nativeFullPositionTakeProfit: true,
|
|
400
401
|
supportedUniverses: ["crypto", "tradfi"],
|
|
401
402
|
defaultUniverse: "crypto"
|
|
402
403
|
};
|
|
@@ -458,6 +459,7 @@ var definiteOrderRejections = /* @__PURE__ */ new Set([
|
|
|
458
459
|
110020,
|
|
459
460
|
110021,
|
|
460
461
|
110023,
|
|
462
|
+
110126,
|
|
461
463
|
30208,
|
|
462
464
|
30209,
|
|
463
465
|
30228
|
|
@@ -1265,22 +1267,41 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
1265
1267
|
const marketClient = await getPublicClient();
|
|
1266
1268
|
if (!client || !marketClient)
|
|
1267
1269
|
throw new Error("Bybit client is unavailable");
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1270
|
+
let cursor;
|
|
1271
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1272
|
+
let sawPositionRow = false;
|
|
1273
|
+
let p;
|
|
1274
|
+
do {
|
|
1275
|
+
const result = await withTimeout(
|
|
1276
|
+
client.getPositionInfo({
|
|
1277
|
+
category: BYBIT_CATEGORY2,
|
|
1278
|
+
symbol,
|
|
1279
|
+
...cursor ? { cursor } : {}
|
|
1280
|
+
}),
|
|
1281
|
+
POSITION_SNAPSHOT_TIMEOUT_MS,
|
|
1282
|
+
`bybit entry position ${symbol}`
|
|
1283
|
+
);
|
|
1284
|
+
if (result.retCode !== 0 || !Array.isArray(result.result?.list))
|
|
1285
|
+
throw new Error("Bybit entry position observation unavailable");
|
|
1286
|
+
for (const row of result.result.list) {
|
|
1287
|
+
const qty = Number(row.size);
|
|
1288
|
+
if (row.symbol !== symbol || row.positionIdx !== 0 || typeof row.size !== "string" || !row.size.trim() || !Number.isFinite(qty) || qty < 0)
|
|
1289
|
+
throw new Error("Invalid Bybit entry position observation");
|
|
1290
|
+
sawPositionRow = true;
|
|
1291
|
+
if (qty === 0) continue;
|
|
1292
|
+
if (p) throw new Error("Ambiguous Bybit entry position");
|
|
1293
|
+
p = row;
|
|
1294
|
+
}
|
|
1295
|
+
cursor = result.result.nextPageCursor || void 0;
|
|
1296
|
+
if (cursor) {
|
|
1297
|
+
if (seen.has(cursor) || seen.size >= 19)
|
|
1298
|
+
throw new Error("Incomplete Bybit entry position pagination");
|
|
1299
|
+
seen.add(cursor);
|
|
1300
|
+
}
|
|
1301
|
+
} while (cursor);
|
|
1302
|
+
if (!sawPositionRow)
|
|
1274
1303
|
throw new Error("Bybit entry position observation unavailable");
|
|
1275
|
-
|
|
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];
|
|
1304
|
+
if (!p) return null;
|
|
1284
1305
|
const price = Number(p.avgPrice);
|
|
1285
1306
|
if (!Number.isFinite(price) || price <= 0 || !["Buy", "Sell"].includes(p.side))
|
|
1286
1307
|
throw new Error("Invalid Bybit entry position");
|
|
@@ -1292,14 +1313,18 @@ var ByBitConnectorCreator = async (config, runtime) => {
|
|
|
1292
1313
|
if (!Number.isFinite(meta.tickSize) || meta.tickSize <= 0)
|
|
1293
1314
|
throw new Error("Invalid Bybit entry price tick");
|
|
1294
1315
|
const slPrice = p.stopLoss ? Number(p.stopLoss) : void 0;
|
|
1316
|
+
const tpPrice = p.takeProfit ? Number(p.takeProfit) : void 0;
|
|
1295
1317
|
if (slPrice !== void 0 && (!Number.isFinite(slPrice) || slPrice < 0))
|
|
1296
1318
|
throw new Error("Invalid Bybit entry stop");
|
|
1319
|
+
if (tpPrice !== void 0 && (!Number.isFinite(tpPrice) || tpPrice < 0))
|
|
1320
|
+
throw new Error("Invalid Bybit entry take profit");
|
|
1297
1321
|
return {
|
|
1298
1322
|
symbol,
|
|
1299
1323
|
qty: Number(p.size),
|
|
1300
1324
|
price,
|
|
1301
1325
|
direction: p.side === "Buy" ? "LONG" : "SHORT",
|
|
1302
1326
|
slPrice,
|
|
1327
|
+
tpPrice,
|
|
1303
1328
|
priceTickSize: meta.tickSize
|
|
1304
1329
|
};
|
|
1305
1330
|
},
|
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.306",
|
|
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.306",
|
|
43
|
+
"@tradejs/types": "^3.1.29-beta.306",
|
|
44
44
|
"bybit-api": "^4.7.1",
|
|
45
45
|
"chalk": "4.1.2",
|
|
46
46
|
"lodash": "^4.18.1"
|