@0xmonaco/core 0.2.6 → 0.2.7
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/market/api.d.ts +2 -2
- package/dist/api/market/api.d.ts.map +1 -1
- package/dist/api/market/api.js +23 -3
- package/dist/api/market/api.js.map +1 -1
- package/dist/api/profile/api.d.ts +25 -1
- package/dist/api/profile/api.d.ts.map +1 -1
- package/dist/api/profile/api.js +35 -0
- package/dist/api/profile/api.js.map +1 -1
- package/dist/api/trading/api.d.ts +9 -25
- package/dist/api/trading/api.d.ts.map +1 -1
- package/dist/api/trading/api.js +11 -48
- package/dist/api/trading/api.js.map +1 -1
- package/package.json +2 -2
package/dist/api/market/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Candlestick, Interval, MarketAPI, TradingPair } from "@0xmonaco/types";
|
|
1
|
+
import type { Candlestick, GetTradingPairsParams, GetTradingPairsResponse, Interval, MarketAPI, TradingPair } from "@0xmonaco/types";
|
|
2
2
|
import { BaseAPI } from "../base";
|
|
3
3
|
/**
|
|
4
4
|
* Market API Implementation
|
|
@@ -6,7 +6,7 @@ import { BaseAPI } from "../base";
|
|
|
6
6
|
* Provides read-only market metadata endpoints such as trading pair listings.
|
|
7
7
|
*/
|
|
8
8
|
export declare class MarketAPIImpl extends BaseAPI implements MarketAPI {
|
|
9
|
-
|
|
9
|
+
getPaginatedTradingPairs(params?: GetTradingPairsParams): Promise<GetTradingPairsResponse>;
|
|
10
10
|
getTradingPairBySymbol(symbol: string): Promise<TradingPair | undefined>;
|
|
11
11
|
getCandlesticks(symbol: string, interval: Interval, startTime: number, endTime: number): Promise<Candlestick[]>;
|
|
12
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/market/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/market/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EAGX,qBAAqB,EACrB,uBAAuB,EACvB,QAAQ,EACR,SAAS,EACT,WAAW,EACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,OAAQ,YAAW,SAAS;IACvD,wBAAwB,CAAC,MAAM,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IA4B1F,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAMxE,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;CAYtH"}
|
package/dist/api/market/api.js
CHANGED
|
@@ -5,9 +5,29 @@ import { BaseAPI } from "../base";
|
|
|
5
5
|
* Provides read-only market metadata endpoints such as trading pair listings.
|
|
6
6
|
*/
|
|
7
7
|
export class MarketAPIImpl extends BaseAPI {
|
|
8
|
-
async
|
|
9
|
-
const
|
|
10
|
-
|
|
8
|
+
async getPaginatedTradingPairs(params) {
|
|
9
|
+
const searchParams = new URLSearchParams();
|
|
10
|
+
if (params?.page !== undefined) {
|
|
11
|
+
searchParams.append("page", params.page.toString());
|
|
12
|
+
}
|
|
13
|
+
if (params?.limit !== undefined) {
|
|
14
|
+
searchParams.append("limit", params.limit.toString());
|
|
15
|
+
}
|
|
16
|
+
if (params?.market_type) {
|
|
17
|
+
searchParams.append("market_type", params.market_type);
|
|
18
|
+
}
|
|
19
|
+
if (params?.base_token) {
|
|
20
|
+
searchParams.append("base_token", params.base_token);
|
|
21
|
+
}
|
|
22
|
+
if (params?.quote_token) {
|
|
23
|
+
searchParams.append("quote_token", params.quote_token);
|
|
24
|
+
}
|
|
25
|
+
if (params?.is_active !== undefined) {
|
|
26
|
+
searchParams.append("is_active", params.is_active.toString());
|
|
27
|
+
}
|
|
28
|
+
const queryString = searchParams.toString();
|
|
29
|
+
const url = queryString ? `/api/v1/market/pairs?${queryString}` : "/api/v1/market/pairs";
|
|
30
|
+
return await this.makePublicRequest(url);
|
|
11
31
|
}
|
|
12
32
|
async getTradingPairBySymbol(symbol) {
|
|
13
33
|
const response = await this.makePublicRequest(`/api/v1/market/pairs/${encodeURIComponent(symbol)}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/api/market/api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/api/market/api.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC;;;;GAIG;AACH,MAAM,OAAO,aAAc,SAAQ,OAAO;IACxC,KAAK,CAAC,wBAAwB,CAAC,MAA8B;QAC3D,MAAM,YAAY,GAAG,IAAI,eAAe,EAAE,CAAC;QAE3C,IAAI,MAAM,EAAE,IAAI,KAAK,SAAS,EAAE,CAAC;YAC/B,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACtD,CAAC;QACD,IAAI,MAAM,EAAE,KAAK,KAAK,SAAS,EAAE,CAAC;YAChC,YAAY,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;QACxD,CAAC;QACD,IAAI,MAAM,EAAE,WAAW,EAAE,CAAC;YACxB,YAAY,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;QACzD,CAAC;QACD,IAAI,MAAM,EAAE,UAAU,EAAE,CAAC;YACvB,YAAY,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,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AAiB,CAAyB,GAAG,CAAC,CAAC;QAE3E,OAAO,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* console.log(`User: ${profile.username} (${profile.address})`);
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
import type { ProfileAPI, UserProfile } from "@0xmonaco/types";
|
|
20
|
+
import type { GetPaginatedUserMovementsResponse, GetUserMovementsParams, ProfileAPI, UserProfile } from "@0xmonaco/types";
|
|
21
21
|
import { BaseAPI } from "../base";
|
|
22
22
|
export declare class ProfileAPIImpl extends BaseAPI implements ProfileAPI {
|
|
23
23
|
/**
|
|
@@ -50,5 +50,29 @@ export declare class ProfileAPIImpl extends BaseAPI implements ProfileAPI {
|
|
|
50
50
|
* ```
|
|
51
51
|
*/
|
|
52
52
|
getProfile(): Promise<UserProfile>;
|
|
53
|
+
/**
|
|
54
|
+
* Get the current user's ledger movements (transaction history) with pagination.
|
|
55
|
+
*
|
|
56
|
+
* Fetches the user's transaction history from the /api/v1/accounts/movements endpoint.
|
|
57
|
+
* Requires a valid access token to be set.
|
|
58
|
+
*
|
|
59
|
+
* @param params - Optional query parameters for pagination
|
|
60
|
+
* @param params.page - Page number (starts from 1, default: 1)
|
|
61
|
+
* @param params.limit - Number of items per page (default: 20, max: 100)
|
|
62
|
+
* @returns Promise resolving to paginated movements response
|
|
63
|
+
* @throws {APIError} When the request fails or user is not authenticated
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* // Get first page with default limit (20)
|
|
68
|
+
* const movements = await profileAPI.getUserMovements();
|
|
69
|
+
* console.log(`Total movements: ${movements.total_count}`);
|
|
70
|
+
*
|
|
71
|
+
* // Get second page with custom limit
|
|
72
|
+
* const page2 = await profileAPI.getUserMovements({ page: 2, limit: 50 });
|
|
73
|
+
* console.log(`Page ${page2.page} of ${page2.total_pages}`);
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
getPaginatedUserMovements(params?: GetUserMovementsParams): Promise<GetPaginatedUserMovementsResponse>;
|
|
53
77
|
}
|
|
54
78
|
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/profile/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/profile/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,iCAAiC,EAAE,sBAAsB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC1H,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,qBAAa,cAAe,SAAQ,OAAQ,YAAW,UAAU;IAC/D;;;;OAIG;gBACS,MAAM,EAAE,MAAM;IAI1B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,UAAU,IAAI,OAAO,CAAC,WAAW,CAAC;IAgBxC;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,yBAAyB,CAAC,MAAM,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,iCAAiC,CAAC;CAe7G"}
|
package/dist/api/profile/api.js
CHANGED
|
@@ -64,5 +64,40 @@ export class ProfileAPIImpl extends BaseAPI {
|
|
|
64
64
|
recent_orders: data.recent_orders || [],
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Get the current user's ledger movements (transaction history) with pagination.
|
|
69
|
+
*
|
|
70
|
+
* Fetches the user's transaction history from the /api/v1/accounts/movements endpoint.
|
|
71
|
+
* Requires a valid access token to be set.
|
|
72
|
+
*
|
|
73
|
+
* @param params - Optional query parameters for pagination
|
|
74
|
+
* @param params.page - Page number (starts from 1, default: 1)
|
|
75
|
+
* @param params.limit - Number of items per page (default: 20, max: 100)
|
|
76
|
+
* @returns Promise resolving to paginated movements response
|
|
77
|
+
* @throws {APIError} When the request fails or user is not authenticated
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* // Get first page with default limit (20)
|
|
82
|
+
* const movements = await profileAPI.getUserMovements();
|
|
83
|
+
* console.log(`Total movements: ${movements.total_count}`);
|
|
84
|
+
*
|
|
85
|
+
* // Get second page with custom limit
|
|
86
|
+
* const page2 = await profileAPI.getUserMovements({ page: 2, limit: 50 });
|
|
87
|
+
* console.log(`Page ${page2.page} of ${page2.total_pages}`);
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
async getPaginatedUserMovements(params) {
|
|
91
|
+
const searchParams = new URLSearchParams();
|
|
92
|
+
if (params?.page !== undefined) {
|
|
93
|
+
searchParams.append("page", params.page.toString());
|
|
94
|
+
}
|
|
95
|
+
if (params?.limit !== undefined) {
|
|
96
|
+
searchParams.append("limit", params.limit.toString());
|
|
97
|
+
}
|
|
98
|
+
const queryString = searchParams.toString();
|
|
99
|
+
const url = queryString ? `/api/v1/accounts/movements?${queryString}` : "/api/v1/accounts/movements";
|
|
100
|
+
return await this.makeAuthenticatedRequest(url);
|
|
101
|
+
}
|
|
67
102
|
}
|
|
68
103
|
//# sourceMappingURL=api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/api/profile/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,OAAO,cAAe,SAAQ,OAAO;IACzC;;;;OAIG;IACH,YAAY,MAAc;QACxB,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsB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AE,IAAI,CAAC,gBAAgB,IAAI,EAAE;YAC7C,aAAa,EAAE,IAAI,CAAC,aAAa,IAAI,EAAE;SACxC,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,KAAK,CAAC,yBAAyB,CAAC,MAA+B;QAC7D,MAAM,YAAY,GAAG,IAAI,eAAe,EAAE,CAAC;QAE3C,IAAI,MAAM,EAAE,IAAI,KAAK,SAAS,EAAE,CAAC;YAC/B,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACtD,CAAC;QACD,IAAI,MAAM,EAAE,KAAK,KAAK,SAAS,EAAE,CAAC;YAChC,YAAY,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;QACxD,CAAC;QAED,MAAM,WAAW,GAAG,YAAY,CAAC,QAAQ,EAAE,CAAC;QAC5C,MAAM,GAAG,GAAG,WAAW,CAAC,CAAC,CAAC,8BAA8B,WAAW,EAAE,CAAC,CAAC,CAAC,4BAA4B,CAAC;QAErG,OAAO,MAAM,IAAI,CAAC,wBAAwB,CAAoC,GAAG,CAAC,CAAC;IACrF,CAAC;CACF"}
|
|
@@ -35,29 +35,13 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
35
35
|
* @param apiUrl - The base URL for the Monaco API Gateway
|
|
36
36
|
*/
|
|
37
37
|
constructor(marketAPI: MarketAPI, apiUrl: string);
|
|
38
|
-
/**
|
|
39
|
-
* Validates if a trading symbol exists and is active.
|
|
40
|
-
*
|
|
41
|
-
* @param symbol - The trading pair symbol to validate (e.g., "BTC-USDC")
|
|
42
|
-
* @returns Promise resolving to true if valid and active, false if invalid/inactive.
|
|
43
|
-
* Returns true on API errors (fail-open approach to avoid blocking trades).
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```typescript
|
|
47
|
-
* const isValid = await tradingAPI.validateSymbol("BTC-USDC");
|
|
48
|
-
* if (!isValid) {
|
|
49
|
-
* throw new Error("Invalid trading pair");
|
|
50
|
-
* }
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
private validateSymbol;
|
|
54
38
|
/**
|
|
55
39
|
* Places a limit order on the order book.
|
|
56
40
|
*
|
|
57
41
|
* Limit orders are executed only when the market price reaches or improves upon
|
|
58
42
|
* the specified price. They provide price protection but may not execute immediately.
|
|
59
43
|
*
|
|
60
|
-
* @param
|
|
44
|
+
* @param tradingPairId - The trading pair UUID
|
|
61
45
|
* @param side - The order side ("BUY" or "SELL")
|
|
62
46
|
* @param quantity - The order quantity as string
|
|
63
47
|
* @param price - The limit price as string
|
|
@@ -71,7 +55,7 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
71
55
|
* ```typescript
|
|
72
56
|
* // Regular limit order
|
|
73
57
|
* const order = await tradingAPI.placeLimitOrder(
|
|
74
|
-
* "
|
|
58
|
+
* "123e4567-e89b-12d3-a456-426614174000",
|
|
75
59
|
* "BUY",
|
|
76
60
|
* "0.5",
|
|
77
61
|
* "35000.00",
|
|
@@ -80,7 +64,7 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
80
64
|
*
|
|
81
65
|
* // GTC order with custom expiration
|
|
82
66
|
* const gtcOrder = await tradingAPI.placeLimitOrder(
|
|
83
|
-
* "
|
|
67
|
+
* "123e4567-e89b-12d3-a456-426614174000",
|
|
84
68
|
* "BUY",
|
|
85
69
|
* "0.5",
|
|
86
70
|
* "35000.00",
|
|
@@ -91,7 +75,7 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
91
75
|
* );
|
|
92
76
|
* ```
|
|
93
77
|
*/
|
|
94
|
-
placeLimitOrder(
|
|
78
|
+
placeLimitOrder(tradingPairId: string, side: OrderSide, quantity: string, price: string, options?: {
|
|
95
79
|
tradingMode?: string;
|
|
96
80
|
useMasterBalance?: boolean;
|
|
97
81
|
expirationDate?: string;
|
|
@@ -102,7 +86,7 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
102
86
|
* Market orders execute immediately at the current market price. They provide
|
|
103
87
|
* immediate execution but may experience slippage.
|
|
104
88
|
*
|
|
105
|
-
* @param
|
|
89
|
+
* @param tradingPairId - The trading pair UUID
|
|
106
90
|
* @param side - The order side ("BUY" or "SELL")
|
|
107
91
|
* @param quantity - The order quantity as string
|
|
108
92
|
* @param options - Optional parameters for the market order
|
|
@@ -114,7 +98,7 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
114
98
|
* ```typescript
|
|
115
99
|
* // Market order with 1% slippage tolerance
|
|
116
100
|
* const order1 = await tradingAPI.placeMarketOrder(
|
|
117
|
-
* "
|
|
101
|
+
* "123e4567-e89b-12d3-a456-426614174000",
|
|
118
102
|
* "SELL",
|
|
119
103
|
* "0.5",
|
|
120
104
|
* { tradingMode: "SPOT", slippageTolerance: 0.01 } // 1% slippage
|
|
@@ -122,7 +106,7 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
122
106
|
*
|
|
123
107
|
* // Market order with zero slippage (only execute at best price)
|
|
124
108
|
* const order2 = await tradingAPI.placeMarketOrder(
|
|
125
|
-
* "
|
|
109
|
+
* "123e4567-e89b-12d3-a456-426614174000",
|
|
126
110
|
* "BUY",
|
|
127
111
|
* "1.0",
|
|
128
112
|
* { slippageTolerance: 0 } // Only execute at best ask price
|
|
@@ -130,14 +114,14 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
|
|
|
130
114
|
*
|
|
131
115
|
* // Market order with unlimited slippage
|
|
132
116
|
* const order3 = await tradingAPI.placeMarketOrder(
|
|
133
|
-
* "
|
|
117
|
+
* "123e4567-e89b-12d3-a456-426614174000",
|
|
134
118
|
* "BUY",
|
|
135
119
|
* "1.0"
|
|
136
120
|
* // No slippageTolerance specified = unlimited slippage
|
|
137
121
|
* );
|
|
138
122
|
* ```
|
|
139
123
|
*/
|
|
140
|
-
placeMarketOrder(
|
|
124
|
+
placeMarketOrder(tradingPairId: string, side: OrderSide, quantity: string, options?: {
|
|
141
125
|
tradingMode?: string;
|
|
142
126
|
slippageTolerance?: number;
|
|
143
127
|
}): Promise<CreateOrderResponse>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/trading/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,wBAAwB,EACxB,0BAA0B,EAC1B,SAAS,EACT,SAAS,EAET,oBAAoB,EACpB,UAAU,EACX,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api/trading/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,wBAAwB,EACxB,0BAA0B,EAC1B,SAAS,EACT,SAAS,EAET,oBAAoB,EACpB,UAAU,EACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,qBAAa,cAAe,SAAQ,OAAQ,YAAW,UAAU;IAC/D,OAAO,CAAC,SAAS,CAAY;IAE7B;;;;;OAKG;gBACS,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM;IAKhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuCG;IACG,eAAe,CACnB,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,GACA,OAAO,CAAC,mBAAmB,CAAC;IAkB/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACG,gBAAgB,CACpB,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B,GACA,OAAO,CAAC,mBAAmB,CAAC;IAiB/B;;;;;;;;;;;;;;;;OAgBG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAW1D,YAAY,CAChB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE;QACR,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,gBAAgB,CAAC,EAAE,OAAO,CAAC;KAC5B,GACA,OAAO,CAAC,oBAAoB,CAAC;IAoBhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,kBAAkB,CAAC,MAAM,CAAC,EAAE,wBAAwB,GAAG,OAAO,CAAC,0BAA0B,CAAC;IA2BhG;;;;;;;;;;;;;;;;;OAiBG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAK3D"}
|
package/dist/api/trading/api.js
CHANGED
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
* const openOrders = await tradingAPI.getOpenOrders({ market: "ETH-USD" });
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
|
-
import { OrderError } from "../../errors";
|
|
28
27
|
import { BaseAPI } from "../base";
|
|
29
28
|
export class TradingAPIImpl extends BaseAPI {
|
|
30
29
|
/**
|
|
@@ -37,39 +36,13 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
37
36
|
super(apiUrl);
|
|
38
37
|
this.marketAPI = marketAPI;
|
|
39
38
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Validates if a trading symbol exists and is active.
|
|
42
|
-
*
|
|
43
|
-
* @param symbol - The trading pair symbol to validate (e.g., "BTC-USDC")
|
|
44
|
-
* @returns Promise resolving to true if valid and active, false if invalid/inactive.
|
|
45
|
-
* Returns true on API errors (fail-open approach to avoid blocking trades).
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* const isValid = await tradingAPI.validateSymbol("BTC-USDC");
|
|
50
|
-
* if (!isValid) {
|
|
51
|
-
* throw new Error("Invalid trading pair");
|
|
52
|
-
* }
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
async validateSymbol(symbol) {
|
|
56
|
-
try {
|
|
57
|
-
const tradingPair = await this.marketAPI.getTradingPairBySymbol(symbol);
|
|
58
|
-
return !!tradingPair?.is_active;
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
// If market API fails, log warning but don't block trading
|
|
62
|
-
console.warn(`Symbol validation failed for ${symbol}:`, error);
|
|
63
|
-
return true; // Fail open to avoid blocking legitimate trades
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
39
|
/**
|
|
67
40
|
* Places a limit order on the order book.
|
|
68
41
|
*
|
|
69
42
|
* Limit orders are executed only when the market price reaches or improves upon
|
|
70
43
|
* the specified price. They provide price protection but may not execute immediately.
|
|
71
44
|
*
|
|
72
|
-
* @param
|
|
45
|
+
* @param tradingPairId - The trading pair UUID
|
|
73
46
|
* @param side - The order side ("BUY" or "SELL")
|
|
74
47
|
* @param quantity - The order quantity as string
|
|
75
48
|
* @param price - The limit price as string
|
|
@@ -83,7 +56,7 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
83
56
|
* ```typescript
|
|
84
57
|
* // Regular limit order
|
|
85
58
|
* const order = await tradingAPI.placeLimitOrder(
|
|
86
|
-
* "
|
|
59
|
+
* "123e4567-e89b-12d3-a456-426614174000",
|
|
87
60
|
* "BUY",
|
|
88
61
|
* "0.5",
|
|
89
62
|
* "35000.00",
|
|
@@ -92,7 +65,7 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
92
65
|
*
|
|
93
66
|
* // GTC order with custom expiration
|
|
94
67
|
* const gtcOrder = await tradingAPI.placeLimitOrder(
|
|
95
|
-
* "
|
|
68
|
+
* "123e4567-e89b-12d3-a456-426614174000",
|
|
96
69
|
* "BUY",
|
|
97
70
|
* "0.5",
|
|
98
71
|
* "35000.00",
|
|
@@ -103,14 +76,9 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
103
76
|
* );
|
|
104
77
|
* ```
|
|
105
78
|
*/
|
|
106
|
-
async placeLimitOrder(
|
|
107
|
-
// Validate the trading symbol before placing order
|
|
108
|
-
const isValidSymbol = await this.validateSymbol(market);
|
|
109
|
-
if (!isValidSymbol) {
|
|
110
|
-
throw new OrderError(`Invalid or inactive trading pair: ${market}`, { market });
|
|
111
|
-
}
|
|
79
|
+
async placeLimitOrder(tradingPairId, side, quantity, price, options) {
|
|
112
80
|
const requestBody = {
|
|
113
|
-
|
|
81
|
+
trading_pair_id: tradingPairId,
|
|
114
82
|
order_type: "LIMIT",
|
|
115
83
|
side,
|
|
116
84
|
price,
|
|
@@ -130,7 +98,7 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
130
98
|
* Market orders execute immediately at the current market price. They provide
|
|
131
99
|
* immediate execution but may experience slippage.
|
|
132
100
|
*
|
|
133
|
-
* @param
|
|
101
|
+
* @param tradingPairId - The trading pair UUID
|
|
134
102
|
* @param side - The order side ("BUY" or "SELL")
|
|
135
103
|
* @param quantity - The order quantity as string
|
|
136
104
|
* @param options - Optional parameters for the market order
|
|
@@ -142,7 +110,7 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
142
110
|
* ```typescript
|
|
143
111
|
* // Market order with 1% slippage tolerance
|
|
144
112
|
* const order1 = await tradingAPI.placeMarketOrder(
|
|
145
|
-
* "
|
|
113
|
+
* "123e4567-e89b-12d3-a456-426614174000",
|
|
146
114
|
* "SELL",
|
|
147
115
|
* "0.5",
|
|
148
116
|
* { tradingMode: "SPOT", slippageTolerance: 0.01 } // 1% slippage
|
|
@@ -150,7 +118,7 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
150
118
|
*
|
|
151
119
|
* // Market order with zero slippage (only execute at best price)
|
|
152
120
|
* const order2 = await tradingAPI.placeMarketOrder(
|
|
153
|
-
* "
|
|
121
|
+
* "123e4567-e89b-12d3-a456-426614174000",
|
|
154
122
|
* "BUY",
|
|
155
123
|
* "1.0",
|
|
156
124
|
* { slippageTolerance: 0 } // Only execute at best ask price
|
|
@@ -158,21 +126,16 @@ export class TradingAPIImpl extends BaseAPI {
|
|
|
158
126
|
*
|
|
159
127
|
* // Market order with unlimited slippage
|
|
160
128
|
* const order3 = await tradingAPI.placeMarketOrder(
|
|
161
|
-
* "
|
|
129
|
+
* "123e4567-e89b-12d3-a456-426614174000",
|
|
162
130
|
* "BUY",
|
|
163
131
|
* "1.0"
|
|
164
132
|
* // No slippageTolerance specified = unlimited slippage
|
|
165
133
|
* );
|
|
166
134
|
* ```
|
|
167
135
|
*/
|
|
168
|
-
async placeMarketOrder(
|
|
169
|
-
// Validate the trading symbol before placing order
|
|
170
|
-
const isValidSymbol = await this.validateSymbol(market);
|
|
171
|
-
if (!isValidSymbol) {
|
|
172
|
-
throw new OrderError(`Invalid or inactive trading pair: ${market}`, { market });
|
|
173
|
-
}
|
|
136
|
+
async placeMarketOrder(tradingPairId, side, quantity, options) {
|
|
174
137
|
const requestBody = {
|
|
175
|
-
|
|
138
|
+
trading_pair_id: tradingPairId,
|
|
176
139
|
order_type: "MARKET",
|
|
177
140
|
side,
|
|
178
141
|
slippage_tolerance_bps: options?.slippageTolerance !== undefined ? Math.round(options.slippageTolerance * 10000) : undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/api/trading/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAcH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/api/trading/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAcH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,OAAO,cAAe,SAAQ,OAAO;IAGzC;;;;;OAKG;IACH,YAAY,SAAoB,EAAE,MAAc;QAC9C,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuCG;IACH,KAAK,CAAC,eAAe,CACnB,aAAqB,EACrB,IAAe,EACf,QAAgB,EAChB,KAAa,EACb,OAIC;QAED,MAAM,WAAW,GAAG;YAClB,eAAe,EAAE,aAAa;YAC9B,UAAU,EAAE,OAAoB;YAChC,IAAI;YACJ,KAAK;YACL,QAAQ;YACR,YAAY,EAAE,OAAO,EAAE,WAAW,IAAI,MAAM;YAC5C,kBAAkB,EAAE,OAAO,EAAE,gBAAgB;YAC7C,eAAe,EAAE,OAAO,EAAE,cAAc;SACzC,CAAC;QAEF,OAAO,MAAM,IAAI,CAAC,wBAAwB,CAAsB,gBAAgB,EAAE;YAChF,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;SAClC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACH,KAAK,CAAC,gBAAgB,CACpB,aAAqB,EACrB,IAAe,EACf,QAAgB,EAChB,OAGC;QAED,MAAM,WAAW,GAAG;YAClB,eAAe,EAAE,aAAa;YAC9B,UAAU,EAAE,QAAqB;YACjC,IAAI;YACJ,sBAAsB,EAAE,OAAO,E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IACL,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xmonaco/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@0xmonaco/contracts": "0.1.8",
|
|
16
|
-
"@0xmonaco/types": "0.2.
|
|
16
|
+
"@0xmonaco/types": "0.2.6"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/node": "^20.11.30",
|