@gbozee/ultimate 0.0.2-43 → 0.0.2-45

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.
@@ -277,5 +277,14 @@ export declare function determine_break_even_price(payload: {
277
277
  price: number;
278
278
  direction: string;
279
279
  };
280
+ export declare function determine_amount_to_buy(payload: {
281
+ orders: any[];
282
+ kind: "long" | "short";
283
+ decimal_places?: string;
284
+ price_places?: string;
285
+ place?: boolean;
286
+ position: any;
287
+ existingOrders: any[];
288
+ }): any[];
280
289
 
281
290
  export {};
@@ -1317,6 +1317,38 @@ function determine_break_even_price(payload) {
1317
1317
  direction: net_quantity > 0 ? "long" : "short"
1318
1318
  };
1319
1319
  }
1320
+ function determine_amount_to_buy(payload) {
1321
+ const {
1322
+ orders,
1323
+ kind,
1324
+ decimal_places = "%.3f",
1325
+ position: position2,
1326
+ existingOrders
1327
+ } = payload;
1328
+ const totalQuantity = orders.reduce((sum, order) => sum + (order.quantity || 0), 0);
1329
+ let runningTotal = to_f2(totalQuantity, decimal_places);
1330
+ let sortedOrders = [...orders].sort((a, b) => (a.entry || 0) - (b.entry || 0));
1331
+ if (kind === "short") {
1332
+ sortedOrders.reverse();
1333
+ }
1334
+ const withCumulative = [];
1335
+ for (const order of sortedOrders) {
1336
+ withCumulative.push({
1337
+ ...order,
1338
+ cumulative_quantity: runningTotal
1339
+ });
1340
+ runningTotal -= order.quantity;
1341
+ runningTotal = to_f2(runningTotal, decimal_places);
1342
+ }
1343
+ let filteredOrders = withCumulative.filter((order) => (order.cumulative_quantity || 0) > position2?.quantity).map((order) => ({
1344
+ ...order,
1345
+ price: order.entry,
1346
+ kind,
1347
+ side: kind.toLowerCase() === "long" ? "buy" : "sell"
1348
+ }));
1349
+ filteredOrders = filteredOrders.filter((k) => !existingOrders.map((j) => j.price).includes(k.price));
1350
+ return filteredOrders;
1351
+ }
1320
1352
  export {
1321
1353
  sortedBuildConfig,
1322
1354
  get_app_config_and_max_size,
@@ -1324,6 +1356,7 @@ export {
1324
1356
  generate_config_params,
1325
1357
  determine_break_even_price,
1326
1358
  determine_average_entry_and_size,
1359
+ determine_amount_to_buy,
1327
1360
  createArray,
1328
1361
  buildConfig,
1329
1362
  buildAvg,
package/dist/index.d.ts CHANGED
@@ -746,6 +746,15 @@ export declare function determine_break_even_price(payload: {
746
746
  price: number;
747
747
  direction: string;
748
748
  };
749
+ export declare function determine_amount_to_buy(payload: {
750
+ orders: any[];
751
+ kind: "long" | "short";
752
+ decimal_places?: string;
753
+ price_places?: string;
754
+ place?: boolean;
755
+ position: any;
756
+ existingOrders: any[];
757
+ }): any[];
749
758
  declare class ExchangePosition {
750
759
  exchange: BaseExchange;
751
760
  exchange_account: ExchangeAccount$1;
@@ -1401,6 +1410,7 @@ export declare function initApp(payload: {
1401
1410
  proxy?: any;
1402
1411
  ignore_proxy?: boolean;
1403
1412
  canWithdraw?: boolean;
1413
+ triggerToken?: string;
1404
1414
  }): Promise<App>;
1405
1415
  export declare function initialize(payload: {
1406
1416
  password?: string;