@blackcube/xgate-sdk 0.24.0 → 0.25.0
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/README.md +22 -6
- package/dist/index.cjs +10 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -12
- package/dist/index.d.ts +55 -12
- package/dist/index.js +10 -7
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -230,12 +230,28 @@ venues.
|
|
|
230
230
|
## Le trading
|
|
231
231
|
|
|
232
232
|
**Jamais un ordre sans stop.** `openWithProtection` est la seule façon d'ouvrir une position, et
|
|
233
|
-
elle exige un `
|
|
233
|
+
elle exige un `sl`. La protection part **avec** l'entrée, en un geste que la venue traite
|
|
234
234
|
atomiquement : si l'entrée ne remplit pas, la protection ne naît jamais.
|
|
235
235
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
236
|
+
### Un niveau se dit en écart OU en prix
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
sl: { pct: 0.02 } // 2 % sous l'entrée en long, 2 % au-dessus en short
|
|
240
|
+
sl: { price: 62500 } // exactement 62 500, quel que soit le prix d'entrée
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Les deux façons de penser un objectif coexistent réellement : « je sors si ça monte de 10 % »
|
|
244
|
+
raisonne en **risque**, « je sors si ça touche 62 500 » raisonne en **niveau technique**. Obliger à
|
|
245
|
+
convertir l'un dans l'autre reviendrait à faire calculer l'appelant, donc à déplacer l'erreur chez
|
|
246
|
+
lui. Les deux modes se mélangent librement dans le même appel.
|
|
247
|
+
|
|
248
|
+
**`part` reste toujours une fraction de la POSITION** — les deux modes ne portent que sur le niveau.
|
|
249
|
+
|
|
250
|
+
Le type rend l'ambiguïté impossible : `ITarget` est une union **exclusive**, donc
|
|
251
|
+
`{ pct: 0.1, price: 62500 }` **ne compile pas**, et `{}` non plus.
|
|
252
|
+
|
|
253
|
+
**XGate arrondit les niveaux à la grille de la paire** et garantit qu'au-delà de 80 % de parts
|
|
254
|
+
cumulées la position ferme entièrement — sans reliquat de 0,01 qui traîne.
|
|
239
255
|
|
|
240
256
|
```typescript
|
|
241
257
|
import { TradingService, XgateEx } from '@blackcube/xgate-sdk';
|
|
@@ -254,9 +270,9 @@ const orders = await trading.openWithProtection(access, {
|
|
|
254
270
|
direction: 'long',
|
|
255
271
|
size: 0.02,
|
|
256
272
|
entry: 3120,
|
|
257
|
-
|
|
273
|
+
sl: { pct: 0.02 }, // stop à 2 % sous l'entrée
|
|
258
274
|
tps: [{ pct: 0.03, part: 0.5 }, // 50 % à +3 %
|
|
259
|
-
{
|
|
275
|
+
{ price: 62500, part: 0.5 }], // 50 % si le prix touche 62 500
|
|
260
276
|
tif: 'ioc',
|
|
261
277
|
});
|
|
262
278
|
```
|
package/dist/index.cjs
CHANGED
|
@@ -1077,6 +1077,13 @@ exports.SpotWsCandlesService = __decorateClass([
|
|
|
1077
1077
|
], exports.SpotWsCandlesService);
|
|
1078
1078
|
|
|
1079
1079
|
// src/helpers/protection.ts
|
|
1080
|
+
function priceOf(cible, entry, direction, gagnant) {
|
|
1081
|
+
if (cible.price !== void 0) {
|
|
1082
|
+
return round8(cible.price);
|
|
1083
|
+
}
|
|
1084
|
+
const dir = (direction === "long" ? 1 : -1) * (gagnant === true ? 1 : -1);
|
|
1085
|
+
return round8(entry * (1 + dir * cible.pct));
|
|
1086
|
+
}
|
|
1080
1087
|
var SLIPPAGE_DEFAUT = 5e-3;
|
|
1081
1088
|
var SEUIL_CLOTURE = 0.8;
|
|
1082
1089
|
function round8(value) {
|
|
@@ -1119,12 +1126,8 @@ function buildLevels(entry, direction, slPct, tpPcts) {
|
|
|
1119
1126
|
function buildProtection(input) {
|
|
1120
1127
|
const slippage = input.slippagePct ?? SLIPPAGE_DEFAUT;
|
|
1121
1128
|
const long = input.direction === "long";
|
|
1122
|
-
const
|
|
1123
|
-
|
|
1124
|
-
input.direction,
|
|
1125
|
-
input.slPct,
|
|
1126
|
-
input.tps.map((tp) => tp.pct)
|
|
1127
|
-
);
|
|
1129
|
+
const sl = priceOf(input.sl, input.entry, input.direction, false);
|
|
1130
|
+
const niveaux = input.tps.map((tp) => priceOf(tp, input.entry, input.direction, true));
|
|
1128
1131
|
const borne = (trigger) => long === true ? trigger * (1 - slippage) : trigger * (1 + slippage);
|
|
1129
1132
|
const sommeParts = input.tps.reduce((total, tp) => total + tp.part, 0);
|
|
1130
1133
|
const clotureIntegrale = sommeParts > SEUIL_CLOTURE;
|
|
@@ -1195,7 +1198,7 @@ exports.TradingService = class TradingService {
|
|
|
1195
1198
|
entry: input.entry,
|
|
1196
1199
|
direction: input.direction,
|
|
1197
1200
|
size: input.size,
|
|
1198
|
-
|
|
1201
|
+
sl: input.sl,
|
|
1199
1202
|
tps: input.tps,
|
|
1200
1203
|
tickSize: input.tickSize,
|
|
1201
1204
|
lotSize: input.lotSize,
|