@tradejs/connectors 2.0.2 → 2.0.4
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 +25 -0
- package/dist/index.mjs +25 -0
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -492,6 +492,7 @@ var mapPositionData = (data) => {
|
|
|
492
492
|
symbol: item.symbol,
|
|
493
493
|
price: parseFloat(item.avgPrice),
|
|
494
494
|
slPrice: parseFloat(item.stopLoss || ""),
|
|
495
|
+
tpPrice: parseFloat(item.takeProfit || ""),
|
|
495
496
|
qty: parseFloat(item.size),
|
|
496
497
|
direction: item.side === "Buy" ? "LONG" : "SHORT"
|
|
497
498
|
}));
|
|
@@ -1387,6 +1388,7 @@ var ByBitConnectorCreator = async (config) => {
|
|
|
1387
1388
|
qty,
|
|
1388
1389
|
direction,
|
|
1389
1390
|
isLimit,
|
|
1391
|
+
positionIntent,
|
|
1390
1392
|
orderId,
|
|
1391
1393
|
signal,
|
|
1392
1394
|
leverage
|
|
@@ -1401,6 +1403,29 @@ var ByBitConnectorCreator = async (config) => {
|
|
|
1401
1403
|
return false;
|
|
1402
1404
|
}
|
|
1403
1405
|
const isLong = direction === "LONG";
|
|
1406
|
+
if (positionIntent === "increase") {
|
|
1407
|
+
const currentPosition = await getPositionSnapshot(symbol);
|
|
1408
|
+
if (!currentPosition || currentPosition.direction !== direction) {
|
|
1409
|
+
const failureReason = currentPosition ? "POSITION_DIRECTION_MISMATCH" : "POSITION_NOT_FOUND";
|
|
1410
|
+
if (signal) {
|
|
1411
|
+
signal.orderFailureReason = failureReason;
|
|
1412
|
+
}
|
|
1413
|
+
import_logger3.logger.log(
|
|
1414
|
+
"warn",
|
|
1415
|
+
"placeOrder: rejected position increase: %s",
|
|
1416
|
+
(0, import_data2.toJson)(
|
|
1417
|
+
{
|
|
1418
|
+
symbol,
|
|
1419
|
+
direction,
|
|
1420
|
+
currentDirection: currentPosition?.direction ?? null,
|
|
1421
|
+
failureReason
|
|
1422
|
+
},
|
|
1423
|
+
true
|
|
1424
|
+
)
|
|
1425
|
+
);
|
|
1426
|
+
return false;
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1404
1429
|
const meta = await getSymbolMeta(marketDataClient, symbol);
|
|
1405
1430
|
const normalizedQty = normalizeQty(qty, meta);
|
|
1406
1431
|
const minNormalizedQty = normalizeQty(meta.minOrderQty, meta);
|
package/dist/index.mjs
CHANGED
|
@@ -447,6 +447,7 @@ var mapPositionData = (data) => {
|
|
|
447
447
|
symbol: item.symbol,
|
|
448
448
|
price: parseFloat(item.avgPrice),
|
|
449
449
|
slPrice: parseFloat(item.stopLoss || ""),
|
|
450
|
+
tpPrice: parseFloat(item.takeProfit || ""),
|
|
450
451
|
qty: parseFloat(item.size),
|
|
451
452
|
direction: item.side === "Buy" ? "LONG" : "SHORT"
|
|
452
453
|
}));
|
|
@@ -1344,6 +1345,7 @@ var ByBitConnectorCreator = async (config) => {
|
|
|
1344
1345
|
qty,
|
|
1345
1346
|
direction,
|
|
1346
1347
|
isLimit,
|
|
1348
|
+
positionIntent,
|
|
1347
1349
|
orderId,
|
|
1348
1350
|
signal,
|
|
1349
1351
|
leverage
|
|
@@ -1358,6 +1360,29 @@ var ByBitConnectorCreator = async (config) => {
|
|
|
1358
1360
|
return false;
|
|
1359
1361
|
}
|
|
1360
1362
|
const isLong = direction === "LONG";
|
|
1363
|
+
if (positionIntent === "increase") {
|
|
1364
|
+
const currentPosition = await getPositionSnapshot(symbol);
|
|
1365
|
+
if (!currentPosition || currentPosition.direction !== direction) {
|
|
1366
|
+
const failureReason = currentPosition ? "POSITION_DIRECTION_MISMATCH" : "POSITION_NOT_FOUND";
|
|
1367
|
+
if (signal) {
|
|
1368
|
+
signal.orderFailureReason = failureReason;
|
|
1369
|
+
}
|
|
1370
|
+
logger3.log(
|
|
1371
|
+
"warn",
|
|
1372
|
+
"placeOrder: rejected position increase: %s",
|
|
1373
|
+
toJson(
|
|
1374
|
+
{
|
|
1375
|
+
symbol,
|
|
1376
|
+
direction,
|
|
1377
|
+
currentDirection: currentPosition?.direction ?? null,
|
|
1378
|
+
failureReason
|
|
1379
|
+
},
|
|
1380
|
+
true
|
|
1381
|
+
)
|
|
1382
|
+
);
|
|
1383
|
+
return false;
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1361
1386
|
const meta = await getSymbolMeta(marketDataClient, symbol);
|
|
1362
1387
|
const normalizedQty = normalizeQty(qty, meta);
|
|
1363
1388
|
const minNormalizedQty = normalizeQty(meta.minOrderQty, meta);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tradejs/connectors",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "MIT-licensed exchange connectors and market data providers for the TradeJS framework.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tradejs",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@tradejs/core": "^2.0.
|
|
37
|
-
"@tradejs/infra": "^2.0.
|
|
38
|
-
"@tradejs/node": "^2.0.
|
|
39
|
-
"@tradejs/types": "^2.0.
|
|
36
|
+
"@tradejs/core": "^2.0.4",
|
|
37
|
+
"@tradejs/infra": "^2.0.4",
|
|
38
|
+
"@tradejs/node": "^2.0.4",
|
|
39
|
+
"@tradejs/types": "^2.0.4",
|
|
40
40
|
"bybit-api": "^4.6.2",
|
|
41
41
|
"chalk": "4.1.2",
|
|
42
42
|
"lodash": "^4.18.1"
|