@0xmonaco/core 0.7.8 → 0.7.9

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.
@@ -21,7 +21,7 @@
21
21
  * );
22
22
  * ```
23
23
  */
24
- import type { BatchCancelOrdersResponse, BatchCreateOrderParams, BatchCreateOrdersResponse, BatchReplaceOrderParams, BatchReplaceOrdersResponse, CancelConditionalOrderResponse, CancelOrderResponse, CreateConditionalOrderParams, CreateConditionalOrderResponse, CreateOrderResponse, GetOrderResponse, GetPaginatedOrdersParams, GetPaginatedOrdersResponse, ListConditionalOrdersParams, ListConditionalOrdersResponse, OrderSide, PositionSide, ReplaceOrderResponse, TimeInForce, TradingAPI, TradingMode } from "@0xmonaco/types";
24
+ import type { BatchCancelOrdersResponse, BatchCreateOrderParams, BatchCreateOrdersResponse, BatchReplaceOrderParams, BatchReplaceOrdersResponse, CancelConditionalOrderResponse, CancelOrderResponse, CreateConditionalOrderParams, CreateConditionalOrderResponse, CreateOrderResponse, GetOrderResponse, GetPaginatedOrdersParams, GetPaginatedOrdersResponse, ListConditionalOrdersParams, ListConditionalOrdersResponse, OrderSide, ParentTpSlLegParams, PositionSide, ReplaceOrderResponse, TimeInForce, TradingAPI, TradingMode } from "@0xmonaco/types";
25
25
  import { BaseAPI } from "../base";
26
26
  export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
27
27
  /**
@@ -83,6 +83,8 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
83
83
  positionSide?: PositionSide;
84
84
  leverage?: string;
85
85
  reduceOnly?: boolean;
86
+ takeProfit?: ParentTpSlLegParams;
87
+ stopLoss?: ParentTpSlLegParams;
86
88
  }): Promise<CreateOrderResponse>;
87
89
  /**
88
90
  * Places a market order for immediate execution.
@@ -132,6 +134,8 @@ export declare class TradingAPIImpl extends BaseAPI implements TradingAPI {
132
134
  positionSide?: PositionSide;
133
135
  leverage?: string;
134
136
  reduceOnly?: boolean;
137
+ takeProfit?: ParentTpSlLegParams;
138
+ stopLoss?: ParentTpSlLegParams;
135
139
  }): Promise<CreateOrderResponse>;
136
140
  /**
137
141
  * Cancels an existing order.
@@ -24,6 +24,18 @@
24
24
  import { BatchCreateOrdersSchema, BatchReplaceOrdersSchema, CancelConditionalOrderSchema, CancelOrderSchema, CreateConditionalOrderSchema, GetPaginatedOrdersSchema, ListConditionalOrdersSchema, PlaceLimitOrderSchema, PlaceMarketOrderSchema, ReplaceOrderSchema, validate, } from "@0xmonaco/types";
25
25
  import { BaseAPI } from "../base";
26
26
  import { perpRoutes } from "../perp";
27
+ function parentTpSlLegToRequest(leg) {
28
+ if (!leg)
29
+ return undefined;
30
+ return {
31
+ trigger_price: leg.triggerPrice,
32
+ order_type: leg.orderType,
33
+ limit_price: leg.limitPrice,
34
+ time_in_force: leg.timeInForce,
35
+ slippage_tolerance_bps: leg.slippageToleranceBps,
36
+ expires_at: leg.expiresAt,
37
+ };
38
+ }
27
39
  export class TradingAPIImpl extends BaseAPI {
28
40
  /**
29
41
  * Places a limit order on the order book.
@@ -98,6 +110,8 @@ export class TradingAPIImpl extends BaseAPI {
98
110
  position_side: options?.positionSide,
99
111
  leverage: options?.leverage,
100
112
  reduce_only: options?.reduceOnly,
113
+ take_profit: parentTpSlLegToRequest(options?.takeProfit),
114
+ stop_loss: parentTpSlLegToRequest(options?.stopLoss),
101
115
  };
102
116
  return await this.makeAuthenticatedRequest(perpRoutes.orders.create(), {
103
117
  method: "POST",
@@ -165,6 +179,8 @@ export class TradingAPIImpl extends BaseAPI {
165
179
  position_side: options?.positionSide,
166
180
  leverage: options?.leverage,
167
181
  reduce_only: options?.reduceOnly,
182
+ take_profit: parentTpSlLegToRequest(options?.takeProfit),
183
+ stop_loss: parentTpSlLegToRequest(options?.stopLoss),
168
184
  };
169
185
  return await this.makeAuthenticatedRequest(perpRoutes.orders.create(), {
170
186
  method: "POST",
@@ -4,10 +4,11 @@ import { keysToCamelCase } from "./utils";
4
4
  const CONNECTION_TIMEOUT = 10000;
5
5
  const HEARTBEAT_INTERVAL = 15000;
6
6
  const MAX_RECONNECT_DELAY = 30000;
7
- const CONDITIONAL_ORDER_REASONS = ["created", "cancelled", "triggered", "failed", "oco_cancelled"];
7
+ const CONDITIONAL_ORDER_REASONS = ["created", "activated", "cancelled", "parent_cancelled", "triggered", "failed", "oco_cancelled"];
8
8
  const CONDITIONAL_ORDER_CONDITION_TYPES = ["STOP_LOSS", "TAKE_PROFIT"];
9
9
  const CONDITIONAL_ORDER_TRIGGER_SOURCES = ["MARK_PRICE"];
10
- const CONDITIONAL_ORDER_STATES = ["ACTIVE", "TRIGGERING", "TRIGGERED", "CANCELLED", "EXPIRED", "FAILED"];
10
+ const CONDITIONAL_ORDER_STATES = ["PENDING_PARENT", "ACTIVE", "TRIGGERING", "TRIGGERED", "CANCELLED", "EXPIRED", "FAILED"];
11
+ const CONDITIONAL_ORDER_ASSOCIATION_TYPES = ["POSITION", "PARENT_ORDER"];
11
12
  function isRecord(value) {
12
13
  return typeof value === "object" && value !== null && !Array.isArray(value);
13
14
  }
@@ -75,6 +76,8 @@ function parseConditionalOrderEvent(rawData) {
75
76
  tradingPairId: readString(data, "tradingPairId"),
76
77
  marginAccountId: readString(data, "marginAccountId"),
77
78
  positionId: readOptionalString(data, "positionId"),
79
+ parentOrderId: readOptionalString(data, "parentOrderId"),
80
+ associationType: readOptionalEnum(data, "associationType", CONDITIONAL_ORDER_ASSOCIATION_TYPES),
78
81
  linkedGroupId: readOptionalString(data, "linkedGroupId"),
79
82
  conditionType: readEnum(data, "conditionType", CONDITIONAL_ORDER_CONDITION_TYPES),
80
83
  triggerSource: readEnum(data, "triggerSource", CONDITIONAL_ORDER_TRIGGER_SOURCES),
@@ -90,6 +93,7 @@ function parseConditionalOrderEvent(rawData) {
90
93
  state: readEnum(data, "state", CONDITIONAL_ORDER_STATES),
91
94
  triggeredOrderId: readOptionalString(data, "triggeredOrderId"),
92
95
  triggeredAt: readOptionalString(data, "triggeredAt"),
96
+ activatedAt: readOptionalString(data, "activatedAt"),
93
97
  cancelledAt: readOptionalString(data, "cancelledAt"),
94
98
  expiresAt: readOptionalString(data, "expiresAt"),
95
99
  failureReason: readOptionalString(data, "failureReason"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xmonaco/core",
3
- "version": "0.7.8",
3
+ "version": "0.7.9",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,8 +23,8 @@
23
23
  "viem": "^2.45.2"
24
24
  },
25
25
  "dependencies": {
26
- "@0xmonaco/contracts": "0.7.8",
27
- "@0xmonaco/types": "0.7.8",
26
+ "@0xmonaco/contracts": "0.7.9",
27
+ "@0xmonaco/types": "0.7.9",
28
28
  "http-status-codes": "^2.3.0"
29
29
  },
30
30
  "devDependencies": {