@0xmonaco/core 0.6.3 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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";
@@ -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
  }
@@ -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
  *
@@ -11,8 +12,8 @@ export class MarketAPIImpl extends BaseAPI {
11
12
  if (params?.page !== undefined) {
12
13
  searchParams.append("page", params.page.toString());
13
14
  }
14
- if (params?.limit !== undefined) {
15
- searchParams.append("limit", params.limit.toString());
15
+ if (params?.page_size !== undefined) {
16
+ searchParams.append("page_size", params.page_size.toString());
16
17
  }
17
18
  if (params?.market_type) {
18
19
  searchParams.append("market_type", params.market_type);
@@ -32,8 +33,8 @@ export class MarketAPIImpl extends BaseAPI {
32
33
  }
33
34
  async getTradingPairBySymbol(symbol) {
34
35
  // Backend endpoint expects UUID, not symbol, so we fetch all pairs and filter
35
- const response = await this.getPaginatedTradingPairs({ limit: 100 });
36
- return response.data.data.find((pair) => pair.symbol === symbol);
36
+ const response = await this.getPaginatedTradingPairs({ page_size: 100 });
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
- const url = `/api/v1/market/pairs/${tradingPairId}/metadata`;
67
- return await this.makePublicRequest(url);
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.pair,
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,89 @@
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
+ position_id: positionId,
21
+ close_type: request.closeType,
22
+ limit_price: request.limitPrice,
23
+ slippage_tolerance_bps: request.slippageToleranceBps,
24
+ quantity: request.quantity,
25
+ }),
26
+ });
27
+ }
28
+ async getPositionRisk(positionId) {
29
+ validate(GetPositionRiskSchema, { positionId });
30
+ return await this.makeAuthenticatedRequest(perpRoutes.positions.risk(positionId));
31
+ }
32
+ async addPositionMargin(positionId, request) {
33
+ validate(AddPositionMarginSchema, { positionId, request });
34
+ return await this.makeAuthenticatedRequest(perpRoutes.positions.addMargin(positionId), {
35
+ method: "POST",
36
+ body: JSON.stringify({
37
+ position_id: positionId,
38
+ amount: request.amount,
39
+ asset: request.asset,
40
+ }),
41
+ });
42
+ }
43
+ async reducePositionMargin(positionId, request) {
44
+ validate(ReducePositionMarginSchema, { positionId, request });
45
+ return await this.makeAuthenticatedRequest(perpRoutes.positions.reduceMargin(positionId), {
46
+ method: "POST",
47
+ body: JSON.stringify({
48
+ position_id: positionId,
49
+ amount: request.amount,
50
+ }),
51
+ });
52
+ }
53
+ async attachPositionTpSl(positionId, request) {
54
+ validate(AttachPositionTpSlSchema, { positionId, request });
55
+ return await this.makeAuthenticatedRequest(perpRoutes.positions.attachTpSl(positionId), {
56
+ method: "POST",
57
+ body: JSON.stringify({
58
+ take_profit: request.takeProfit
59
+ ? {
60
+ trigger_price: request.takeProfit.triggerPrice,
61
+ order_type: request.takeProfit.orderType,
62
+ limit_price: request.takeProfit.limitPrice,
63
+ quantity: request.takeProfit.quantity,
64
+ time_in_force: request.takeProfit.timeInForce,
65
+ slippage_tolerance_bps: request.takeProfit.slippageToleranceBps,
66
+ expires_at: request.takeProfit.expiresAt,
67
+ }
68
+ : undefined,
69
+ stop_loss: request.stopLoss
70
+ ? {
71
+ trigger_price: request.stopLoss.triggerPrice,
72
+ order_type: request.stopLoss.orderType,
73
+ limit_price: request.stopLoss.limitPrice,
74
+ quantity: request.stopLoss.quantity,
75
+ time_in_force: request.stopLoss.timeInForce,
76
+ slippage_tolerance_bps: request.stopLoss.slippageToleranceBps,
77
+ expires_at: request.stopLoss.expiresAt,
78
+ }
79
+ : undefined,
80
+ }),
81
+ });
82
+ }
83
+ async listPositionHistory(params) {
84
+ if (params) {
85
+ validate(ListPositionHistorySchema, params);
86
+ }
87
+ return await this.makeAuthenticatedRequest(perpRoutes.positions.history(params));
88
+ }
89
+ }
@@ -0,0 +1 @@
1
+ export { PositionsAPIImpl } from "./api";
@@ -0,0 +1 @@
1
+ export { PositionsAPIImpl } from "./api";
@@ -61,12 +61,12 @@ export declare class ProfileAPIImpl extends BaseAPI implements ProfileAPI {
61
61
  *
62
62
  * @example
63
63
  * ```typescript
64
- * // Get first page with default limit (20)
64
+ * // Get first page with default page_size (20)
65
65
  * const movements = await profileAPI.getPaginatedUserMovements();
66
- * console.log(`Total movements: ${movements.total_count}`);
66
+ * console.log(`Total movements: ${movements.total}`);
67
67
  *
68
- * // Get second page with custom limit
69
- * const page2 = await profileAPI.getPaginatedUserMovements({ page: 2, limit: 50 });
68
+ * // Get second page with custom page_size
69
+ * const page2 = await profileAPI.getPaginatedUserMovements({ page: 2, page_size: 50 });
70
70
  * console.log(`Page ${page2.page} of ${page2.total_pages}`);
71
71
  *
72
72
  * // Filter by entry type and transaction type
@@ -84,8 +84,8 @@ export declare class ProfileAPIImpl extends BaseAPI implements ProfileAPI {
84
84
  * Requires a valid access token to be set.
85
85
  *
86
86
  * @param params - Optional query parameters for pagination
87
- * @param params.limit - Number of items to return (default: 20)
88
- * @param params.offset - Number of items to skip (default: 0)
87
+ * @param params.page - Page number (starts from 1, default: 1)
88
+ * @param params.page_size - Number of items per page (default: 20, max: 100)
89
89
  * @returns Promise resolving to paginated balances response
90
90
  * @throws {APIError} When the request fails or user is not authenticated
91
91
  *
@@ -98,8 +98,8 @@ export declare class ProfileAPIImpl extends BaseAPI implements ProfileAPI {
98
98
  * console.log(`${balance.symbol}: ${balance.available_balance}`);
99
99
  * });
100
100
  *
101
- * // Get next 50 balances with offset
102
- * const nextBalances = await profileAPI.getUserBalances({ limit: 50, offset: 20 });
101
+ * // Get page 2 with 50 items per page
102
+ * const nextBalances = await profileAPI.getUserBalances({ page: 2, page_size: 50 });
103
103
  * console.log(`Returned ${nextBalances.balances.length} balances`);
104
104
  * ```
105
105
  */
@@ -171,7 +171,7 @@ export declare class ProfileAPIImpl extends BaseAPI implements ProfileAPI {
171
171
  *
172
172
  * @param params - Optional query parameters for pagination and filtering
173
173
  * @param params.page - Page number (starts from 1, default: 1)
174
- * @param params.limit - Number of items per page (default: 20, max: 100)
174
+ * @param params.page_size - Number of items per page (default: 20, max: 100)
175
175
  * @param params.trading_pair_id - Filter by trading pair ID (UUID)
176
176
  * @returns Promise resolving to paginated trades response
177
177
  * @throws {ValidationError} When the provided params fail client-side validation
@@ -181,7 +181,7 @@ export declare class ProfileAPIImpl extends BaseAPI implements ProfileAPI {
181
181
  * ```typescript
182
182
  * // Get first page of trades
183
183
  * const trades = await profileAPI.getUserTrades();
184
- * console.log(`Total trades: ${trades.total_count}`);
184
+ * console.log(`Total trades: ${trades.total}`);
185
185
  *
186
186
  * // Filter by trading pair
187
187
  * const pairTrades = await profileAPI.getUserTrades({ trading_pair_id: "550e8400-e29b-41d4-a716-446655440000" });