@blackcube/xgate-sdk 0.58.0 → 0.58.2

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
@@ -161,17 +161,22 @@ function createAccountXex(xex, access) {
161
161
  },
162
162
  { default: "a" }
163
163
  );
164
- case "pacifica" /* Pacifica */:
164
+ case "pacifica" /* Pacifica */: {
165
+ const secretKey = access.privateKey ?? "";
166
+ const signataire = secretKey === "" ? null : new pacificaSdk.Pacifica().helpers().solanaAddress(secretKey);
167
+ const compte = adresse();
165
168
  return new pacificaSdk.Pacifica(
166
169
  {
167
170
  a: {
168
- secretKey: access.privateKey ?? "",
169
- publicKey: adresse(),
170
- network: access.network ?? "mainnet"
171
+ secretKey,
172
+ publicKey: compte,
173
+ network: access.network ?? "mainnet",
174
+ ...signataire !== null && signataire !== compte ? { agentWallet: signataire } : {}
171
175
  }
172
176
  },
173
177
  { default: "a" }
174
178
  );
179
+ }
175
180
  case "lighter" /* Lighter */:
176
181
  return new lighterSdk.Lighter(
177
182
  {
@@ -1703,15 +1708,25 @@ exports.TradingService = class TradingService {
1703
1708
  * take-profit peut remplir en plusieurs fois. Seul l'historique porte le prix réellement obtenu, et
1704
1709
  * c'est lui qui doit servir au calcul du résultat — sinon le PnL affiché est une fiction.
1705
1710
  *
1706
- * On retient le **dernier** ordre de sortie rempli après `openedAt` : les précédents sont les
1707
- * take-profits partiels, celui-là est la clôture.
1711
+ * On lit les **exécutions** (`trades`), jamais les ordres : le prix d'un ordre est sa LIMITE — chez
1712
+ * hyperliquid, un market est un IOC borné à mark ± glissement, et son « prix » est cette borne, pas le
1713
+ * prix obtenu (BNB, 2026-10-01 : sortie lue à 844,44 pour des fills à 767,69). Le prix de sortie est la
1714
+ * moyenne des exécutions de sortie après `openedAt` — et avant `until` quand il est donné — pondérée par
1715
+ * leur taille : TP partiels et clôture compris, c'est le prix auquel la position est réellement sortie.
1708
1716
  */
1709
- async exitPrice(access, symbolXex, direction, openedAt) {
1717
+ async exitPrice(access, symbolXex, direction, openedAt, until) {
1710
1718
  const exit = direction === "long" ? "sell" : "buy";
1711
- const history = await this.perpOf(access).getHistory({ name: symbolXex });
1712
- const exits = history.filter((order) => order.name === symbolXex && order.side === exit).filter((order) => order.status === "filled" || order.status === "partiallyFilled").filter((order) => order.placedAt.getTime() > openedAt.getTime()).filter((order) => order.price !== null && Number(order.price) > 0).sort((left, right) => right.placedAt.getTime() - left.placedAt.getTime());
1713
- const last = exits[0];
1714
- return last === void 0 ? null : last.price;
1719
+ const fin = until === void 0 ? Number.POSITIVE_INFINITY : until.getTime();
1720
+ const fills = (await this.trades(access)).filter((fill) => fill.symbolXex === symbolXex && fill.side === exit).filter(
1721
+ (fill) => fill.filledAt.getTime() > openedAt.getTime() && fill.filledAt.getTime() <= fin
1722
+ ).filter((fill) => Number(fill.price) > 0 && Number(fill.size) > 0);
1723
+ const taille = fills.reduce((total, fill) => total + Number(fill.size), 0);
1724
+ if (taille === 0) {
1725
+ return null;
1726
+ }
1727
+ const moyenne = fills.reduce((total, fill) => total + Number(fill.price) * Number(fill.size), 0) / taille;
1728
+ const decimales = Math.max(...fills.map((fill) => (fill.price.split(".")[1] ?? "").length));
1729
+ return String(Number(moyenne.toFixed(decimales)));
1715
1730
  }
1716
1731
  /**
1717
1732
  * L'HISTORIQUE DES ORDRES du compte — ce qui a été soumis, rempli, annulé ou expiré.