@katanaperps/katana-perps-sdk 2.1.0-beta.13 → 2.1.0-beta.14

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.
@@ -0,0 +1,155 @@
1
+ import { OrderSide, TimeInForce } from '#types/enums/request';
2
+ import type { LeverageParameters } from '#orderbook/quantities';
3
+ import type { OrderBookLevelL2 } from '#types/orderBook';
4
+ import type { KatanaPerpsInitialMarginFractionOverride, KatanaPerpsMarket, KatanaPerpsOrder, KatanaPerpsWallet } from '#types/rest/endpoints/index';
5
+ /**
6
+ * The quantity for a buy/sell panel estimate may be expressed in one of three
7
+ * ways: in base asset terms, in quote asset terms, or as a fraction of the
8
+ * wallet's available collateral to be consumed (the panel's slider; `1` (one
9
+ * pip-fraction, i.e. {@link oneInPips}) consumes all available collateral).
10
+ *
11
+ * Exactly one of the three must be provided.
12
+ */
13
+ export type BuySellPanelEstimateQuantity = {
14
+ baseQuantity: bigint;
15
+ quoteQuantity?: undefined;
16
+ availableCollateralRatio?: undefined;
17
+ } | {
18
+ baseQuantity?: undefined;
19
+ quoteQuantity: bigint;
20
+ availableCollateralRatio?: undefined;
21
+ } | {
22
+ baseQuantity?: undefined;
23
+ quoteQuantity?: undefined;
24
+ /** Fraction of available collateral to consume, in pips (`0` to {@link oneInPips}) */
25
+ availableCollateralRatio: bigint;
26
+ };
27
+ /**
28
+ * The buy/sell panel's order inputs.
29
+ *
30
+ * - Omitting {@link BuySellPanelOrder.limitPrice limitPrice} produces a market
31
+ * order estimate; providing it produces a limit order estimate.
32
+ * - {@link BuySellPanelOrder.timeInForce timeInForce} defaults to
33
+ * {@link TimeInForce.gtc gtc}.
34
+ */
35
+ export type BuySellPanelOrder = {
36
+ side: OrderSide;
37
+ /** Present for limit orders only; in pips */
38
+ limitPrice?: bigint;
39
+ /** Defaults to {@link TimeInForce.gtc} */
40
+ timeInForce?: TimeInForce;
41
+ /** Defaults to `false` */
42
+ reduceOnly?: boolean;
43
+ } & BuySellPanelEstimateQuantity;
44
+ export interface BuySellPanelEstimateArgs {
45
+ market: Pick<KatanaPerpsMarket, 'market' | 'indexPrice' | keyof LeverageParameters | 'maintenanceMarginFraction' | 'marketOrderExecutionPriceLimit' | 'limitOrderExecutionPriceLimit'>;
46
+ /**
47
+ * The wallet placing the order, as returned by the "Get Wallets" endpoint
48
+ * (with positions included).
49
+ */
50
+ wallet: Pick<KatanaPerpsWallet, 'equity' | 'heldCollateral' | 'quoteBalance' | 'marginRatio' | 'makerFeeRate' | 'takerFeeRate' | 'positions'>;
51
+ /**
52
+ * The order book of the order's market. {@link OrderBookLevelL2.size size}
53
+ * values are expected to include the wallet's own standing orders. Asks are
54
+ * expected to be sorted ascending (lowest price first) and bids descending
55
+ * (highest price first); both are re-sorted defensively.
56
+ */
57
+ orderBook: {
58
+ asks: OrderBookLevelL2[];
59
+ bids: OrderBookLevelL2[];
60
+ };
61
+ /**
62
+ * All of the wallet's standing (open) orders. Orders in other markets are
63
+ * ignored. Used to detect self-trades and to determine how the wallet's held
64
+ * collateral changes as a result of the estimated order.
65
+ */
66
+ walletsStandingOrders?: Pick<KatanaPerpsOrder, 'market' | 'side' | 'price' | 'originalQuantity' | 'executedQuantity' | 'status'>[];
67
+ /**
68
+ * The wallet's initial margin fraction overrides, as returned by the "Get
69
+ * Initial Margin Fraction Override" endpoint. Only the entry for the order's
70
+ * market is used.
71
+ */
72
+ walletInitialMarginFractionOverrides?: KatanaPerpsInitialMarginFractionOverride[];
73
+ /**
74
+ * The taker gas fee charged per matched maker order, in quote asset pips. Not
75
+ * exposed by the public API; defaults to zero. The sum of the trade and gas
76
+ * fee on any single fill is capped at 5% of the fill's quote quantity.
77
+ */
78
+ takerTradeGasFee?: bigint;
79
+ order: BuySellPanelOrder;
80
+ }
81
+ export interface BuySellPanelEstimate {
82
+ /** Base quantity of the portion of the order that crosses the spread (a trade) */
83
+ tradeBaseQuantity: bigint;
84
+ /** Quote quantity of the portion of the order that crosses the spread (a trade) */
85
+ tradeQuoteQuantity: bigint;
86
+ /** Base quantity of the portion of the order that would rest on the books */
87
+ makerBaseQuantity: bigint;
88
+ /**
89
+ * The change in the wallet's available collateral, in quote asset pips. A
90
+ * positive value is a cost (available collateral decreases); a negative value
91
+ * indicates that available collateral increases (e.g. when closing a position
92
+ * frees up collateral).
93
+ */
94
+ cost: bigint;
95
+ /**
96
+ * The index price at which the account would be liquidated after the
97
+ * estimated order, in pips. `null` if the resulting position is zero (no
98
+ * liquidation risk), `0n` if the account cannot be liquidated by an adverse
99
+ * move (a positive liquidation price does not exist).
100
+ */
101
+ liquidationPrice: bigint | null;
102
+ /** `true` if the estimate matched one of the wallet's own standing orders */
103
+ selfTradeEncountered: boolean;
104
+ /**
105
+ * `true` if the crossing portion of the order would leave the wallet below
106
+ * its margin requirement (the order would be rejected)
107
+ */
108
+ freeCollateralExceeded: boolean;
109
+ /**
110
+ * `true` if a non-crossing (resting) order's held collateral would exceed the
111
+ * wallet's available collateral (the order would be rejected)
112
+ */
113
+ availableCollateralExceeded: boolean;
114
+ /**
115
+ * `true` if the order's price (limit orders) or a matched price (market
116
+ * orders) lies outside the market's allowed execution price range
117
+ */
118
+ executionPriceLimitExceeded: boolean;
119
+ /** `true` if the resulting position would exceed the maximum position size */
120
+ maximumPositionSizeExceeded: boolean;
121
+ /** `true` if a post-only ({@link TimeInForce.gtx gtx}) order would cross the spread (rejected) */
122
+ postOnlyWouldCross: boolean;
123
+ /** `true` if a fill-or-kill ({@link TimeInForce.fok fok}) order could not be fully filled (rejected) */
124
+ fillOrKillWouldNotExecute: boolean;
125
+ /** `true` if a reduce-only order is on the same side as the open position (rejected) */
126
+ reduceOnlyWouldNotReducePosition: boolean;
127
+ /** `true` if a reduce-only order is placed with no open position (rejected) */
128
+ reduceOnlyNoOpenPosition: boolean;
129
+ /**
130
+ * `true` if a reduce-only order's resting (maker) quantity would exceed the
131
+ * remaining open position size (the order would not be fully reducing)
132
+ */
133
+ reduceOnlyOpenPositionSizeExceeded: boolean;
134
+ }
135
+ /**
136
+ * Generates an estimate of how a taker order submitted via the buy/sell panel
137
+ * would be executed by the trading engine. The estimate takes into account
138
+ * trade and gas fees, the (incremental) initial margin fraction and its
139
+ * overrides, the maximum position size, collateral freed up by the reduction of
140
+ * positions, the effect of differences between the execution and index price on
141
+ * collateral, self-trades, held collateral (for standing orders), and changes
142
+ * in held collateral as a result of self-trades and position size changes.
143
+ *
144
+ * The minimum taker quantity is intentionally ignored; the estimate generates
145
+ * results for quantities that do not meet the minimum.
146
+ *
147
+ * The order's quantity may be expressed in base asset terms, in quote asset
148
+ * terms, or as a fraction of the wallet's available collateral to consume (the
149
+ * panel's slider). See {@link BuySellPanelEstimateQuantity}.
150
+ *
151
+ * All quantities, prices, and collateral values are expressed in pips
152
+ * (see {@link decimalToPip}).
153
+ */
154
+ export declare function calculateBuySellPanelEstimate(args: BuySellPanelEstimateArgs): BuySellPanelEstimate;
155
+ //# sourceMappingURL=buySellPanelEstimate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buySellPanelEstimate.d.ts","sourceRoot":"","sources":["../../src/orderbook/buySellPanelEstimate.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAE9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EACV,wCAAwC,EACxC,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AAUrC;;;;;;;GAOG;AACH,MAAM,MAAM,4BAA4B,GACpC;IACE,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,SAAS,CAAC;IAC1B,wBAAwB,CAAC,EAAE,SAAS,CAAC;CACtC,GACD;IACE,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,aAAa,EAAE,MAAM,CAA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