@gbozee/ultimate 0.0.2-next.66 → 0.0.2-next.68
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.cjs +103 -56
- package/dist/index.js +94 -61
- package/dist/mcp-client.cjs +61 -40
- package/dist/mcp-client.js +51 -33
- package/dist/mcp-server.cjs +118 -71
- package/dist/mcp-server.js +109 -76
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4,39 +4,60 @@ var __defProp = Object.defineProperty;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
7
12
|
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
8
20
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
21
|
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
22
|
for (let key of __getOwnPropNames(mod))
|
|
11
23
|
if (!__hasOwnProp.call(to, key))
|
|
12
24
|
__defProp(to, key, {
|
|
13
|
-
get: (
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
14
26
|
enumerable: true
|
|
15
27
|
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
16
30
|
return to;
|
|
17
31
|
};
|
|
18
|
-
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
19
32
|
var __toCommonJS = (from) => {
|
|
20
|
-
var entry = __moduleCache.get(from), desc;
|
|
33
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
21
34
|
if (entry)
|
|
22
35
|
return entry;
|
|
23
36
|
entry = __defProp({}, "__esModule", { value: true });
|
|
24
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
38
|
+
for (var key of __getOwnPropNames(from))
|
|
39
|
+
if (!__hasOwnProp.call(entry, key))
|
|
40
|
+
__defProp(entry, key, {
|
|
41
|
+
get: __accessProp.bind(from, key),
|
|
42
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
43
|
+
});
|
|
44
|
+
}
|
|
29
45
|
__moduleCache.set(from, entry);
|
|
30
46
|
return entry;
|
|
31
47
|
};
|
|
48
|
+
var __moduleCache;
|
|
32
49
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
50
|
+
var __returnValue = (v) => v;
|
|
51
|
+
function __exportSetter(name2, newValue) {
|
|
52
|
+
this[name2] = __returnValue.bind(null, newValue);
|
|
53
|
+
}
|
|
33
54
|
var __export = (target, all) => {
|
|
34
55
|
for (var name2 in all)
|
|
35
56
|
__defProp(target, name2, {
|
|
36
57
|
get: all[name2],
|
|
37
58
|
enumerable: true,
|
|
38
59
|
configurable: true,
|
|
39
|
-
set: (
|
|
60
|
+
set: __exportSetter.bind(all, name2)
|
|
40
61
|
});
|
|
41
62
|
};
|
|
42
63
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
@@ -23872,7 +23893,7 @@ var require_round = __commonJS((exports2, module2) => {
|
|
|
23872
23893
|
|
|
23873
23894
|
// node_modules/math-intrinsics/isNaN.js
|
|
23874
23895
|
var require_isNaN = __commonJS((exports2, module2) => {
|
|
23875
|
-
module2.exports = Number.isNaN || function
|
|
23896
|
+
module2.exports = Number.isNaN || function isNaN2(a) {
|
|
23876
23897
|
return a !== a;
|
|
23877
23898
|
};
|
|
23878
23899
|
});
|
|
@@ -23880,7 +23901,7 @@ var require_isNaN = __commonJS((exports2, module2) => {
|
|
|
23880
23901
|
// node_modules/math-intrinsics/sign.js
|
|
23881
23902
|
var require_sign = __commonJS((exports2, module2) => {
|
|
23882
23903
|
var $isNaN = require_isNaN();
|
|
23883
|
-
module2.exports = function
|
|
23904
|
+
module2.exports = function sign3(number) {
|
|
23884
23905
|
if ($isNaN(number) || number === 0) {
|
|
23885
23906
|
return number;
|
|
23886
23907
|
}
|
|
@@ -24006,7 +24027,7 @@ var require_implementation = __commonJS((exports2, module2) => {
|
|
|
24006
24027
|
var toStr = Object.prototype.toString;
|
|
24007
24028
|
var max = Math.max;
|
|
24008
24029
|
var funcType = "[object Function]";
|
|
24009
|
-
var concatty = function
|
|
24030
|
+
var concatty = function concatty2(a, b) {
|
|
24010
24031
|
var arr = [];
|
|
24011
24032
|
for (var i2 = 0;i2 < a.length; i2 += 1) {
|
|
24012
24033
|
arr[i2] = a[i2];
|
|
@@ -24016,7 +24037,7 @@ var require_implementation = __commonJS((exports2, module2) => {
|
|
|
24016
24037
|
}
|
|
24017
24038
|
return arr;
|
|
24018
24039
|
};
|
|
24019
|
-
var slicy = function
|
|
24040
|
+
var slicy = function slicy2(arrLike, offset) {
|
|
24020
24041
|
var arr = [];
|
|
24021
24042
|
for (var i2 = offset || 0, j = 0;i2 < arrLike.length; i2 += 1, j += 1) {
|
|
24022
24043
|
arr[j] = arrLike[i2];
|
|
@@ -24057,7 +24078,7 @@ var require_implementation = __commonJS((exports2, module2) => {
|
|
|
24057
24078
|
}
|
|
24058
24079
|
bound = Function("binder", "return function (" + joiny(boundArgs, ",") + "){ return binder.apply(this,arguments); }")(binder);
|
|
24059
24080
|
if (target.prototype) {
|
|
24060
|
-
var Empty = function
|
|
24081
|
+
var Empty = function Empty2() {};
|
|
24061
24082
|
Empty.prototype = target.prototype;
|
|
24062
24083
|
bound.prototype = new Empty;
|
|
24063
24084
|
Empty.prototype = null;
|
|
@@ -24296,7 +24317,7 @@ var require_get_intrinsic = __commonJS((exports2, module2) => {
|
|
|
24296
24317
|
}
|
|
24297
24318
|
}
|
|
24298
24319
|
var errorProto;
|
|
24299
|
-
var doEval = function
|
|
24320
|
+
var doEval = function doEval2(name2) {
|
|
24300
24321
|
var value;
|
|
24301
24322
|
if (name2 === "%AsyncFunction%") {
|
|
24302
24323
|
value = getEvalledConstructor("async function () {}");
|
|
@@ -24305,12 +24326,12 @@ var require_get_intrinsic = __commonJS((exports2, module2) => {
|
|
|
24305
24326
|
} else if (name2 === "%AsyncGeneratorFunction%") {
|
|
24306
24327
|
value = getEvalledConstructor("async function* () {}");
|
|
24307
24328
|
} else if (name2 === "%AsyncGenerator%") {
|
|
24308
|
-
var fn =
|
|
24329
|
+
var fn = doEval2("%AsyncGeneratorFunction%");
|
|
24309
24330
|
if (fn) {
|
|
24310
24331
|
value = fn.prototype;
|
|
24311
24332
|
}
|
|
24312
24333
|
} else if (name2 === "%AsyncIteratorPrototype%") {
|
|
24313
|
-
var gen =
|
|
24334
|
+
var gen = doEval2("%AsyncGenerator%");
|
|
24314
24335
|
if (gen && getProto) {
|
|
24315
24336
|
value = getProto(gen.prototype);
|
|
24316
24337
|
}
|
|
@@ -24381,7 +24402,7 @@ var require_get_intrinsic = __commonJS((exports2, module2) => {
|
|
|
24381
24402
|
var $exec = bind.call($call, RegExp.prototype.exec);
|
|
24382
24403
|
var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
|
|
24383
24404
|
var reEscapeChar = /\\(\\)?/g;
|
|
24384
|
-
var stringToPath = function
|
|
24405
|
+
var stringToPath = function stringToPath2(string) {
|
|
24385
24406
|
var first = $strSlice(string, 0, 1);
|
|
24386
24407
|
var last = $strSlice(string, -1);
|
|
24387
24408
|
if (first === "%" && last !== "%") {
|
|
@@ -24395,7 +24416,7 @@ var require_get_intrinsic = __commonJS((exports2, module2) => {
|
|
|
24395
24416
|
});
|
|
24396
24417
|
return result;
|
|
24397
24418
|
};
|
|
24398
|
-
var getBaseIntrinsic = function
|
|
24419
|
+
var getBaseIntrinsic = function getBaseIntrinsic2(name2, allowMissing) {
|
|
24399
24420
|
var intrinsicName = name2;
|
|
24400
24421
|
var alias;
|
|
24401
24422
|
if (hasOwn(LEGACY_ALIASES, intrinsicName)) {
|
|
@@ -25423,7 +25444,7 @@ var require_axios = __commonJS((exports2, module2) => {
|
|
|
25423
25444
|
var zlib__default = /* @__PURE__ */ _interopDefaultLegacy(zlib);
|
|
25424
25445
|
var stream__default = /* @__PURE__ */ _interopDefaultLegacy(stream2);
|
|
25425
25446
|
function bind(fn, thisArg) {
|
|
25426
|
-
return function
|
|
25447
|
+
return function wrap3() {
|
|
25427
25448
|
return fn.apply(thisArg, arguments);
|
|
25428
25449
|
};
|
|
25429
25450
|
}
|
|
@@ -26005,7 +26026,7 @@ var require_axios = __commonJS((exports2, module2) => {
|
|
|
26005
26026
|
prototype.append = function append(name2, value) {
|
|
26006
26027
|
this._pairs.push([name2, value]);
|
|
26007
26028
|
};
|
|
26008
|
-
prototype.toString = function
|
|
26029
|
+
prototype.toString = function toString2(encoder2) {
|
|
26009
26030
|
const _encode = encoder2 ? function(value) {
|
|
26010
26031
|
return encoder2.call(this, value, encode$1);
|
|
26011
26032
|
} : encode$1;
|
|
@@ -27218,7 +27239,7 @@ var require_axios = __commonJS((exports2, module2) => {
|
|
|
27218
27239
|
return req;
|
|
27219
27240
|
}
|
|
27220
27241
|
};
|
|
27221
|
-
var httpAdapter = isHttpAdapterSupported && function
|
|
27242
|
+
var httpAdapter = isHttpAdapterSupported && function httpAdapter2(config2) {
|
|
27222
27243
|
return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
|
|
27223
27244
|
let { data, lookup, family, httpVersion = 1, http2Options } = config2;
|
|
27224
27245
|
const { responseType, responseEncoding } = config2;
|
|
@@ -28274,7 +28295,7 @@ var require_axios = __commonJS((exports2, module2) => {
|
|
|
28274
28295
|
}
|
|
28275
28296
|
var validators$1 = {};
|
|
28276
28297
|
["object", "boolean", "number", "function", "string", "symbol"].forEach((type, i2) => {
|
|
28277
|
-
validators$1[type] = function
|
|
28298
|
+
validators$1[type] = function validator2(thing) {
|
|
28278
28299
|
return typeof thing === type || "a" + (i2 < 1 ? "n " : " ") + type;
|
|
28279
28300
|
};
|
|
28280
28301
|
});
|
|
@@ -28570,7 +28591,7 @@ var require_axios = __commonJS((exports2, module2) => {
|
|
|
28570
28591
|
}
|
|
28571
28592
|
var CancelToken$1 = CancelToken;
|
|
28572
28593
|
function spread(callback) {
|
|
28573
|
-
return function
|
|
28594
|
+
return function wrap3(arr) {
|
|
28574
28595
|
return callback.apply(null, arr);
|
|
28575
28596
|
};
|
|
28576
28597
|
}
|
|
@@ -32153,7 +32174,7 @@ var require_stream = __commonJS((exports2, module2) => {
|
|
|
32153
32174
|
objectMode: false,
|
|
32154
32175
|
writableObjectMode: false
|
|
32155
32176
|
});
|
|
32156
|
-
ws.on("message", function
|
|
32177
|
+
ws.on("message", function message2(msg, isBinary) {
|
|
32157
32178
|
const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
|
|
32158
32179
|
if (!duplex.push(data))
|
|
32159
32180
|
ws.pause();
|
|
@@ -40852,7 +40873,7 @@ var require_axios2 = __commonJS((exports2, module2) => {
|
|
|
40852
40873
|
var zlib__default = /* @__PURE__ */ _interopDefaultLegacy(zlib);
|
|
40853
40874
|
var stream__default = /* @__PURE__ */ _interopDefaultLegacy(stream2);
|
|
40854
40875
|
function bind(fn, thisArg) {
|
|
40855
|
-
return function
|
|
40876
|
+
return function wrap3() {
|
|
40856
40877
|
return fn.apply(thisArg, arguments);
|
|
40857
40878
|
};
|
|
40858
40879
|
}
|
|
@@ -41430,7 +41451,7 @@ var require_axios2 = __commonJS((exports2, module2) => {
|
|
|
41430
41451
|
prototype.append = function append(name2, value2) {
|
|
41431
41452
|
this._pairs.push([name2, value2]);
|
|
41432
41453
|
};
|
|
41433
|
-
prototype.toString = function
|
|
41454
|
+
prototype.toString = function toString2(encoder2) {
|
|
41434
41455
|
const _encode = encoder2 ? function(value2) {
|
|
41435
41456
|
return encoder2.call(this, value2, encode$1);
|
|
41436
41457
|
} : encode$1;
|
|
@@ -42490,7 +42511,7 @@ var require_axios2 = __commonJS((exports2, module2) => {
|
|
|
42490
42511
|
};
|
|
42491
42512
|
};
|
|
42492
42513
|
var buildAddressEntry = (address, family) => resolveFamily(utils$1.isObject(address) ? address : { address, family });
|
|
42493
|
-
var httpAdapter = isHttpAdapterSupported && function
|
|
42514
|
+
var httpAdapter = isHttpAdapterSupported && function httpAdapter2(config2) {
|
|
42494
42515
|
return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
|
|
42495
42516
|
let { data, lookup, family } = config2;
|
|
42496
42517
|
const { responseType, responseEncoding } = config2;
|
|
@@ -43441,7 +43462,7 @@ var require_axios2 = __commonJS((exports2, module2) => {
|
|
|
43441
43462
|
}
|
|
43442
43463
|
var validators$1 = {};
|
|
43443
43464
|
["object", "boolean", "number", "function", "string", "symbol"].forEach((type, i2) => {
|
|
43444
|
-
validators$1[type] = function
|
|
43465
|
+
validators$1[type] = function validator2(thing) {
|
|
43445
43466
|
return typeof thing === type || "a" + (i2 < 1 ? "n " : " ") + type;
|
|
43446
43467
|
};
|
|
43447
43468
|
});
|
|
@@ -43738,7 +43759,7 @@ var require_axios2 = __commonJS((exports2, module2) => {
|
|
|
43738
43759
|
}
|
|
43739
43760
|
var CancelToken$1 = CancelToken;
|
|
43740
43761
|
function spread(callback) {
|
|
43741
|
-
return function
|
|
43762
|
+
return function wrap3(arr) {
|
|
43742
43763
|
return callback.apply(null, arr);
|
|
43743
43764
|
};
|
|
43744
43765
|
}
|
|
@@ -65309,7 +65330,7 @@ function cookieSerialize(t, s, i) {
|
|
|
65309
65330
|
a += "; Path=" + n.path;
|
|
65310
65331
|
}
|
|
65311
65332
|
if (n.expires) {
|
|
65312
|
-
if (!function
|
|
65333
|
+
if (!function isDate2(e2) {
|
|
65313
65334
|
return Object.prototype.toString.call(e2) === "[object Date]" || e2 instanceof Date;
|
|
65314
65335
|
}(n.expires) || isNaN(n.expires.valueOf()))
|
|
65315
65336
|
throw new TypeError("option expires is invalid");
|
|
@@ -71707,6 +71728,7 @@ function transformTradesToExchangeType({
|
|
|
71707
71728
|
trades,
|
|
71708
71729
|
take_profit,
|
|
71709
71730
|
stop_loss,
|
|
71731
|
+
stop_losses,
|
|
71710
71732
|
kind
|
|
71711
71733
|
}) {
|
|
71712
71734
|
const currentTime = Date.now();
|
|
@@ -71791,7 +71813,8 @@ function transformTradesToExchangeType({
|
|
|
71791
71813
|
});
|
|
71792
71814
|
nextOrderId++;
|
|
71793
71815
|
}
|
|
71794
|
-
|
|
71816
|
+
const effectiveStops = stop_losses && stop_losses.length > 0 ? stop_losses : stop_loss && stop_loss.quantity > 0 ? [stop_loss] : [];
|
|
71817
|
+
for (const sl of effectiveStops) {
|
|
71795
71818
|
const slSide = kind === "long" ? "sell" : "buy";
|
|
71796
71819
|
const slPositionSide = kind.toUpperCase();
|
|
71797
71820
|
result.push({
|
|
@@ -71807,28 +71830,29 @@ function transformTradesToExchangeType({
|
|
|
71807
71830
|
orderId: nextOrderId,
|
|
71808
71831
|
order_id: nextOrderId,
|
|
71809
71832
|
order_type: "future",
|
|
71810
|
-
origQty:
|
|
71833
|
+
origQty: sl.quantity,
|
|
71811
71834
|
origType: "LIMIT",
|
|
71812
71835
|
positionSide: slPositionSide,
|
|
71813
|
-
price:
|
|
71836
|
+
price: sl.price,
|
|
71814
71837
|
priceMatch: "NONE",
|
|
71815
71838
|
priceProtect: false,
|
|
71816
|
-
qty:
|
|
71817
|
-
quantity:
|
|
71839
|
+
qty: sl.quantity,
|
|
71840
|
+
quantity: sl.quantity,
|
|
71818
71841
|
reduceOnly: true,
|
|
71819
71842
|
selfTradePreventionMode: "EXPIRE_MAKER",
|
|
71820
71843
|
side: slSide,
|
|
71821
71844
|
status: "NEW",
|
|
71822
|
-
stop:
|
|
71823
|
-
stopPrice:
|
|
71845
|
+
stop: sl.price,
|
|
71846
|
+
stopPrice: sl.price,
|
|
71824
71847
|
symbol: undefined,
|
|
71825
71848
|
time: currentTime,
|
|
71826
71849
|
timeInForce: "GTC",
|
|
71827
|
-
triggerPrice:
|
|
71850
|
+
triggerPrice: sl.price,
|
|
71828
71851
|
type: "LIMIT",
|
|
71829
71852
|
updateTime: currentTime,
|
|
71830
71853
|
workingType: "CONTRACT_PRICE"
|
|
71831
71854
|
});
|
|
71855
|
+
nextOrderId++;
|
|
71832
71856
|
}
|
|
71833
71857
|
return result;
|
|
71834
71858
|
}
|
|
@@ -71846,7 +71870,7 @@ function transformExchangeOrderToTradeWithValidation(orders, options) {
|
|
|
71846
71870
|
} = options || {};
|
|
71847
71871
|
const trades = [];
|
|
71848
71872
|
let take_profit;
|
|
71849
|
-
|
|
71873
|
+
const stop_losses = [];
|
|
71850
71874
|
orders.forEach((order, index) => {
|
|
71851
71875
|
if (validatePrice && (typeof order.price !== "number" || order.price <= 0)) {
|
|
71852
71876
|
throw new Error(`Invalid price at index ${index}: ${order.price}. Price must be a positive number`);
|
|
@@ -71864,11 +71888,11 @@ function transformExchangeOrderToTradeWithValidation(orders, options) {
|
|
|
71864
71888
|
};
|
|
71865
71889
|
return;
|
|
71866
71890
|
}
|
|
71867
|
-
if (isStopLossOrder(order)
|
|
71868
|
-
|
|
71891
|
+
if (isStopLossOrder(order)) {
|
|
71892
|
+
stop_losses.push({
|
|
71869
71893
|
price: order.price,
|
|
71870
71894
|
quantity: order.quantity
|
|
71871
|
-
};
|
|
71895
|
+
});
|
|
71872
71896
|
return;
|
|
71873
71897
|
}
|
|
71874
71898
|
trades.push({
|
|
@@ -71877,7 +71901,7 @@ function transformExchangeOrderToTradeWithValidation(orders, options) {
|
|
|
71877
71901
|
avg_size: order.quantity,
|
|
71878
71902
|
neg_pnl: 0,
|
|
71879
71903
|
avg_entry: order.price,
|
|
71880
|
-
stop:
|
|
71904
|
+
stop: stop_losses[0]?.price || order.stop || defaultStop,
|
|
71881
71905
|
reverse_avg_entry: order.price,
|
|
71882
71906
|
reverse_avg_quantity: order.quantity,
|
|
71883
71907
|
fee: 0,
|
|
@@ -71887,7 +71911,8 @@ function transformExchangeOrderToTradeWithValidation(orders, options) {
|
|
|
71887
71911
|
return {
|
|
71888
71912
|
trades,
|
|
71889
71913
|
take_profit,
|
|
71890
|
-
stop_loss
|
|
71914
|
+
stop_loss: stop_losses[0],
|
|
71915
|
+
stop_losses
|
|
71891
71916
|
};
|
|
71892
71917
|
}
|
|
71893
71918
|
function updatePositionBasedOffTpOrSl({
|
|
@@ -71898,7 +71923,7 @@ function updatePositionBasedOffTpOrSl({
|
|
|
71898
71923
|
}) {
|
|
71899
71924
|
const position2 = positions[kind];
|
|
71900
71925
|
const side_orders = orders.filter((o) => o.positionSide.toLowerCase() === kind);
|
|
71901
|
-
const { trades, take_profit, stop_loss } = transformExchangeOrderToTradeWithValidation(side_orders, {
|
|
71926
|
+
const { trades, take_profit, stop_loss, stop_losses } = transformExchangeOrderToTradeWithValidation(side_orders, {
|
|
71902
71927
|
validatePrice: false,
|
|
71903
71928
|
validateQuantity: false,
|
|
71904
71929
|
defaultStop: 0
|
|
@@ -71924,25 +71949,41 @@ function updatePositionBasedOffTpOrSl({
|
|
|
71924
71949
|
orders: transformTradesToExchangeType({
|
|
71925
71950
|
trades,
|
|
71926
71951
|
kind,
|
|
71927
|
-
stop_loss
|
|
71952
|
+
stop_loss,
|
|
71953
|
+
stop_losses
|
|
71928
71954
|
}),
|
|
71929
71955
|
changed: "tp"
|
|
71930
71956
|
};
|
|
71931
71957
|
}
|
|
71932
71958
|
}
|
|
71933
|
-
|
|
71934
|
-
|
|
71935
|
-
|
|
71936
|
-
|
|
71959
|
+
const all_stops = stop_losses && stop_losses.length > 0 ? stop_losses : stop_loss && stop_loss.quantity ? [stop_loss] : [];
|
|
71960
|
+
if (all_stops.length > 0) {
|
|
71961
|
+
const sorted_stops = [...all_stops].sort((a, b) => kind === "long" ? b.price - a.price : a.price - b.price);
|
|
71962
|
+
const triggered = [];
|
|
71963
|
+
const remaining = [];
|
|
71964
|
+
for (const sl of sorted_stops) {
|
|
71965
|
+
const should_close = kind === "long" ? current_price <= sl.price : current_price >= sl.price;
|
|
71966
|
+
if (should_close) {
|
|
71967
|
+
triggered.push(sl);
|
|
71968
|
+
} else {
|
|
71969
|
+
remaining.push(sl);
|
|
71970
|
+
}
|
|
71971
|
+
}
|
|
71972
|
+
if (triggered.length > 0) {
|
|
71973
|
+
const totalStopQty = triggered.reduce((sum, sl) => sum + sl.quantity, 0);
|
|
71974
|
+
position2.quantity = Math.max(0, position2.quantity - totalStopQty);
|
|
71937
71975
|
if (position2.quantity === 0) {
|
|
71938
71976
|
position2.entry = 0;
|
|
71939
71977
|
}
|
|
71978
|
+
const furthestTriggered = kind === "long" ? Math.min(...triggered.map((sl) => sl.price)) : Math.max(...triggered.map((sl) => sl.price));
|
|
71979
|
+
const remainingTrades = trades.filter((t2) => kind === "long" ? t2.entry < furthestTriggered : t2.entry > furthestTriggered);
|
|
71940
71980
|
return {
|
|
71941
71981
|
position: position2,
|
|
71942
71982
|
orders: transformTradesToExchangeType({
|
|
71943
|
-
trades:
|
|
71983
|
+
trades: remainingTrades,
|
|
71944
71984
|
kind,
|
|
71945
|
-
take_profit
|
|
71985
|
+
take_profit,
|
|
71986
|
+
stop_losses: remaining.length > 0 ? remaining : undefined
|
|
71946
71987
|
}),
|
|
71947
71988
|
changed: "sl",
|
|
71948
71989
|
trades
|
|
@@ -76759,11 +76800,13 @@ async function updateDbDetails(client, payload, current_account_info, new_payloa
|
|
|
76759
76800
|
price: position2.stop_loss,
|
|
76760
76801
|
quantity: position2.stop_quantity
|
|
76761
76802
|
} : undefined);
|
|
76803
|
+
const stop_losses = new_payload.stop_losses;
|
|
76762
76804
|
const as_exchange_orders = new_payload.raw ? new_payload.orders : transformTradesToExchangeType({
|
|
76763
76805
|
trades: new_payload.orders,
|
|
76764
76806
|
kind: payload.kind,
|
|
76765
76807
|
take_profit,
|
|
76766
|
-
stop_loss
|
|
76808
|
+
stop_loss,
|
|
76809
|
+
stop_losses
|
|
76767
76810
|
});
|
|
76768
76811
|
const reverse_kind = payload.kind === "long" ? "short" : "long";
|
|
76769
76812
|
const reverse_orders = current_account_info.config.trades.exchange_info.open_orders.filter((o) => {
|
|
@@ -77086,10 +77129,14 @@ async function placeStopOrder3(client, payload) {
|
|
|
77086
77129
|
price: order.stop,
|
|
77087
77130
|
quantity: order.quantity
|
|
77088
77131
|
};
|
|
77089
|
-
const { trades } = transformExchangeOrderToTradeWithValidation(sameKindOrders, {
|
|
77132
|
+
const { trades, stop_losses: existingStops } = transformExchangeOrderToTradeWithValidation(sameKindOrders, {
|
|
77090
77133
|
validateQuantity: false,
|
|
77091
77134
|
validatePrice: false
|
|
77092
77135
|
});
|
|
77136
|
+
const all_stop_losses = [
|
|
77137
|
+
...existingStops || [],
|
|
77138
|
+
stop_loss
|
|
77139
|
+
];
|
|
77093
77140
|
return savePaperDetails(client, {
|
|
77094
77141
|
kind: order.kind,
|
|
77095
77142
|
symbol: payload.symbol,
|
|
@@ -77098,7 +77145,7 @@ async function placeStopOrder3(client, payload) {
|
|
|
77098
77145
|
}, {
|
|
77099
77146
|
position: {},
|
|
77100
77147
|
orders: trades,
|
|
77101
|
-
|
|
77148
|
+
stop_losses: all_stop_losses
|
|
77102
77149
|
});
|
|
77103
77150
|
}
|
|
77104
77151
|
async function placeTpOrder3(client, payload) {
|