@blackcube/xgate-sdk 0.58.0 → 0.58.1
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 +17 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +17 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1703,15 +1703,25 @@ exports.TradingService = class TradingService {
|
|
|
1703
1703
|
* take-profit peut remplir en plusieurs fois. Seul l'historique porte le prix réellement obtenu, et
|
|
1704
1704
|
* c'est lui qui doit servir au calcul du résultat — sinon le PnL affiché est une fiction.
|
|
1705
1705
|
*
|
|
1706
|
-
* On
|
|
1707
|
-
*
|
|
1706
|
+
* On lit les **exécutions** (`trades`), jamais les ordres : le prix d'un ordre est sa LIMITE — chez
|
|
1707
|
+
* hyperliquid, un market est un IOC borné à mark ± glissement, et son « prix » est cette borne, pas le
|
|
1708
|
+
* prix obtenu (BNB, 2026-10-01 : sortie lue à 844,44 pour des fills à 767,69). Le prix de sortie est la
|
|
1709
|
+
* moyenne des exécutions de sortie après `openedAt` — et avant `until` quand il est donné — pondérée par
|
|
1710
|
+
* leur taille : TP partiels et clôture compris, c'est le prix auquel la position est réellement sortie.
|
|
1708
1711
|
*/
|
|
1709
|
-
async exitPrice(access, symbolXex, direction, openedAt) {
|
|
1712
|
+
async exitPrice(access, symbolXex, direction, openedAt, until) {
|
|
1710
1713
|
const exit = direction === "long" ? "sell" : "buy";
|
|
1711
|
-
const
|
|
1712
|
-
const
|
|
1713
|
-
|
|
1714
|
-
|
|
1714
|
+
const fin = until === void 0 ? Number.POSITIVE_INFINITY : until.getTime();
|
|
1715
|
+
const fills = (await this.trades(access)).filter((fill) => fill.symbolXex === symbolXex && fill.side === exit).filter(
|
|
1716
|
+
(fill) => fill.filledAt.getTime() > openedAt.getTime() && fill.filledAt.getTime() <= fin
|
|
1717
|
+
).filter((fill) => Number(fill.price) > 0 && Number(fill.size) > 0);
|
|
1718
|
+
const taille = fills.reduce((total, fill) => total + Number(fill.size), 0);
|
|
1719
|
+
if (taille === 0) {
|
|
1720
|
+
return null;
|
|
1721
|
+
}
|
|
1722
|
+
const moyenne = fills.reduce((total, fill) => total + Number(fill.price) * Number(fill.size), 0) / taille;
|
|
1723
|
+
const decimales = Math.max(...fills.map((fill) => (fill.price.split(".")[1] ?? "").length));
|
|
1724
|
+
return String(Number(moyenne.toFixed(decimales)));
|
|
1715
1725
|
}
|
|
1716
1726
|
/**
|
|
1717
1727
|
* L'HISTORIQUE DES ORDRES du compte — ce qui a été soumis, rempli, annulé ou expiré.
|