@0xmonaco/core 0.6.2 → 0.7.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/api/auth/api.d.ts +9 -8
- package/dist/api/auth/api.js +9 -11
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.js +3 -0
- package/dist/api/margin-accounts/api.d.ts +12 -0
- package/dist/api/margin-accounts/api.js +69 -0
- package/dist/api/margin-accounts/index.d.ts +1 -0
- package/dist/api/margin-accounts/index.js +1 -0
- package/dist/api/market/api.d.ts +8 -1
- package/dist/api/market/api.js +31 -3
- package/dist/api/orderbook/api.js +1 -1
- package/dist/api/perp/index.d.ts +1 -0
- package/dist/api/perp/index.js +1 -0
- package/dist/api/perp/routes.d.ts +133 -0
- package/dist/api/perp/routes.js +85 -0
- package/dist/api/positions/api.d.ts +12 -0
- package/dist/api/positions/api.js +88 -0
- package/dist/api/positions/index.d.ts +1 -0
- package/dist/api/positions/index.js +1 -0
- package/dist/api/trades/api.d.ts +1 -1
- package/dist/api/trades/api.js +2 -2
- package/dist/api/trading/api.d.ts +14 -3
- package/dist/api/trading/api.js +76 -15
- package/dist/api/websocket/types.d.ts +3 -1
- package/dist/api/websocket/websocket.js +153 -17
- package/dist/sdk.d.ts +7 -5
- package/dist/sdk.js +17 -9
- package/package.json +1 -1
- package/dist/api/applications/api.d.ts.map +0 -1
- package/dist/api/applications/api.js.map +0 -1
- package/dist/api/applications/index.d.ts.map +0 -1
- package/dist/api/applications/index.js.map +0 -1
- package/dist/api/auth/api.d.ts.map +0 -1
- package/dist/api/auth/api.js.map +0 -1
- package/dist/api/auth/index.d.ts.map +0 -1
- package/dist/api/auth/index.js.map +0 -1
- package/dist/api/base.d.ts.map +0 -1
- package/dist/api/base.js.map +0 -1
- package/dist/api/fees/api.d.ts.map +0 -1
- package/dist/api/fees/api.js.map +0 -1
- package/dist/api/fees/index.d.ts.map +0 -1
- package/dist/api/fees/index.js.map +0 -1
- package/dist/api/index.d.ts.map +0 -1
- package/dist/api/index.js.map +0 -1
- package/dist/api/market/api.d.ts.map +0 -1
- package/dist/api/market/api.js.map +0 -1
- package/dist/api/market/index.d.ts.map +0 -1
- package/dist/api/market/index.js.map +0 -1
- package/dist/api/orderbook/api.d.ts.map +0 -1
- package/dist/api/orderbook/api.js.map +0 -1
- package/dist/api/orderbook/index.d.ts.map +0 -1
- package/dist/api/orderbook/index.js.map +0 -1
- package/dist/api/profile/api.d.ts.map +0 -1
- package/dist/api/profile/api.js.map +0 -1
- package/dist/api/profile/index.d.ts.map +0 -1
- package/dist/api/profile/index.js.map +0 -1
- package/dist/api/trades/api.d.ts.map +0 -1
- package/dist/api/trades/api.js.map +0 -1
- package/dist/api/trades/index.d.ts.map +0 -1
- package/dist/api/trades/index.js.map +0 -1
- package/dist/api/trading/api.d.ts.map +0 -1
- package/dist/api/trading/api.js.map +0 -1
- package/dist/api/trading/index.d.ts.map +0 -1
- package/dist/api/trading/index.js.map +0 -1
- package/dist/api/vault/api.d.ts.map +0 -1
- package/dist/api/vault/api.js.map +0 -1
- package/dist/api/vault/index.d.ts.map +0 -1
- package/dist/api/vault/index.js.map +0 -1
- package/dist/api/websocket/index.d.ts.map +0 -1
- package/dist/api/websocket/index.js.map +0 -1
- package/dist/api/websocket/types.d.ts.map +0 -1
- package/dist/api/websocket/types.js.map +0 -1
- package/dist/api/websocket/utils.d.ts.map +0 -1
- package/dist/api/websocket/utils.js.map +0 -1
- package/dist/api/websocket/websocket.d.ts.map +0 -1
- package/dist/api/websocket/websocket.js.map +0 -1
- package/dist/errors/errors.d.ts.map +0 -1
- package/dist/errors/errors.js.map +0 -1
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/networks/index.d.ts.map +0 -1
- package/dist/networks/index.js.map +0 -1
- package/dist/networks/networks.d.ts.map +0 -1
- package/dist/networks/networks.js.map +0 -1
- package/dist/sdk.d.ts.map +0 -1
- package/dist/sdk.js.map +0 -1
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/magnitude.d.ts.map +0 -1
- package/dist/utils/magnitude.js.map +0 -1
package/dist/api/auth/api.d.ts
CHANGED
|
@@ -182,14 +182,15 @@ export declare class AuthAPIImpl extends BaseAPI implements AuthAPI {
|
|
|
182
182
|
*/
|
|
183
183
|
refreshToken(refreshToken: string): Promise<TokenRefreshResponse>;
|
|
184
184
|
/**
|
|
185
|
-
* Revokes
|
|
185
|
+
* Revokes the current session's refresh token.
|
|
186
186
|
*
|
|
187
|
-
* Invalidates
|
|
188
|
-
* new access tokens. This is useful
|
|
189
|
-
* a token has been compromised.
|
|
187
|
+
* Invalidates the refresh token associated with the current access token,
|
|
188
|
+
* preventing it from being used to obtain new access tokens. This is useful
|
|
189
|
+
* for logout functionality or when a token has been compromised.
|
|
190
|
+
*
|
|
191
|
+
* The server identifies the token to revoke from the access token in the
|
|
192
|
+
* Authorization header — no request body is needed.
|
|
190
193
|
*
|
|
191
|
-
* **Important:** Pass the `refreshToken` from the authentication response.
|
|
192
|
-
* @param refreshToken - The refresh token to revoke (from authResult.refreshToken)
|
|
193
194
|
* @returns Promise resolving when the token is revoked
|
|
194
195
|
* @throws {APIError} When token revocation fails
|
|
195
196
|
*
|
|
@@ -197,9 +198,9 @@ export declare class AuthAPIImpl extends BaseAPI implements AuthAPI {
|
|
|
197
198
|
* ```typescript
|
|
198
199
|
* // After authentication
|
|
199
200
|
* const authResult = await authAPI.authenticate(clientId);
|
|
200
|
-
* await authAPI.revokeToken(
|
|
201
|
+
* await authAPI.revokeToken();
|
|
201
202
|
* console.log("Token revoked successfully");
|
|
202
203
|
* ```
|
|
203
204
|
*/
|
|
204
|
-
revokeToken(
|
|
205
|
+
revokeToken(): Promise<void>;
|
|
205
206
|
}
|
package/dist/api/auth/api.js
CHANGED
|
@@ -277,14 +277,15 @@ export class AuthAPIImpl extends BaseAPI {
|
|
|
277
277
|
};
|
|
278
278
|
}
|
|
279
279
|
/**
|
|
280
|
-
* Revokes
|
|
280
|
+
* Revokes the current session's refresh token.
|
|
281
281
|
*
|
|
282
|
-
* Invalidates
|
|
283
|
-
* new access tokens. This is useful
|
|
284
|
-
* a token has been compromised.
|
|
282
|
+
* Invalidates the refresh token associated with the current access token,
|
|
283
|
+
* preventing it from being used to obtain new access tokens. This is useful
|
|
284
|
+
* for logout functionality or when a token has been compromised.
|
|
285
|
+
*
|
|
286
|
+
* The server identifies the token to revoke from the access token in the
|
|
287
|
+
* Authorization header — no request body is needed.
|
|
285
288
|
*
|
|
286
|
-
* **Important:** Pass the `refreshToken` from the authentication response.
|
|
287
|
-
* @param refreshToken - The refresh token to revoke (from authResult.refreshToken)
|
|
288
289
|
* @returns Promise resolving when the token is revoked
|
|
289
290
|
* @throws {APIError} When token revocation fails
|
|
290
291
|
*
|
|
@@ -292,16 +293,13 @@ export class AuthAPIImpl extends BaseAPI {
|
|
|
292
293
|
* ```typescript
|
|
293
294
|
* // After authentication
|
|
294
295
|
* const authResult = await authAPI.authenticate(clientId);
|
|
295
|
-
* await authAPI.revokeToken(
|
|
296
|
+
* await authAPI.revokeToken();
|
|
296
297
|
* console.log("Token revoked successfully");
|
|
297
298
|
* ```
|
|
298
299
|
*/
|
|
299
|
-
async revokeToken(
|
|
300
|
+
async revokeToken() {
|
|
300
301
|
await this.makeAuthenticatedRequest("/api/v1/auth/revoke", {
|
|
301
302
|
method: "POST",
|
|
302
|
-
body: JSON.stringify({
|
|
303
|
-
refresh_token: refreshToken,
|
|
304
|
-
}),
|
|
305
303
|
});
|
|
306
304
|
}
|
|
307
305
|
}
|
package/dist/api/index.d.ts
CHANGED
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
export * from "./applications/index";
|
|
7
7
|
export * from "./base";
|
|
8
8
|
export * from "./fees";
|
|
9
|
+
export * from "./margin-accounts";
|
|
9
10
|
export * from "./market";
|
|
10
11
|
export * from "./orderbook";
|
|
12
|
+
export * from "./perp";
|
|
13
|
+
export * from "./positions";
|
|
11
14
|
export * from "./profile";
|
|
12
15
|
export * from "./trades";
|
|
13
16
|
export * from "./trading";
|
package/dist/api/index.js
CHANGED
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
export * from "./applications/index";
|
|
7
7
|
export * from "./base";
|
|
8
8
|
export * from "./fees";
|
|
9
|
+
export * from "./margin-accounts";
|
|
9
10
|
export * from "./market";
|
|
10
11
|
export * from "./orderbook";
|
|
12
|
+
export * from "./perp";
|
|
13
|
+
export * from "./positions";
|
|
11
14
|
export * from "./profile";
|
|
12
15
|
export * from "./trades";
|
|
13
16
|
export * from "./trading";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CreateMarginAccountRequest, CreateMarginAccountResponse, GetAvailableCollateralParams, GetAvailableCollateralResponse, GetMarginAccountMovementsParams, GetMarginAccountMovementsResponse, ListMarginAccountsParams, ListMarginAccountsResponse, MarginAccountSummary, MarginAccountsAPI, SimulateOrderRiskRequest, SimulateOrderRiskResponse, TransferCollateralRequest, TransferCollateralResponse } from "@0xmonaco/types";
|
|
2
|
+
import { BaseAPI } from "../base";
|
|
3
|
+
export declare class MarginAccountsAPIImpl extends BaseAPI implements MarginAccountsAPI {
|
|
4
|
+
listMarginAccounts(params?: ListMarginAccountsParams): Promise<ListMarginAccountsResponse>;
|
|
5
|
+
createMarginAccount(request?: CreateMarginAccountRequest): Promise<CreateMarginAccountResponse>;
|
|
6
|
+
getMarginAccountSummary(marginAccountId: string): Promise<MarginAccountSummary>;
|
|
7
|
+
getAvailableCollateral(params?: GetAvailableCollateralParams): Promise<GetAvailableCollateralResponse>;
|
|
8
|
+
transferCollateralToMarginAccount(marginAccountId: string, request: TransferCollateralRequest): Promise<TransferCollateralResponse>;
|
|
9
|
+
transferCollateralFromMarginAccount(marginAccountId: string, request: TransferCollateralRequest): Promise<TransferCollateralResponse>;
|
|
10
|
+
getMarginAccountMovements(marginAccountId: string, params?: GetMarginAccountMovementsParams): Promise<GetMarginAccountMovementsResponse>;
|
|
11
|
+
simulateOrderRisk(marginAccountId: string, request: SimulateOrderRiskRequest): Promise<SimulateOrderRiskResponse>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { CreateMarginAccountSchema, GetAvailableCollateralSchema, GetMarginAccountMovementsSchema, GetMarginAccountSummarySchema, ListMarginAccountsSchema, SimulateOrderRiskSchema, TransferCollateralSchema, validate, } from "@0xmonaco/types";
|
|
2
|
+
import { BaseAPI } from "../base";
|
|
3
|
+
import { perpRoutes } from "../perp";
|
|
4
|
+
export class MarginAccountsAPIImpl extends BaseAPI {
|
|
5
|
+
async listMarginAccounts(params) {
|
|
6
|
+
if (params) {
|
|
7
|
+
validate(ListMarginAccountsSchema, params);
|
|
8
|
+
}
|
|
9
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.list(params));
|
|
10
|
+
}
|
|
11
|
+
async createMarginAccount(request) {
|
|
12
|
+
validate(CreateMarginAccountSchema, request);
|
|
13
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.create(), {
|
|
14
|
+
method: "POST",
|
|
15
|
+
body: JSON.stringify({
|
|
16
|
+
label: request?.label,
|
|
17
|
+
collateral_asset: request?.collateralAsset,
|
|
18
|
+
}),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async getMarginAccountSummary(marginAccountId) {
|
|
22
|
+
validate(GetMarginAccountSummarySchema, { marginAccountId });
|
|
23
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.summary(marginAccountId));
|
|
24
|
+
}
|
|
25
|
+
async getAvailableCollateral(params) {
|
|
26
|
+
validate(GetAvailableCollateralSchema, params);
|
|
27
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.availableCollateral(params));
|
|
28
|
+
}
|
|
29
|
+
async transferCollateralToMarginAccount(marginAccountId, request) {
|
|
30
|
+
validate(TransferCollateralSchema, { marginAccountId, request });
|
|
31
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.transferIn(marginAccountId), {
|
|
32
|
+
method: "POST",
|
|
33
|
+
body: JSON.stringify({
|
|
34
|
+
asset: request.asset,
|
|
35
|
+
amount: request.amount,
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async transferCollateralFromMarginAccount(marginAccountId, request) {
|
|
40
|
+
validate(TransferCollateralSchema, { marginAccountId, request });
|
|
41
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.transferOut(marginAccountId), {
|
|
42
|
+
method: "POST",
|
|
43
|
+
body: JSON.stringify({
|
|
44
|
+
asset: request.asset,
|
|
45
|
+
amount: request.amount,
|
|
46
|
+
}),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async getMarginAccountMovements(marginAccountId, params) {
|
|
50
|
+
validate(GetMarginAccountMovementsSchema, { marginAccountId, ...params });
|
|
51
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.movements(marginAccountId, params));
|
|
52
|
+
}
|
|
53
|
+
async simulateOrderRisk(marginAccountId, request) {
|
|
54
|
+
validate(SimulateOrderRiskSchema, { marginAccountId, request });
|
|
55
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.simulateOrderRisk(marginAccountId), {
|
|
56
|
+
method: "POST",
|
|
57
|
+
body: JSON.stringify({
|
|
58
|
+
trading_pair_id: request.tradingPairId,
|
|
59
|
+
side: request.side,
|
|
60
|
+
position_side: request.positionSide,
|
|
61
|
+
order_type: request.orderType,
|
|
62
|
+
price: request.price,
|
|
63
|
+
quantity: request.quantity,
|
|
64
|
+
leverage: request.leverage,
|
|
65
|
+
reduce_only: request.reduceOnly,
|
|
66
|
+
}),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MarginAccountsAPIImpl } from "./api";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MarginAccountsAPIImpl } from "./api";
|
package/dist/api/market/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Candlestick, GetCandlesticksParams, GetTradingPairsParams, GetTradingPairsResponse, Interval, MarketAPI, MarketMetadata, TradingPair } from "@0xmonaco/types";
|
|
1
|
+
import type { Candlestick, FundingState, GetCandlesticksParams, GetTradingPairsParams, GetTradingPairsResponse, IndexPrice, Interval, ListFundingHistoryParams, ListFundingHistoryResponse, MarketAPI, MarketMetadata, MarkPrice, OpenInterest, PerpMarketConfig, PerpMarketSummary, TradingPair } from "@0xmonaco/types";
|
|
2
2
|
import { BaseAPI } from "../base";
|
|
3
3
|
/**
|
|
4
4
|
* Market API Implementation
|
|
@@ -10,4 +10,11 @@ export declare class MarketAPIImpl extends BaseAPI implements MarketAPI {
|
|
|
10
10
|
getTradingPairBySymbol(symbol: string): Promise<TradingPair | undefined>;
|
|
11
11
|
getCandlesticks(tradingPairId: string, interval: Interval, params?: GetCandlesticksParams): Promise<Candlestick[]>;
|
|
12
12
|
getMarketMetadata(tradingPairId: string): Promise<MarketMetadata>;
|
|
13
|
+
getPerpMarketConfig(tradingPairId: string): Promise<PerpMarketConfig>;
|
|
14
|
+
getPerpMarketSummary(tradingPairId: string): Promise<PerpMarketSummary>;
|
|
15
|
+
getMarkPrice(tradingPairId: string): Promise<MarkPrice>;
|
|
16
|
+
getIndexPrice(tradingPairId: string): Promise<IndexPrice>;
|
|
17
|
+
getFundingState(tradingPairId: string): Promise<FundingState>;
|
|
18
|
+
listFundingHistory(tradingPairId: string, params?: ListFundingHistoryParams): Promise<ListFundingHistoryResponse>;
|
|
19
|
+
getOpenInterest(tradingPairId: string): Promise<OpenInterest>;
|
|
13
20
|
}
|
package/dist/api/market/api.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GetCandlesticksByPairIdSchema, GetMarketMetadataSchema, validate } from "@0xmonaco/types";
|
|
2
2
|
import { BaseAPI } from "../base";
|
|
3
|
+
import { perpRoutes } from "../perp";
|
|
3
4
|
/**
|
|
4
5
|
* Market API Implementation
|
|
5
6
|
*
|
|
@@ -33,7 +34,7 @@ export class MarketAPIImpl extends BaseAPI {
|
|
|
33
34
|
async getTradingPairBySymbol(symbol) {
|
|
34
35
|
// Backend endpoint expects UUID, not symbol, so we fetch all pairs and filter
|
|
35
36
|
const response = await this.getPaginatedTradingPairs({ page_size: 100 });
|
|
36
|
-
return response.
|
|
37
|
+
return response.trading_pairs.find((pair) => pair.symbol === symbol);
|
|
37
38
|
}
|
|
38
39
|
async getCandlesticks(tradingPairId, interval, params) {
|
|
39
40
|
// Validate inputs using the trading pair ID schema
|
|
@@ -63,7 +64,34 @@ export class MarketAPIImpl extends BaseAPI {
|
|
|
63
64
|
}
|
|
64
65
|
async getMarketMetadata(tradingPairId) {
|
|
65
66
|
validate(GetMarketMetadataSchema, { tradingPairId });
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
return await this.makePublicRequest(perpRoutes.market.getMarketMetadata(tradingPairId));
|
|
68
|
+
}
|
|
69
|
+
async getPerpMarketConfig(tradingPairId) {
|
|
70
|
+
validate(GetMarketMetadataSchema, { tradingPairId });
|
|
71
|
+
return await this.makePublicRequest(perpRoutes.market.getPerpMarketConfig(tradingPairId));
|
|
72
|
+
}
|
|
73
|
+
async getPerpMarketSummary(tradingPairId) {
|
|
74
|
+
validate(GetMarketMetadataSchema, { tradingPairId });
|
|
75
|
+
return await this.makePublicRequest(perpRoutes.market.getPerpMarketSummary(tradingPairId));
|
|
76
|
+
}
|
|
77
|
+
async getMarkPrice(tradingPairId) {
|
|
78
|
+
validate(GetMarketMetadataSchema, { tradingPairId });
|
|
79
|
+
return await this.makePublicRequest(perpRoutes.market.getMarkPrice(tradingPairId));
|
|
80
|
+
}
|
|
81
|
+
async getIndexPrice(tradingPairId) {
|
|
82
|
+
validate(GetMarketMetadataSchema, { tradingPairId });
|
|
83
|
+
return await this.makePublicRequest(perpRoutes.market.getIndexPrice(tradingPairId));
|
|
84
|
+
}
|
|
85
|
+
async getFundingState(tradingPairId) {
|
|
86
|
+
validate(GetMarketMetadataSchema, { tradingPairId });
|
|
87
|
+
return await this.makePublicRequest(perpRoutes.market.getFundingState(tradingPairId));
|
|
88
|
+
}
|
|
89
|
+
async listFundingHistory(tradingPairId, params) {
|
|
90
|
+
validate(GetMarketMetadataSchema, { tradingPairId });
|
|
91
|
+
return await this.makePublicRequest(perpRoutes.market.listFundingHistory(tradingPairId, params));
|
|
92
|
+
}
|
|
93
|
+
async getOpenInterest(tradingPairId) {
|
|
94
|
+
validate(GetMarketMetadataSchema, { tradingPairId });
|
|
95
|
+
return await this.makePublicRequest(perpRoutes.market.getOpenInterest(tradingPairId));
|
|
68
96
|
}
|
|
69
97
|
}
|
|
@@ -12,7 +12,7 @@ export class OrderbookAPIImpl extends BaseAPI {
|
|
|
12
12
|
params.set("denomination", denomination.toLowerCase());
|
|
13
13
|
const response = await this.makePublicRequest(`/api/v1/orderbook/${encodeURIComponent(tradingPairId)}?${params.toString()}`);
|
|
14
14
|
return {
|
|
15
|
-
tradingPairId: response.
|
|
15
|
+
tradingPairId: response.symbol,
|
|
16
16
|
tradingMode: response.trading_mode,
|
|
17
17
|
bids: response.data.bids.map((level) => ({
|
|
18
18
|
price: level.price,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { perpRoutes } from "./routes";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { perpRoutes } from "./routes";
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
export declare const perpRoutes: {
|
|
2
|
+
readonly orders: {
|
|
3
|
+
readonly create: () => string;
|
|
4
|
+
readonly list: (params?: {
|
|
5
|
+
page?: number;
|
|
6
|
+
page_size?: number;
|
|
7
|
+
status?: string;
|
|
8
|
+
trading_pair?: string;
|
|
9
|
+
trading_mode?: string;
|
|
10
|
+
margin_account_id?: string;
|
|
11
|
+
}) => string;
|
|
12
|
+
readonly get: (orderId: string) => string;
|
|
13
|
+
readonly replace: (orderId: string) => string;
|
|
14
|
+
readonly cancel: () => string;
|
|
15
|
+
readonly batchCancel: () => string;
|
|
16
|
+
readonly batchCancelAll: () => string;
|
|
17
|
+
readonly batchCancelAllByPair: (tradingPairId: string) => string;
|
|
18
|
+
readonly batchCreate: () => string;
|
|
19
|
+
readonly batchReplace: () => string;
|
|
20
|
+
readonly createConditional: () => string;
|
|
21
|
+
readonly listConditional: (params?: {
|
|
22
|
+
margin_account_id?: string;
|
|
23
|
+
trading_pair_id?: string;
|
|
24
|
+
state?: string;
|
|
25
|
+
page?: number;
|
|
26
|
+
page_size?: number;
|
|
27
|
+
}) => string;
|
|
28
|
+
readonly cancelConditional: (conditionalOrderId: string) => string;
|
|
29
|
+
};
|
|
30
|
+
readonly market: {
|
|
31
|
+
readonly listTradingPairs: (params?: {
|
|
32
|
+
page?: number;
|
|
33
|
+
limit?: number;
|
|
34
|
+
market_type?: string;
|
|
35
|
+
base_token?: string;
|
|
36
|
+
quote_token?: string;
|
|
37
|
+
is_active?: boolean;
|
|
38
|
+
}) => string;
|
|
39
|
+
readonly getTradingPair: (tradingPairId: string) => string;
|
|
40
|
+
readonly getCandles: (tradingPairId: string, interval: string, params?: {
|
|
41
|
+
start_time?: number;
|
|
42
|
+
end_time?: number;
|
|
43
|
+
limit?: number;
|
|
44
|
+
}) => string;
|
|
45
|
+
readonly getMarketMetadata: (tradingPairId: string) => string;
|
|
46
|
+
readonly getPerpMarketConfig: (tradingPairId: string) => string;
|
|
47
|
+
readonly getPerpMarketSummary: (tradingPairId: string) => string;
|
|
48
|
+
readonly getMarkPrice: (tradingPairId: string) => string;
|
|
49
|
+
readonly getIndexPrice: (tradingPairId: string) => string;
|
|
50
|
+
readonly getFundingState: (tradingPairId: string) => string;
|
|
51
|
+
readonly listFundingHistory: (tradingPairId: string, params?: {
|
|
52
|
+
start_time?: string;
|
|
53
|
+
end_time?: string;
|
|
54
|
+
page?: number;
|
|
55
|
+
page_size?: number;
|
|
56
|
+
}) => string;
|
|
57
|
+
readonly getOpenInterest: (tradingPairId: string) => string;
|
|
58
|
+
};
|
|
59
|
+
readonly orderbook: {
|
|
60
|
+
readonly get: (tradingPairId: string, params?: {
|
|
61
|
+
levels?: number;
|
|
62
|
+
trading_mode?: string;
|
|
63
|
+
magnitude?: string | number;
|
|
64
|
+
denomination?: string;
|
|
65
|
+
}) => string;
|
|
66
|
+
};
|
|
67
|
+
readonly trades: {
|
|
68
|
+
readonly publicByPair: (tradingPairId: string, params?: {
|
|
69
|
+
skip?: number;
|
|
70
|
+
limit?: number;
|
|
71
|
+
}) => string;
|
|
72
|
+
readonly user: (params?: {
|
|
73
|
+
margin_account_id?: string;
|
|
74
|
+
trading_pair_id?: string;
|
|
75
|
+
page?: number;
|
|
76
|
+
page_size?: number;
|
|
77
|
+
}) => string;
|
|
78
|
+
};
|
|
79
|
+
readonly positions: {
|
|
80
|
+
readonly list: (params?: {
|
|
81
|
+
margin_account_id?: string;
|
|
82
|
+
trading_pair_id?: string;
|
|
83
|
+
status?: string;
|
|
84
|
+
page?: number;
|
|
85
|
+
page_size?: number;
|
|
86
|
+
}) => string;
|
|
87
|
+
readonly get: (positionId: string) => string;
|
|
88
|
+
readonly close: (positionId: string) => string;
|
|
89
|
+
readonly risk: (positionId: string) => string;
|
|
90
|
+
readonly addMargin: (positionId: string) => string;
|
|
91
|
+
readonly reduceMargin: (positionId: string) => string;
|
|
92
|
+
readonly attachTpSl: (positionId: string) => string;
|
|
93
|
+
readonly history: (params?: {
|
|
94
|
+
position_id?: string;
|
|
95
|
+
margin_account_id?: string;
|
|
96
|
+
trading_pair_id?: string;
|
|
97
|
+
page?: number;
|
|
98
|
+
page_size?: number;
|
|
99
|
+
}) => string;
|
|
100
|
+
};
|
|
101
|
+
readonly marginAccounts: {
|
|
102
|
+
readonly list: (params?: {
|
|
103
|
+
page?: number;
|
|
104
|
+
page_size?: number;
|
|
105
|
+
state?: string;
|
|
106
|
+
}) => string;
|
|
107
|
+
readonly create: () => string;
|
|
108
|
+
readonly summary: (marginAccountId: string) => string;
|
|
109
|
+
readonly availableCollateral: (params?: {
|
|
110
|
+
asset?: string;
|
|
111
|
+
}) => string;
|
|
112
|
+
readonly transferIn: (marginAccountId: string) => string;
|
|
113
|
+
readonly transferOut: (marginAccountId: string) => string;
|
|
114
|
+
readonly movements: (marginAccountId: string, params?: {
|
|
115
|
+
movement_type?: string;
|
|
116
|
+
page?: number;
|
|
117
|
+
page_size?: number;
|
|
118
|
+
}) => string;
|
|
119
|
+
readonly simulateOrderRisk: (marginAccountId: string) => string;
|
|
120
|
+
};
|
|
121
|
+
readonly streams: {
|
|
122
|
+
readonly orderbook: () => string;
|
|
123
|
+
readonly trades: () => string;
|
|
124
|
+
readonly perpMarketSummaries: () => string;
|
|
125
|
+
readonly markPrices: () => string;
|
|
126
|
+
readonly privateTrades: () => string;
|
|
127
|
+
readonly orders: () => string;
|
|
128
|
+
readonly positions: () => string;
|
|
129
|
+
readonly marginAccount: () => string;
|
|
130
|
+
readonly funding: () => string;
|
|
131
|
+
readonly liquidationAlerts: () => string;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const API_V1 = "/api/v1";
|
|
2
|
+
function encodeSegment(value) {
|
|
3
|
+
return encodeURIComponent(value);
|
|
4
|
+
}
|
|
5
|
+
function withQuery(path, params) {
|
|
6
|
+
if (!params)
|
|
7
|
+
return path;
|
|
8
|
+
const searchParams = new URLSearchParams();
|
|
9
|
+
for (const [key, value] of Object.entries(params)) {
|
|
10
|
+
if (value !== undefined) {
|
|
11
|
+
searchParams.set(key, String(value));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const query = searchParams.toString();
|
|
15
|
+
return query ? `${path}?${query}` : path;
|
|
16
|
+
}
|
|
17
|
+
export const perpRoutes = {
|
|
18
|
+
orders: {
|
|
19
|
+
create: () => `${API_V1}/orders`,
|
|
20
|
+
list: (params) => withQuery(`${API_V1}/orders`, params),
|
|
21
|
+
get: (orderId) => `${API_V1}/orders/${encodeSegment(orderId)}`,
|
|
22
|
+
replace: (orderId) => `${API_V1}/orders/${encodeSegment(orderId)}`,
|
|
23
|
+
cancel: () => `${API_V1}/orders/cancel`,
|
|
24
|
+
batchCancel: () => `${API_V1}/orders/batch-cancel`,
|
|
25
|
+
batchCancelAll: () => `${API_V1}/orders/batch-cancel-all`,
|
|
26
|
+
batchCancelAllByPair: (tradingPairId) => `${API_V1}/orders/batch-cancel-all/${encodeSegment(tradingPairId)}`,
|
|
27
|
+
batchCreate: () => `${API_V1}/orders/batch-create`,
|
|
28
|
+
batchReplace: () => `${API_V1}/orders/batch-replace`,
|
|
29
|
+
createConditional: () => `${API_V1}/orders/conditional`,
|
|
30
|
+
listConditional: (params) => withQuery(`${API_V1}/orders/conditional`, params),
|
|
31
|
+
cancelConditional: (conditionalOrderId) => `${API_V1}/orders/conditional/${encodeSegment(conditionalOrderId)}`,
|
|
32
|
+
},
|
|
33
|
+
market: {
|
|
34
|
+
listTradingPairs: (params) => withQuery(`${API_V1}/market/pairs`, params),
|
|
35
|
+
getTradingPair: (tradingPairId) => `${API_V1}/market/pairs/${encodeSegment(tradingPairId)}`,
|
|
36
|
+
getCandles: (tradingPairId, interval, params) => withQuery(`${API_V1}/market/pairs/charts/candlestick/${encodeSegment(tradingPairId)}/${encodeSegment(interval)}`, params),
|
|
37
|
+
getMarketMetadata: (tradingPairId) => `${API_V1}/market/pairs/${encodeSegment(tradingPairId)}/metadata`,
|
|
38
|
+
getPerpMarketConfig: (tradingPairId) => `${API_V1}/market/pairs/${encodeSegment(tradingPairId)}/perp/config`,
|
|
39
|
+
getPerpMarketSummary: (tradingPairId) => `${API_V1}/market/pairs/${encodeSegment(tradingPairId)}/perp/summary`,
|
|
40
|
+
getMarkPrice: (tradingPairId) => `${API_V1}/market/pairs/${encodeSegment(tradingPairId)}/mark-price`,
|
|
41
|
+
getIndexPrice: (tradingPairId) => `${API_V1}/market/pairs/${encodeSegment(tradingPairId)}/index-price`,
|
|
42
|
+
getFundingState: (tradingPairId) => `${API_V1}/market/pairs/${encodeSegment(tradingPairId)}/funding`,
|
|
43
|
+
listFundingHistory: (tradingPairId, params) => withQuery(`${API_V1}/market/pairs/${encodeSegment(tradingPairId)}/funding/history`, params),
|
|
44
|
+
getOpenInterest: (tradingPairId) => `${API_V1}/market/pairs/${encodeSegment(tradingPairId)}/open-interest`,
|
|
45
|
+
},
|
|
46
|
+
orderbook: {
|
|
47
|
+
get: (tradingPairId, params) => withQuery(`${API_V1}/orderbook/${encodeSegment(tradingPairId)}`, params),
|
|
48
|
+
},
|
|
49
|
+
trades: {
|
|
50
|
+
publicByPair: (tradingPairId, params) => withQuery(`${API_V1}/trades/${encodeSegment(tradingPairId)}`, params),
|
|
51
|
+
user: (params) => withQuery(`${API_V1}/accounts/trades`, params),
|
|
52
|
+
},
|
|
53
|
+
positions: {
|
|
54
|
+
list: (params) => withQuery(`${API_V1}/positions`, params),
|
|
55
|
+
get: (positionId) => `${API_V1}/positions/${encodeSegment(positionId)}`,
|
|
56
|
+
close: (positionId) => `${API_V1}/positions/${encodeSegment(positionId)}/close`,
|
|
57
|
+
risk: (positionId) => `${API_V1}/positions/${encodeSegment(positionId)}/risk`,
|
|
58
|
+
addMargin: (positionId) => `${API_V1}/positions/${encodeSegment(positionId)}/margin/add`,
|
|
59
|
+
reduceMargin: (positionId) => `${API_V1}/positions/${encodeSegment(positionId)}/margin/reduce`,
|
|
60
|
+
attachTpSl: (positionId) => `${API_V1}/positions/${encodeSegment(positionId)}/tp-sl`,
|
|
61
|
+
history: (params) => withQuery(`${API_V1}/positions/history`, params),
|
|
62
|
+
},
|
|
63
|
+
marginAccounts: {
|
|
64
|
+
list: (params) => withQuery(`${API_V1}/margin/accounts`, params),
|
|
65
|
+
create: () => `${API_V1}/margin/accounts`,
|
|
66
|
+
summary: (marginAccountId) => `${API_V1}/margin/accounts/${encodeSegment(marginAccountId)}`,
|
|
67
|
+
availableCollateral: (params) => withQuery(`${API_V1}/margin/collateral/available`, params),
|
|
68
|
+
transferIn: (marginAccountId) => `${API_V1}/margin/accounts/${encodeSegment(marginAccountId)}/collateral/transfer-in`,
|
|
69
|
+
transferOut: (marginAccountId) => `${API_V1}/margin/accounts/${encodeSegment(marginAccountId)}/collateral/transfer-out`,
|
|
70
|
+
movements: (marginAccountId, params) => withQuery(`${API_V1}/margin/accounts/${encodeSegment(marginAccountId)}/movements`, params),
|
|
71
|
+
simulateOrderRisk: (marginAccountId) => `${API_V1}/margin/accounts/${encodeSegment(marginAccountId)}/simulate-order-risk`,
|
|
72
|
+
},
|
|
73
|
+
streams: {
|
|
74
|
+
orderbook: () => `${API_V1}/streaming/orderbook`,
|
|
75
|
+
trades: () => `${API_V1}/streaming/trades`,
|
|
76
|
+
perpMarketSummaries: () => `${API_V1}/streaming/perp-market-summaries`,
|
|
77
|
+
markPrices: () => `${API_V1}/streaming/mark-prices`,
|
|
78
|
+
privateTrades: () => `${API_V1}/streaming/private-trades`,
|
|
79
|
+
orders: () => `${API_V1}/streaming/orders`,
|
|
80
|
+
positions: () => `${API_V1}/streaming/positions`,
|
|
81
|
+
marginAccount: () => `${API_V1}/streaming/margin-account`,
|
|
82
|
+
funding: () => `${API_V1}/streaming/funding`,
|
|
83
|
+
liquidationAlerts: () => `${API_V1}/streaming/liquidation-alerts`,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AddPositionMarginRequest, AttachPositionTpSlRequest, AttachPositionTpSlResponse, ClosePositionRequest, ClosePositionResponse, GetPositionResponse, ListPositionHistoryParams, ListPositionHistoryResponse, ListPositionsParams, ListPositionsResponse, PositionMarginResponse, PositionRisk, PositionsAPI, ReducePositionMarginRequest } from "@0xmonaco/types";
|
|
2
|
+
import { BaseAPI } from "../base";
|
|
3
|
+
export declare class PositionsAPIImpl extends BaseAPI implements PositionsAPI {
|
|
4
|
+
listPositions(params?: ListPositionsParams): Promise<ListPositionsResponse>;
|
|
5
|
+
getPosition(positionId: string): Promise<GetPositionResponse>;
|
|
6
|
+
closePosition(positionId: string, request: ClosePositionRequest): Promise<ClosePositionResponse>;
|
|
7
|
+
getPositionRisk(positionId: string): Promise<PositionRisk>;
|
|
8
|
+
addPositionMargin(positionId: string, request: AddPositionMarginRequest): Promise<PositionMarginResponse>;
|
|
9
|
+
reducePositionMargin(positionId: string, request: ReducePositionMarginRequest): Promise<PositionMarginResponse>;
|
|
10
|
+
attachPositionTpSl(positionId: string, request: AttachPositionTpSlRequest): Promise<AttachPositionTpSlResponse>;
|
|
11
|
+
listPositionHistory(params?: ListPositionHistoryParams): Promise<ListPositionHistoryResponse>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { AddPositionMarginSchema, AttachPositionTpSlSchema, ClosePositionSchema, GetPositionRiskSchema, GetPositionSchema, ListPositionHistorySchema, ListPositionsSchema, ReducePositionMarginSchema, validate, } from "@0xmonaco/types";
|
|
2
|
+
import { BaseAPI } from "../base";
|
|
3
|
+
import { perpRoutes } from "../perp";
|
|
4
|
+
export class PositionsAPIImpl extends BaseAPI {
|
|
5
|
+
async listPositions(params) {
|
|
6
|
+
if (params) {
|
|
7
|
+
validate(ListPositionsSchema, params);
|
|
8
|
+
}
|
|
9
|
+
return await this.makeAuthenticatedRequest(perpRoutes.positions.list(params));
|
|
10
|
+
}
|
|
11
|
+
async getPosition(positionId) {
|
|
12
|
+
validate(GetPositionSchema, { positionId });
|
|
13
|
+
return await this.makeAuthenticatedRequest(perpRoutes.positions.get(positionId));
|
|
14
|
+
}
|
|
15
|
+
async closePosition(positionId, request) {
|
|
16
|
+
validate(ClosePositionSchema, { positionId, request });
|
|
17
|
+
return await this.makeAuthenticatedRequest(perpRoutes.positions.close(positionId), {
|
|
18
|
+
method: "POST",
|
|
19
|
+
body: JSON.stringify({
|
|
20
|
+
close_type: request.closeType,
|
|
21
|
+
limit_price: request.limitPrice,
|
|
22
|
+
slippage_tolerance_bps: request.slippageToleranceBps,
|
|
23
|
+
quantity: request.quantity,
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async getPositionRisk(positionId) {
|
|
28
|
+
validate(GetPositionRiskSchema, { positionId });
|
|
29
|
+
return await this.makeAuthenticatedRequest(perpRoutes.positions.risk(positionId));
|
|
30
|
+
}
|
|
31
|
+
async addPositionMargin(positionId, request) {
|
|
32
|
+
validate(AddPositionMarginSchema, { positionId, request });
|
|
33
|
+
return await this.makeAuthenticatedRequest(perpRoutes.positions.addMargin(positionId), {
|
|
34
|
+
method: "POST",
|
|
35
|
+
body: JSON.stringify({
|
|
36
|
+
position_id: positionId,
|
|
37
|
+
amount: request.amount,
|
|
38
|
+
asset: request.asset,
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async reducePositionMargin(positionId, request) {
|
|
43
|
+
validate(ReducePositionMarginSchema, { positionId, request });
|
|
44
|
+
return await this.makeAuthenticatedRequest(perpRoutes.positions.reduceMargin(positionId), {
|
|
45
|
+
method: "POST",
|
|
46
|
+
body: JSON.stringify({
|
|
47
|
+
position_id: positionId,
|
|
48
|
+
amount: request.amount,
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async attachPositionTpSl(positionId, request) {
|
|
53
|
+
validate(AttachPositionTpSlSchema, { positionId, request });
|
|
54
|
+
return await this.makeAuthenticatedRequest(perpRoutes.positions.attachTpSl(positionId), {
|
|
55
|
+
method: "POST",
|
|
56
|
+
body: JSON.stringify({
|
|
57
|
+
take_profit: request.takeProfit
|
|
58
|
+
? {
|
|
59
|
+
trigger_price: request.takeProfit.triggerPrice,
|
|
60
|
+
order_type: request.takeProfit.orderType,
|
|
61
|
+
limit_price: request.takeProfit.limitPrice,
|
|
62
|
+
quantity: request.takeProfit.quantity,
|
|
63
|
+
time_in_force: request.takeProfit.timeInForce,
|
|
64
|
+
slippage_tolerance_bps: request.takeProfit.slippageToleranceBps,
|
|
65
|
+
expires_at: request.takeProfit.expiresAt,
|
|
66
|
+
}
|
|
67
|
+
: undefined,
|
|
68
|
+
stop_loss: request.stopLoss
|
|
69
|
+
? {
|
|
70
|
+
trigger_price: request.stopLoss.triggerPrice,
|
|
71
|
+
order_type: request.stopLoss.orderType,
|
|
72
|
+
limit_price: request.stopLoss.limitPrice,
|
|
73
|
+
quantity: request.stopLoss.quantity,
|
|
74
|
+
time_in_force: request.stopLoss.timeInForce,
|
|
75
|
+
slippage_tolerance_bps: request.stopLoss.slippageToleranceBps,
|
|
76
|
+
expires_at: request.stopLoss.expiresAt,
|
|
77
|
+
}
|
|
78
|
+
: undefined,
|
|
79
|
+
}),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async listPositionHistory(params) {
|
|
83
|
+
if (params) {
|
|
84
|
+
validate(ListPositionHistorySchema, params);
|
|
85
|
+
}
|
|
86
|
+
return await this.makeAuthenticatedRequest(perpRoutes.positions.history(params));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PositionsAPIImpl } from "./api";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PositionsAPIImpl } from "./api";
|
package/dist/api/trades/api.d.ts
CHANGED
package/dist/api/trades/api.js
CHANGED
|
@@ -5,7 +5,7 @@ import { BaseAPI } from "../base";
|
|
|
5
5
|
export function parseRawTradeEvent(raw) {
|
|
6
6
|
return {
|
|
7
7
|
eventType: "trade",
|
|
8
|
-
tradingPairId: raw.
|
|
8
|
+
tradingPairId: raw.trading_pair_id,
|
|
9
9
|
tradingMode: raw.trading_mode.toUpperCase(),
|
|
10
10
|
data: {
|
|
11
11
|
tradeId: raw.data.trade_id,
|
|
@@ -37,6 +37,6 @@ export class TradesAPIImpl extends BaseAPI {
|
|
|
37
37
|
}
|
|
38
38
|
params.set("page_size", String(page_size));
|
|
39
39
|
const response = await this.makePublicRequest(`/api/v1/trades/${encodeURIComponent(tradingPairId)}?${params.toString()}`);
|
|
40
|
-
return response.
|
|
40
|
+
return response.trades.map(parseRawTradeEvent);
|
|
41
41
|
}
|
|
42
42
|
}
|