@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.
package/dist/index.js CHANGED
@@ -4,25 +4,43 @@ var __getProtoOf = Object.getPrototypeOf;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
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
32
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
33
+ var __returnValue = (v) => v;
34
+ function __exportSetter(name2, newValue) {
35
+ this[name2] = __returnValue.bind(null, newValue);
36
+ }
19
37
  var __export = (target, all) => {
20
38
  for (var name2 in all)
21
39
  __defProp(target, name2, {
22
40
  get: all[name2],
23
41
  enumerable: true,
24
42
  configurable: true,
25
- set: (newValue) => all[name2] = () => newValue
43
+ set: __exportSetter.bind(all, name2)
26
44
  });
27
45
  };
28
46
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
@@ -23486,17 +23504,6 @@ var require_db = __commonJS((exports, module) => {
23486
23504
  };
23487
23505
  });
23488
23506
 
23489
- // node_modules/form-data/node_modules/mime-types/node_modules/mime-db/index.js
23490
- var require_mime_db = __commonJS((exports, module) => {
23491
- /*!
23492
- * mime-db
23493
- * Copyright(c) 2014 Jonathan Ong
23494
- * Copyright(c) 2015-2022 Douglas Christopher Wilson
23495
- * MIT Licensed
23496
- */
23497
- module.exports = require_db();
23498
- });
23499
-
23500
23507
  // node_modules/form-data/node_modules/mime-types/index.js
23501
23508
  var require_mime_types = __commonJS((exports) => {
23502
23509
  /*!
@@ -23505,7 +23512,7 @@ var require_mime_types = __commonJS((exports) => {
23505
23512
  * Copyright(c) 2015 Douglas Christopher Wilson
23506
23513
  * MIT Licensed
23507
23514
  */
23508
- var db = require_mime_db();
23515
+ var db = require_db();
23509
23516
  var extname = __require("path").extname;
23510
23517
  var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/;
23511
23518
  var TEXT_TYPE_REGEXP = /^text\//i;
@@ -23852,7 +23859,7 @@ var require_round = __commonJS((exports, module) => {
23852
23859
 
23853
23860
  // node_modules/math-intrinsics/isNaN.js
23854
23861
  var require_isNaN = __commonJS((exports, module) => {
23855
- module.exports = Number.isNaN || function isNaN(a) {
23862
+ module.exports = Number.isNaN || function isNaN2(a) {
23856
23863
  return a !== a;
23857
23864
  };
23858
23865
  });
@@ -23860,7 +23867,7 @@ var require_isNaN = __commonJS((exports, module) => {
23860
23867
  // node_modules/math-intrinsics/sign.js
23861
23868
  var require_sign = __commonJS((exports, module) => {
23862
23869
  var $isNaN = require_isNaN();
23863
- module.exports = function sign(number) {
23870
+ module.exports = function sign3(number) {
23864
23871
  if ($isNaN(number) || number === 0) {
23865
23872
  return number;
23866
23873
  }
@@ -23986,7 +23993,7 @@ var require_implementation = __commonJS((exports, module) => {
23986
23993
  var toStr = Object.prototype.toString;
23987
23994
  var max = Math.max;
23988
23995
  var funcType = "[object Function]";
23989
- var concatty = function concatty(a, b) {
23996
+ var concatty = function concatty2(a, b) {
23990
23997
  var arr = [];
23991
23998
  for (var i2 = 0;i2 < a.length; i2 += 1) {
23992
23999
  arr[i2] = a[i2];
@@ -23996,7 +24003,7 @@ var require_implementation = __commonJS((exports, module) => {
23996
24003
  }
23997
24004
  return arr;
23998
24005
  };
23999
- var slicy = function slicy(arrLike, offset) {
24006
+ var slicy = function slicy2(arrLike, offset) {
24000
24007
  var arr = [];
24001
24008
  for (var i2 = offset || 0, j = 0;i2 < arrLike.length; i2 += 1, j += 1) {
24002
24009
  arr[j] = arrLike[i2];
@@ -24037,7 +24044,7 @@ var require_implementation = __commonJS((exports, module) => {
24037
24044
  }
24038
24045
  bound = Function("binder", "return function (" + joiny(boundArgs, ",") + "){ return binder.apply(this,arguments); }")(binder);
24039
24046
  if (target.prototype) {
24040
- var Empty = function Empty() {};
24047
+ var Empty = function Empty2() {};
24041
24048
  Empty.prototype = target.prototype;
24042
24049
  bound.prototype = new Empty;
24043
24050
  Empty.prototype = null;
@@ -24276,7 +24283,7 @@ var require_get_intrinsic = __commonJS((exports, module) => {
24276
24283
  }
24277
24284
  }
24278
24285
  var errorProto;
24279
- var doEval = function doEval(name2) {
24286
+ var doEval = function doEval2(name2) {
24280
24287
  var value;
24281
24288
  if (name2 === "%AsyncFunction%") {
24282
24289
  value = getEvalledConstructor("async function () {}");
@@ -24285,12 +24292,12 @@ var require_get_intrinsic = __commonJS((exports, module) => {
24285
24292
  } else if (name2 === "%AsyncGeneratorFunction%") {
24286
24293
  value = getEvalledConstructor("async function* () {}");
24287
24294
  } else if (name2 === "%AsyncGenerator%") {
24288
- var fn = doEval("%AsyncGeneratorFunction%");
24295
+ var fn = doEval2("%AsyncGeneratorFunction%");
24289
24296
  if (fn) {
24290
24297
  value = fn.prototype;
24291
24298
  }
24292
24299
  } else if (name2 === "%AsyncIteratorPrototype%") {
24293
- var gen = doEval("%AsyncGenerator%");
24300
+ var gen = doEval2("%AsyncGenerator%");
24294
24301
  if (gen && getProto) {
24295
24302
  value = getProto(gen.prototype);
24296
24303
  }
@@ -24361,7 +24368,7 @@ var require_get_intrinsic = __commonJS((exports, module) => {
24361
24368
  var $exec = bind.call($call, RegExp.prototype.exec);
24362
24369
  var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
24363
24370
  var reEscapeChar = /\\(\\)?/g;
24364
- var stringToPath = function stringToPath(string) {
24371
+ var stringToPath = function stringToPath2(string) {
24365
24372
  var first = $strSlice(string, 0, 1);
24366
24373
  var last = $strSlice(string, -1);
24367
24374
  if (first === "%" && last !== "%") {
@@ -24375,7 +24382,7 @@ var require_get_intrinsic = __commonJS((exports, module) => {
24375
24382
  });
24376
24383
  return result;
24377
24384
  };
24378
- var getBaseIntrinsic = function getBaseIntrinsic(name2, allowMissing) {
24385
+ var getBaseIntrinsic = function getBaseIntrinsic2(name2, allowMissing) {
24379
24386
  var intrinsicName = name2;
24380
24387
  var alias;
24381
24388
  if (hasOwn(LEGACY_ALIASES, intrinsicName)) {
@@ -25403,7 +25410,7 @@ var require_axios = __commonJS((exports, module) => {
25403
25410
  var zlib__default = /* @__PURE__ */ _interopDefaultLegacy(zlib);
25404
25411
  var stream__default = /* @__PURE__ */ _interopDefaultLegacy(stream2);
25405
25412
  function bind(fn, thisArg) {
25406
- return function wrap() {
25413
+ return function wrap3() {
25407
25414
  return fn.apply(thisArg, arguments);
25408
25415
  };
25409
25416
  }
@@ -25985,7 +25992,7 @@ var require_axios = __commonJS((exports, module) => {
25985
25992
  prototype.append = function append(name2, value) {
25986
25993
  this._pairs.push([name2, value]);
25987
25994
  };
25988
- prototype.toString = function toString(encoder2) {
25995
+ prototype.toString = function toString2(encoder2) {
25989
25996
  const _encode = encoder2 ? function(value) {
25990
25997
  return encoder2.call(this, value, encode$1);
25991
25998
  } : encode$1;
@@ -27198,7 +27205,7 @@ var require_axios = __commonJS((exports, module) => {
27198
27205
  return req;
27199
27206
  }
27200
27207
  };
27201
- var httpAdapter = isHttpAdapterSupported && function httpAdapter(config2) {
27208
+ var httpAdapter = isHttpAdapterSupported && function httpAdapter2(config2) {
27202
27209
  return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
27203
27210
  let { data, lookup, family, httpVersion = 1, http2Options } = config2;
27204
27211
  const { responseType, responseEncoding } = config2;
@@ -28254,7 +28261,7 @@ var require_axios = __commonJS((exports, module) => {
28254
28261
  }
28255
28262
  var validators$1 = {};
28256
28263
  ["object", "boolean", "number", "function", "string", "symbol"].forEach((type, i2) => {
28257
- validators$1[type] = function validator(thing) {
28264
+ validators$1[type] = function validator2(thing) {
28258
28265
  return typeof thing === type || "a" + (i2 < 1 ? "n " : " ") + type;
28259
28266
  };
28260
28267
  });
@@ -28550,7 +28557,7 @@ var require_axios = __commonJS((exports, module) => {
28550
28557
  }
28551
28558
  var CancelToken$1 = CancelToken;
28552
28559
  function spread(callback) {
28553
- return function wrap(arr) {
28560
+ return function wrap3(arr) {
28554
28561
  return callback.apply(null, arr);
28555
28562
  };
28556
28563
  }
@@ -32133,7 +32140,7 @@ var require_stream = __commonJS((exports, module) => {
32133
32140
  objectMode: false,
32134
32141
  writableObjectMode: false
32135
32142
  });
32136
- ws.on("message", function message(msg, isBinary) {
32143
+ ws.on("message", function message2(msg, isBinary) {
32137
32144
  const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
32138
32145
  if (!duplex.push(data))
32139
32146
  ws.pause();
@@ -40827,7 +40834,7 @@ var require_axios2 = __commonJS((exports, module) => {
40827
40834
  var zlib__default = /* @__PURE__ */ _interopDefaultLegacy(zlib);
40828
40835
  var stream__default = /* @__PURE__ */ _interopDefaultLegacy(stream2);
40829
40836
  function bind(fn, thisArg) {
40830
- return function wrap() {
40837
+ return function wrap3() {
40831
40838
  return fn.apply(thisArg, arguments);
40832
40839
  };
40833
40840
  }
@@ -41405,7 +41412,7 @@ var require_axios2 = __commonJS((exports, module) => {
41405
41412
  prototype.append = function append(name2, value2) {
41406
41413
  this._pairs.push([name2, value2]);
41407
41414
  };
41408
- prototype.toString = function toString(encoder2) {
41415
+ prototype.toString = function toString2(encoder2) {
41409
41416
  const _encode = encoder2 ? function(value2) {
41410
41417
  return encoder2.call(this, value2, encode$1);
41411
41418
  } : encode$1;
@@ -42465,7 +42472,7 @@ var require_axios2 = __commonJS((exports, module) => {
42465
42472
  };
42466
42473
  };
42467
42474
  var buildAddressEntry = (address, family) => resolveFamily(utils$1.isObject(address) ? address : { address, family });
42468
- var httpAdapter = isHttpAdapterSupported && function httpAdapter(config2) {
42475
+ var httpAdapter = isHttpAdapterSupported && function httpAdapter2(config2) {
42469
42476
  return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
42470
42477
  let { data, lookup, family } = config2;
42471
42478
  const { responseType, responseEncoding } = config2;
@@ -43416,7 +43423,7 @@ var require_axios2 = __commonJS((exports, module) => {
43416
43423
  }
43417
43424
  var validators$1 = {};
43418
43425
  ["object", "boolean", "number", "function", "string", "symbol"].forEach((type, i2) => {
43419
- validators$1[type] = function validator(thing) {
43426
+ validators$1[type] = function validator2(thing) {
43420
43427
  return typeof thing === type || "a" + (i2 < 1 ? "n " : " ") + type;
43421
43428
  };
43422
43429
  });
@@ -43713,7 +43720,7 @@ var require_axios2 = __commonJS((exports, module) => {
43713
43720
  }
43714
43721
  var CancelToken$1 = CancelToken;
43715
43722
  function spread(callback) {
43716
- return function wrap(arr) {
43723
+ return function wrap3(arr) {
43717
43724
  return callback.apply(null, arr);
43718
43725
  };
43719
43726
  }
@@ -65221,7 +65228,7 @@ function cookieSerialize(t, s, i) {
65221
65228
  a += "; Path=" + n.path;
65222
65229
  }
65223
65230
  if (n.expires) {
65224
- if (!function isDate(e2) {
65231
+ if (!function isDate2(e2) {
65225
65232
  return Object.prototype.toString.call(e2) === "[object Date]" || e2 instanceof Date;
65226
65233
  }(n.expires) || isNaN(n.expires.valueOf()))
65227
65234
  throw new TypeError("option expires is invalid");
@@ -71619,6 +71626,7 @@ function transformTradesToExchangeType({
71619
71626
  trades,
71620
71627
  take_profit,
71621
71628
  stop_loss,
71629
+ stop_losses,
71622
71630
  kind
71623
71631
  }) {
71624
71632
  const currentTime = Date.now();
@@ -71703,7 +71711,8 @@ function transformTradesToExchangeType({
71703
71711
  });
71704
71712
  nextOrderId++;
71705
71713
  }
71706
- if (stop_loss && stop_loss.quantity > 0) {
71714
+ const effectiveStops = stop_losses && stop_losses.length > 0 ? stop_losses : stop_loss && stop_loss.quantity > 0 ? [stop_loss] : [];
71715
+ for (const sl of effectiveStops) {
71707
71716
  const slSide = kind === "long" ? "sell" : "buy";
71708
71717
  const slPositionSide = kind.toUpperCase();
71709
71718
  result.push({
@@ -71719,28 +71728,29 @@ function transformTradesToExchangeType({
71719
71728
  orderId: nextOrderId,
71720
71729
  order_id: nextOrderId,
71721
71730
  order_type: "future",
71722
- origQty: stop_loss.quantity,
71731
+ origQty: sl.quantity,
71723
71732
  origType: "LIMIT",
71724
71733
  positionSide: slPositionSide,
71725
- price: stop_loss.price,
71734
+ price: sl.price,
71726
71735
  priceMatch: "NONE",
71727
71736
  priceProtect: false,
71728
- qty: stop_loss.quantity,
71729
- quantity: stop_loss.quantity,
71737
+ qty: sl.quantity,
71738
+ quantity: sl.quantity,
71730
71739
  reduceOnly: true,
71731
71740
  selfTradePreventionMode: "EXPIRE_MAKER",
71732
71741
  side: slSide,
71733
71742
  status: "NEW",
71734
- stop: stop_loss.price,
71735
- stopPrice: stop_loss.price,
71743
+ stop: sl.price,
71744
+ stopPrice: sl.price,
71736
71745
  symbol: undefined,
71737
71746
  time: currentTime,
71738
71747
  timeInForce: "GTC",
71739
- triggerPrice: stop_loss.price,
71748
+ triggerPrice: sl.price,
71740
71749
  type: "LIMIT",
71741
71750
  updateTime: currentTime,
71742
71751
  workingType: "CONTRACT_PRICE"
71743
71752
  });
71753
+ nextOrderId++;
71744
71754
  }
71745
71755
  return result;
71746
71756
  }
@@ -71758,7 +71768,7 @@ function transformExchangeOrderToTradeWithValidation(orders, options) {
71758
71768
  } = options || {};
71759
71769
  const trades = [];
71760
71770
  let take_profit;
71761
- let stop_loss;
71771
+ const stop_losses = [];
71762
71772
  orders.forEach((order, index) => {
71763
71773
  if (validatePrice && (typeof order.price !== "number" || order.price <= 0)) {
71764
71774
  throw new Error(`Invalid price at index ${index}: ${order.price}. Price must be a positive number`);
@@ -71776,11 +71786,11 @@ function transformExchangeOrderToTradeWithValidation(orders, options) {
71776
71786
  };
71777
71787
  return;
71778
71788
  }
71779
- if (isStopLossOrder(order) && !stop_loss) {
71780
- stop_loss = {
71789
+ if (isStopLossOrder(order)) {
71790
+ stop_losses.push({
71781
71791
  price: order.price,
71782
71792
  quantity: order.quantity
71783
- };
71793
+ });
71784
71794
  return;
71785
71795
  }
71786
71796
  trades.push({
@@ -71789,7 +71799,7 @@ function transformExchangeOrderToTradeWithValidation(orders, options) {
71789
71799
  avg_size: order.quantity,
71790
71800
  neg_pnl: 0,
71791
71801
  avg_entry: order.price,
71792
- stop: stop_loss?.price || order.stop || defaultStop,
71802
+ stop: stop_losses[0]?.price || order.stop || defaultStop,
71793
71803
  reverse_avg_entry: order.price,
71794
71804
  reverse_avg_quantity: order.quantity,
71795
71805
  fee: 0,
@@ -71799,7 +71809,8 @@ function transformExchangeOrderToTradeWithValidation(orders, options) {
71799
71809
  return {
71800
71810
  trades,
71801
71811
  take_profit,
71802
- stop_loss
71812
+ stop_loss: stop_losses[0],
71813
+ stop_losses
71803
71814
  };
71804
71815
  }
71805
71816
  function updatePositionBasedOffTpOrSl({
@@ -71810,7 +71821,7 @@ function updatePositionBasedOffTpOrSl({
71810
71821
  }) {
71811
71822
  const position2 = positions[kind];
71812
71823
  const side_orders = orders.filter((o) => o.positionSide.toLowerCase() === kind);
71813
- const { trades, take_profit, stop_loss } = transformExchangeOrderToTradeWithValidation(side_orders, {
71824
+ const { trades, take_profit, stop_loss, stop_losses } = transformExchangeOrderToTradeWithValidation(side_orders, {
71814
71825
  validatePrice: false,
71815
71826
  validateQuantity: false,
71816
71827
  defaultStop: 0
@@ -71836,25 +71847,41 @@ function updatePositionBasedOffTpOrSl({
71836
71847
  orders: transformTradesToExchangeType({
71837
71848
  trades,
71838
71849
  kind,
71839
- stop_loss
71850
+ stop_loss,
71851
+ stop_losses
71840
71852
  }),
71841
71853
  changed: "tp"
71842
71854
  };
71843
71855
  }
71844
71856
  }
71845
- if (stop_loss && stop_loss.quantity) {
71846
- const should_close = kind === "long" ? current_price <= stop_loss.price : current_price >= stop_loss.price;
71847
- if (should_close) {
71848
- position2.quantity = Math.max(0, position2.quantity - stop_loss.quantity);
71857
+ const all_stops = stop_losses && stop_losses.length > 0 ? stop_losses : stop_loss && stop_loss.quantity ? [stop_loss] : [];
71858
+ if (all_stops.length > 0) {
71859
+ const sorted_stops = [...all_stops].sort((a, b) => kind === "long" ? b.price - a.price : a.price - b.price);
71860
+ const triggered = [];
71861
+ const remaining = [];
71862
+ for (const sl of sorted_stops) {
71863
+ const should_close = kind === "long" ? current_price <= sl.price : current_price >= sl.price;
71864
+ if (should_close) {
71865
+ triggered.push(sl);
71866
+ } else {
71867
+ remaining.push(sl);
71868
+ }
71869
+ }
71870
+ if (triggered.length > 0) {
71871
+ const totalStopQty = triggered.reduce((sum, sl) => sum + sl.quantity, 0);
71872
+ position2.quantity = Math.max(0, position2.quantity - totalStopQty);
71849
71873
  if (position2.quantity === 0) {
71850
71874
  position2.entry = 0;
71851
71875
  }
71876
+ const furthestTriggered = kind === "long" ? Math.min(...triggered.map((sl) => sl.price)) : Math.max(...triggered.map((sl) => sl.price));
71877
+ const remainingTrades = trades.filter((t2) => kind === "long" ? t2.entry < furthestTriggered : t2.entry > furthestTriggered);
71852
71878
  return {
71853
71879
  position: position2,
71854
71880
  orders: transformTradesToExchangeType({
71855
- trades: trades.filter((t2) => kind === "long" ? t2.entry < stop_loss.price : t2.entry > stop_loss.price),
71881
+ trades: remainingTrades,
71856
71882
  kind,
71857
- take_profit
71883
+ take_profit,
71884
+ stop_losses: remaining.length > 0 ? remaining : undefined
71858
71885
  }),
71859
71886
  changed: "sl",
71860
71887
  trades
@@ -76671,11 +76698,13 @@ async function updateDbDetails(client, payload, current_account_info, new_payloa
76671
76698
  price: position2.stop_loss,
76672
76699
  quantity: position2.stop_quantity
76673
76700
  } : undefined);
76701
+ const stop_losses = new_payload.stop_losses;
76674
76702
  const as_exchange_orders = new_payload.raw ? new_payload.orders : transformTradesToExchangeType({
76675
76703
  trades: new_payload.orders,
76676
76704
  kind: payload.kind,
76677
76705
  take_profit,
76678
- stop_loss
76706
+ stop_loss,
76707
+ stop_losses
76679
76708
  });
76680
76709
  const reverse_kind = payload.kind === "long" ? "short" : "long";
76681
76710
  const reverse_orders = current_account_info.config.trades.exchange_info.open_orders.filter((o) => {
@@ -76772,6 +76801,19 @@ async function fetchDBExchangeData(client, symbol, options) {
76772
76801
  short: short_result.trades
76773
76802
  };
76774
76803
  }
76804
+ const stop_losses_by_kind = {
76805
+ long: [],
76806
+ short: []
76807
+ };
76808
+ for (const o of orders) {
76809
+ const k = o.positionSide?.toLowerCase();
76810
+ if (k && (o.isStop || o.stopPrice > 0)) {
76811
+ stop_losses_by_kind[k].push({
76812
+ price: o.stopPrice || o.stop || o.price,
76813
+ quantity: o.origQty || o.quantity
76814
+ });
76815
+ }
76816
+ }
76775
76817
  return {
76776
76818
  orders,
76777
76819
  symbol_config,
@@ -76781,11 +76823,12 @@ async function fetchDBExchangeData(client, symbol, options) {
76781
76823
  trades,
76782
76824
  drift,
76783
76825
  priceChanged,
76826
+ stop_losses_by_kind,
76784
76827
  raw_data: live_exchange_details?.data
76785
76828
  };
76786
76829
  }
76787
76830
  async function reconcileEngineState(client, symbol, options) {
76788
- const { positions, symbol_config, current_price, raw_data, trades, drift, priceChanged } = await fetchDBExchangeData(client, symbol, options);
76831
+ const { positions, symbol_config, current_price, raw_data, trades, drift, priceChanged, stop_losses_by_kind } = await fetchDBExchangeData(client, symbol, options);
76789
76832
  const long_generator = new TradeEngine({
76790
76833
  position: {
76791
76834
  kind: "long",
@@ -76830,7 +76873,13 @@ async function reconcileEngineState(client, symbol, options) {
76830
76873
  state.position.quantity = 0;
76831
76874
  tp = { price: 0, quantity: 0 };
76832
76875
  }
76833
- await updateDbDetails(client, { kind, symbol }, raw_data, { take_profit: tp, position: _position, orders: state_trades });
76876
+ const kind_stops = stop_losses_by_kind[kind];
76877
+ await updateDbDetails(client, { kind, symbol }, raw_data, {
76878
+ take_profit: tp,
76879
+ position: _position,
76880
+ orders: state_trades,
76881
+ stop_losses: kind_stops.length > 0 ? kind_stops : undefined
76882
+ });
76834
76883
  changed = true;
76835
76884
  }
76836
76885
  }
@@ -76998,10 +77047,14 @@ async function placeStopOrder3(client, payload) {
76998
77047
  price: order.stop,
76999
77048
  quantity: order.quantity
77000
77049
  };
77001
- const { trades } = transformExchangeOrderToTradeWithValidation(sameKindOrders, {
77050
+ const { trades, stop_losses: existingStops } = transformExchangeOrderToTradeWithValidation(sameKindOrders, {
77002
77051
  validateQuantity: false,
77003
77052
  validatePrice: false
77004
77053
  });
77054
+ const all_stop_losses = [
77055
+ ...existingStops || [],
77056
+ stop_loss
77057
+ ];
77005
77058
  return savePaperDetails(client, {
77006
77059
  kind: order.kind,
77007
77060
  symbol: payload.symbol,
@@ -77010,7 +77063,7 @@ async function placeStopOrder3(client, payload) {
77010
77063
  }, {
77011
77064
  position: {},
77012
77065
  orders: trades,
77013
- stop_loss
77066
+ stop_losses: all_stop_losses
77014
77067
  });
77015
77068
  }
77016
77069
  async function placeTpOrder3(client, payload) {