@tradejs/connectors 3.1.29-beta.305 → 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 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
  };
@@ -1314,22 +1315,41 @@ var ByBitConnectorCreator = async (config, runtime) => {
1314
1315
  const marketClient = await getPublicClient();
1315
1316
  if (!client || !marketClient)
1316
1317
  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)
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)
1323
1351
  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];
1352
+ if (!p) return null;
1333
1353
  const price = Number(p.avgPrice);
1334
1354
  if (!Number.isFinite(price) || price <= 0 || !["Buy", "Sell"].includes(p.side))
1335
1355
  throw new Error("Invalid Bybit entry position");
@@ -1341,14 +1361,18 @@ var ByBitConnectorCreator = async (config, runtime) => {
1341
1361
  if (!Number.isFinite(meta.tickSize) || meta.tickSize <= 0)
1342
1362
  throw new Error("Invalid Bybit entry price tick");
1343
1363
  const slPrice = p.stopLoss ? Number(p.stopLoss) : void 0;
1364
+ const tpPrice = p.takeProfit ? Number(p.takeProfit) : void 0;
1344
1365
  if (slPrice !== void 0 && (!Number.isFinite(slPrice) || slPrice < 0))
1345
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");
1346
1369
  return {
1347
1370
  symbol,
1348
1371
  qty: Number(p.size),
1349
1372
  price,
1350
1373
  direction: p.side === "Buy" ? "LONG" : "SHORT",
1351
1374
  slPrice,
1375
+ tpPrice,
1352
1376
  priceTickSize: meta.tickSize
1353
1377
  };
1354
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
  };
@@ -1266,22 +1267,41 @@ var ByBitConnectorCreator = async (config, runtime) => {
1266
1267
  const marketClient = await getPublicClient();
1267
1268
  if (!client || !marketClient)
1268
1269
  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)
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)
1275
1303
  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];
1304
+ if (!p) return null;
1285
1305
  const price = Number(p.avgPrice);
1286
1306
  if (!Number.isFinite(price) || price <= 0 || !["Buy", "Sell"].includes(p.side))
1287
1307
  throw new Error("Invalid Bybit entry position");
@@ -1293,14 +1313,18 @@ var ByBitConnectorCreator = async (config, runtime) => {
1293
1313
  if (!Number.isFinite(meta.tickSize) || meta.tickSize <= 0)
1294
1314
  throw new Error("Invalid Bybit entry price tick");
1295
1315
  const slPrice = p.stopLoss ? Number(p.stopLoss) : void 0;
1316
+ const tpPrice = p.takeProfit ? Number(p.takeProfit) : void 0;
1296
1317
  if (slPrice !== void 0 && (!Number.isFinite(slPrice) || slPrice < 0))
1297
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");
1298
1321
  return {
1299
1322
  symbol,
1300
1323
  qty: Number(p.size),
1301
1324
  price,
1302
1325
  direction: p.side === "Buy" ? "LONG" : "SHORT",
1303
1326
  slPrice,
1327
+ tpPrice,
1304
1328
  priceTickSize: meta.tickSize
1305
1329
  };
1306
1330
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tradejs/connectors",
3
- "version": "3.1.29-beta.305",
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.305",
43
- "@tradejs/types": "^3.1.29-beta.305",
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"