@gbozee/ultimate 0.0.2-next.67 → 0.0.2-next.69

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.
@@ -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: () => mod[key],
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
- __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
26
- get: () => from[key],
27
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
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: (newValue) => all[name2] = () => newValue
60
+ set: __exportSetter.bind(all, name2)
40
61
  });
41
62
  };
42
63
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
@@ -211,10 +232,10 @@ var require_uri_all = __commonJS((exports2, module2) => {
211
232
  }
212
233
  return output;
213
234
  }
214
- var ucs2encode = function ucs2encode(array) {
235
+ var ucs2encode = function ucs2encode2(array) {
215
236
  return String.fromCodePoint.apply(String, toConsumableArray(array));
216
237
  };
217
- var basicToDigit = function basicToDigit(codePoint) {
238
+ var basicToDigit = function basicToDigit2(codePoint) {
218
239
  if (codePoint - 48 < 10) {
219
240
  return codePoint - 22;
220
241
  }
@@ -226,10 +247,10 @@ var require_uri_all = __commonJS((exports2, module2) => {
226
247
  }
227
248
  return base;
228
249
  };
229
- var digitToBasic = function digitToBasic(digit, flag) {
250
+ var digitToBasic = function digitToBasic2(digit, flag) {
230
251
  return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
231
252
  };
232
- var adapt = function adapt(delta, numPoints, firstTime) {
253
+ var adapt = function adapt2(delta, numPoints, firstTime) {
233
254
  var k = 0;
234
255
  delta = firstTime ? floor(delta / damp) : delta >> 1;
235
256
  delta += floor(delta / numPoints);
@@ -238,7 +259,7 @@ var require_uri_all = __commonJS((exports2, module2) => {
238
259
  }
239
260
  return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
240
261
  };
241
- var decode = function decode(input) {
262
+ var decode = function decode2(input) {
242
263
  var output = [];
243
264
  var inputLength = input.length;
244
265
  var i = 0;
@@ -286,7 +307,7 @@ var require_uri_all = __commonJS((exports2, module2) => {
286
307
  }
287
308
  return String.fromCodePoint.apply(String, output);
288
309
  };
289
- var encode = function encode(input) {
310
+ var encode = function encode2(input) {
290
311
  var output = [];
291
312
  input = ucs2decode(input);
292
313
  var inputLength = input.length;
@@ -400,12 +421,12 @@ var require_uri_all = __commonJS((exports2, module2) => {
400
421
  }
401
422
  return output.join("");
402
423
  };
403
- var toUnicode = function toUnicode(input) {
424
+ var toUnicode = function toUnicode2(input) {
404
425
  return mapDomain(input, function(string) {
405
426
  return regexPunycode.test(string) ? decode(string.slice(4).toLowerCase()) : string;
406
427
  });
407
428
  };
408
- var toASCII = function toASCII(input) {
429
+ var toASCII = function toASCII2(input) {
409
430
  return mapDomain(input, function(string) {
410
431
  return regexNonASCII.test(string) ? "xn--" + encode(string) : string;
411
432
  });
@@ -802,13 +823,13 @@ var require_uri_all = __commonJS((exports2, module2) => {
802
823
  var handler = {
803
824
  scheme: "http",
804
825
  domainHost: true,
805
- parse: function parse(components, options) {
826
+ parse: function parse2(components, options) {
806
827
  if (!components.host) {
807
828
  components.error = components.error || "HTTP URIs must have a host.";
808
829
  }
809
830
  return components;
810
831
  },
811
- serialize: function serialize(components, options) {
832
+ serialize: function serialize2(components, options) {
812
833
  var secure = String(components.scheme).toLowerCase() === "https";
813
834
  if (components.port === (secure ? 443 : 80) || components.port === "") {
814
835
  components.port = undefined;
@@ -831,7 +852,7 @@ var require_uri_all = __commonJS((exports2, module2) => {
831
852
  var handler$2 = {
832
853
  scheme: "ws",
833
854
  domainHost: true,
834
- parse: function parse(components, options) {
855
+ parse: function parse2(components, options) {
835
856
  var wsComponents = components;
836
857
  wsComponents.secure = isSecure(wsComponents);
837
858
  wsComponents.resourceName = (wsComponents.path || "/") + (wsComponents.query ? "?" + wsComponents.query : "");
@@ -839,7 +860,7 @@ var require_uri_all = __commonJS((exports2, module2) => {
839
860
  wsComponents.query = undefined;
840
861
  return wsComponents;
841
862
  },
842
- serialize: function serialize(wsComponents, options) {
863
+ serialize: function serialize2(wsComponents, options) {
843
864
  if (wsComponents.port === (isSecure(wsComponents) ? 443 : 80) || wsComponents.port === "") {
844
865
  wsComponents.port = undefined;
845
866
  }
@@ -1007,7 +1028,7 @@ var require_uri_all = __commonJS((exports2, module2) => {
1007
1028
  var UUID = /^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/;
1008
1029
  var handler$6 = {
1009
1030
  scheme: "urn:uuid",
1010
- parse: function parse(urnComponents, options) {
1031
+ parse: function parse2(urnComponents, options) {
1011
1032
  var uuidComponents = urnComponents;
1012
1033
  uuidComponents.uuid = uuidComponents.nss;
1013
1034
  uuidComponents.nss = undefined;
@@ -1016,7 +1037,7 @@ var require_uri_all = __commonJS((exports2, module2) => {
1016
1037
  }
1017
1038
  return uuidComponents;
1018
1039
  },
1019
- serialize: function serialize(uuidComponents, options) {
1040
+ serialize: function serialize2(uuidComponents, options) {
1020
1041
  var urnComponents = uuidComponents;
1021
1042
  urnComponents.nss = (uuidComponents.uuid || "").toLowerCase();
1022
1043
  return urnComponents;
@@ -2462,7 +2483,7 @@ var require_compile = __commonJS((exports2, module2) => {
2462
2483
 
2463
2484
  // node_modules/ajv/lib/cache.js
2464
2485
  var require_cache = __commonJS((exports2, module2) => {
2465
- var Cache = module2.exports = function Cache() {
2486
+ var Cache = module2.exports = function Cache2() {
2466
2487
  this._cache = {};
2467
2488
  };
2468
2489
  Cache.prototype.put = function Cache_put(key, value) {
@@ -30039,7 +30060,7 @@ var require_round = __commonJS((exports2, module2) => {
30039
30060
 
30040
30061
  // node_modules/math-intrinsics/isNaN.js
30041
30062
  var require_isNaN = __commonJS((exports2, module2) => {
30042
- module2.exports = Number.isNaN || function isNaN(a) {
30063
+ module2.exports = Number.isNaN || function isNaN2(a) {
30043
30064
  return a !== a;
30044
30065
  };
30045
30066
  });
@@ -30047,7 +30068,7 @@ var require_isNaN = __commonJS((exports2, module2) => {
30047
30068
  // node_modules/math-intrinsics/sign.js
30048
30069
  var require_sign = __commonJS((exports2, module2) => {
30049
30070
  var $isNaN = require_isNaN();
30050
- module2.exports = function sign(number2) {
30071
+ module2.exports = function sign3(number2) {
30051
30072
  if ($isNaN(number2) || number2 === 0) {
30052
30073
  return number2;
30053
30074
  }
@@ -30173,7 +30194,7 @@ var require_implementation = __commonJS((exports2, module2) => {
30173
30194
  var toStr = Object.prototype.toString;
30174
30195
  var max = Math.max;
30175
30196
  var funcType = "[object Function]";
30176
- var concatty = function concatty(a, b) {
30197
+ var concatty = function concatty2(a, b) {
30177
30198
  var arr = [];
30178
30199
  for (var i2 = 0;i2 < a.length; i2 += 1) {
30179
30200
  arr[i2] = a[i2];
@@ -30183,7 +30204,7 @@ var require_implementation = __commonJS((exports2, module2) => {
30183
30204
  }
30184
30205
  return arr;
30185
30206
  };
30186
- var slicy = function slicy(arrLike, offset) {
30207
+ var slicy = function slicy2(arrLike, offset) {
30187
30208
  var arr = [];
30188
30209
  for (var i2 = offset || 0, j = 0;i2 < arrLike.length; i2 += 1, j += 1) {
30189
30210
  arr[j] = arrLike[i2];
@@ -30224,7 +30245,7 @@ var require_implementation = __commonJS((exports2, module2) => {
30224
30245
  }
30225
30246
  bound = Function("binder", "return function (" + joiny(boundArgs, ",") + "){ return binder.apply(this,arguments); }")(binder);
30226
30247
  if (target.prototype) {
30227
- var Empty = function Empty() {};
30248
+ var Empty = function Empty2() {};
30228
30249
  Empty.prototype = target.prototype;
30229
30250
  bound.prototype = new Empty;
30230
30251
  Empty.prototype = null;
@@ -30463,7 +30484,7 @@ var require_get_intrinsic = __commonJS((exports2, module2) => {
30463
30484
  }
30464
30485
  }
30465
30486
  var errorProto;
30466
- var doEval = function doEval(name2) {
30487
+ var doEval = function doEval2(name2) {
30467
30488
  var value;
30468
30489
  if (name2 === "%AsyncFunction%") {
30469
30490
  value = getEvalledConstructor("async function () {}");
@@ -30472,12 +30493,12 @@ var require_get_intrinsic = __commonJS((exports2, module2) => {
30472
30493
  } else if (name2 === "%AsyncGeneratorFunction%") {
30473
30494
  value = getEvalledConstructor("async function* () {}");
30474
30495
  } else if (name2 === "%AsyncGenerator%") {
30475
- var fn = doEval("%AsyncGeneratorFunction%");
30496
+ var fn = doEval2("%AsyncGeneratorFunction%");
30476
30497
  if (fn) {
30477
30498
  value = fn.prototype;
30478
30499
  }
30479
30500
  } else if (name2 === "%AsyncIteratorPrototype%") {
30480
- var gen = doEval("%AsyncGenerator%");
30501
+ var gen = doEval2("%AsyncGenerator%");
30481
30502
  if (gen && getProto) {
30482
30503
  value = getProto(gen.prototype);
30483
30504
  }
@@ -30548,7 +30569,7 @@ var require_get_intrinsic = __commonJS((exports2, module2) => {
30548
30569
  var $exec = bind.call($call, RegExp.prototype.exec);
30549
30570
  var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
30550
30571
  var reEscapeChar = /\\(\\)?/g;
30551
- var stringToPath = function stringToPath(string2) {
30572
+ var stringToPath = function stringToPath2(string2) {
30552
30573
  var first = $strSlice(string2, 0, 1);
30553
30574
  var last = $strSlice(string2, -1);
30554
30575
  if (first === "%" && last !== "%") {
@@ -30562,7 +30583,7 @@ var require_get_intrinsic = __commonJS((exports2, module2) => {
30562
30583
  });
30563
30584
  return result;
30564
30585
  };
30565
- var getBaseIntrinsic = function getBaseIntrinsic(name2, allowMissing) {
30586
+ var getBaseIntrinsic = function getBaseIntrinsic2(name2, allowMissing) {
30566
30587
  var intrinsicName = name2;
30567
30588
  var alias;
30568
30589
  if (hasOwn(LEGACY_ALIASES, intrinsicName)) {
@@ -31590,7 +31611,7 @@ var require_axios = __commonJS((exports2, module2) => {
31590
31611
  var zlib__default = /* @__PURE__ */ _interopDefaultLegacy(zlib);
31591
31612
  var stream__default = /* @__PURE__ */ _interopDefaultLegacy(stream2);
31592
31613
  function bind(fn, thisArg) {
31593
- return function wrap() {
31614
+ return function wrap3() {
31594
31615
  return fn.apply(thisArg, arguments);
31595
31616
  };
31596
31617
  }
@@ -32172,7 +32193,7 @@ var require_axios = __commonJS((exports2, module2) => {
32172
32193
  prototype.append = function append(name2, value) {
32173
32194
  this._pairs.push([name2, value]);
32174
32195
  };
32175
- prototype.toString = function toString(encoder2) {
32196
+ prototype.toString = function toString2(encoder2) {
32176
32197
  const _encode = encoder2 ? function(value) {
32177
32198
  return encoder2.call(this, value, encode$1);
32178
32199
  } : encode$1;
@@ -33385,7 +33406,7 @@ var require_axios = __commonJS((exports2, module2) => {
33385
33406
  return req;
33386
33407
  }
33387
33408
  };
33388
- var httpAdapter = isHttpAdapterSupported && function httpAdapter(config2) {
33409
+ var httpAdapter = isHttpAdapterSupported && function httpAdapter2(config2) {
33389
33410
  return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
33390
33411
  let { data, lookup, family, httpVersion = 1, http2Options } = config2;
33391
33412
  const { responseType, responseEncoding } = config2;
@@ -34441,7 +34462,7 @@ var require_axios = __commonJS((exports2, module2) => {
34441
34462
  }
34442
34463
  var validators$1 = {};
34443
34464
  ["object", "boolean", "number", "function", "string", "symbol"].forEach((type, i2) => {
34444
- validators$1[type] = function validator(thing) {
34465
+ validators$1[type] = function validator2(thing) {
34445
34466
  return typeof thing === type || "a" + (i2 < 1 ? "n " : " ") + type;
34446
34467
  };
34447
34468
  });
@@ -34737,7 +34758,7 @@ var require_axios = __commonJS((exports2, module2) => {
34737
34758
  }
34738
34759
  var CancelToken$1 = CancelToken;
34739
34760
  function spread(callback) {
34740
- return function wrap(arr) {
34761
+ return function wrap3(arr) {
34741
34762
  return callback.apply(null, arr);
34742
34763
  };
34743
34764
  }
@@ -38320,7 +38341,7 @@ var require_stream = __commonJS((exports2, module2) => {
38320
38341
  objectMode: false,
38321
38342
  writableObjectMode: false
38322
38343
  });
38323
- ws.on("message", function message(msg, isBinary) {
38344
+ ws.on("message", function message2(msg, isBinary) {
38324
38345
  const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
38325
38346
  if (!duplex.push(data))
38326
38347
  ws.pause();
@@ -47019,7 +47040,7 @@ var require_axios2 = __commonJS((exports2, module2) => {
47019
47040
  var zlib__default = /* @__PURE__ */ _interopDefaultLegacy(zlib);
47020
47041
  var stream__default = /* @__PURE__ */ _interopDefaultLegacy(stream2);
47021
47042
  function bind(fn, thisArg) {
47022
- return function wrap() {
47043
+ return function wrap3() {
47023
47044
  return fn.apply(thisArg, arguments);
47024
47045
  };
47025
47046
  }
@@ -47597,7 +47618,7 @@ var require_axios2 = __commonJS((exports2, module2) => {
47597
47618
  prototype.append = function append(name2, value2) {
47598
47619
  this._pairs.push([name2, value2]);
47599
47620
  };
47600
- prototype.toString = function toString(encoder2) {
47621
+ prototype.toString = function toString2(encoder2) {
47601
47622
  const _encode = encoder2 ? function(value2) {
47602
47623
  return encoder2.call(this, value2, encode$1);
47603
47624
  } : encode$1;
@@ -48657,7 +48678,7 @@ var require_axios2 = __commonJS((exports2, module2) => {
48657
48678
  };
48658
48679
  };
48659
48680
  var buildAddressEntry = (address, family) => resolveFamily(utils$1.isObject(address) ? address : { address, family });
48660
- var httpAdapter = isHttpAdapterSupported && function httpAdapter(config2) {
48681
+ var httpAdapter = isHttpAdapterSupported && function httpAdapter2(config2) {
48661
48682
  return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
48662
48683
  let { data, lookup, family } = config2;
48663
48684
  const { responseType, responseEncoding } = config2;
@@ -49608,7 +49629,7 @@ var require_axios2 = __commonJS((exports2, module2) => {
49608
49629
  }
49609
49630
  var validators$1 = {};
49610
49631
  ["object", "boolean", "number", "function", "string", "symbol"].forEach((type, i2) => {
49611
- validators$1[type] = function validator(thing) {
49632
+ validators$1[type] = function validator2(thing) {
49612
49633
  return typeof thing === type || "a" + (i2 < 1 ? "n " : " ") + type;
49613
49634
  };
49614
49635
  });
@@ -49905,7 +49926,7 @@ var require_axios2 = __commonJS((exports2, module2) => {
49905
49926
  }
49906
49927
  var CancelToken$1 = CancelToken;
49907
49928
  function spread(callback) {
49908
- return function wrap(arr) {
49929
+ return function wrap3(arr) {
49909
49930
  return callback.apply(null, arr);
49910
49931
  };
49911
49932
  }
@@ -69149,7 +69170,7 @@ function cookieSerialize(t, s, i) {
69149
69170
  a += "; Path=" + n.path;
69150
69171
  }
69151
69172
  if (n.expires) {
69152
- if (!function isDate(e2) {
69173
+ if (!function isDate2(e2) {
69153
69174
  return Object.prototype.toString.call(e2) === "[object Date]" || e2 instanceof Date;
69154
69175
  }(n.expires) || isNaN(n.expires.valueOf()))
69155
69176
  throw new TypeError("option expires is invalid");
@@ -75429,6 +75450,7 @@ function transformTradesToExchangeType({
75429
75450
  trades,
75430
75451
  take_profit,
75431
75452
  stop_loss,
75453
+ stop_losses,
75432
75454
  kind
75433
75455
  }) {
75434
75456
  const currentTime = Date.now();
@@ -75513,7 +75535,8 @@ function transformTradesToExchangeType({
75513
75535
  });
75514
75536
  nextOrderId++;
75515
75537
  }
75516
- if (stop_loss && stop_loss.quantity > 0) {
75538
+ const effectiveStops = stop_losses && stop_losses.length > 0 ? stop_losses : stop_loss && stop_loss.quantity > 0 ? [stop_loss] : [];
75539
+ for (const sl of effectiveStops) {
75517
75540
  const slSide = kind === "long" ? "sell" : "buy";
75518
75541
  const slPositionSide = kind.toUpperCase();
75519
75542
  result.push({
@@ -75529,28 +75552,29 @@ function transformTradesToExchangeType({
75529
75552
  orderId: nextOrderId,
75530
75553
  order_id: nextOrderId,
75531
75554
  order_type: "future",
75532
- origQty: stop_loss.quantity,
75555
+ origQty: sl.quantity,
75533
75556
  origType: "LIMIT",
75534
75557
  positionSide: slPositionSide,
75535
- price: stop_loss.price,
75558
+ price: sl.price,
75536
75559
  priceMatch: "NONE",
75537
75560
  priceProtect: false,
75538
- qty: stop_loss.quantity,
75539
- quantity: stop_loss.quantity,
75561
+ qty: sl.quantity,
75562
+ quantity: sl.quantity,
75540
75563
  reduceOnly: true,
75541
75564
  selfTradePreventionMode: "EXPIRE_MAKER",
75542
75565
  side: slSide,
75543
75566
  status: "NEW",
75544
- stop: stop_loss.price,
75545
- stopPrice: stop_loss.price,
75567
+ stop: sl.price,
75568
+ stopPrice: sl.price,
75546
75569
  symbol: undefined,
75547
75570
  time: currentTime,
75548
75571
  timeInForce: "GTC",
75549
- triggerPrice: stop_loss.price,
75572
+ triggerPrice: sl.price,
75550
75573
  type: "LIMIT",
75551
75574
  updateTime: currentTime,
75552
75575
  workingType: "CONTRACT_PRICE"
75553
75576
  });
75577
+ nextOrderId++;
75554
75578
  }
75555
75579
  return result;
75556
75580
  }
@@ -75568,7 +75592,7 @@ function transformExchangeOrderToTradeWithValidation(orders, options) {
75568
75592
  } = options || {};
75569
75593
  const trades = [];
75570
75594
  let take_profit;
75571
- let stop_loss;
75595
+ const stop_losses = [];
75572
75596
  orders.forEach((order, index) => {
75573
75597
  if (validatePrice && (typeof order.price !== "number" || order.price <= 0)) {
75574
75598
  throw new Error(`Invalid price at index ${index}: ${order.price}. Price must be a positive number`);
@@ -75586,11 +75610,11 @@ function transformExchangeOrderToTradeWithValidation(orders, options) {
75586
75610
  };
75587
75611
  return;
75588
75612
  }
75589
- if (isStopLossOrder(order) && !stop_loss) {
75590
- stop_loss = {
75613
+ if (isStopLossOrder(order)) {
75614
+ stop_losses.push({
75591
75615
  price: order.price,
75592
75616
  quantity: order.quantity
75593
- };
75617
+ });
75594
75618
  return;
75595
75619
  }
75596
75620
  trades.push({
@@ -75599,7 +75623,7 @@ function transformExchangeOrderToTradeWithValidation(orders, options) {
75599
75623
  avg_size: order.quantity,
75600
75624
  neg_pnl: 0,
75601
75625
  avg_entry: order.price,
75602
- stop: stop_loss?.price || order.stop || defaultStop,
75626
+ stop: stop_losses[0]?.price || order.stop || defaultStop,
75603
75627
  reverse_avg_entry: order.price,
75604
75628
  reverse_avg_quantity: order.quantity,
75605
75629
  fee: 0,
@@ -75609,7 +75633,8 @@ function transformExchangeOrderToTradeWithValidation(orders, options) {
75609
75633
  return {
75610
75634
  trades,
75611
75635
  take_profit,
75612
- stop_loss
75636
+ stop_loss: stop_losses[0],
75637
+ stop_losses
75613
75638
  };
75614
75639
  }
75615
75640
  function updatePositionBasedOffTpOrSl({
@@ -75620,7 +75645,7 @@ function updatePositionBasedOffTpOrSl({
75620
75645
  }) {
75621
75646
  const position2 = positions[kind];
75622
75647
  const side_orders = orders.filter((o) => o.positionSide.toLowerCase() === kind);
75623
- const { trades, take_profit, stop_loss } = transformExchangeOrderToTradeWithValidation(side_orders, {
75648
+ const { trades, take_profit, stop_loss, stop_losses } = transformExchangeOrderToTradeWithValidation(side_orders, {
75624
75649
  validatePrice: false,
75625
75650
  validateQuantity: false,
75626
75651
  defaultStop: 0
@@ -75646,25 +75671,41 @@ function updatePositionBasedOffTpOrSl({
75646
75671
  orders: transformTradesToExchangeType({
75647
75672
  trades,
75648
75673
  kind,
75649
- stop_loss
75674
+ stop_loss,
75675
+ stop_losses
75650
75676
  }),
75651
75677
  changed: "tp"
75652
75678
  };
75653
75679
  }
75654
75680
  }
75655
- if (stop_loss && stop_loss.quantity) {
75656
- const should_close = kind === "long" ? current_price <= stop_loss.price : current_price >= stop_loss.price;
75657
- if (should_close) {
75658
- position2.quantity = Math.max(0, position2.quantity - stop_loss.quantity);
75681
+ const all_stops = stop_losses && stop_losses.length > 0 ? stop_losses : stop_loss && stop_loss.quantity ? [stop_loss] : [];
75682
+ if (all_stops.length > 0) {
75683
+ const sorted_stops = [...all_stops].sort((a, b) => kind === "long" ? b.price - a.price : a.price - b.price);
75684
+ const triggered = [];
75685
+ const remaining = [];
75686
+ for (const sl of sorted_stops) {
75687
+ const should_close = kind === "long" ? current_price <= sl.price : current_price >= sl.price;
75688
+ if (should_close) {
75689
+ triggered.push(sl);
75690
+ } else {
75691
+ remaining.push(sl);
75692
+ }
75693
+ }
75694
+ if (triggered.length > 0) {
75695
+ const totalStopQty = triggered.reduce((sum, sl) => sum + sl.quantity, 0);
75696
+ position2.quantity = Math.max(0, position2.quantity - totalStopQty);
75659
75697
  if (position2.quantity === 0) {
75660
75698
  position2.entry = 0;
75661
75699
  }
75700
+ const furthestTriggered = kind === "long" ? Math.min(...triggered.map((sl) => sl.price)) : Math.max(...triggered.map((sl) => sl.price));
75701
+ const remainingTrades = trades.filter((t2) => kind === "long" ? t2.entry < furthestTriggered : t2.entry > furthestTriggered);
75662
75702
  return {
75663
75703
  position: position2,
75664
75704
  orders: transformTradesToExchangeType({
75665
- trades: trades.filter((t2) => kind === "long" ? t2.entry < stop_loss.price : t2.entry > stop_loss.price),
75705
+ trades: remainingTrades,
75666
75706
  kind,
75667
- take_profit
75707
+ take_profit,
75708
+ stop_losses: remaining.length > 0 ? remaining : undefined
75668
75709
  }),
75669
75710
  changed: "sl",
75670
75711
  trades
@@ -80481,11 +80522,13 @@ async function updateDbDetails(client, payload, current_account_info, new_payloa
80481
80522
  price: position2.stop_loss,
80482
80523
  quantity: position2.stop_quantity
80483
80524
  } : undefined);
80525
+ const stop_losses = new_payload.stop_losses;
80484
80526
  const as_exchange_orders = new_payload.raw ? new_payload.orders : transformTradesToExchangeType({
80485
80527
  trades: new_payload.orders,
80486
80528
  kind: payload.kind,
80487
80529
  take_profit,
80488
- stop_loss
80530
+ stop_loss,
80531
+ stop_losses
80489
80532
  });
80490
80533
  const reverse_kind = payload.kind === "long" ? "short" : "long";
80491
80534
  const reverse_orders = current_account_info.config.trades.exchange_info.open_orders.filter((o) => {
@@ -80582,6 +80625,19 @@ async function fetchDBExchangeData(client, symbol, options) {
80582
80625
  short: short_result.trades
80583
80626
  };
80584
80627
  }
80628
+ const stop_losses_by_kind = {
80629
+ long: [],
80630
+ short: []
80631
+ };
80632
+ for (const o of orders) {
80633
+ const k = o.positionSide?.toLowerCase();
80634
+ if (k && (o.isStop || o.stopPrice > 0)) {
80635
+ stop_losses_by_kind[k].push({
80636
+ price: o.stopPrice || o.stop || o.price,
80637
+ quantity: o.origQty || o.quantity
80638
+ });
80639
+ }
80640
+ }
80585
80641
  return {
80586
80642
  orders,
80587
80643
  symbol_config,
@@ -80591,11 +80647,12 @@ async function fetchDBExchangeData(client, symbol, options) {
80591
80647
  trades,
80592
80648
  drift,
80593
80649
  priceChanged,
80650
+ stop_losses_by_kind,
80594
80651
  raw_data: live_exchange_details?.data
80595
80652
  };
80596
80653
  }
80597
80654
  async function reconcileEngineState(client, symbol, options) {
80598
- const { positions, symbol_config, current_price, raw_data, trades, drift, priceChanged } = await fetchDBExchangeData(client, symbol, options);
80655
+ const { positions, symbol_config, current_price, raw_data, trades, drift, priceChanged, stop_losses_by_kind } = await fetchDBExchangeData(client, symbol, options);
80599
80656
  const long_generator = new TradeEngine({
80600
80657
  position: {
80601
80658
  kind: "long",
@@ -80640,7 +80697,13 @@ async function reconcileEngineState(client, symbol, options) {
80640
80697
  state.position.quantity = 0;
80641
80698
  tp = { price: 0, quantity: 0 };
80642
80699
  }
80643
- await updateDbDetails(client, { kind, symbol }, raw_data, { take_profit: tp, position: _position, orders: state_trades });
80700
+ const kind_stops = stop_losses_by_kind[kind];
80701
+ await updateDbDetails(client, { kind, symbol }, raw_data, {
80702
+ take_profit: tp,
80703
+ position: _position,
80704
+ orders: state_trades,
80705
+ stop_losses: kind_stops.length > 0 ? kind_stops : undefined
80706
+ });
80644
80707
  changed = true;
80645
80708
  }
80646
80709
  }
@@ -80808,10 +80871,14 @@ async function placeStopOrder3(client, payload) {
80808
80871
  price: order.stop,
80809
80872
  quantity: order.quantity
80810
80873
  };
80811
- const { trades } = transformExchangeOrderToTradeWithValidation(sameKindOrders, {
80874
+ const { trades, stop_losses: existingStops } = transformExchangeOrderToTradeWithValidation(sameKindOrders, {
80812
80875
  validateQuantity: false,
80813
80876
  validatePrice: false
80814
80877
  });
80878
+ const all_stop_losses = [
80879
+ ...existingStops || [],
80880
+ stop_loss
80881
+ ];
80815
80882
  return savePaperDetails(client, {
80816
80883
  kind: order.kind,
80817
80884
  symbol: payload.symbol,
@@ -80820,7 +80887,7 @@ async function placeStopOrder3(client, payload) {
80820
80887
  }, {
80821
80888
  position: {},
80822
80889
  orders: trades,
80823
- stop_loss
80890
+ stop_losses: all_stop_losses
80824
80891
  });
80825
80892
  }
80826
80893
  async function placeTpOrder3(client, payload) {