@gbozee/ultimate 0.0.2-next.81 → 0.0.2-next.82

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 CHANGED
@@ -78367,7 +78367,7 @@ async function cancelOrders3(payload) {
78367
78367
  });
78368
78368
  }
78369
78369
  async function createLimitPurchaseOrders2(client, payload) {
78370
- const { positions, symbol_config, current_price, raw_data, stop_losses_by_kind } = await fetchDBExchangeData(client, payload.symbol);
78370
+ const { positions, symbol_config, current_price, raw_data, stop_losses_by_kind, trades: existingTrades } = await fetchDBExchangeData(client, payload.symbol);
78371
78371
  const kind = payload.orders[0].kind || payload.kind;
78372
78372
  const params = {
78373
78373
  position: {
@@ -78386,20 +78386,30 @@ async function createLimitPurchaseOrders2(client, payload) {
78386
78386
  entry: state.position.entry,
78387
78387
  quantity: state.position.quantity
78388
78388
  };
78389
- const remaining_orders = state.newTrades;
78389
+ const allNewOrders = payload.orders.map((o) => ({
78390
+ entry: o.entry || o.price,
78391
+ quantity: o.quantity
78392
+ }));
78393
+ const existingLimitTrades = (existingTrades[kind] || []).map((t2) => ({
78394
+ entry: t2.entry,
78395
+ quantity: t2.quantity
78396
+ }));
78397
+ const newEntryPrices = new Set(allNewOrders.map((o) => o.entry));
78398
+ const preservedExisting = existingLimitTrades.filter((t2) => !newEntryPrices.has(t2.entry));
78399
+ const mergedOrders = [...preservedExisting, ...allNewOrders];
78390
78400
  const existingStops = stop_losses_by_kind[kind];
78391
78401
  const stopPayload = existingStops && existingStops.length > 0 ? { stop_losses: existingStops } : {};
78392
78402
  console.log({
78393
- length: remaining_orders.length,
78403
+ length: mergedOrders.length,
78394
78404
  position: current_position_state,
78395
- last: remaining_orders[remaining_orders.length - 1]
78405
+ last: mergedOrders[mergedOrders.length - 1]
78396
78406
  });
78397
78407
  return await updateDbDetails(client, {
78398
78408
  kind,
78399
78409
  symbol: payload.symbol
78400
78410
  }, raw_data, {
78401
78411
  position: current_position_state,
78402
- orders: remaining_orders,
78412
+ orders: mergedOrders,
78403
78413
  ...stopPayload
78404
78414
  });
78405
78415
  return await savePaperDetails(client, {
@@ -78409,7 +78419,7 @@ async function createLimitPurchaseOrders2(client, payload) {
78409
78419
  decimal_places: payload.decimal_places
78410
78420
  }, {
78411
78421
  position: current_position_state,
78412
- orders: remaining_orders,
78422
+ orders: mergedOrders,
78413
78423
  ...stopPayload
78414
78424
  });
78415
78425
  }
package/dist/index.js CHANGED
@@ -78265,7 +78265,7 @@ async function cancelOrders3(payload) {
78265
78265
  });
78266
78266
  }
78267
78267
  async function createLimitPurchaseOrders2(client, payload) {
78268
- const { positions, symbol_config, current_price, raw_data, stop_losses_by_kind } = await fetchDBExchangeData(client, payload.symbol);
78268
+ const { positions, symbol_config, current_price, raw_data, stop_losses_by_kind, trades: existingTrades } = await fetchDBExchangeData(client, payload.symbol);
78269
78269
  const kind = payload.orders[0].kind || payload.kind;
78270
78270
  const params = {
78271
78271
  position: {
@@ -78284,20 +78284,30 @@ async function createLimitPurchaseOrders2(client, payload) {
78284
78284
  entry: state.position.entry,
78285
78285
  quantity: state.position.quantity
78286
78286
  };
78287
- const remaining_orders = state.newTrades;
78287
+ const allNewOrders = payload.orders.map((o) => ({
78288
+ entry: o.entry || o.price,
78289
+ quantity: o.quantity
78290
+ }));
78291
+ const existingLimitTrades = (existingTrades[kind] || []).map((t2) => ({
78292
+ entry: t2.entry,
78293
+ quantity: t2.quantity
78294
+ }));
78295
+ const newEntryPrices = new Set(allNewOrders.map((o) => o.entry));
78296
+ const preservedExisting = existingLimitTrades.filter((t2) => !newEntryPrices.has(t2.entry));
78297
+ const mergedOrders = [...preservedExisting, ...allNewOrders];
78288
78298
  const existingStops = stop_losses_by_kind[kind];
78289
78299
  const stopPayload = existingStops && existingStops.length > 0 ? { stop_losses: existingStops } : {};
78290
78300
  console.log({
78291
- length: remaining_orders.length,
78301
+ length: mergedOrders.length,
78292
78302
  position: current_position_state,
78293
- last: remaining_orders[remaining_orders.length - 1]
78303
+ last: mergedOrders[mergedOrders.length - 1]
78294
78304
  });
78295
78305
  return await updateDbDetails(client, {
78296
78306
  kind,
78297
78307
  symbol: payload.symbol
78298
78308
  }, raw_data, {
78299
78309
  position: current_position_state,
78300
- orders: remaining_orders,
78310
+ orders: mergedOrders,
78301
78311
  ...stopPayload
78302
78312
  });
78303
78313
  return await savePaperDetails(client, {
@@ -78307,7 +78317,7 @@ async function createLimitPurchaseOrders2(client, payload) {
78307
78317
  decimal_places: payload.decimal_places
78308
78318
  }, {
78309
78319
  position: current_position_state,
78310
- orders: remaining_orders,
78320
+ orders: mergedOrders,
78311
78321
  ...stopPayload
78312
78322
  });
78313
78323
  }
@@ -82087,7 +82087,7 @@ async function cancelOrders3(payload) {
82087
82087
  });
82088
82088
  }
82089
82089
  async function createLimitPurchaseOrders2(client, payload) {
82090
- const { positions, symbol_config, current_price, raw_data, stop_losses_by_kind } = await fetchDBExchangeData(client, payload.symbol);
82090
+ const { positions, symbol_config, current_price, raw_data, stop_losses_by_kind, trades: existingTrades } = await fetchDBExchangeData(client, payload.symbol);
82091
82091
  const kind = payload.orders[0].kind || payload.kind;
82092
82092
  const params = {
82093
82093
  position: {
@@ -82106,20 +82106,30 @@ async function createLimitPurchaseOrders2(client, payload) {
82106
82106
  entry: state.position.entry,
82107
82107
  quantity: state.position.quantity
82108
82108
  };
82109
- const remaining_orders = state.newTrades;
82109
+ const allNewOrders = payload.orders.map((o) => ({
82110
+ entry: o.entry || o.price,
82111
+ quantity: o.quantity
82112
+ }));
82113
+ const existingLimitTrades = (existingTrades[kind] || []).map((t2) => ({
82114
+ entry: t2.entry,
82115
+ quantity: t2.quantity
82116
+ }));
82117
+ const newEntryPrices = new Set(allNewOrders.map((o) => o.entry));
82118
+ const preservedExisting = existingLimitTrades.filter((t2) => !newEntryPrices.has(t2.entry));
82119
+ const mergedOrders = [...preservedExisting, ...allNewOrders];
82110
82120
  const existingStops = stop_losses_by_kind[kind];
82111
82121
  const stopPayload = existingStops && existingStops.length > 0 ? { stop_losses: existingStops } : {};
82112
82122
  console.log({
82113
- length: remaining_orders.length,
82123
+ length: mergedOrders.length,
82114
82124
  position: current_position_state,
82115
- last: remaining_orders[remaining_orders.length - 1]
82125
+ last: mergedOrders[mergedOrders.length - 1]
82116
82126
  });
82117
82127
  return await updateDbDetails(client, {
82118
82128
  kind,
82119
82129
  symbol: payload.symbol
82120
82130
  }, raw_data, {
82121
82131
  position: current_position_state,
82122
- orders: remaining_orders,
82132
+ orders: mergedOrders,
82123
82133
  ...stopPayload
82124
82134
  });
82125
82135
  return await savePaperDetails(client, {
@@ -82129,7 +82139,7 @@ async function createLimitPurchaseOrders2(client, payload) {
82129
82139
  decimal_places: payload.decimal_places
82130
82140
  }, {
82131
82141
  position: current_position_state,
82132
- orders: remaining_orders,
82142
+ orders: mergedOrders,
82133
82143
  ...stopPayload
82134
82144
  });
82135
82145
  }
@@ -82046,7 +82046,7 @@ async function cancelOrders3(payload) {
82046
82046
  });
82047
82047
  }
82048
82048
  async function createLimitPurchaseOrders2(client, payload) {
82049
- const { positions, symbol_config, current_price, raw_data, stop_losses_by_kind } = await fetchDBExchangeData(client, payload.symbol);
82049
+ const { positions, symbol_config, current_price, raw_data, stop_losses_by_kind, trades: existingTrades } = await fetchDBExchangeData(client, payload.symbol);
82050
82050
  const kind = payload.orders[0].kind || payload.kind;
82051
82051
  const params = {
82052
82052
  position: {
@@ -82065,20 +82065,30 @@ async function createLimitPurchaseOrders2(client, payload) {
82065
82065
  entry: state.position.entry,
82066
82066
  quantity: state.position.quantity
82067
82067
  };
82068
- const remaining_orders = state.newTrades;
82068
+ const allNewOrders = payload.orders.map((o) => ({
82069
+ entry: o.entry || o.price,
82070
+ quantity: o.quantity
82071
+ }));
82072
+ const existingLimitTrades = (existingTrades[kind] || []).map((t2) => ({
82073
+ entry: t2.entry,
82074
+ quantity: t2.quantity
82075
+ }));
82076
+ const newEntryPrices = new Set(allNewOrders.map((o) => o.entry));
82077
+ const preservedExisting = existingLimitTrades.filter((t2) => !newEntryPrices.has(t2.entry));
82078
+ const mergedOrders = [...preservedExisting, ...allNewOrders];
82069
82079
  const existingStops = stop_losses_by_kind[kind];
82070
82080
  const stopPayload = existingStops && existingStops.length > 0 ? { stop_losses: existingStops } : {};
82071
82081
  console.log({
82072
- length: remaining_orders.length,
82082
+ length: mergedOrders.length,
82073
82083
  position: current_position_state,
82074
- last: remaining_orders[remaining_orders.length - 1]
82084
+ last: mergedOrders[mergedOrders.length - 1]
82075
82085
  });
82076
82086
  return await updateDbDetails(client, {
82077
82087
  kind,
82078
82088
  symbol: payload.symbol
82079
82089
  }, raw_data, {
82080
82090
  position: current_position_state,
82081
- orders: remaining_orders,
82091
+ orders: mergedOrders,
82082
82092
  ...stopPayload
82083
82093
  });
82084
82094
  return await savePaperDetails(client, {
@@ -82088,7 +82098,7 @@ async function createLimitPurchaseOrders2(client, payload) {
82088
82098
  decimal_places: payload.decimal_places
82089
82099
  }, {
82090
82100
  position: current_position_state,
82091
- orders: remaining_orders,
82101
+ orders: mergedOrders,
82092
82102
  ...stopPayload
82093
82103
  });
82094
82104
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gbozee/ultimate",
3
3
  "type": "module",
4
- "version": "0.0.2-next.81",
4
+ "version": "0.0.2-next.82",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",