@lifi/perps-types 18.0.0 → 19.0.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/dist/cjs/account.d.ts +63 -62
- package/dist/cjs/account.d.ts.map +1 -1
- package/dist/cjs/action.d.ts +17 -16
- package/dist/cjs/action.d.ts.map +1 -1
- package/dist/cjs/asset.d.ts +2 -1
- package/dist/cjs/asset.d.ts.map +1 -1
- package/dist/cjs/decimal.d.ts +4 -0
- package/dist/cjs/decimal.d.ts.map +1 -0
- package/dist/cjs/decimal.js +9 -0
- package/dist/cjs/decimal.js.map +1 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/market.d.ts +24 -23
- package/dist/cjs/market.d.ts.map +1 -1
- package/dist/cjs/portfolioHistory.d.ts +5 -4
- package/dist/cjs/portfolioHistory.d.ts.map +1 -1
- package/dist/cjs/providers.d.ts +6 -5
- package/dist/cjs/providers.d.ts.map +1 -1
- package/dist/cjs/quote.d.ts +7 -6
- package/dist/cjs/quote.d.ts.map +1 -1
- package/dist/cjs/referral.d.ts +4 -3
- package/dist/cjs/referral.d.ts.map +1 -1
- package/dist/cjs/referral.js.map +1 -1
- package/dist/cjs/subscriptions.d.ts +3 -1
- package/dist/cjs/subscriptions.d.ts.map +1 -1
- package/dist/esm/account.d.ts +63 -62
- package/dist/esm/account.d.ts.map +1 -1
- package/dist/esm/action.d.ts +17 -16
- package/dist/esm/action.d.ts.map +1 -1
- package/dist/esm/asset.d.ts +2 -1
- package/dist/esm/asset.d.ts.map +1 -1
- package/dist/esm/decimal.d.ts +23 -0
- package/dist/esm/decimal.d.ts.map +1 -0
- package/dist/esm/decimal.js +17 -0
- package/dist/esm/decimal.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/market.d.ts +30 -30
- package/dist/esm/market.d.ts.map +1 -1
- package/dist/esm/portfolioHistory.d.ts +5 -4
- package/dist/esm/portfolioHistory.d.ts.map +1 -1
- package/dist/esm/providers.d.ts +24 -11
- package/dist/esm/providers.d.ts.map +1 -1
- package/dist/esm/quote.d.ts +7 -6
- package/dist/esm/quote.d.ts.map +1 -1
- package/dist/esm/referral.d.ts +4 -3
- package/dist/esm/referral.d.ts.map +1 -1
- package/dist/esm/referral.js.map +1 -1
- package/dist/esm/subscriptions.d.ts +5 -1
- package/dist/esm/subscriptions.d.ts.map +1 -1
- package/dist/types/account.d.ts +63 -62
- package/dist/types/account.d.ts.map +1 -1
- package/dist/types/action.d.ts +17 -16
- package/dist/types/action.d.ts.map +1 -1
- package/dist/types/asset.d.ts +2 -1
- package/dist/types/asset.d.ts.map +1 -1
- package/dist/types/decimal.d.ts +23 -0
- package/dist/types/decimal.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/market.d.ts +30 -30
- package/dist/types/market.d.ts.map +1 -1
- package/dist/types/portfolioHistory.d.ts +5 -4
- package/dist/types/portfolioHistory.d.ts.map +1 -1
- package/dist/types/providers.d.ts +24 -11
- package/dist/types/providers.d.ts.map +1 -1
- package/dist/types/quote.d.ts +7 -6
- package/dist/types/quote.d.ts.map +1 -1
- package/dist/types/referral.d.ts +4 -3
- package/dist/types/referral.d.ts.map +1 -1
- package/dist/types/subscriptions.d.ts +5 -1
- package/dist/types/subscriptions.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/account.ts +63 -62
- package/src/action.ts +17 -16
- package/src/asset.ts +3 -1
- package/src/decimal.ts +26 -0
- package/src/index.ts +1 -0
- package/src/market.ts +30 -30
- package/src/portfolioHistory.ts +6 -4
- package/src/providers.ts +24 -11
- package/src/quote.ts +7 -6
- package/src/referral.ts +4 -3
- package/src/subscriptions.ts +4 -1
package/src/account.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Asset, AssetDisplay } from './asset.js'
|
|
2
|
+
import type { DecimalString } from './decimal.js'
|
|
2
3
|
import type {
|
|
3
4
|
ActionType,
|
|
4
5
|
ActivityType,
|
|
@@ -23,9 +24,9 @@ import type { Address, ProviderId } from './primitives.js'
|
|
|
23
24
|
*/
|
|
24
25
|
export interface FeeTier {
|
|
25
26
|
/** Decimal fraction charged to maker fills, represented as a string. */
|
|
26
|
-
maker:
|
|
27
|
+
maker: DecimalString
|
|
27
28
|
/** Decimal fraction charged to taker fills, represented as a string. */
|
|
28
|
-
taker:
|
|
29
|
+
taker: DecimalString
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
/**
|
|
@@ -38,22 +39,22 @@ export interface Position {
|
|
|
38
39
|
market: PerpsMarketDisplay
|
|
39
40
|
side: PositionSide
|
|
40
41
|
/** Position quantity in base-asset units. */
|
|
41
|
-
size:
|
|
42
|
+
size: DecimalString
|
|
42
43
|
/** Average entry price in quote-asset units. */
|
|
43
|
-
entryPrice:
|
|
44
|
+
entryPrice: DecimalString
|
|
44
45
|
/** Current provider mark price in quote-asset units. */
|
|
45
|
-
markPrice:
|
|
46
|
+
markPrice: DecimalString
|
|
46
47
|
/** Estimated liquidation price in quote-asset units. */
|
|
47
|
-
liquidationPrice:
|
|
48
|
+
liquidationPrice: DecimalString
|
|
48
49
|
/** Unrealized PnL in quote-currency units. */
|
|
49
|
-
unrealizedPnl:
|
|
50
|
+
unrealizedPnl: DecimalString
|
|
50
51
|
/**
|
|
51
52
|
* Funding this position accrued since it opened, in quote-currency units.
|
|
52
53
|
* Positive means the account received funding and negative means the account
|
|
53
54
|
* paid it, matching {@link FundingActivity} amounts. Every venue resets the
|
|
54
55
|
* value when the position returns to flat.
|
|
55
56
|
*/
|
|
56
|
-
accruedFunding:
|
|
57
|
+
accruedFunding: DecimalString
|
|
57
58
|
/** Position leverage as a numeric multiple. */
|
|
58
59
|
leverage: number
|
|
59
60
|
/**
|
|
@@ -62,12 +63,12 @@ export interface Position {
|
|
|
62
63
|
* Hyperliquid isolated `marginUsed` includes the unrealized PnL of the
|
|
63
64
|
* position; Lighter `allocated_margin` excludes it.
|
|
64
65
|
*/
|
|
65
|
-
marginUsed:
|
|
66
|
+
marginUsed: DecimalString
|
|
66
67
|
/**
|
|
67
68
|
* Exact initial margin the venue currently requires for this position.
|
|
68
69
|
* Unlike `leverage`, this decimal string is safe for risk calculations.
|
|
69
70
|
*/
|
|
70
|
-
initialMarginRequirement:
|
|
71
|
+
initialMarginRequirement: DecimalString
|
|
71
72
|
marginMode: MarginMode
|
|
72
73
|
}
|
|
73
74
|
|
|
@@ -82,10 +83,10 @@ export interface OrderBase {
|
|
|
82
83
|
status: OrderStatus
|
|
83
84
|
/** Venue text for a REJECTED or CANCELLED order, when the venue gives one. */
|
|
84
85
|
statusReason?: string
|
|
85
|
-
originalSize:
|
|
86
|
-
remainingSize:
|
|
87
|
-
filledSize:
|
|
88
|
-
averagePrice?:
|
|
86
|
+
originalSize: DecimalString
|
|
87
|
+
remainingSize: DecimalString
|
|
88
|
+
filledSize: DecimalString
|
|
89
|
+
averagePrice?: DecimalString
|
|
89
90
|
reduceOnly: boolean
|
|
90
91
|
/** Parent of a placement TP/SL leg or TWAP child; absent on position-level triggers. */
|
|
91
92
|
parentOrderId?: string
|
|
@@ -98,7 +99,7 @@ export interface OrderBase {
|
|
|
98
99
|
/** Market or limit order with a time-in-force policy. */
|
|
99
100
|
export interface RegularOrder extends OrderBase {
|
|
100
101
|
type: OrderType.MARKET | OrderType.LIMIT
|
|
101
|
-
price?:
|
|
102
|
+
price?: DecimalString
|
|
102
103
|
timeInForce: TimeInForce
|
|
103
104
|
expiresAt?: string
|
|
104
105
|
}
|
|
@@ -110,9 +111,9 @@ export interface TriggerOrder extends OrderBase {
|
|
|
110
111
|
| OrderType.STOP_LIMIT
|
|
111
112
|
| OrderType.TAKE_PROFIT_MARKET
|
|
112
113
|
| OrderType.TAKE_PROFIT_LIMIT
|
|
113
|
-
triggerPrice:
|
|
114
|
+
triggerPrice: DecimalString
|
|
114
115
|
triggerCondition: TriggerCondition
|
|
115
|
-
limitPrice?:
|
|
116
|
+
limitPrice?: DecimalString
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
/** Time-weighted execution parent. */
|
|
@@ -135,18 +136,18 @@ export interface Balance {
|
|
|
135
136
|
/** Which category/venue this balance sits in — references a {@link ProviderCategory}. */
|
|
136
137
|
categoryId: string
|
|
137
138
|
asset: Asset
|
|
138
|
-
units:
|
|
139
|
+
units: DecimalString
|
|
139
140
|
/** USD value the SDK fills from the prices map; consumers render with zero math. */
|
|
140
|
-
valueUsd:
|
|
141
|
+
valueUsd: DecimalString
|
|
141
142
|
/** USD price of one unit. Absent when the provider holds no price for the asset. */
|
|
142
|
-
price?:
|
|
143
|
+
price?: DecimalString
|
|
143
144
|
/**
|
|
144
145
|
* Part of `units` the venue releases from this category, as a decimal
|
|
145
146
|
* string clamped to `[0, units]`. Every collateral row and every spot row
|
|
146
147
|
* carries it. It is not the withdrawal ceiling: read
|
|
147
148
|
* `PerpsClient.getWithdrawableBalances` for that.
|
|
148
149
|
*/
|
|
149
|
-
transferable?:
|
|
150
|
+
transferable?: DecimalString
|
|
150
151
|
}
|
|
151
152
|
|
|
152
153
|
/**
|
|
@@ -170,9 +171,9 @@ export interface AccountResponse {
|
|
|
170
171
|
/** Open positions the snapshot already computed; equals the unfiltered `getPositions` output. */
|
|
171
172
|
positions: Position[]
|
|
172
173
|
/** Margin reserved across the account, represented as a decimal string. */
|
|
173
|
-
marginUsed:
|
|
174
|
+
marginUsed: DecimalString
|
|
174
175
|
/** Unrealized account PnL, represented as a decimal string. */
|
|
175
|
-
unrealizedPnl:
|
|
176
|
+
unrealizedPnl: DecimalString
|
|
176
177
|
feeTier: FeeTier
|
|
177
178
|
config: AccountConfig
|
|
178
179
|
}
|
|
@@ -185,13 +186,13 @@ export interface AccountResponse {
|
|
|
185
186
|
*/
|
|
186
187
|
export interface AccountSummary {
|
|
187
188
|
/** Total account portfolio value in USD. */
|
|
188
|
-
portfolioValue:
|
|
189
|
+
portfolioValue: DecimalString
|
|
189
190
|
/** Margin currently available for new orders in USD. */
|
|
190
|
-
availableMargin:
|
|
191
|
+
availableMargin: DecimalString
|
|
191
192
|
/** Margin currently reserved by open positions/orders in USD. */
|
|
192
|
-
marginUsed:
|
|
193
|
+
marginUsed: DecimalString
|
|
193
194
|
/** Aggregate unrealized PnL in USD. */
|
|
194
|
-
unrealizedPnl:
|
|
195
|
+
unrealizedPnl: DecimalString
|
|
195
196
|
}
|
|
196
197
|
|
|
197
198
|
/**
|
|
@@ -208,9 +209,9 @@ export interface AvailableToTrade {
|
|
|
208
209
|
/** The market's margin asset, which both amounts are denominated in. */
|
|
209
210
|
asset: AssetDisplay
|
|
210
211
|
/** Amount the account can still buy, represented as a decimal string. */
|
|
211
|
-
buy:
|
|
212
|
+
buy: DecimalString
|
|
212
213
|
/** Amount the account can still sell, represented as a decimal string. */
|
|
213
|
-
sell:
|
|
214
|
+
sell: DecimalString
|
|
214
215
|
}
|
|
215
216
|
|
|
216
217
|
/**
|
|
@@ -251,7 +252,7 @@ export interface OrdersResponse {
|
|
|
251
252
|
*/
|
|
252
253
|
export interface Fee {
|
|
253
254
|
/** Decimal string in `asset`'s units. */
|
|
254
|
-
amount:
|
|
255
|
+
amount: DecimalString
|
|
255
256
|
/**
|
|
256
257
|
* Display symbol the fee is denominated in, resolved by the provider
|
|
257
258
|
* adapter. Falls back to the venue's own asset id when the registry knows no
|
|
@@ -276,10 +277,10 @@ export interface Fill {
|
|
|
276
277
|
* Hyperliquid taker fill, which may be a market or an aggressive limit order).
|
|
277
278
|
*/
|
|
278
279
|
type?: OrderType
|
|
279
|
-
size:
|
|
280
|
-
price:
|
|
280
|
+
size: DecimalString
|
|
281
|
+
price: DecimalString
|
|
281
282
|
liquidity: LiquidityRole
|
|
282
|
-
filledSize?:
|
|
283
|
+
filledSize?: DecimalString
|
|
283
284
|
/** Absent when the venue reports no fee for the fill. */
|
|
284
285
|
fee?: Fee
|
|
285
286
|
/**
|
|
@@ -300,8 +301,8 @@ export interface Fill {
|
|
|
300
301
|
* a sentinel value.
|
|
301
302
|
*/
|
|
302
303
|
leverage?: number
|
|
303
|
-
realizedPnl?:
|
|
304
|
-
startPosition?:
|
|
304
|
+
realizedPnl?: DecimalString | null
|
|
305
|
+
startPosition?: DecimalString
|
|
305
306
|
classification: FillClassification
|
|
306
307
|
createdAt: string
|
|
307
308
|
/** Fully-resolved block-explorer URL for the settling on-chain tx. Absent when
|
|
@@ -354,7 +355,7 @@ export interface BaseActivity {
|
|
|
354
355
|
export interface DepositActivity extends BaseActivity {
|
|
355
356
|
type: ActivityType.DEPOSIT
|
|
356
357
|
asset: Asset
|
|
357
|
-
amount:
|
|
358
|
+
amount: DecimalString
|
|
358
359
|
/**
|
|
359
360
|
* Address the deposited funds came from, as the venue reports it. Absent
|
|
360
361
|
* when the venue's deposit payload names no source address.
|
|
@@ -373,7 +374,7 @@ export interface DepositActivity extends BaseActivity {
|
|
|
373
374
|
export interface WithdrawalActivity extends BaseActivity {
|
|
374
375
|
type: ActivityType.WITHDRAWAL
|
|
375
376
|
asset: Asset
|
|
376
|
-
amount:
|
|
377
|
+
amount: DecimalString
|
|
377
378
|
/** Absent when the venue reports no fee for the withdrawal. */
|
|
378
379
|
fee?: Fee
|
|
379
380
|
/** Fully-resolved block-explorer URL for the on-chain withdrawal tx. */
|
|
@@ -388,7 +389,7 @@ export interface WithdrawalActivity extends BaseActivity {
|
|
|
388
389
|
export interface LiquidatedPosition {
|
|
389
390
|
market: MarketDisplay
|
|
390
391
|
/** Absent when the venue reports no liquidated size for the position. */
|
|
391
|
-
size?:
|
|
392
|
+
size?: DecimalString
|
|
392
393
|
}
|
|
393
394
|
|
|
394
395
|
/**
|
|
@@ -402,9 +403,9 @@ export interface LiquidatedPosition {
|
|
|
402
403
|
export interface LiquidationActivity extends BaseActivity {
|
|
403
404
|
type: ActivityType.LIQUIDATION
|
|
404
405
|
/** Absent when the venue reports no liquidated notional. */
|
|
405
|
-
liquidatedNotionalPosition?:
|
|
406
|
+
liquidatedNotionalPosition?: DecimalString
|
|
406
407
|
/** Absent when the venue reports no account value at liquidation time. */
|
|
407
|
-
accountValue?:
|
|
408
|
+
accountValue?: DecimalString
|
|
408
409
|
/**
|
|
409
410
|
* Margin mode the liquidated account ran under, in the venue's own
|
|
410
411
|
* vocabulary — typically `cross` or `isolated`, but the venue may report
|
|
@@ -432,9 +433,9 @@ export interface FundingActivity extends BaseActivity {
|
|
|
432
433
|
* Signed, in quote-currency units. Positive means the account received
|
|
433
434
|
* funding; negative means the account paid it.
|
|
434
435
|
*/
|
|
435
|
-
amount:
|
|
436
|
-
positionSize:
|
|
437
|
-
fundingRate:
|
|
436
|
+
amount: DecimalString
|
|
437
|
+
positionSize: DecimalString
|
|
438
|
+
fundingRate: DecimalString
|
|
438
439
|
}
|
|
439
440
|
|
|
440
441
|
// At least one of `counterpartyAccountIndex` / `counterpartyAddress` is always
|
|
@@ -451,7 +452,7 @@ export type TransferActivity = BaseActivity & {
|
|
|
451
452
|
type: ActivityType.TRANSFER
|
|
452
453
|
direction: 'IN' | 'OUT'
|
|
453
454
|
asset: Asset
|
|
454
|
-
amount:
|
|
455
|
+
amount: DecimalString
|
|
455
456
|
/**
|
|
456
457
|
* Every fee the venue charged for the transfer, in the order the venue
|
|
457
458
|
* reports them. A venue may charge several fees for one transfer, each in a
|
|
@@ -509,7 +510,7 @@ export type HyperliquidAgent = Record<string, unknown>
|
|
|
509
510
|
export interface HyperliquidBuilderFeeApproval {
|
|
510
511
|
builderAddress: string
|
|
511
512
|
/** Basis points as a string. */
|
|
512
|
-
maxFeeRate:
|
|
513
|
+
maxFeeRate: DecimalString
|
|
513
514
|
approved: boolean
|
|
514
515
|
}
|
|
515
516
|
|
|
@@ -521,10 +522,10 @@ export interface HyperliquidBuilderFeeApproval {
|
|
|
521
522
|
*/
|
|
522
523
|
export interface HyperliquidMarginSummary {
|
|
523
524
|
/** Total equity: locked margin and unrealized PnL included. */
|
|
524
|
-
accountValue:
|
|
525
|
-
totalNtlPos:
|
|
526
|
-
totalRawUsd:
|
|
527
|
-
totalMarginUsed:
|
|
525
|
+
accountValue: DecimalString
|
|
526
|
+
totalNtlPos: DecimalString
|
|
527
|
+
totalRawUsd: DecimalString
|
|
528
|
+
totalMarginUsed: DecimalString
|
|
528
529
|
}
|
|
529
530
|
|
|
530
531
|
/**
|
|
@@ -539,8 +540,8 @@ export interface HyperliquidDexAccountState {
|
|
|
539
540
|
marginSummary: HyperliquidMarginSummary
|
|
540
541
|
/** Cross-margin subset of {@link HyperliquidDexAccountState.marginSummary}. */
|
|
541
542
|
crossMarginSummary: HyperliquidMarginSummary
|
|
542
|
-
crossMaintenanceMarginUsed:
|
|
543
|
-
withdrawable:
|
|
543
|
+
crossMaintenanceMarginUsed: DecimalString
|
|
544
|
+
withdrawable: DecimalString
|
|
544
545
|
}
|
|
545
546
|
|
|
546
547
|
/**
|
|
@@ -561,7 +562,7 @@ export interface HyperliquidAccountConfig {
|
|
|
561
562
|
* `tokenToAvailableAfterMaintenance` list. Unified and portfolio-margin
|
|
562
563
|
* accounts only; other modes derive buying power from `marginSummary`.
|
|
563
564
|
*/
|
|
564
|
-
availableAfterMaintenance?:
|
|
565
|
+
availableAfterMaintenance?: DecimalString
|
|
565
566
|
}
|
|
566
567
|
|
|
567
568
|
/**
|
|
@@ -614,23 +615,23 @@ export interface LighterAccountConfig {
|
|
|
614
615
|
* equity above its initial margin requirement and subtracts the shortfall
|
|
615
616
|
* below it. A decimal string in quote-asset units.
|
|
616
617
|
*/
|
|
617
|
-
availableBalance:
|
|
618
|
+
availableBalance: DecimalString
|
|
618
619
|
/**
|
|
619
620
|
* Lighter `cross_asset_value`: cross-margin collateral plus the unrealized
|
|
620
621
|
* PnL of the cross positions. A decimal string in quote-asset units.
|
|
621
622
|
*/
|
|
622
|
-
crossAssetValue:
|
|
623
|
+
crossAssetValue: DecimalString
|
|
623
624
|
/**
|
|
624
625
|
* Lighter `cross_initial_margin_requirement`: the initial margin the cross
|
|
625
626
|
* positions lock. A decimal string in quote-asset units.
|
|
626
627
|
*/
|
|
627
|
-
crossInitialMarginRequirement:
|
|
628
|
+
crossInitialMarginRequirement: DecimalString
|
|
628
629
|
/**
|
|
629
630
|
* Lighter `total_asset_value`: perps-route equity, isolated allocations and
|
|
630
631
|
* unrealized PnL included. It excludes the spot-route balances. A decimal
|
|
631
632
|
* string in quote-asset units.
|
|
632
633
|
*/
|
|
633
|
-
totalAssetValue:
|
|
634
|
+
totalAssetValue: DecimalString
|
|
634
635
|
/**
|
|
635
636
|
* Lighter `user_tier_name` from `/accountLimits`, in the tier vocabulary
|
|
636
637
|
* `changeAccountTier` accepts. Absent on an unauthenticated read, which
|
|
@@ -669,15 +670,15 @@ export interface LighterAccountConfig {
|
|
|
669
670
|
*/
|
|
670
671
|
export interface OndoAccountBalance {
|
|
671
672
|
/** Collateral only: locked margin included, unrealized PnL excluded. */
|
|
672
|
-
walletBalance:
|
|
673
|
-
unrealizedPnl:
|
|
673
|
+
walletBalance: DecimalString
|
|
674
|
+
unrealizedPnl: DecimalString
|
|
674
675
|
/** Total equity. */
|
|
675
|
-
marginBalance:
|
|
676
|
-
usedMargin:
|
|
676
|
+
marginBalance: DecimalString
|
|
677
|
+
usedMargin: DecimalString
|
|
677
678
|
/** Venue buying power. */
|
|
678
|
-
availableMargin:
|
|
679
|
+
availableMargin: DecimalString
|
|
679
680
|
/** Venue withdrawable figure, at or below {@link OndoAccountBalance.availableMargin}. */
|
|
680
|
-
withdrawableMargin:
|
|
681
|
+
withdrawableMargin: DecimalString
|
|
681
682
|
}
|
|
682
683
|
|
|
683
684
|
/**
|
package/src/action.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AcceptTermsParams } from './acceptTerms.js'
|
|
2
|
+
import type { DecimalString } from './decimal.js'
|
|
2
3
|
import type {
|
|
3
4
|
ActionType,
|
|
4
5
|
MarginMode,
|
|
@@ -271,13 +272,13 @@ export type ActionResult =
|
|
|
271
272
|
* @public
|
|
272
273
|
*/
|
|
273
274
|
export interface TriggerOrderInput {
|
|
274
|
-
triggerPrice:
|
|
275
|
-
limitPrice?:
|
|
275
|
+
triggerPrice: DecimalString
|
|
276
|
+
limitPrice?: DecimalString
|
|
276
277
|
/**
|
|
277
278
|
* Base-asset size the trigger closes. Omitted covers the entire position,
|
|
278
279
|
* tracking later size changes; set, it is a fixed partial amount.
|
|
279
280
|
*/
|
|
280
|
-
size?:
|
|
281
|
+
size?: DecimalString
|
|
281
282
|
}
|
|
282
283
|
|
|
283
284
|
/**
|
|
@@ -287,10 +288,10 @@ export interface TriggerOrderInput {
|
|
|
287
288
|
*/
|
|
288
289
|
export interface ModifyOrderInput {
|
|
289
290
|
id: string
|
|
290
|
-
price?:
|
|
291
|
-
size?:
|
|
292
|
-
triggerPrice?:
|
|
293
|
-
limitPrice?:
|
|
291
|
+
price?: DecimalString
|
|
292
|
+
size?: DecimalString
|
|
293
|
+
triggerPrice?: DecimalString
|
|
294
|
+
limitPrice?: DecimalString
|
|
294
295
|
}
|
|
295
296
|
|
|
296
297
|
/**
|
|
@@ -302,8 +303,8 @@ export interface PlaceOrderParams {
|
|
|
302
303
|
market: MarketRef
|
|
303
304
|
side: OrderSide
|
|
304
305
|
type?: Exclude<OrderType, OrderType.TWAP>
|
|
305
|
-
size:
|
|
306
|
-
price?:
|
|
306
|
+
size: DecimalString
|
|
307
|
+
price?: DecimalString
|
|
307
308
|
leverage?: number
|
|
308
309
|
/**
|
|
309
310
|
* Hyperliquid: requires `leverage`. Omitted leaves the market's current
|
|
@@ -344,7 +345,7 @@ export interface PlaceTwapOrderParams {
|
|
|
344
345
|
market: MarketRef
|
|
345
346
|
side: OrderSide
|
|
346
347
|
/** Total base-asset size executed across the TWAP's lifetime, as a decimal string. */
|
|
347
|
-
size:
|
|
348
|
+
size: DecimalString
|
|
348
349
|
/** Total execution window in seconds. */
|
|
349
350
|
durationSeconds: number
|
|
350
351
|
reduceOnly?: boolean
|
|
@@ -353,9 +354,9 @@ export interface PlaceTwapOrderParams {
|
|
|
353
354
|
/** Ondo: interval between child orders in seconds. */
|
|
354
355
|
frequencySeconds?: number
|
|
355
356
|
/** Ondo: lowest acceptable child-order price, as a decimal string. */
|
|
356
|
-
minPrice?:
|
|
357
|
+
minPrice?: DecimalString
|
|
357
358
|
/** Ondo: highest acceptable child-order price, as a decimal string. */
|
|
358
|
-
maxPrice?:
|
|
359
|
+
maxPrice?: DecimalString
|
|
359
360
|
}
|
|
360
361
|
|
|
361
362
|
/**
|
|
@@ -417,7 +418,7 @@ export interface UpdateLeverageParams {
|
|
|
417
418
|
export interface UpdatePositionMarginParams {
|
|
418
419
|
market: MarketRef
|
|
419
420
|
action: 'add' | 'remove'
|
|
420
|
-
amount:
|
|
421
|
+
amount: DecimalString
|
|
421
422
|
}
|
|
422
423
|
|
|
423
424
|
/**
|
|
@@ -449,7 +450,7 @@ export type WithdrawalRoute = 'perps' | 'spot'
|
|
|
449
450
|
*/
|
|
450
451
|
export interface WithdrawalParams {
|
|
451
452
|
destination: Address
|
|
452
|
-
amount:
|
|
453
|
+
amount: DecimalString
|
|
453
454
|
/** Lighter: provider-native `Asset.id` to withdraw. Omitted withdraws the quote asset. */
|
|
454
455
|
assetId?: string
|
|
455
456
|
/** Lighter: balance route to draw from. Omitted is `perps`. */
|
|
@@ -469,7 +470,7 @@ export interface WithdrawalParams {
|
|
|
469
470
|
*/
|
|
470
471
|
export interface DepositParams {
|
|
471
472
|
/** Amount of the token to deposit, as an integer string in the token's base units (e.g. "100500000" for 100.5 USDC). */
|
|
472
|
-
amount:
|
|
473
|
+
amount: DecimalString
|
|
473
474
|
/** ERC-20 token address on the source chain. */
|
|
474
475
|
tokenAddress: Address
|
|
475
476
|
/** Chain ID of the source chain (e.g. 1 for Ethereum, 42161 for Arbitrum). */
|
|
@@ -534,7 +535,7 @@ export interface SendAssetParams {
|
|
|
534
535
|
collateral: string
|
|
535
536
|
sourceDex: string
|
|
536
537
|
destinationDex: string
|
|
537
|
-
amount:
|
|
538
|
+
amount: DecimalString
|
|
538
539
|
}
|
|
539
540
|
|
|
540
541
|
/**
|
package/src/asset.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { DecimalString } from './decimal.js'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Underlying token/registry entry. The base entity of the perps taxonomy:
|
|
3
5
|
* a tradable unit referenced by markets (as base/quote legs) and held by
|
|
@@ -32,7 +34,7 @@ export interface Asset {
|
|
|
32
34
|
/** L1 token contract; the zero address denotes native gas. */
|
|
33
35
|
l1Address?: string
|
|
34
36
|
/** Venue minimum for a single withdrawal, denominated in this asset — not USD. */
|
|
35
|
-
minWithdrawalAmount?:
|
|
37
|
+
minWithdrawalAmount?: DecimalString
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
/**
|
package/src/decimal.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plain decimal string: optional `-`, digits, optional fraction. No grouping,
|
|
3
|
+
* exponent, currency sign or whitespace; matches {@link DECIMAL_PATTERN}. Build
|
|
4
|
+
* it with an SDK `snap*`/`calculate*` helper or a provider, not `.toString()`.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export type DecimalString = string
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The single spelling rule for a {@link DecimalString}. It stays byte-identical
|
|
12
|
+
* to the pattern `lifi-perps-backend` matches every stored decimal against, so
|
|
13
|
+
* one amount has exactly one spelling in all three repositories.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export const DECIMAL_PATTERN = /^-?(?:0|[1-9]\d*)(?:\.\d+)?$/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Narrows an unknown value to a {@link DecimalString}.
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export function isDecimalString(value: unknown): value is DecimalString {
|
|
25
|
+
return typeof value === 'string' && DECIMAL_PATTERN.test(value)
|
|
26
|
+
}
|
package/src/index.ts
CHANGED
package/src/market.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Asset } from './asset.js'
|
|
2
|
+
import type { DecimalString } from './decimal.js'
|
|
2
3
|
import type { PositionMarginAdjustment } from './enums.js'
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -9,7 +10,7 @@ import type { PositionMarginAdjustment } from './enums.js'
|
|
|
9
10
|
*/
|
|
10
11
|
export interface FundingInfo {
|
|
11
12
|
/** Funding rate as a decimal fraction. */
|
|
12
|
-
rate:
|
|
13
|
+
rate: DecimalString
|
|
13
14
|
/** Next funding timestamp in Unix milliseconds. */
|
|
14
15
|
nextFundingTime: number
|
|
15
16
|
}
|
|
@@ -33,24 +34,24 @@ export interface BaseMarket {
|
|
|
33
34
|
/**
|
|
34
35
|
* Maximum decimal places the venue accepts for order prices on this market.
|
|
35
36
|
* Some venues impose further constraints on top of this budget (e.g. a
|
|
36
|
-
* significant-figure cap), so always
|
|
37
|
-
* `
|
|
37
|
+
* significant-figure cap), so always snap prices through the provider's
|
|
38
|
+
* `snapOrderPrice` rather than applying this field directly.
|
|
38
39
|
*/
|
|
39
40
|
priceDecimals?: number
|
|
40
41
|
/**
|
|
41
42
|
* Exact price tick as a plain decimal string (e.g. `'0.25'`). Present when
|
|
42
43
|
* the venue's grid is not a power of ten, where `priceDecimals` alone cannot
|
|
43
|
-
* describe the tick.
|
|
44
|
+
* describe the tick. Snap prices through the provider's `snapOrderPrice`
|
|
44
45
|
* rather than applying this field directly.
|
|
45
46
|
*/
|
|
46
|
-
priceIncrement?:
|
|
47
|
+
priceIncrement?: DecimalString
|
|
47
48
|
/**
|
|
48
49
|
* Exact size lot as a plain decimal string (e.g. `'0.05'`). Present when the
|
|
49
50
|
* venue's grid is not a power of ten, where `szDecimals` alone cannot
|
|
50
|
-
* describe the lot.
|
|
51
|
+
* describe the lot. Snap sizes through the provider's `snapOrderSize`
|
|
51
52
|
* rather than applying this field directly.
|
|
52
53
|
*/
|
|
53
|
-
sizeIncrement?:
|
|
54
|
+
sizeIncrement?: DecimalString
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
/**
|
|
@@ -67,15 +68,14 @@ export interface PerpsMarket extends BaseMarket {
|
|
|
67
68
|
defaultLeverage?: number
|
|
68
69
|
/**
|
|
69
70
|
* Minimum order notional in USD for this market, as a plain decimal string.
|
|
70
|
-
* Lighter applies it to resting (post-only) orders only.
|
|
71
|
-
* venue-wide `Provider.minOrderValueUsd
|
|
72
|
-
* string before comparing the two.
|
|
71
|
+
* Lighter applies it to resting (post-only) orders only. This per-market
|
|
72
|
+
* floor is separate from the venue-wide `Provider.minOrderValueUsd`.
|
|
73
73
|
*/
|
|
74
|
-
minOrderValueUsd?:
|
|
74
|
+
minOrderValueUsd?: DecimalString
|
|
75
75
|
/** Maximum market-order notional in USD, as a plain decimal string. */
|
|
76
|
-
maxMarketOrderUsd?:
|
|
76
|
+
maxMarketOrderUsd?: DecimalString
|
|
77
77
|
/** Maximum limit-order notional in USD, as a plain decimal string. */
|
|
78
|
-
maxLimitOrderUsd?:
|
|
78
|
+
maxLimitOrderUsd?: DecimalString
|
|
79
79
|
onlyIsolated: boolean
|
|
80
80
|
/** Whether individual position margin can be added and/or removed. */
|
|
81
81
|
positionMarginAdjustment: PositionMarginAdjustment
|
|
@@ -150,16 +150,16 @@ export interface MarketContext {
|
|
|
150
150
|
/** Opaque provider market identifier for this context frame. */
|
|
151
151
|
marketId: string
|
|
152
152
|
/** Current order-book midpoint, as a decimal quote string. */
|
|
153
|
-
midPrice:
|
|
153
|
+
midPrice: DecimalString
|
|
154
154
|
/** Provider mark price, as a decimal quote string. */
|
|
155
|
-
markPrice:
|
|
156
|
-
oraclePrice?:
|
|
157
|
-
prevDayPrice?:
|
|
158
|
-
priceChange24h?:
|
|
159
|
-
volume24h?:
|
|
160
|
-
marketCap?:
|
|
155
|
+
markPrice: DecimalString
|
|
156
|
+
oraclePrice?: DecimalString
|
|
157
|
+
prevDayPrice?: DecimalString
|
|
158
|
+
priceChange24h?: DecimalString
|
|
159
|
+
volume24h?: DecimalString
|
|
160
|
+
marketCap?: DecimalString
|
|
161
161
|
/** Quote-asset open-interest notional as a decimal string. */
|
|
162
|
-
openInterest?:
|
|
162
|
+
openInterest?: DecimalString
|
|
163
163
|
funding?: FundingInfo
|
|
164
164
|
}
|
|
165
165
|
|
|
@@ -176,11 +176,11 @@ export interface PricesResponse {
|
|
|
176
176
|
*/
|
|
177
177
|
export interface Candle {
|
|
178
178
|
t: number
|
|
179
|
-
o:
|
|
180
|
-
h:
|
|
181
|
-
l:
|
|
182
|
-
c:
|
|
183
|
-
v:
|
|
179
|
+
o: DecimalString
|
|
180
|
+
h: DecimalString
|
|
181
|
+
l: DecimalString
|
|
182
|
+
c: DecimalString
|
|
183
|
+
v: DecimalString
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
/** Response containing candles for one provider market and interval. @public */
|
|
@@ -215,8 +215,8 @@ export type OhlcvInterval =
|
|
|
215
215
|
|
|
216
216
|
/** One price/size level in an order book; both values are decimal strings. @public */
|
|
217
217
|
export interface OrderbookLevel {
|
|
218
|
-
price:
|
|
219
|
-
size:
|
|
218
|
+
price: DecimalString
|
|
219
|
+
size: DecimalString
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
/** Snapshot of bids and asks for one market. `timestamp` is Unix milliseconds. @public */
|
|
@@ -232,8 +232,8 @@ export interface OrderbookResponse {
|
|
|
232
232
|
export interface Trade {
|
|
233
233
|
provider: string
|
|
234
234
|
marketId: string
|
|
235
|
-
price:
|
|
236
|
-
size:
|
|
235
|
+
price: DecimalString
|
|
236
|
+
size: DecimalString
|
|
237
237
|
timestamp: number
|
|
238
238
|
side: 'buy' | 'sell'
|
|
239
239
|
id?: string
|
package/src/portfolioHistory.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { DecimalString } from './decimal.js'
|
|
2
|
+
|
|
1
3
|
/** Lookback window of a portfolio history read. @public */
|
|
2
4
|
export type PortfolioHistoryRange = '24h' | '7d' | '30d' | 'all'
|
|
3
5
|
|
|
@@ -9,9 +11,9 @@ export type PortfolioHistoryRange = '24h' | '7d' | '30d' | 'all'
|
|
|
9
11
|
export interface PortfolioHistoryPoint {
|
|
10
12
|
/** Unix milliseconds. */
|
|
11
13
|
timestamp: number
|
|
12
|
-
accountValue:
|
|
14
|
+
accountValue: DecimalString
|
|
13
15
|
/** Cumulative PnL from the start of the requested window. */
|
|
14
|
-
pnl:
|
|
16
|
+
pnl: DecimalString
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
/**
|
|
@@ -22,6 +24,6 @@ export interface PortfolioHistoryPoint {
|
|
|
22
24
|
export interface PortfolioHistoryResponse {
|
|
23
25
|
range: PortfolioHistoryRange
|
|
24
26
|
points: PortfolioHistoryPoint[]
|
|
25
|
-
volume?:
|
|
26
|
-
totalPnl?:
|
|
27
|
+
volume?: DecimalString
|
|
28
|
+
totalPnl?: DecimalString
|
|
27
29
|
}
|