@gbozee/ultimate 0.0.2-next.80 → 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 } = 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,18 +78386,31 @@ 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];
78400
+ const existingStops = stop_losses_by_kind[kind];
78401
+ const stopPayload = existingStops && existingStops.length > 0 ? { stop_losses: existingStops } : {};
78390
78402
  console.log({
78391
- length: remaining_orders.length,
78403
+ length: mergedOrders.length,
78392
78404
  position: current_position_state,
78393
- last: remaining_orders[remaining_orders.length - 1]
78405
+ last: mergedOrders[mergedOrders.length - 1]
78394
78406
  });
78395
78407
  return await updateDbDetails(client, {
78396
78408
  kind,
78397
78409
  symbol: payload.symbol
78398
78410
  }, raw_data, {
78399
78411
  position: current_position_state,
78400
- orders: remaining_orders
78412
+ orders: mergedOrders,
78413
+ ...stopPayload
78401
78414
  });
78402
78415
  return await savePaperDetails(client, {
78403
78416
  kind,
@@ -78406,7 +78419,8 @@ async function createLimitPurchaseOrders2(client, payload) {
78406
78419
  decimal_places: payload.decimal_places
78407
78420
  }, {
78408
78421
  position: current_position_state,
78409
- orders: remaining_orders
78422
+ orders: mergedOrders,
78423
+ ...stopPayload
78410
78424
  });
78411
78425
  }
78412
78426
 
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 } = 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,18 +78284,31 @@ 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];
78298
+ const existingStops = stop_losses_by_kind[kind];
78299
+ const stopPayload = existingStops && existingStops.length > 0 ? { stop_losses: existingStops } : {};
78288
78300
  console.log({
78289
- length: remaining_orders.length,
78301
+ length: mergedOrders.length,
78290
78302
  position: current_position_state,
78291
- last: remaining_orders[remaining_orders.length - 1]
78303
+ last: mergedOrders[mergedOrders.length - 1]
78292
78304
  });
78293
78305
  return await updateDbDetails(client, {
78294
78306
  kind,
78295
78307
  symbol: payload.symbol
78296
78308
  }, raw_data, {
78297
78309
  position: current_position_state,
78298
- orders: remaining_orders
78310
+ orders: mergedOrders,
78311
+ ...stopPayload
78299
78312
  });
78300
78313
  return await savePaperDetails(client, {
78301
78314
  kind,
@@ -78304,7 +78317,8 @@ async function createLimitPurchaseOrders2(client, payload) {
78304
78317
  decimal_places: payload.decimal_places
78305
78318
  }, {
78306
78319
  position: current_position_state,
78307
- orders: remaining_orders
78320
+ orders: mergedOrders,
78321
+ ...stopPayload
78308
78322
  });
78309
78323
  }
78310
78324
 
@@ -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 } = 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,18 +82106,31 @@ 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];
82120
+ const existingStops = stop_losses_by_kind[kind];
82121
+ const stopPayload = existingStops && existingStops.length > 0 ? { stop_losses: existingStops } : {};
82110
82122
  console.log({
82111
- length: remaining_orders.length,
82123
+ length: mergedOrders.length,
82112
82124
  position: current_position_state,
82113
- last: remaining_orders[remaining_orders.length - 1]
82125
+ last: mergedOrders[mergedOrders.length - 1]
82114
82126
  });
82115
82127
  return await updateDbDetails(client, {
82116
82128
  kind,
82117
82129
  symbol: payload.symbol
82118
82130
  }, raw_data, {
82119
82131
  position: current_position_state,
82120
- orders: remaining_orders
82132
+ orders: mergedOrders,
82133
+ ...stopPayload
82121
82134
  });
82122
82135
  return await savePaperDetails(client, {
82123
82136
  kind,
@@ -82126,7 +82139,8 @@ async function createLimitPurchaseOrders2(client, payload) {
82126
82139
  decimal_places: payload.decimal_places
82127
82140
  }, {
82128
82141
  position: current_position_state,
82129
- orders: remaining_orders
82142
+ orders: mergedOrders,
82143
+ ...stopPayload
82130
82144
  });
82131
82145
  }
82132
82146
 
@@ -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 } = 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,18 +82065,31 @@ 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];
82079
+ const existingStops = stop_losses_by_kind[kind];
82080
+ const stopPayload = existingStops && existingStops.length > 0 ? { stop_losses: existingStops } : {};
82069
82081
  console.log({
82070
- length: remaining_orders.length,
82082
+ length: mergedOrders.length,
82071
82083
  position: current_position_state,
82072
- last: remaining_orders[remaining_orders.length - 1]
82084
+ last: mergedOrders[mergedOrders.length - 1]
82073
82085
  });
82074
82086
  return await updateDbDetails(client, {
82075
82087
  kind,
82076
82088
  symbol: payload.symbol
82077
82089
  }, raw_data, {
82078
82090
  position: current_position_state,
82079
- orders: remaining_orders
82091
+ orders: mergedOrders,
82092
+ ...stopPayload
82080
82093
  });
82081
82094
  return await savePaperDetails(client, {
82082
82095
  kind,
@@ -82085,7 +82098,8 @@ async function createLimitPurchaseOrders2(client, payload) {
82085
82098
  decimal_places: payload.decimal_places
82086
82099
  }, {
82087
82100
  position: current_position_state,
82088
- orders: remaining_orders
82101
+ orders: mergedOrders,
82102
+ ...stopPayload
82089
82103
  });
82090
82104
  }
82091
82105
 
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.80",
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",