@strkfarm/sdk 1.1.69 → 2.0.0-dev.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/cli.js +2 -2
- package/dist/cli.mjs +2 -2
- package/dist/index.browser.global.js +66861 -59746
- package/dist/index.browser.mjs +24970 -18579
- package/dist/index.d.ts +1969 -776
- package/dist/index.js +25259 -18845
- package/dist/index.mjs +25464 -19090
- package/package.json +80 -76
- package/src/data/extended-deposit.abi.json +3613 -0
- package/src/data/universal-vault.abi.json +135 -20
- package/src/dataTypes/address.ts +8 -1
- package/src/global.ts +240 -193
- package/src/interfaces/common.tsx +26 -2
- package/src/modules/ExtendedWrapperSDk/index.ts +62 -0
- package/src/modules/ExtendedWrapperSDk/types.ts +311 -0
- package/src/modules/ExtendedWrapperSDk/wrapper.ts +395 -0
- package/src/modules/avnu.ts +17 -4
- package/src/modules/ekubo-quoter.ts +99 -11
- package/src/modules/erc20.ts +67 -21
- package/src/modules/harvests.ts +16 -29
- package/src/modules/index.ts +5 -1
- package/src/modules/lst-apr.ts +36 -0
- package/src/modules/midas.ts +159 -0
- package/src/modules/pricer-from-api.ts +2 -2
- package/src/modules/pricer.ts +3 -38
- package/src/modules/token-market-data.ts +202 -0
- package/src/node/deployer.ts +1 -36
- package/src/strategies/autoCompounderStrk.ts +1 -1
- package/src/strategies/base-strategy.ts +20 -3
- package/src/strategies/ekubo-cl-vault.tsx +123 -306
- package/src/strategies/index.ts +4 -1
- package/src/strategies/svk-strategy.ts +247 -0
- package/src/strategies/universal-adapters/adapter-optimizer.ts +65 -0
- package/src/strategies/universal-adapters/adapter-utils.ts +5 -1
- package/src/strategies/universal-adapters/avnu-adapter.ts +418 -0
- package/src/strategies/universal-adapters/baseAdapter.ts +181 -153
- package/src/strategies/universal-adapters/common-adapter.ts +98 -77
- package/src/strategies/universal-adapters/extended-adapter.ts +544 -0
- package/src/strategies/universal-adapters/index.ts +5 -1
- package/src/strategies/universal-adapters/unused-balance-adapter.ts +109 -0
- package/src/strategies/universal-adapters/vesu-adapter.ts +220 -218
- package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +924 -0
- package/src/strategies/universal-adapters/vesu-supply-only-adapter.ts +58 -51
- package/src/strategies/universal-lst-muliplier-strategy.tsx +707 -774
- package/src/strategies/universal-strategy.tsx +1098 -1180
- package/src/strategies/vesu-extended-strategy/services/operationService.ts +28 -0
- package/src/strategies/vesu-extended-strategy/utils/config.runtime.ts +77 -0
- package/src/strategies/vesu-extended-strategy/utils/constants.ts +48 -0
- package/src/strategies/vesu-extended-strategy/utils/helper.ts +374 -0
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +992 -0
- package/src/strategies/vesu-rebalance.tsx +16 -19
- package/src/utils/health-factor-math.ts +11 -5
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript type definitions for Extended Exchange API
|
|
3
|
+
* Based on Python SDK models from x10.perpetual
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Enums
|
|
7
|
+
export enum OrderSide {
|
|
8
|
+
BUY = "BUY",
|
|
9
|
+
SELL = "SELL",
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export enum TimeInForce {
|
|
13
|
+
GTT = "GTT",
|
|
14
|
+
IOC = "IOC",
|
|
15
|
+
FOK = "FOK",
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export enum OrderType {
|
|
19
|
+
LIMIT = "LIMIT",
|
|
20
|
+
CONDITIONAL = "CONDITIONAL",
|
|
21
|
+
MARKET = "MARKET",
|
|
22
|
+
TPSL = "TPSL",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export enum OrderStatus {
|
|
26
|
+
UNKNOWN = "UNKNOWN",
|
|
27
|
+
NEW = "NEW",
|
|
28
|
+
UNTRIGGERED = "UNTRIGGERED",
|
|
29
|
+
PARTIALLY_FILLED = "PARTIALLY_FILLED",
|
|
30
|
+
FILLED = "FILLED",
|
|
31
|
+
CANCELLED = "CANCELLED",
|
|
32
|
+
EXPIRED = "EXPIRED",
|
|
33
|
+
REJECTED = "REJECTED",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export enum OrderStatusReason {
|
|
37
|
+
UNKNOWN = "UNKNOWN",
|
|
38
|
+
NONE = "NONE",
|
|
39
|
+
UNKNOWN_MARKET = "UNKNOWN_MARKET",
|
|
40
|
+
DISABLED_MARKET = "DISABLED_MARKET",
|
|
41
|
+
NOT_ENOUGH_FUNDS = "NOT_ENOUGH_FUNDS",
|
|
42
|
+
NO_LIQUIDITY = "NO_LIQUIDITY",
|
|
43
|
+
INVALID_FEE = "INVALID_FEE",
|
|
44
|
+
INVALID_QTY = "INVALID_QTY",
|
|
45
|
+
INVALID_PRICE = "INVALID_PRICE",
|
|
46
|
+
INVALID_VALUE = "INVALID_VALUE",
|
|
47
|
+
UNKNOWN_ACCOUNT = "UNKNOWN_ACCOUNT",
|
|
48
|
+
SELF_TRADE_PROTECTION = "SELF_TRADE_PROTECTION",
|
|
49
|
+
POST_ONLY_FAILED = "POST_ONLY_FAILED",
|
|
50
|
+
REDUCE_ONLY_FAILED = "REDUCE_ONLY_FAILED",
|
|
51
|
+
INVALID_EXPIRE_TIME = "INVALID_EXPIRE_TIME",
|
|
52
|
+
POSITION_TPSL_CONFLICT = "POSITION_TPSL_CONFLICT",
|
|
53
|
+
INVALID_LEVERAGE = "INVALID_LEVERAGE",
|
|
54
|
+
PREV_ORDER_NOT_FOUND = "PREV_ORDER_NOT_FOUND",
|
|
55
|
+
PREV_ORDER_TRIGGERED = "PREV_ORDER_TRIGGERED",
|
|
56
|
+
TPSL_OTHER_SIDE_FILLED = "TPSL_OTHER_SIDE_FILLED",
|
|
57
|
+
PREV_ORDER_CONFLICT = "PREV_ORDER_CONFLICT",
|
|
58
|
+
ORDER_REPLACED = "ORDER_REPLACED",
|
|
59
|
+
POST_ONLY_MODE = "POST_ONLY_MODE",
|
|
60
|
+
REDUCE_ONLY_MODE = "REDUCE_ONLY_MODE",
|
|
61
|
+
TRADING_OFF_MODE = "TRADING_OFF_MODE",
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export enum PositionSide {
|
|
65
|
+
LONG = "LONG",
|
|
66
|
+
SHORT = "SHORT",
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export enum ExitType {
|
|
70
|
+
TRADE = "TRADE",
|
|
71
|
+
LIQUIDATION = "LIQUIDATION",
|
|
72
|
+
ADL = "ADL",
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export enum AssetOperationType {
|
|
76
|
+
DEPOSIT = "DEPOSIT",
|
|
77
|
+
WITHDRAWAL = "WITHDRAWAL",
|
|
78
|
+
TRANSFER = "TRANSFER",
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export enum AssetOperationStatus {
|
|
82
|
+
PENDING = "PENDING",
|
|
83
|
+
COMPLETED = "COMPLETED",
|
|
84
|
+
FAILED = "FAILED",
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Base types
|
|
88
|
+
export interface SettlementSignature {
|
|
89
|
+
r: string;
|
|
90
|
+
s: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface StarkSettlement {
|
|
94
|
+
signature: SettlementSignature;
|
|
95
|
+
stark_key: string;
|
|
96
|
+
collateral_position: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface StarkDebuggingOrderAmounts {
|
|
100
|
+
collateral_amount: string;
|
|
101
|
+
fee_amount: string;
|
|
102
|
+
synthetic_amount: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Order types
|
|
106
|
+
export interface PlacedOrder {
|
|
107
|
+
id: number;
|
|
108
|
+
external_id: string;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface OpenOrder {
|
|
112
|
+
id: number;
|
|
113
|
+
account_id: number;
|
|
114
|
+
external_id: string;
|
|
115
|
+
market: string;
|
|
116
|
+
type: OrderType;
|
|
117
|
+
side: OrderSide;
|
|
118
|
+
status: OrderStatus;
|
|
119
|
+
status_reason?: OrderStatusReason;
|
|
120
|
+
price: string;
|
|
121
|
+
average_price?: string;
|
|
122
|
+
qty: string;
|
|
123
|
+
filled_qty?: string;
|
|
124
|
+
reduce_only: boolean;
|
|
125
|
+
post_only: boolean;
|
|
126
|
+
payed_fee?: string;
|
|
127
|
+
created_time: number;
|
|
128
|
+
updated_time: number;
|
|
129
|
+
expiry_time?: number;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Position types
|
|
133
|
+
export interface Position {
|
|
134
|
+
id: number;
|
|
135
|
+
accountId: number;
|
|
136
|
+
market: string;
|
|
137
|
+
side: PositionSide;
|
|
138
|
+
leverage: string;
|
|
139
|
+
size: string;
|
|
140
|
+
value: string;
|
|
141
|
+
openPrice: string;
|
|
142
|
+
markPrice: string;
|
|
143
|
+
liquidationPrice?: string;
|
|
144
|
+
unrealisedPnl: string;
|
|
145
|
+
realisedPnl: string;
|
|
146
|
+
tpPrice?: string;
|
|
147
|
+
slPrice?: string;
|
|
148
|
+
adl?: number;
|
|
149
|
+
createdAt: number;
|
|
150
|
+
updatedAt: number;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface PositionHistory {
|
|
154
|
+
id: number;
|
|
155
|
+
account_id: number;
|
|
156
|
+
market: string;
|
|
157
|
+
side: PositionSide;
|
|
158
|
+
leverage: string;
|
|
159
|
+
size: string;
|
|
160
|
+
open_price: string;
|
|
161
|
+
exit_type?: ExitType;
|
|
162
|
+
exit_price?: string;
|
|
163
|
+
realised_pnl: string;
|
|
164
|
+
created_time: number;
|
|
165
|
+
closed_time?: number;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Balance types
|
|
169
|
+
export interface Balance {
|
|
170
|
+
collateral_name: string;
|
|
171
|
+
balance: string;
|
|
172
|
+
equity: string;
|
|
173
|
+
availableForTrade: string;
|
|
174
|
+
availableForWithdrawal: string;
|
|
175
|
+
unrealisedPnl: string;
|
|
176
|
+
initialMargin: string;
|
|
177
|
+
marginRatio: string;
|
|
178
|
+
updatedTime: number;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Market types
|
|
182
|
+
export interface RiskFactorConfig {
|
|
183
|
+
upper_bound: string;
|
|
184
|
+
risk_factor: string;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface MarketStats {
|
|
188
|
+
daily_volume: string;
|
|
189
|
+
daily_volume_base: string;
|
|
190
|
+
daily_price_change: string;
|
|
191
|
+
daily_low: string;
|
|
192
|
+
daily_high: string;
|
|
193
|
+
last_price: string;
|
|
194
|
+
ask_price: string;
|
|
195
|
+
bid_price: string;
|
|
196
|
+
mark_price: string;
|
|
197
|
+
index_price: string;
|
|
198
|
+
funding_rate: string;
|
|
199
|
+
next_funding_rate: number;
|
|
200
|
+
open_interest: string;
|
|
201
|
+
open_interest_base: string;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface TradingConfig {
|
|
205
|
+
min_order_size: string;
|
|
206
|
+
min_order_size_change: string;
|
|
207
|
+
min_price_change: string;
|
|
208
|
+
max_market_order_value: string;
|
|
209
|
+
max_limit_order_value: string;
|
|
210
|
+
max_position_value: string;
|
|
211
|
+
max_leverage: string;
|
|
212
|
+
max_num_orders: number;
|
|
213
|
+
limit_price_cap: string;
|
|
214
|
+
limit_price_floor: string;
|
|
215
|
+
risk_factor_config: RiskFactorConfig[];
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export interface L2Config {
|
|
219
|
+
type: string;
|
|
220
|
+
collateral_id: string;
|
|
221
|
+
collateral_resolution: number;
|
|
222
|
+
synthetic_id: string;
|
|
223
|
+
synthetic_resolution: number;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export interface Market {
|
|
227
|
+
name: string;
|
|
228
|
+
asset_name: string;
|
|
229
|
+
asset_precision: number;
|
|
230
|
+
collateral_asset_name: string;
|
|
231
|
+
collateral_asset_precision: number;
|
|
232
|
+
active: boolean;
|
|
233
|
+
market_stats: MarketStats;
|
|
234
|
+
trading_config: TradingConfig;
|
|
235
|
+
l2_config: L2Config;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Asset operation types
|
|
239
|
+
export interface AssetOperation {
|
|
240
|
+
id: number;
|
|
241
|
+
type: AssetOperationType;
|
|
242
|
+
status: AssetOperationStatus;
|
|
243
|
+
amount: string;
|
|
244
|
+
asset: string;
|
|
245
|
+
created_time: number;
|
|
246
|
+
updated_time: number;
|
|
247
|
+
description?: string;
|
|
248
|
+
transactionHash?:string;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Request types
|
|
252
|
+
export interface CreateOrderRequest {
|
|
253
|
+
market_name: string;
|
|
254
|
+
amount: string;
|
|
255
|
+
price: string;
|
|
256
|
+
side: OrderSide;
|
|
257
|
+
post_only?: boolean;
|
|
258
|
+
previous_order_id?: number;
|
|
259
|
+
external_id?: string;
|
|
260
|
+
time_in_force?: TimeInForce;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export interface WithdrawRequest {
|
|
264
|
+
amount: string;
|
|
265
|
+
asset?: string;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export interface SignedWithdrawRequest {
|
|
269
|
+
recipient: string;
|
|
270
|
+
position_id: number;
|
|
271
|
+
amount: number;
|
|
272
|
+
expiration: number;
|
|
273
|
+
salt: number;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export interface CancelOrderRequest {
|
|
277
|
+
order_id: number;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Response wrapper type
|
|
281
|
+
export interface ApiResponse<T> {
|
|
282
|
+
success: boolean;
|
|
283
|
+
message: string;
|
|
284
|
+
data: T;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Extended API response wrapper (matches Python WrappedApiResponse)
|
|
288
|
+
export interface ExtendedApiResponse<T> {
|
|
289
|
+
status: 'OK' | 'ERROR';
|
|
290
|
+
message: string;
|
|
291
|
+
data: T;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Configuration types
|
|
295
|
+
export interface ExtendedWrapperConfig {
|
|
296
|
+
baseUrl: string;
|
|
297
|
+
apiKey?: string;
|
|
298
|
+
timeout?: number;
|
|
299
|
+
retries?: number;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export interface UpdateLeverageRequest {
|
|
303
|
+
leverage: string;
|
|
304
|
+
market: string;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export interface FundingRate {
|
|
308
|
+
m: string;
|
|
309
|
+
f:string;
|
|
310
|
+
t:number;
|
|
311
|
+
}
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExtendedWrapper - TypeScript wrapper for Extended Exchange API
|
|
3
|
+
* Provides a clean interface to interact with the Extended Exchange trading API
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
CreateOrderRequest,
|
|
8
|
+
WithdrawRequest,
|
|
9
|
+
SignedWithdrawRequest,
|
|
10
|
+
CancelOrderRequest,
|
|
11
|
+
PlacedOrder,
|
|
12
|
+
OpenOrder,
|
|
13
|
+
Position,
|
|
14
|
+
Balance,
|
|
15
|
+
Market,
|
|
16
|
+
MarketStats,
|
|
17
|
+
AssetOperation,
|
|
18
|
+
ExtendedApiResponse,
|
|
19
|
+
ExtendedWrapperConfig,
|
|
20
|
+
OrderSide,
|
|
21
|
+
TimeInForce,
|
|
22
|
+
AssetOperationType,
|
|
23
|
+
AssetOperationStatus,
|
|
24
|
+
FundingRate,
|
|
25
|
+
UpdateLeverageRequest,
|
|
26
|
+
} from "./types";
|
|
27
|
+
|
|
28
|
+
export class ExtendedWrapper {
|
|
29
|
+
private baseUrl: string;
|
|
30
|
+
private apiKey?: string;
|
|
31
|
+
private timeout: number;
|
|
32
|
+
private retries: number;
|
|
33
|
+
|
|
34
|
+
constructor(config: ExtendedWrapperConfig) {
|
|
35
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, ""); // Remove trailing slash
|
|
36
|
+
this.apiKey = config.apiKey;
|
|
37
|
+
this.timeout = config.timeout || 30000; // 30 seconds default
|
|
38
|
+
this.retries = config.retries || 3;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Make HTTP request with retry logic and error handling
|
|
43
|
+
*/
|
|
44
|
+
private async makeRequest<T>(
|
|
45
|
+
endpoint: string,
|
|
46
|
+
options: RequestInit = {}
|
|
47
|
+
): Promise<ExtendedApiResponse<T>> {
|
|
48
|
+
const url = `${this.baseUrl}${endpoint}`;
|
|
49
|
+
|
|
50
|
+
const headers: Record<string, any> = {
|
|
51
|
+
"Content-Type": "application/json",
|
|
52
|
+
...options.headers,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
if (this.apiKey) {
|
|
56
|
+
headers["X-API-Key"] = this.apiKey;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const requestOptions: RequestInit = {
|
|
60
|
+
...options,
|
|
61
|
+
headers,
|
|
62
|
+
signal: AbortSignal.timeout(this.timeout),
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
let lastError: Error | null = null;
|
|
66
|
+
|
|
67
|
+
for (let attempt = 1; attempt <= this.retries; attempt++) {
|
|
68
|
+
try {
|
|
69
|
+
const response = await fetch(url, requestOptions);
|
|
70
|
+
|
|
71
|
+
if (!response.ok) {
|
|
72
|
+
const errorData = await response.json().catch(() => ({}));
|
|
73
|
+
throw new Error(
|
|
74
|
+
`HTTP ${response.status}: ${
|
|
75
|
+
errorData.detail || response.statusText
|
|
76
|
+
}`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const data = await response.json();
|
|
81
|
+
return data;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
lastError = error as Error;
|
|
84
|
+
|
|
85
|
+
if (attempt < this.retries) {
|
|
86
|
+
// Exponential backoff
|
|
87
|
+
const delay = Math.pow(2, attempt) * 1000;
|
|
88
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
throw lastError || new Error("Request failed after all retries");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Create a new order on Extended Exchange
|
|
98
|
+
*/
|
|
99
|
+
async createOrder(
|
|
100
|
+
request: CreateOrderRequest
|
|
101
|
+
): Promise<ExtendedApiResponse<PlacedOrder>> {
|
|
102
|
+
return this.makeRequest<PlacedOrder>("/api/v1/orders", {
|
|
103
|
+
method: "POST",
|
|
104
|
+
body: JSON.stringify(request),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Get all markets
|
|
110
|
+
*/
|
|
111
|
+
async getMarkets(
|
|
112
|
+
marketNames?: string
|
|
113
|
+
): Promise<ExtendedApiResponse<Market[]>> {
|
|
114
|
+
const params = marketNames
|
|
115
|
+
? `?market_names=${encodeURIComponent(marketNames)}`
|
|
116
|
+
: "";
|
|
117
|
+
return this.makeRequest<Market[]>(`/api/v1/markets${params}`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
*
|
|
122
|
+
* @param orderId - The ID of the order to get
|
|
123
|
+
* @returns The order
|
|
124
|
+
*/
|
|
125
|
+
async getOrderByOrderId(orderId: string): Promise<ExtendedApiResponse<OpenOrder>> {
|
|
126
|
+
const orderIdInt = parseInt(orderId);
|
|
127
|
+
return this.makeRequest<OpenOrder>(`/api/v1/orderId/${orderIdInt}`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Get market statistics for a specific market
|
|
132
|
+
*/
|
|
133
|
+
async getMarketStatistics(
|
|
134
|
+
marketName: string
|
|
135
|
+
): Promise<ExtendedApiResponse<MarketStats>> {
|
|
136
|
+
return this.makeRequest<MarketStats>(
|
|
137
|
+
`/api/v1/markets/statistics?market_name=${encodeURIComponent(marketName)}`
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Get current trading positions
|
|
143
|
+
*/
|
|
144
|
+
async getPositions(
|
|
145
|
+
marketNames?: string
|
|
146
|
+
): Promise<ExtendedApiResponse<Position[]>> {
|
|
147
|
+
const params = marketNames
|
|
148
|
+
? `?market_names=${encodeURIComponent(marketNames)}`
|
|
149
|
+
: "";
|
|
150
|
+
return this.makeRequest<Position[]>(`/api/v1/positions${params}`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Get account balance and holdings
|
|
155
|
+
*/
|
|
156
|
+
async getHoldings(): Promise<ExtendedApiResponse<Balance>> {
|
|
157
|
+
return this.makeRequest<Balance>("/api/v1/holdings");
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Initiate a withdrawal from Extended Exchange
|
|
162
|
+
*/
|
|
163
|
+
async withdraw(
|
|
164
|
+
request: WithdrawRequest
|
|
165
|
+
): Promise<ExtendedApiResponse<number>> {
|
|
166
|
+
return this.makeRequest<number>("/api/v1/withdraw", {
|
|
167
|
+
method: "POST",
|
|
168
|
+
body: JSON.stringify(request),
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Create and sign a withdrawal request hash
|
|
174
|
+
*/
|
|
175
|
+
async signWithdrawalRequest(request: SignedWithdrawRequest): Promise<
|
|
176
|
+
ExtendedApiResponse<{
|
|
177
|
+
withdraw_request_hash: string;
|
|
178
|
+
signature: {
|
|
179
|
+
r: string;
|
|
180
|
+
s: string;
|
|
181
|
+
};
|
|
182
|
+
}>
|
|
183
|
+
> {
|
|
184
|
+
return this.makeRequest("/api/v1/withdraw/sign", {
|
|
185
|
+
method: "POST",
|
|
186
|
+
body: JSON.stringify(request),
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Cancel an existing order
|
|
192
|
+
*/
|
|
193
|
+
async cancelOrder(
|
|
194
|
+
request: CancelOrderRequest
|
|
195
|
+
): Promise<ExtendedApiResponse<{}>> {
|
|
196
|
+
return this.makeRequest<{}>("/api/v1/orders/cancel", {
|
|
197
|
+
method: "POST",
|
|
198
|
+
body: JSON.stringify(request),
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Get all open orders
|
|
205
|
+
*/
|
|
206
|
+
async getOpenOrders(
|
|
207
|
+
marketName?: string
|
|
208
|
+
): Promise<ExtendedApiResponse<OpenOrder[]>> {
|
|
209
|
+
const endpoint = marketName
|
|
210
|
+
? `/api/v1/marketOrders/${marketName}`
|
|
211
|
+
: "/api/v1/marketOrders";
|
|
212
|
+
return this.makeRequest<OpenOrder[]>(endpoint,{
|
|
213
|
+
method: "GET",
|
|
214
|
+
headers: {
|
|
215
|
+
"Content-Type": "application/json",
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Update leverage on the market
|
|
222
|
+
* @param request
|
|
223
|
+
* @returns
|
|
224
|
+
*/
|
|
225
|
+
async updateLeverage(
|
|
226
|
+
request: UpdateLeverageRequest
|
|
227
|
+
): Promise<ExtendedApiResponse<{}>> {
|
|
228
|
+
return this.makeRequest<{}>("/api/v1/leverage", {
|
|
229
|
+
method: "POST",
|
|
230
|
+
body: JSON.stringify(request),
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Get asset operations with optional filtering
|
|
236
|
+
*/
|
|
237
|
+
async getAssetOperations(
|
|
238
|
+
options: {
|
|
239
|
+
id?: number;
|
|
240
|
+
operationsType?: AssetOperationType[];
|
|
241
|
+
operationsStatus?: AssetOperationStatus[];
|
|
242
|
+
startTime?: number;
|
|
243
|
+
endTime?: number;
|
|
244
|
+
cursor?: number;
|
|
245
|
+
limit?: number;
|
|
246
|
+
} = {}
|
|
247
|
+
): Promise<ExtendedApiResponse<AssetOperation[]>> {
|
|
248
|
+
const params = new URLSearchParams();
|
|
249
|
+
|
|
250
|
+
if (options.id !== undefined) params.append("id", options.id.toString());
|
|
251
|
+
if (options.operationsType) {
|
|
252
|
+
params.append("operations_type", options.operationsType.join(","));
|
|
253
|
+
}
|
|
254
|
+
if (options.operationsStatus) {
|
|
255
|
+
params.append("operations_status", options.operationsStatus.join(","));
|
|
256
|
+
}
|
|
257
|
+
if (options.startTime !== undefined)
|
|
258
|
+
params.append("start_time", options.startTime.toString());
|
|
259
|
+
if (options.endTime !== undefined)
|
|
260
|
+
params.append("end_time", options.endTime.toString());
|
|
261
|
+
if (options.cursor !== undefined)
|
|
262
|
+
params.append("cursor", options.cursor.toString());
|
|
263
|
+
if (options.limit !== undefined)
|
|
264
|
+
params.append("limit", options.limit.toString());
|
|
265
|
+
|
|
266
|
+
const queryString = params.toString();
|
|
267
|
+
const endpoint = `/api/v1/asset-operations${
|
|
268
|
+
queryString ? `?${queryString}` : ""
|
|
269
|
+
}`;
|
|
270
|
+
|
|
271
|
+
return this.makeRequest<AssetOperation[]>(endpoint);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Health check endpoint
|
|
276
|
+
*/
|
|
277
|
+
async healthCheck(): Promise<ExtendedApiResponse<MarketStats>> {
|
|
278
|
+
return this.makeRequest<MarketStats>("/api/v1/health");
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Convenience method to create a buy order
|
|
283
|
+
*/
|
|
284
|
+
async createBuyOrder(
|
|
285
|
+
marketName: string,
|
|
286
|
+
amount: string,
|
|
287
|
+
price: string,
|
|
288
|
+
options: {
|
|
289
|
+
postOnly?: boolean;
|
|
290
|
+
previousOrderId?: number;
|
|
291
|
+
externalId?: string;
|
|
292
|
+
timeInForce?: TimeInForce;
|
|
293
|
+
} = {}
|
|
294
|
+
): Promise<ExtendedApiResponse<PlacedOrder>> {
|
|
295
|
+
return this.createOrder({
|
|
296
|
+
market_name: marketName,
|
|
297
|
+
amount,
|
|
298
|
+
price,
|
|
299
|
+
side: OrderSide.BUY,
|
|
300
|
+
...options,
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Get order by ID
|
|
306
|
+
* @param orderId - The ID of the order to get
|
|
307
|
+
* @returns The order
|
|
308
|
+
*/
|
|
309
|
+
async getOrderById(orderId: number): Promise<ExtendedApiResponse<OpenOrder>> {
|
|
310
|
+
return this.makeRequest<OpenOrder>(`/api/v1/orderId/${orderId}`);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Convenience method to create a sell order
|
|
315
|
+
*/
|
|
316
|
+
async createSellOrder(
|
|
317
|
+
marketName: string,
|
|
318
|
+
amount: string,
|
|
319
|
+
price: string,
|
|
320
|
+
options: {
|
|
321
|
+
postOnly?: boolean;
|
|
322
|
+
previousOrderId?: number;
|
|
323
|
+
externalId?: string;
|
|
324
|
+
timeInForce?: TimeInForce;
|
|
325
|
+
} = {}
|
|
326
|
+
): Promise<ExtendedApiResponse<PlacedOrder>> {
|
|
327
|
+
return this.createOrder({
|
|
328
|
+
market_name: marketName,
|
|
329
|
+
amount,
|
|
330
|
+
price,
|
|
331
|
+
side: OrderSide.SELL,
|
|
332
|
+
...options,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Get positions for a specific market
|
|
338
|
+
*/
|
|
339
|
+
async getPositionsForMarket(
|
|
340
|
+
marketName: string
|
|
341
|
+
): Promise<ExtendedApiResponse<Position[]>> {
|
|
342
|
+
return this.getPositions(marketName);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Get open orders for a specific market
|
|
347
|
+
*/
|
|
348
|
+
async getOpenOrdersForMarket(
|
|
349
|
+
marketName: string
|
|
350
|
+
): Promise<ExtendedApiResponse<OpenOrder[]>> {
|
|
351
|
+
return this.getOpenOrders(marketName);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Cancel order by ID (convenience method)
|
|
356
|
+
*/
|
|
357
|
+
async cancelOrderById(orderId: number): Promise<ExtendedApiResponse<{}>> {
|
|
358
|
+
return this.cancelOrder({ order_id: orderId });
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Get order history for a specific market
|
|
363
|
+
* @param marketName - The name of the market to get order history for
|
|
364
|
+
* @returns The order history for the specified market
|
|
365
|
+
*/
|
|
366
|
+
async getOrderHistory(marketName: string): Promise<ExtendedApiResponse<OpenOrder[]>> {
|
|
367
|
+
return this.makeRequest<OpenOrder[]>(`/api/v1/marketOrders/${marketName}`);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Withdraw USDC (convenience method)
|
|
372
|
+
*/
|
|
373
|
+
async withdrawUSDC(amount: string): Promise<ExtendedApiResponse<number>> {
|
|
374
|
+
return this.withdraw({ amount, asset: "USDC" });
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Get funding rates for a specific market
|
|
379
|
+
* @param marketName - The name of the market to get funding rates for
|
|
380
|
+
* @returns The funding rates for the specified market
|
|
381
|
+
*/
|
|
382
|
+
async getFundingRates(
|
|
383
|
+
marketName: string,
|
|
384
|
+
side: string
|
|
385
|
+
): Promise<ExtendedApiResponse<FundingRate[]>> {
|
|
386
|
+
return this.makeRequest<FundingRate[]>(
|
|
387
|
+
`/api/v1/markets/funding-rates?market_name=${encodeURIComponent(
|
|
388
|
+
marketName
|
|
389
|
+
)}&side=${encodeURIComponent(side)}`
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
export default ExtendedWrapper;
|