@0xmonaco/core 0.8.5 → 0.8.7-develop.0f12336
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -12
- package/dist/api/applications/api.d.ts +61 -8
- package/dist/api/applications/api.js +75 -11
- package/dist/api/auth/api.d.ts +44 -76
- package/dist/api/auth/api.js +68 -111
- package/dist/api/base.d.ts +50 -9
- package/dist/api/base.js +97 -14
- package/dist/api/delegated-agents/api.d.ts +2 -1
- package/dist/api/delegated-agents/api.js +15 -11
- package/dist/api/faucet/api.d.ts +25 -0
- package/dist/api/faucet/api.js +29 -0
- package/dist/api/faucet/index.d.ts +1 -0
- package/dist/api/faucet/index.js +1 -0
- package/dist/api/fees/api.d.ts +13 -13
- package/dist/api/fees/api.js +18 -18
- package/dist/api/index.d.ts +4 -0
- package/dist/api/index.js +4 -0
- package/dist/api/margin-accounts/api.d.ts +9 -5
- package/dist/api/margin-accounts/api.js +70 -33
- package/dist/api/market/api.d.ts +5 -2
- package/dist/api/market/api.js +32 -16
- package/dist/api/orderbook/api.js +13 -12
- package/dist/api/perp/routes.d.ts +113 -37
- package/dist/api/perp/routes.js +37 -6
- package/dist/api/positions/api.d.ts +2 -1
- package/dist/api/positions/api.js +30 -18
- package/dist/api/profile/api.d.ts +40 -23
- package/dist/api/profile/api.js +78 -38
- package/dist/api/sub-accounts/api.d.ts +62 -0
- package/dist/api/sub-accounts/api.js +80 -0
- package/dist/api/sub-accounts/index.d.ts +1 -0
- package/dist/api/sub-accounts/index.js +1 -0
- package/dist/api/trades/api.d.ts +21 -10
- package/dist/api/trades/api.js +22 -10
- package/dist/api/trading/api.d.ts +11 -8
- package/dist/api/trading/api.js +76 -90
- package/dist/api/vault/api.d.ts +96 -29
- package/dist/api/vault/api.js +172 -43
- package/dist/api/vault/index.d.ts +1 -1
- package/dist/api/vault/index.js +1 -1
- package/dist/api/websocket/types.d.ts +5 -5
- package/dist/api/websocket/websocket.js +43 -22
- package/dist/api/whitelist/api.d.ts +27 -0
- package/dist/api/whitelist/api.js +32 -0
- package/dist/api/whitelist/index.d.ts +1 -0
- package/dist/api/whitelist/index.js +1 -0
- package/dist/api/withdrawals/api.d.ts +18 -0
- package/dist/api/withdrawals/api.js +35 -0
- package/dist/api/withdrawals/index.d.ts +1 -0
- package/dist/api/withdrawals/index.js +1 -0
- package/dist/coverage.d.ts +93 -0
- package/dist/coverage.js +93 -0
- package/dist/crypto/session.d.ts +40 -0
- package/dist/crypto/session.js +60 -0
- package/dist/sdk.d.ts +58 -20
- package/dist/sdk.js +156 -53
- package/package.json +5 -3
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Faucet API Implementation
|
|
3
|
+
*
|
|
4
|
+
* Testnet token faucet. Session-authenticated. Performs real on-chain mints
|
|
5
|
+
* from a backend-operator-funded signer and is rate-limited per user
|
|
6
|
+
* (default 1 request / 24h). It is unavailable if the gateway operator has not
|
|
7
|
+
* configured a signer — the SDK caller has no control over that.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const { minted, failed, remainingRequests24h } = await sdk.faucet.mint();
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
import { BaseAPI } from "../base";
|
|
15
|
+
import { perpRoutes } from "../perp/routes";
|
|
16
|
+
export class FaucetAPIImpl extends BaseAPI {
|
|
17
|
+
/**
|
|
18
|
+
* Mints the full set of testnet tokens to the authenticated user.
|
|
19
|
+
*
|
|
20
|
+
* Partial success is possible — inspect `minted` and `failed` in the response.
|
|
21
|
+
*
|
|
22
|
+
* @returns Promise resolving to the minted/failed tokens and remaining quota
|
|
23
|
+
*/
|
|
24
|
+
async mint() {
|
|
25
|
+
return await this.makeAuthenticatedRequest(perpRoutes.faucet.mint(), {
|
|
26
|
+
method: "POST",
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FaucetAPIImpl } from "./api";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FaucetAPIImpl } from "./api";
|
package/dist/api/fees/api.d.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* // Simulate fees for an order
|
|
16
16
|
* const feeDetails = await feesAPI.simulateFees({
|
|
17
|
-
*
|
|
17
|
+
* tradingPairId: "123e4567-e89b-12d3-a456-426614174000",
|
|
18
18
|
* side: "BUY",
|
|
19
19
|
* price: "40000.00",
|
|
20
20
|
* quantity: "0.5"
|
|
@@ -31,41 +31,41 @@ export declare class FeesAPIImpl extends BaseAPI implements FeesAPI {
|
|
|
31
31
|
* application fees, and total amounts the taker must pay or maker will receive.
|
|
32
32
|
*
|
|
33
33
|
* @param params - Parameters for fee simulation
|
|
34
|
-
* @param params.
|
|
34
|
+
* @param params.tradingPairId - The trading pair UUID
|
|
35
35
|
* @param params.side - The order side ("BUY" or "SELL")
|
|
36
36
|
* @param params.price - The price per unit as string
|
|
37
37
|
* @param params.quantity - The quantity to trade as string
|
|
38
|
-
* @param params.
|
|
39
|
-
* @param params.
|
|
38
|
+
* @param params.orderType - Order type: "LIMIT" (default) or "MARKET"
|
|
39
|
+
* @param params.slippageToleranceBps - Slippage tolerance in bps (0–1000, MARKET only, default 500)
|
|
40
40
|
* @returns Promise resolving to SimulateFeeResponse with fee breakdown
|
|
41
41
|
*
|
|
42
42
|
* @example
|
|
43
43
|
* ```typescript
|
|
44
44
|
* // Simulate fees for a buy order
|
|
45
45
|
* const buyFees = await feesAPI.simulateFees({
|
|
46
|
-
*
|
|
46
|
+
* tradingPairId: "123e4567-e89b-12d3-a456-426614174000",
|
|
47
47
|
* side: "BUY",
|
|
48
48
|
* price: "40000.00",
|
|
49
49
|
* quantity: "0.5"
|
|
50
50
|
* });
|
|
51
51
|
*
|
|
52
52
|
* console.log(`Notional value: ${buyFees.notional}`);
|
|
53
|
-
* console.log(`Monaco taker fee: ${buyFees.
|
|
54
|
-
* console.log(`Application taker fee: ${buyFees.
|
|
55
|
-
* console.log(`Total taker fees: ${buyFees.
|
|
56
|
-
* console.log(`Total payment required: ${buyFees.
|
|
57
|
-
* console.log(`Lock amount for BUY: ${buyFees.
|
|
53
|
+
* console.log(`Monaco taker fee: ${buyFees.monacoTakerFee}`);
|
|
54
|
+
* console.log(`Application taker fee: ${buyFees.applicationTakerFee}`);
|
|
55
|
+
* console.log(`Total taker fees: ${buyFees.totalTakerFees}`);
|
|
56
|
+
* console.log(`Total payment required: ${buyFees.takerTotalPayment}`);
|
|
57
|
+
* console.log(`Lock amount for BUY: ${buyFees.buyOrderLockAmount}`);
|
|
58
58
|
*
|
|
59
59
|
* // Simulate fees for a sell order
|
|
60
60
|
* const sellFees = await feesAPI.simulateFees({
|
|
61
|
-
*
|
|
61
|
+
* tradingPairId: "123e4567-e89b-12d3-a456-426614174000",
|
|
62
62
|
* side: "SELL",
|
|
63
63
|
* price: "40000.00",
|
|
64
64
|
* quantity: "0.5"
|
|
65
65
|
* });
|
|
66
66
|
*
|
|
67
|
-
* console.log(`Maker rebate: ${sellFees.
|
|
68
|
-
* console.log(`Maker total receipt: ${sellFees.
|
|
67
|
+
* console.log(`Maker rebate: ${sellFees.monacoMakerRebate}`);
|
|
68
|
+
* console.log(`Maker total receipt: ${sellFees.makerTotalReceipt}`);
|
|
69
69
|
* ```
|
|
70
70
|
*/
|
|
71
71
|
simulateFees(params: SimulateFeeParams): Promise<SimulateFeeResponse>;
|
package/dist/api/fees/api.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* // Simulate fees for an order
|
|
16
16
|
* const feeDetails = await feesAPI.simulateFees({
|
|
17
|
-
*
|
|
17
|
+
* tradingPairId: "123e4567-e89b-12d3-a456-426614174000",
|
|
18
18
|
* side: "BUY",
|
|
19
19
|
* price: "40000.00",
|
|
20
20
|
* quantity: "0.5"
|
|
@@ -31,56 +31,56 @@ export class FeesAPIImpl extends BaseAPI {
|
|
|
31
31
|
* application fees, and total amounts the taker must pay or maker will receive.
|
|
32
32
|
*
|
|
33
33
|
* @param params - Parameters for fee simulation
|
|
34
|
-
* @param params.
|
|
34
|
+
* @param params.tradingPairId - The trading pair UUID
|
|
35
35
|
* @param params.side - The order side ("BUY" or "SELL")
|
|
36
36
|
* @param params.price - The price per unit as string
|
|
37
37
|
* @param params.quantity - The quantity to trade as string
|
|
38
|
-
* @param params.
|
|
39
|
-
* @param params.
|
|
38
|
+
* @param params.orderType - Order type: "LIMIT" (default) or "MARKET"
|
|
39
|
+
* @param params.slippageToleranceBps - Slippage tolerance in bps (0–1000, MARKET only, default 500)
|
|
40
40
|
* @returns Promise resolving to SimulateFeeResponse with fee breakdown
|
|
41
41
|
*
|
|
42
42
|
* @example
|
|
43
43
|
* ```typescript
|
|
44
44
|
* // Simulate fees for a buy order
|
|
45
45
|
* const buyFees = await feesAPI.simulateFees({
|
|
46
|
-
*
|
|
46
|
+
* tradingPairId: "123e4567-e89b-12d3-a456-426614174000",
|
|
47
47
|
* side: "BUY",
|
|
48
48
|
* price: "40000.00",
|
|
49
49
|
* quantity: "0.5"
|
|
50
50
|
* });
|
|
51
51
|
*
|
|
52
52
|
* console.log(`Notional value: ${buyFees.notional}`);
|
|
53
|
-
* console.log(`Monaco taker fee: ${buyFees.
|
|
54
|
-
* console.log(`Application taker fee: ${buyFees.
|
|
55
|
-
* console.log(`Total taker fees: ${buyFees.
|
|
56
|
-
* console.log(`Total payment required: ${buyFees.
|
|
57
|
-
* console.log(`Lock amount for BUY: ${buyFees.
|
|
53
|
+
* console.log(`Monaco taker fee: ${buyFees.monacoTakerFee}`);
|
|
54
|
+
* console.log(`Application taker fee: ${buyFees.applicationTakerFee}`);
|
|
55
|
+
* console.log(`Total taker fees: ${buyFees.totalTakerFees}`);
|
|
56
|
+
* console.log(`Total payment required: ${buyFees.takerTotalPayment}`);
|
|
57
|
+
* console.log(`Lock amount for BUY: ${buyFees.buyOrderLockAmount}`);
|
|
58
58
|
*
|
|
59
59
|
* // Simulate fees for a sell order
|
|
60
60
|
* const sellFees = await feesAPI.simulateFees({
|
|
61
|
-
*
|
|
61
|
+
* tradingPairId: "123e4567-e89b-12d3-a456-426614174000",
|
|
62
62
|
* side: "SELL",
|
|
63
63
|
* price: "40000.00",
|
|
64
64
|
* quantity: "0.5"
|
|
65
65
|
* });
|
|
66
66
|
*
|
|
67
|
-
* console.log(`Maker rebate: ${sellFees.
|
|
68
|
-
* console.log(`Maker total receipt: ${sellFees.
|
|
67
|
+
* console.log(`Maker rebate: ${sellFees.monacoMakerRebate}`);
|
|
68
|
+
* console.log(`Maker total receipt: ${sellFees.makerTotalReceipt}`);
|
|
69
69
|
* ```
|
|
70
70
|
*/
|
|
71
71
|
async simulateFees(params) {
|
|
72
72
|
// Validate parameters using the validate helper
|
|
73
73
|
const validatedParams = validate(SimulateFeeParamsSchema, params);
|
|
74
74
|
const searchParams = new URLSearchParams();
|
|
75
|
-
searchParams.append("
|
|
75
|
+
searchParams.append("tradingPairId", validatedParams.tradingPairId);
|
|
76
76
|
searchParams.append("side", validatedParams.side);
|
|
77
77
|
searchParams.append("price", validatedParams.price);
|
|
78
78
|
searchParams.append("quantity", validatedParams.quantity);
|
|
79
|
-
if (validatedParams.
|
|
80
|
-
searchParams.append("
|
|
79
|
+
if (validatedParams.orderType !== undefined) {
|
|
80
|
+
searchParams.append("orderType", validatedParams.orderType);
|
|
81
81
|
}
|
|
82
|
-
if (validatedParams.
|
|
83
|
-
searchParams.append("
|
|
82
|
+
if (validatedParams.slippageToleranceBps !== undefined) {
|
|
83
|
+
searchParams.append("slippageToleranceBps", String(validatedParams.slippageToleranceBps));
|
|
84
84
|
}
|
|
85
85
|
const endpoint = `/api/v1/fees/simulate?${searchParams.toString()}`;
|
|
86
86
|
return await this.makeAuthenticatedRequest(endpoint, {
|
package/dist/api/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
export * from "./applications/index";
|
|
7
7
|
export * from "./base";
|
|
8
8
|
export * from "./delegated-agents";
|
|
9
|
+
export * from "./faucet";
|
|
9
10
|
export * from "./fees";
|
|
10
11
|
export * from "./margin-accounts";
|
|
11
12
|
export * from "./market";
|
|
@@ -13,7 +14,10 @@ export * from "./orderbook";
|
|
|
13
14
|
export * from "./perp";
|
|
14
15
|
export * from "./positions";
|
|
15
16
|
export * from "./profile";
|
|
17
|
+
export * from "./sub-accounts";
|
|
16
18
|
export * from "./trades";
|
|
17
19
|
export * from "./trading";
|
|
18
20
|
export * from "./vault";
|
|
19
21
|
export * from "./websocket";
|
|
22
|
+
export * from "./whitelist";
|
|
23
|
+
export * from "./withdrawals";
|
package/dist/api/index.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
export * from "./applications/index";
|
|
7
7
|
export * from "./base";
|
|
8
8
|
export * from "./delegated-agents";
|
|
9
|
+
export * from "./faucet";
|
|
9
10
|
export * from "./fees";
|
|
10
11
|
export * from "./margin-accounts";
|
|
11
12
|
export * from "./market";
|
|
@@ -13,7 +14,10 @@ export * from "./orderbook";
|
|
|
13
14
|
export * from "./perp";
|
|
14
15
|
export * from "./positions";
|
|
15
16
|
export * from "./profile";
|
|
17
|
+
export * from "./sub-accounts";
|
|
16
18
|
export * from "./trades";
|
|
17
19
|
export * from "./trading";
|
|
18
20
|
export * from "./vault";
|
|
19
21
|
export * from "./websocket";
|
|
22
|
+
export * from "./whitelist";
|
|
23
|
+
export * from "./withdrawals";
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GetAvailableCollateralParams, GetAvailableCollateralResponse, GetMarginAccountMovementsParams, GetMarginAccountMovementsResponse, GetMarginAccountSummaryParams, ListMarginAccountsParams, ListMarginAccountsResponse, MarginAccountSummary, MarginAccountsAPI, SimulateOrderRiskRequest, SimulateOrderRiskResponse, SimulateRiskBucketOrderRiskRequest, TransferCollateralFromParentMarginAccountRequest, TransferCollateralRequest, TransferCollateralResponse, TransferCollateralToParentMarginAccountRequest, TransferCollateralToRiskBucketRequest } from "@0xmonaco/types";
|
|
2
2
|
import { BaseAPI } from "../base";
|
|
3
3
|
export declare class MarginAccountsAPIImpl extends BaseAPI implements MarginAccountsAPI {
|
|
4
4
|
listMarginAccounts(params?: ListMarginAccountsParams): Promise<ListMarginAccountsResponse>;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
getMarginAccountSummary(marginAccountId: string, params?: GetMarginAccountSummaryParams): Promise<MarginAccountSummary>;
|
|
6
|
+
getParentMarginAccountSummary(params?: GetMarginAccountSummaryParams): Promise<MarginAccountSummary>;
|
|
7
7
|
getAvailableCollateral(params?: GetAvailableCollateralParams): Promise<GetAvailableCollateralResponse>;
|
|
8
8
|
transferCollateralToMarginAccount(marginAccountId: string, request: TransferCollateralRequest): Promise<TransferCollateralResponse>;
|
|
9
|
-
|
|
9
|
+
transferCollateralToParentMarginAccount(request: TransferCollateralToParentMarginAccountRequest): Promise<TransferCollateralResponse>;
|
|
10
|
+
transferCollateralToRiskBucket(request: TransferCollateralToRiskBucketRequest): Promise<TransferCollateralResponse>;
|
|
10
11
|
transferCollateralFromMarginAccount(marginAccountId: string, request: TransferCollateralRequest): Promise<TransferCollateralResponse>;
|
|
12
|
+
transferCollateralFromParentMarginAccount(request: TransferCollateralFromParentMarginAccountRequest): Promise<TransferCollateralResponse>;
|
|
11
13
|
getMarginAccountMovements(marginAccountId: string, params?: GetMarginAccountMovementsParams): Promise<GetMarginAccountMovementsResponse>;
|
|
14
|
+
getParentMarginAccountMovements(params?: GetMarginAccountMovementsParams): Promise<GetMarginAccountMovementsResponse>;
|
|
12
15
|
simulateOrderRisk(marginAccountId: string, request: SimulateOrderRiskRequest): Promise<SimulateOrderRiskResponse>;
|
|
13
|
-
|
|
16
|
+
simulateParentMarginOrderRisk(request: SimulateOrderRiskRequest): Promise<SimulateOrderRiskResponse>;
|
|
17
|
+
simulateRiskBucketOrderRisk(request: SimulateRiskBucketOrderRiskRequest): Promise<SimulateOrderRiskResponse>;
|
|
14
18
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GetAvailableCollateralSchema, GetMarginAccountMovementsSchema, GetMarginAccountSummarySchema, GetParentMarginAccountMovementsSchema, GetParentMarginAccountSummarySchema, ListMarginAccountsSchema, SimulateOrderRiskSchema, SimulateParentMarginOrderRiskSchema, SimulateRiskBucketOrderRiskSchema, TransferCollateralFromParentMarginAccountSchema, TransferCollateralSchema, TransferCollateralToParentMarginAccountSchema, TransferCollateralToRiskBucketSchema, validate, } from "@0xmonaco/types";
|
|
2
2
|
import { BaseAPI } from "../base";
|
|
3
3
|
import { perpRoutes } from "../perp";
|
|
4
4
|
export class MarginAccountsAPIImpl extends BaseAPI {
|
|
@@ -9,25 +9,19 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
9
9
|
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.list(params
|
|
10
10
|
? {
|
|
11
11
|
page: params.page,
|
|
12
|
-
|
|
12
|
+
pageSize: params.pageSize,
|
|
13
13
|
state: params.state,
|
|
14
|
-
|
|
14
|
+
tradingPairId: params.tradingPairId,
|
|
15
15
|
}
|
|
16
16
|
: undefined));
|
|
17
17
|
}
|
|
18
|
-
async
|
|
19
|
-
validate(
|
|
20
|
-
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.
|
|
21
|
-
method: "POST",
|
|
22
|
-
body: JSON.stringify({
|
|
23
|
-
label: request?.label,
|
|
24
|
-
collateral_asset: request?.collateralAsset,
|
|
25
|
-
}),
|
|
26
|
-
});
|
|
18
|
+
async getMarginAccountSummary(marginAccountId, params) {
|
|
19
|
+
validate(GetMarginAccountSummarySchema, { marginAccountId, ...params });
|
|
20
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.summary(marginAccountId, { tradingPairId: params?.tradingPairId }));
|
|
27
21
|
}
|
|
28
|
-
async
|
|
29
|
-
validate(
|
|
30
|
-
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.
|
|
22
|
+
async getParentMarginAccountSummary(params) {
|
|
23
|
+
validate(GetParentMarginAccountSummarySchema, params);
|
|
24
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.parentSummary({ tradingPairId: params?.tradingPairId }));
|
|
31
25
|
}
|
|
32
26
|
async getAvailableCollateral(params) {
|
|
33
27
|
validate(GetAvailableCollateralSchema, params);
|
|
@@ -36,6 +30,18 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
36
30
|
async transferCollateralToMarginAccount(marginAccountId, request) {
|
|
37
31
|
validate(TransferCollateralSchema, { marginAccountId, request });
|
|
38
32
|
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.transferIn(marginAccountId), {
|
|
33
|
+
method: "POST",
|
|
34
|
+
body: JSON.stringify({
|
|
35
|
+
asset: request.asset,
|
|
36
|
+
amount: request.amount,
|
|
37
|
+
tradingPairId: request.tradingPairId,
|
|
38
|
+
strategyKey: request.strategyKey,
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async transferCollateralToParentMarginAccount(request) {
|
|
43
|
+
validate(TransferCollateralToParentMarginAccountSchema, { request });
|
|
44
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.transferInParent(), {
|
|
39
45
|
method: "POST",
|
|
40
46
|
body: JSON.stringify({
|
|
41
47
|
asset: request.asset,
|
|
@@ -43,21 +49,33 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
43
49
|
}),
|
|
44
50
|
});
|
|
45
51
|
}
|
|
46
|
-
async
|
|
47
|
-
validate(
|
|
48
|
-
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.
|
|
52
|
+
async transferCollateralToRiskBucket(request) {
|
|
53
|
+
validate(TransferCollateralToRiskBucketSchema, { request });
|
|
54
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.transferInRiskBucket(), {
|
|
49
55
|
method: "POST",
|
|
50
56
|
body: JSON.stringify({
|
|
51
57
|
asset: request.asset,
|
|
52
58
|
amount: request.amount,
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
tradingPairId: request.tradingPairId,
|
|
60
|
+
strategyKey: request.strategyKey,
|
|
55
61
|
}),
|
|
56
62
|
});
|
|
57
63
|
}
|
|
58
64
|
async transferCollateralFromMarginAccount(marginAccountId, request) {
|
|
59
65
|
validate(TransferCollateralSchema, { marginAccountId, request });
|
|
60
66
|
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.transferOut(marginAccountId), {
|
|
67
|
+
method: "POST",
|
|
68
|
+
body: JSON.stringify({
|
|
69
|
+
asset: request.asset,
|
|
70
|
+
amount: request.amount,
|
|
71
|
+
tradingPairId: request.tradingPairId,
|
|
72
|
+
strategyKey: request.strategyKey,
|
|
73
|
+
}),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async transferCollateralFromParentMarginAccount(request) {
|
|
77
|
+
validate(TransferCollateralFromParentMarginAccountSchema, { request });
|
|
78
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.transferOutParent(), {
|
|
61
79
|
method: "POST",
|
|
62
80
|
body: JSON.stringify({
|
|
63
81
|
asset: request.asset,
|
|
@@ -69,37 +87,56 @@ export class MarginAccountsAPIImpl extends BaseAPI {
|
|
|
69
87
|
validate(GetMarginAccountMovementsSchema, { marginAccountId, ...params });
|
|
70
88
|
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.movements(marginAccountId, params));
|
|
71
89
|
}
|
|
90
|
+
async getParentMarginAccountMovements(params) {
|
|
91
|
+
validate(GetParentMarginAccountMovementsSchema, params);
|
|
92
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.parentMovements(params));
|
|
93
|
+
}
|
|
72
94
|
async simulateOrderRisk(marginAccountId, request) {
|
|
73
95
|
validate(SimulateOrderRiskSchema, { marginAccountId, request });
|
|
74
96
|
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.simulateOrderRisk(marginAccountId), {
|
|
75
97
|
method: "POST",
|
|
76
98
|
body: JSON.stringify({
|
|
77
|
-
|
|
78
|
-
|
|
99
|
+
tradingPairId: request.tradingPairId,
|
|
100
|
+
side: request.side,
|
|
101
|
+
positionSide: request.positionSide,
|
|
102
|
+
orderType: request.orderType,
|
|
103
|
+
price: request.price,
|
|
104
|
+
quantity: request.quantity,
|
|
105
|
+
leverage: request.leverage,
|
|
106
|
+
reduceOnly: request.reduceOnly,
|
|
107
|
+
}),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
async simulateParentMarginOrderRisk(request) {
|
|
111
|
+
validate(SimulateParentMarginOrderRiskSchema, { request });
|
|
112
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.simulateParentMarginOrderRisk(), {
|
|
113
|
+
method: "POST",
|
|
114
|
+
body: JSON.stringify({
|
|
115
|
+
tradingPairId: request.tradingPairId,
|
|
79
116
|
side: request.side,
|
|
80
|
-
|
|
81
|
-
|
|
117
|
+
positionSide: request.positionSide,
|
|
118
|
+
orderType: request.orderType,
|
|
82
119
|
price: request.price,
|
|
83
120
|
quantity: request.quantity,
|
|
84
121
|
leverage: request.leverage,
|
|
85
|
-
|
|
122
|
+
reduceOnly: request.reduceOnly,
|
|
86
123
|
}),
|
|
87
124
|
});
|
|
88
125
|
}
|
|
89
|
-
async
|
|
90
|
-
validate(
|
|
91
|
-
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.
|
|
126
|
+
async simulateRiskBucketOrderRisk(request) {
|
|
127
|
+
validate(SimulateRiskBucketOrderRiskSchema, { request });
|
|
128
|
+
return await this.makeAuthenticatedRequest(perpRoutes.marginAccounts.simulateRiskBucketOrderRisk(), {
|
|
92
129
|
method: "POST",
|
|
93
130
|
body: JSON.stringify({
|
|
94
|
-
|
|
95
|
-
|
|
131
|
+
tradingPairId: request.tradingPairId,
|
|
132
|
+
strategyKey: request.strategyKey,
|
|
96
133
|
side: request.side,
|
|
97
|
-
|
|
98
|
-
|
|
134
|
+
positionSide: request.positionSide,
|
|
135
|
+
orderType: request.orderType,
|
|
99
136
|
price: request.price,
|
|
100
137
|
quantity: request.quantity,
|
|
101
138
|
leverage: request.leverage,
|
|
102
|
-
|
|
139
|
+
reduceOnly: request.reduceOnly,
|
|
103
140
|
}),
|
|
104
141
|
});
|
|
105
142
|
}
|
package/dist/api/market/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Candlestick, FundingState, GetCandlesticksParams, GetTradingPairsParams, GetTradingPairsResponse, IndexPrice, Interval, ListFundingHistoryParams, ListFundingHistoryResponse, MarketAPI, MarketMetadata, MarkPrice, OpenInterest, PerpMarketConfig, PerpMarketSummary, TradingPair } from "@0xmonaco/types";
|
|
1
|
+
import type { Candlestick, FundingState, GetCandlesticksParams, GetScreenerParams, GetScreenerResponse, GetTradingPairsParams, GetTradingPairsResponse, IndexPrice, Interval, ListFundingHistoryParams, ListFundingHistoryResponse, MarketAPI, MarketMetadata, MarketStats, MarkPrice, OpenInterest, PerpMarketConfig, PerpMarketSummary, TradingMode, TradingPair } from "@0xmonaco/types";
|
|
2
2
|
import { BaseAPI } from "../base";
|
|
3
3
|
/**
|
|
4
4
|
* Market API Implementation
|
|
@@ -7,7 +7,8 @@ import { BaseAPI } from "../base";
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class MarketAPIImpl extends BaseAPI implements MarketAPI {
|
|
9
9
|
getPaginatedTradingPairs(params?: GetTradingPairsParams): Promise<GetTradingPairsResponse>;
|
|
10
|
-
|
|
10
|
+
getTradingPair(tradingPairId: string): Promise<TradingPair>;
|
|
11
|
+
getTradingPairBySymbol(symbol: string, marketType?: TradingMode): Promise<TradingPair | undefined>;
|
|
11
12
|
getCandlesticks(tradingPairId: string, interval: Interval, params?: GetCandlesticksParams): Promise<Candlestick[]>;
|
|
12
13
|
getMarketMetadata(tradingPairId: string): Promise<MarketMetadata>;
|
|
13
14
|
getPerpMarketConfig(tradingPairId: string): Promise<PerpMarketConfig>;
|
|
@@ -17,4 +18,6 @@ export declare class MarketAPIImpl extends BaseAPI implements MarketAPI {
|
|
|
17
18
|
getFundingState(tradingPairId: string): Promise<FundingState>;
|
|
18
19
|
listFundingHistory(tradingPairId: string, params?: ListFundingHistoryParams): Promise<ListFundingHistoryResponse>;
|
|
19
20
|
getOpenInterest(tradingPairId: string): Promise<OpenInterest>;
|
|
21
|
+
getScreener(params?: GetScreenerParams): Promise<GetScreenerResponse>;
|
|
22
|
+
getMarketStats(): Promise<MarketStats>;
|
|
20
23
|
}
|
package/dist/api/market/api.js
CHANGED
|
@@ -12,29 +12,39 @@ export class MarketAPIImpl extends BaseAPI {
|
|
|
12
12
|
if (params?.page !== undefined) {
|
|
13
13
|
searchParams.append("page", params.page.toString());
|
|
14
14
|
}
|
|
15
|
-
if (params?.
|
|
16
|
-
searchParams.append("
|
|
15
|
+
if (params?.pageSize !== undefined) {
|
|
16
|
+
searchParams.append("pageSize", params.pageSize.toString());
|
|
17
17
|
}
|
|
18
|
-
if (params?.
|
|
19
|
-
searchParams.append("
|
|
18
|
+
if (params?.marketType) {
|
|
19
|
+
searchParams.append("marketType", params.marketType);
|
|
20
20
|
}
|
|
21
|
-
if (params?.
|
|
22
|
-
searchParams.append("
|
|
21
|
+
if (params?.baseToken) {
|
|
22
|
+
searchParams.append("baseToken", params.baseToken);
|
|
23
23
|
}
|
|
24
|
-
if (params?.
|
|
25
|
-
searchParams.append("
|
|
24
|
+
if (params?.quoteToken) {
|
|
25
|
+
searchParams.append("quoteToken", params.quoteToken);
|
|
26
26
|
}
|
|
27
|
-
if (params?.
|
|
28
|
-
searchParams.append("
|
|
27
|
+
if (params?.isActive !== undefined) {
|
|
28
|
+
searchParams.append("isActive", params.isActive.toString());
|
|
29
|
+
}
|
|
30
|
+
if (params?.category) {
|
|
31
|
+
searchParams.append("category", params.category);
|
|
29
32
|
}
|
|
30
33
|
const queryString = searchParams.toString();
|
|
31
34
|
const url = queryString ? `/api/v1/market/pairs?${queryString}` : "/api/v1/market/pairs";
|
|
32
35
|
return await this.makePublicRequest(url);
|
|
33
36
|
}
|
|
34
|
-
async
|
|
35
|
-
|
|
36
|
-
const response = await this.
|
|
37
|
-
return response.
|
|
37
|
+
async getTradingPair(tradingPairId) {
|
|
38
|
+
validate(GetMarketMetadataSchema, { tradingPairId });
|
|
39
|
+
const response = await this.makePublicRequest(perpRoutes.market.getTradingPair(tradingPairId));
|
|
40
|
+
return response.tradingPair;
|
|
41
|
+
}
|
|
42
|
+
async getTradingPairBySymbol(symbol, marketType) {
|
|
43
|
+
// Backend endpoint expects UUID, not symbol, so we fetch all pairs and filter.
|
|
44
|
+
// An optional marketType narrows the listing so a symbol present in both
|
|
45
|
+
// SPOT and MARGIN resolves unambiguously instead of returning the first match.
|
|
46
|
+
const response = await this.getPaginatedTradingPairs({ pageSize: 100, marketType: marketType });
|
|
47
|
+
return response.tradingPairs.find((pair) => pair.symbol === symbol);
|
|
38
48
|
}
|
|
39
49
|
async getCandlesticks(tradingPairId, interval, params) {
|
|
40
50
|
// Validate inputs using the trading pair ID schema
|
|
@@ -47,10 +57,10 @@ export class MarketAPIImpl extends BaseAPI {
|
|
|
47
57
|
});
|
|
48
58
|
const searchParams = new URLSearchParams();
|
|
49
59
|
if (params?.startTime !== undefined) {
|
|
50
|
-
searchParams.append("
|
|
60
|
+
searchParams.append("startTime", params.startTime.toString());
|
|
51
61
|
}
|
|
52
62
|
if (params?.endTime !== undefined) {
|
|
53
|
-
searchParams.append("
|
|
63
|
+
searchParams.append("endTime", params.endTime.toString());
|
|
54
64
|
}
|
|
55
65
|
if (params?.limit !== undefined) {
|
|
56
66
|
searchParams.append("limit", params.limit.toString());
|
|
@@ -94,4 +104,10 @@ export class MarketAPIImpl extends BaseAPI {
|
|
|
94
104
|
validate(GetMarketMetadataSchema, { tradingPairId });
|
|
95
105
|
return await this.makePublicRequest(perpRoutes.market.getOpenInterest(tradingPairId));
|
|
96
106
|
}
|
|
107
|
+
async getScreener(params) {
|
|
108
|
+
return await this.makePublicRequest(perpRoutes.market.getScreener(params));
|
|
109
|
+
}
|
|
110
|
+
async getMarketStats() {
|
|
111
|
+
return await this.makePublicRequest(perpRoutes.market.getMarketStats());
|
|
112
|
+
}
|
|
97
113
|
}
|
|
@@ -5,33 +5,34 @@ export class OrderbookAPIImpl extends BaseAPI {
|
|
|
5
5
|
const params = new URLSearchParams();
|
|
6
6
|
params.set("levels", String(depth));
|
|
7
7
|
if (tradingMode)
|
|
8
|
-
params.set("
|
|
8
|
+
params.set("tradingMode", tradingMode);
|
|
9
9
|
if (magnitude !== undefined)
|
|
10
10
|
params.set("magnitude", String(magnitude));
|
|
11
11
|
if (denomination)
|
|
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
|
|
16
|
-
|
|
15
|
+
// `tradingPairId` is the pair UUID; `symbol` is the display string.
|
|
16
|
+
tradingPairId: response.tradingPairId,
|
|
17
|
+
tradingMode: response.tradingMode,
|
|
17
18
|
bids: response.data.bids.map((level) => ({
|
|
18
19
|
price: level.price,
|
|
19
20
|
quantity: level.quantity,
|
|
20
|
-
orderCount: level.
|
|
21
|
+
orderCount: level.orderCount,
|
|
21
22
|
})),
|
|
22
23
|
asks: response.data.asks.map((level) => ({
|
|
23
24
|
price: level.price,
|
|
24
25
|
quantity: level.quantity,
|
|
25
|
-
orderCount: level.
|
|
26
|
+
orderCount: level.orderCount,
|
|
26
27
|
})),
|
|
27
|
-
bestBid: response.data.
|
|
28
|
-
bestAsk: response.data.
|
|
29
|
-
bidVolume: response.data.
|
|
30
|
-
askVolume: response.data.
|
|
31
|
-
baseDecimals: response.
|
|
32
|
-
quoteDecimals: response.
|
|
28
|
+
bestBid: response.data.bestBid,
|
|
29
|
+
bestAsk: response.data.bestAsk,
|
|
30
|
+
bidVolume: response.data.bidVolume,
|
|
31
|
+
askVolume: response.data.askVolume,
|
|
32
|
+
baseDecimals: response.baseDecimals,
|
|
33
|
+
quoteDecimals: response.quoteDecimals,
|
|
33
34
|
timestamp: response.timestamp,
|
|
34
|
-
sequence: response.
|
|
35
|
+
sequence: response.sequenceNumber,
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
}
|