bybit-api 2.3.2 → 2.4.0-beta.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.
Files changed (92) hide show
  1. package/README.md +60 -152
  2. package/lib/account-asset-client.d.ts +42 -0
  3. package/lib/account-asset-client.js +104 -0
  4. package/lib/account-asset-client.js.map +1 -0
  5. package/lib/constants/enum.d.ts +18 -0
  6. package/lib/constants/enum.js +18 -0
  7. package/lib/constants/enum.js.map +1 -1
  8. package/lib/copy-trading-client.d.ts +54 -0
  9. package/lib/copy-trading-client.js +112 -0
  10. package/lib/copy-trading-client.js.map +1 -0
  11. package/lib/index.d.ts +7 -1
  12. package/lib/index.js +7 -1
  13. package/lib/index.js.map +1 -1
  14. package/lib/inverse-client.d.ts +5 -13
  15. package/lib/inverse-client.js +6 -13
  16. package/lib/inverse-client.js.map +1 -1
  17. package/lib/inverse-futures-client.d.ts +4 -12
  18. package/lib/inverse-futures-client.js +5 -12
  19. package/lib/inverse-futures-client.js.map +1 -1
  20. package/lib/linear-client.d.ts +4 -12
  21. package/lib/linear-client.js +5 -12
  22. package/lib/linear-client.js.map +1 -1
  23. package/lib/spot-client-v3.d.ts +105 -0
  24. package/lib/spot-client-v3.js +222 -0
  25. package/lib/spot-client-v3.js.map +1 -0
  26. package/lib/spot-client.d.ts +5 -12
  27. package/lib/spot-client.js +6 -12
  28. package/lib/spot-client.js.map +1 -1
  29. package/lib/types/index.d.ts +1 -1
  30. package/lib/types/index.js +1 -1
  31. package/lib/types/index.js.map +1 -1
  32. package/lib/types/request/account-asset.d.ts +76 -0
  33. package/lib/types/request/account-asset.js +3 -0
  34. package/lib/types/request/account-asset.js.map +1 -0
  35. package/lib/types/request/copy-trading.d.ts +47 -0
  36. package/lib/types/request/copy-trading.js +3 -0
  37. package/lib/types/request/copy-trading.js.map +1 -0
  38. package/lib/types/request/index.d.ts +7 -0
  39. package/lib/types/request/index.js +7 -0
  40. package/lib/types/request/index.js.map +1 -1
  41. package/lib/types/request/spot.d.ts +72 -0
  42. package/lib/types/{spot.js → request/spot.js} +0 -0
  43. package/lib/types/{spot.js.map → request/spot.js.map} +1 -1
  44. package/lib/types/request/unified-margin.d.ts +223 -0
  45. package/lib/types/request/unified-margin.js +3 -0
  46. package/lib/types/request/unified-margin.js.map +1 -0
  47. package/lib/types/request/usdc-options.d.ts +119 -0
  48. package/lib/types/request/usdc-options.js +3 -0
  49. package/lib/types/request/usdc-options.js.map +1 -0
  50. package/lib/types/request/usdc-perp.d.ts +86 -0
  51. package/lib/types/request/usdc-perp.js +3 -0
  52. package/lib/types/request/usdc-perp.js.map +1 -0
  53. package/lib/types/request/usdc-shared.d.ts +29 -0
  54. package/lib/types/request/usdc-shared.js +3 -0
  55. package/lib/types/request/usdc-shared.js.map +1 -0
  56. package/lib/types/shared.d.ts +16 -5
  57. package/lib/types/websockets.d.ts +40 -0
  58. package/lib/types/websockets.js +3 -0
  59. package/lib/types/websockets.js.map +1 -0
  60. package/lib/unified-margin-client.d.ts +137 -0
  61. package/lib/unified-margin-client.js +269 -0
  62. package/lib/unified-margin-client.js.map +1 -0
  63. package/lib/usdc-option-client.d.ts +100 -0
  64. package/lib/usdc-option-client.js +186 -0
  65. package/lib/usdc-option-client.js.map +1 -0
  66. package/lib/usdc-perpetual-client.d.ts +88 -0
  67. package/lib/usdc-perpetual-client.js +181 -0
  68. package/lib/usdc-perpetual-client.js.map +1 -0
  69. package/lib/util/BaseRestClient.d.ts +15 -2
  70. package/lib/util/BaseRestClient.js +93 -29
  71. package/lib/util/BaseRestClient.js.map +1 -1
  72. package/lib/util/WsStore.d.ts +28 -8
  73. package/lib/util/WsStore.js +11 -3
  74. package/lib/util/WsStore.js.map +1 -1
  75. package/lib/util/index.d.ts +5 -0
  76. package/lib/util/index.js +18 -0
  77. package/lib/util/index.js.map +1 -0
  78. package/lib/{logger.d.ts → util/logger.d.ts} +0 -0
  79. package/lib/{logger.js → util/logger.js} +0 -0
  80. package/lib/util/logger.js.map +1 -0
  81. package/lib/util/requestUtils.d.ts +5 -1
  82. package/lib/util/requestUtils.js +9 -20
  83. package/lib/util/requestUtils.js.map +1 -1
  84. package/lib/util/websocket-util.d.ts +8 -0
  85. package/lib/util/websocket-util.js +39 -0
  86. package/lib/util/websocket-util.js.map +1 -0
  87. package/lib/websocket-client.d.ts +6 -58
  88. package/lib/websocket-client.js +63 -114
  89. package/lib/websocket-client.js.map +1 -1
  90. package/package.json +1 -1
  91. package/lib/logger.js.map +0 -1
  92. package/lib/types/spot.d.ts +0 -30
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.USDCOptionClient = void 0;
16
+ const util_1 = require("./util");
17
+ const BaseRestClient_1 = __importDefault(require("./util/BaseRestClient"));
18
+ /**
19
+ * REST API client for USDC Option APIs
20
+ */
21
+ class USDCOptionClient extends BaseRestClient_1.default {
22
+ getClientType() {
23
+ return util_1.REST_CLIENT_TYPE_ENUM.v3;
24
+ }
25
+ fetchServerTime() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const res = yield this.getServerTime();
28
+ return Number(res.time_now);
29
+ });
30
+ }
31
+ /**
32
+ *
33
+ * Market Data Endpoints
34
+ *
35
+ */
36
+ /** Query order book info. Each side has a depth of 25 orders. */
37
+ getOrderBook(symbol) {
38
+ return this.get('/option/usdc/openapi/public/v1/order-book', { symbol });
39
+ }
40
+ /** Fetch trading rules (such as min/max qty). Query for all if blank. */
41
+ getContractInfo(params) {
42
+ return this.get('/option/usdc/openapi/public/v1/symbols', params);
43
+ }
44
+ /** Get a symbol price/statistics ticker */
45
+ getSymbolTicker(symbol) {
46
+ return this.get('/option/usdc/openapi/public/v1/tick', { symbol });
47
+ }
48
+ /** Get delivery information */
49
+ getDeliveryPrice(params) {
50
+ return this.get('/option/usdc/openapi/public/v1/delivery-price', params);
51
+ }
52
+ /** Returned records are Taker Buy in default. */
53
+ getLast500Trades(params) {
54
+ return this.get('/option/usdc/openapi/public/v1/query-trade-latest', params);
55
+ }
56
+ /**
57
+ * The data is in hourly.
58
+ * If time field is not passed, it returns the recent 1 hour data by default.
59
+ * It could be any timeframe by inputting startTime & endTime, but it must satisfy [endTime - startTime] <= 30 days.
60
+ * It returns all data in 2 years when startTime & endTime are not passed.
61
+ * Both startTime & endTime entered together or both are left blank
62
+ */
63
+ getHistoricalVolatility(params) {
64
+ return this.get('/option/usdc/openapi/public/v1/query-historical-volatility', params);
65
+ }
66
+ /**
67
+ *
68
+ * Account Data Endpoints
69
+ *
70
+ */
71
+ /** -> Order API */
72
+ /**
73
+ * Place an order using the USDC Derivatives Account.
74
+ * The request status can be queried in real-time.
75
+ * The response parameters must be queried through a query or a WebSocket response.
76
+ */
77
+ submitOrder(params) {
78
+ return this.postPrivate('/option/usdc/openapi/private/v1/place-order', params);
79
+ }
80
+ /**
81
+ * Each request supports a max. of four orders. The reduceOnly parameter should be separate and unique for each order in the request.
82
+ */
83
+ batchSubmitOrders(orderRequest) {
84
+ return this.postPrivate('/option/usdc/openapi/private/v1/batch-place-orders', { orderRequest });
85
+ }
86
+ /** For Options, at least one of the three parameters — price, quantity or implied volatility — must be input. */
87
+ modifyOrder(params) {
88
+ return this.postPrivate('/option/usdc/openapi/private/v1/replace-order', params);
89
+ }
90
+ /** Each request supports a max. of four orders. The reduceOnly parameter should be separate and unique for each order in the request. */
91
+ batchModifyOrders(replaceOrderRequest) {
92
+ return this.postPrivate('/option/usdc/openapi/private/v1/batch-replace-orders', { replaceOrderRequest });
93
+ }
94
+ /** Cancel order */
95
+ cancelOrder(params) {
96
+ return this.postPrivate('/option/usdc/openapi/private/v1/cancel-order', params);
97
+ }
98
+ /** Batch cancel orders */
99
+ batchCancelOrders(cancelRequest) {
100
+ return this.postPrivate('/option/usdc/openapi/private/v1/batch-cancel-orders', { cancelRequest });
101
+ }
102
+ /** This is used to cancel all active orders. The real-time response indicates whether the request is successful, depending on retCode. */
103
+ cancelActiveOrders(params) {
104
+ return this.postPrivate('/option/usdc/openapi/private/v1/cancel-all', params);
105
+ }
106
+ /** Query Unfilled/Partially Filled Orders(real-time), up to last 7 days of partially filled/unfilled orders */
107
+ getActiveRealtimeOrders(params) {
108
+ return this.getPrivate('/option/usdc/openapi/private/v1/trade/query-active-orders', params);
109
+ }
110
+ /** Query Unfilled/Partially Filled Orders */
111
+ getActiveOrders(params) {
112
+ return this.postPrivate('/option/usdc/openapi/private/v1/query-active-orders', params);
113
+ }
114
+ /** Query order history. The endpoint only supports up to 30 days of queried records */
115
+ getHistoricOrders(params) {
116
+ return this.postPrivate('/option/usdc/openapi/private/v1/query-order-history', params);
117
+ }
118
+ /** Query trade history. The endpoint only supports up to 30 days of queried records. An error will be returned if startTime is more than 30 days. */
119
+ getOrderExecutionHistory(params) {
120
+ return this.postPrivate('/option/usdc/openapi/private/v1/execution-list', params);
121
+ }
122
+ /** -> Account API */
123
+ /** The endpoint only supports up to 30 days of queried records. An error will be returned if startTime is more than 30 days. */
124
+ getTransactionLog(params) {
125
+ return this.postPrivate('/option/usdc/openapi/private/v1/query-transaction-log', params);
126
+ }
127
+ /** Wallet info for USDC account. */
128
+ getBalances() {
129
+ return this.postPrivate('/option/usdc/openapi/private/v1/query-wallet-balance');
130
+ }
131
+ /** Asset Info */
132
+ getAssetInfo(baseCoin) {
133
+ return this.postPrivate('/option/usdc/openapi/private/v1/query-asset-info', { baseCoin });
134
+ }
135
+ /**
136
+ * If USDC derivatives account balance is greater than X, you can open PORTFOLIO_MARGIN, and if it is less than Y, it will automatically close PORTFOLIO_MARGIN and change back to REGULAR_MARGIN. X and Y will be adjusted according to operational requirements.
137
+ * Rest API returns the result of checking prerequisites. You could get the real status of margin mode change by subscribing margin mode.
138
+ */
139
+ setMarginMode(newMarginMode) {
140
+ return this.postPrivate('/option/usdc/private/asset/account/setMarginMode', { setMarginMode: newMarginMode });
141
+ }
142
+ /** Query margin mode for USDC account. */
143
+ getMarginMode() {
144
+ return this.postPrivate('/option/usdc/openapi/private/v1/query-margin-info');
145
+ }
146
+ /** -> Positions API */
147
+ /** Query my positions */
148
+ getPositions(params) {
149
+ return this.postPrivate('/option/usdc/openapi/private/v1/query-position', params);
150
+ }
151
+ /** Query Delivery History */
152
+ getDeliveryHistory(params) {
153
+ return this.postPrivate('/option/usdc/openapi/private/v1/query-delivery-list', params);
154
+ }
155
+ /** Query Positions Info Upon Expiry */
156
+ getPositionsInfoUponExpiry(params) {
157
+ return this.postPrivate('/option/usdc/openapi/private/v1/query-position-exp-date', params);
158
+ }
159
+ /** -> Market Maker Protection */
160
+ /** modifyMMP */
161
+ modifyMMP(params) {
162
+ return this.postPrivate('/option/usdc/openapi/private/v1/mmp-modify', params);
163
+ }
164
+ /** resetMMP */
165
+ resetMMP(currency) {
166
+ return this.postPrivate('/option/usdc/openapi/private/v1/mmp-reset', {
167
+ currency,
168
+ });
169
+ }
170
+ /** queryMMPState */
171
+ queryMMPState(baseCoin) {
172
+ return this.postPrivate('/option/usdc/openapi/private/v1/get-mmp-state', {
173
+ baseCoin,
174
+ });
175
+ }
176
+ /**
177
+ *
178
+ * API Data Endpoints
179
+ *
180
+ */
181
+ getServerTime() {
182
+ return this.get('/v2/public/time');
183
+ }
184
+ }
185
+ exports.USDCOptionClient = USDCOptionClient;
186
+ //# sourceMappingURL=usdc-option-client.js.map
@@ -0,0 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QACvB,OAAO,IAAI,CAAC,WAAW,CAAC,2CAA2C,EAAE;YACnE,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;IAED,oBAAoB;IACpB,aAAa,CAAC,QAAgB;QAC5B,OAAO,IAAI,CAAC,WAAW,CAAC,+CAA+C,EAAE;YACvE,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IAEH,aAAa;QACX,OAAO,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;CACF;AA1SD,4CA0SC"}
@@ -0,0 +1,88 @@
1
+ import { APIResponseWithTime, SymbolLimitParam, SymbolPeriodLimitParam, APIResponseV3, USDCKlineRequest, USDCLast500TradesRequest, USDCOpenInterestRequest, USDCOrderFilter, USDCPerpActiveOrdersRequest, USDCPerpCancelOrderRequest, USDCPerpHistoricOrdersRequest, USDCPerpModifyOrderRequest, USDCPerpOrderRequest, USDCPositionsRequest, USDCSymbolDirectionLimit, USDCSymbolDirectionLimitCursor, USDCTransactionLogRequest } from './types';
2
+ import BaseRestClient from './util/BaseRestClient';
3
+ /**
4
+ * REST API client for USDC Perpetual APIs
5
+ */
6
+ export declare class USDCPerpetualClient extends BaseRestClient {
7
+ getClientType(): "v3";
8
+ fetchServerTime(): Promise<number>;
9
+ /**
10
+ *
11
+ * Market Data Endpoints
12
+ *
13
+ */
14
+ getOrderBook(symbol: string): Promise<APIResponseV3<any>>;
15
+ /** Fetch trading rules (such as min/max qty). Query for all if blank. */
16
+ getContractInfo(params?: USDCSymbolDirectionLimit): Promise<APIResponseV3<any>>;
17
+ /** Get a symbol price/statistics ticker */
18
+ getSymbolTicker(symbol: string): Promise<APIResponseV3<any>>;
19
+ getCandles(params: USDCKlineRequest): Promise<APIResponseV3<any>>;
20
+ getMarkPrice(params: USDCKlineRequest): Promise<APIResponseV3<any>>;
21
+ getIndexPrice(params: USDCKlineRequest): Promise<APIResponseV3<any>>;
22
+ getIndexPremium(params: USDCKlineRequest): Promise<APIResponseV3<any>>;
23
+ getOpenInterest(params: USDCOpenInterestRequest): Promise<APIResponseV3<any>>;
24
+ getLargeOrders(params: SymbolLimitParam<string>): Promise<APIResponseV3<any>>;
25
+ getLongShortRatio(params: SymbolPeriodLimitParam<string>): Promise<APIResponseV3<any>>;
26
+ getLast500Trades(params: USDCLast500TradesRequest): Promise<APIResponseV3<any>>;
27
+ /**
28
+ *
29
+ * Account Data Endpoints
30
+ *
31
+ */
32
+ /** -> Order API */
33
+ /**
34
+ * Place an order using the USDC Derivatives Account.
35
+ * The request status can be queried in real-time.
36
+ * The response parameters must be queried through a query or a WebSocket response.
37
+ */
38
+ submitOrder(params: USDCPerpOrderRequest): Promise<APIResponseV3<any>>;
39
+ /** Active order parameters (such as quantity, price) and stop order parameters cannot be modified in one request at the same time. Please request modification separately. */
40
+ modifyOrder(params: USDCPerpModifyOrderRequest): Promise<APIResponseV3<any>>;
41
+ /** Cancel order */
42
+ cancelOrder(params: USDCPerpCancelOrderRequest): Promise<APIResponseV3<any>>;
43
+ /** Cancel all active orders. The real-time response indicates whether the request is successful, depending on retCode. */
44
+ cancelActiveOrders(symbol: string, orderFilter: USDCOrderFilter): Promise<APIResponseV3<any>>;
45
+ /** Query Unfilled/Partially Filled Orders */
46
+ getActiveOrders(params: USDCPerpActiveOrdersRequest): Promise<APIResponseV3<any>>;
47
+ /** Query order history. The endpoint only supports up to 30 days of queried records */
48
+ getHistoricOrders(params: USDCPerpHistoricOrdersRequest): Promise<APIResponseV3<any>>;
49
+ /** Query trade history. The endpoint only supports up to 30 days of queried records. An error will be returned if startTime is more than 30 days. */
50
+ getOrderExecutionHistory(params: USDCPerpActiveOrdersRequest): Promise<APIResponseV3<any>>;
51
+ /** -> Account API */
52
+ /** The endpoint only supports up to 30 days of queried records. An error will be returned if startTime is more than 30 days. */
53
+ getTransactionLog(params: USDCTransactionLogRequest): Promise<APIResponseV3<any>>;
54
+ /** Wallet info for USDC account. */
55
+ getBalances(): Promise<APIResponseV3<any>>;
56
+ /** Asset Info */
57
+ getAssetInfo(baseCoin?: string): Promise<APIResponseV3<any>>;
58
+ /**
59
+ * If USDC derivatives account balance is greater than X, you can open PORTFOLIO_MARGIN, and if it is less than Y, it will automatically close PORTFOLIO_MARGIN and change back to REGULAR_MARGIN. X and Y will be adjusted according to operational requirements.
60
+ * Rest API returns the result of checking prerequisites. You could get the real status of margin mode change by subscribing margin mode.
61
+ */
62
+ setMarginMode(newMarginMode: 'REGULAR_MARGIN' | 'PORTFOLIO_MARGIN'): Promise<APIResponseV3<any>>;
63
+ /** Query margin mode for USDC account. */
64
+ getMarginMode(): Promise<APIResponseV3<any>>;
65
+ /** -> Positions API */
66
+ /** Query my positions */
67
+ getPositions(params: USDCPositionsRequest): Promise<APIResponseV3<any>>;
68
+ /** Only for REGULAR_MARGIN */
69
+ setLeverage(symbol: string, leverage: string): Promise<APIResponseV3<any>>;
70
+ /** Query Settlement History */
71
+ getSettlementHistory(params?: USDCSymbolDirectionLimitCursor): Promise<APIResponseV3<any>>;
72
+ /** -> Risk Limit API */
73
+ /** Query risk limit */
74
+ getRiskLimit(symbol: string): Promise<APIResponseV3<any>>;
75
+ /** Set risk limit */
76
+ setRiskLimit(symbol: string, riskId: number): Promise<APIResponseV3<any>>;
77
+ /** -> Funding API */
78
+ /** Funding settlement occurs every 8 hours at 00:00 UTC, 08:00 UTC and 16:00 UTC. The current interval's fund fee settlement is based on the previous interval's fund rate. For example, at 16:00, the settlement is based on the fund rate generated at 8:00. The fund rate generated at 16:00 will be used at 0:00 the next day. */
79
+ getLastFundingRate(symbol: string): Promise<APIResponseV3<any>>;
80
+ /** Get predicted funding rate and my predicted funding fee */
81
+ getPredictedFundingRate(symbol: string): Promise<APIResponseV3<any>>;
82
+ /**
83
+ *
84
+ * API Data Endpoints
85
+ *
86
+ */
87
+ getServerTime(): Promise<APIResponseWithTime>;
88
+ }
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.USDCPerpetualClient = void 0;
16
+ const util_1 = require("./util");
17
+ const BaseRestClient_1 = __importDefault(require("./util/BaseRestClient"));
18
+ /**
19
+ * REST API client for USDC Perpetual APIs
20
+ */
21
+ class USDCPerpetualClient extends BaseRestClient_1.default {
22
+ getClientType() {
23
+ return util_1.REST_CLIENT_TYPE_ENUM.v3;
24
+ }
25
+ fetchServerTime() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const res = yield this.getServerTime();
28
+ return Number(res.time_now);
29
+ });
30
+ }
31
+ /**
32
+ *
33
+ * Market Data Endpoints
34
+ *
35
+ */
36
+ getOrderBook(symbol) {
37
+ return this.get('/perpetual/usdc/openapi/public/v1/order-book', { symbol });
38
+ }
39
+ /** Fetch trading rules (such as min/max qty). Query for all if blank. */
40
+ getContractInfo(params) {
41
+ return this.get('/perpetual/usdc/openapi/public/v1/symbols', params);
42
+ }
43
+ /** Get a symbol price/statistics ticker */
44
+ getSymbolTicker(symbol) {
45
+ return this.get('/perpetual/usdc/openapi/public/v1/tick', { symbol });
46
+ }
47
+ getCandles(params) {
48
+ return this.get('/perpetual/usdc/openapi/public/v1/kline/list', params);
49
+ }
50
+ getMarkPrice(params) {
51
+ return this.get('/perpetual/usdc/openapi/public/v1/mark-price-kline', params);
52
+ }
53
+ getIndexPrice(params) {
54
+ return this.get('/perpetual/usdc/openapi/public/v1/index-price-kline', params);
55
+ }
56
+ getIndexPremium(params) {
57
+ return this.get('/perpetual/usdc/openapi/public/v1/premium-index-kline', params);
58
+ }
59
+ getOpenInterest(params) {
60
+ return this.get('/perpetual/usdc/openapi/public/v1/open-interest', params);
61
+ }
62
+ getLargeOrders(params) {
63
+ return this.get('/perpetual/usdc/openapi/public/v1/big-deal', params);
64
+ }
65
+ getLongShortRatio(params) {
66
+ return this.get('/perpetual/usdc/openapi/public/v1/account-ratio', params);
67
+ }
68
+ getLast500Trades(params) {
69
+ return this.get('/option/usdc/openapi/public/v1/query-trade-latest', params);
70
+ }
71
+ /**
72
+ *
73
+ * Account Data Endpoints
74
+ *
75
+ */
76
+ /** -> Order API */
77
+ /**
78
+ * Place an order using the USDC Derivatives Account.
79
+ * The request status can be queried in real-time.
80
+ * The response parameters must be queried through a query or a WebSocket response.
81
+ */
82
+ submitOrder(params) {
83
+ return this.postPrivate('/perpetual/usdc/openapi/private/v1/place-order', params);
84
+ }
85
+ /** Active order parameters (such as quantity, price) and stop order parameters cannot be modified in one request at the same time. Please request modification separately. */
86
+ modifyOrder(params) {
87
+ return this.postPrivate('/perpetual/usdc/openapi/private/v1/replace-order', params);
88
+ }
89
+ /** Cancel order */
90
+ cancelOrder(params) {
91
+ return this.postPrivate('/perpetual/usdc/openapi/private/v1/cancel-order', params);
92
+ }
93
+ /** Cancel all active orders. The real-time response indicates whether the request is successful, depending on retCode. */
94
+ cancelActiveOrders(symbol, orderFilter) {
95
+ return this.postPrivate('/perpetual/usdc/openapi/private/v1/cancel-all', {
96
+ symbol,
97
+ orderFilter,
98
+ });
99
+ }
100
+ /** Query Unfilled/Partially Filled Orders */
101
+ getActiveOrders(params) {
102
+ return this.postPrivate('/option/usdc/openapi/private/v1/query-active-orders', params);
103
+ }
104
+ /** Query order history. The endpoint only supports up to 30 days of queried records */
105
+ getHistoricOrders(params) {
106
+ return this.postPrivate('/option/usdc/openapi/private/v1/query-order-history', params);
107
+ }
108
+ /** Query trade history. The endpoint only supports up to 30 days of queried records. An error will be returned if startTime is more than 30 days. */
109
+ getOrderExecutionHistory(params) {
110
+ return this.postPrivate('/option/usdc/openapi/private/v1/execution-list', params);
111
+ }
112
+ /** -> Account API */
113
+ /** The endpoint only supports up to 30 days of queried records. An error will be returned if startTime is more than 30 days. */
114
+ getTransactionLog(params) {
115
+ return this.postPrivate('/option/usdc/openapi/private/v1/query-transaction-log', params);
116
+ }
117
+ /** Wallet info for USDC account. */
118
+ getBalances() {
119
+ return this.postPrivate('/option/usdc/openapi/private/v1/query-wallet-balance');
120
+ }
121
+ /** Asset Info */
122
+ getAssetInfo(baseCoin) {
123
+ return this.postPrivate('/option/usdc/openapi/private/v1/query-asset-info', { baseCoin });
124
+ }
125
+ /**
126
+ * If USDC derivatives account balance is greater than X, you can open PORTFOLIO_MARGIN, and if it is less than Y, it will automatically close PORTFOLIO_MARGIN and change back to REGULAR_MARGIN. X and Y will be adjusted according to operational requirements.
127
+ * Rest API returns the result of checking prerequisites. You could get the real status of margin mode change by subscribing margin mode.
128
+ */
129
+ setMarginMode(newMarginMode) {
130
+ return this.postPrivate('/option/usdc/private/asset/account/setMarginMode', { setMarginMode: newMarginMode });
131
+ }
132
+ /** Query margin mode for USDC account. */
133
+ getMarginMode() {
134
+ return this.postPrivate('/option/usdc/openapi/private/v1/query-margin-info');
135
+ }
136
+ /** -> Positions API */
137
+ /** Query my positions */
138
+ getPositions(params) {
139
+ return this.postPrivate('/option/usdc/openapi/private/v1/query-position', params);
140
+ }
141
+ /** Only for REGULAR_MARGIN */
142
+ setLeverage(symbol, leverage) {
143
+ return this.postPrivate('/perpetual/usdc/openapi/private/v1/position/leverage/save', { symbol, leverage });
144
+ }
145
+ /** Query Settlement History */
146
+ getSettlementHistory(params) {
147
+ return this.postPrivate('/option/usdc/openapi/private/v1/session-settlement', params);
148
+ }
149
+ /** -> Risk Limit API */
150
+ /** Query risk limit */
151
+ getRiskLimit(symbol) {
152
+ return this.getPrivate('/perpetual/usdc/openapi/public/v1/risk-limit/list', {
153
+ symbol,
154
+ });
155
+ }
156
+ /** Set risk limit */
157
+ setRiskLimit(symbol, riskId) {
158
+ return this.postPrivate('/perpetual/usdc/openapi/private/v1/position/set-risk-limit', { symbol, riskId });
159
+ }
160
+ /** -> Funding API */
161
+ /** Funding settlement occurs every 8 hours at 00:00 UTC, 08:00 UTC and 16:00 UTC. The current interval's fund fee settlement is based on the previous interval's fund rate. For example, at 16:00, the settlement is based on the fund rate generated at 8:00. The fund rate generated at 16:00 will be used at 0:00 the next day. */
162
+ getLastFundingRate(symbol) {
163
+ return this.get('/perpetual/usdc/openapi/public/v1/prev-funding-rate', {
164
+ symbol,
165
+ });
166
+ }
167
+ /** Get predicted funding rate and my predicted funding fee */
168
+ getPredictedFundingRate(symbol) {
169
+ return this.postPrivate('/perpetual/usdc/openapi/private/v1/predicted-funding', { symbol });
170
+ }
171
+ /**
172
+ *
173
+ * API Data Endpoints
174
+ *
175
+ */
176
+ getServerTime() {
177
+ return this.get('/v2/public/time');
178
+ }
179
+ }
180
+ exports.USDCPerpetualClient = USDCPerpetualClient;
181
+ //# sourceMappingURL=usdc-perpetual-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usdc-perpetual-client.js","sourceRoot":"","sources":["../src/usdc-perpetual-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAmBA,iCAA+C;AAC/C,2EAAmD;AAEnD;;GAEG;AACH,MAAa,mBAAoB,SAAQ,wBAAc;IACrD,aAAa;QACX,OAAO,4BAAqB,CAAC,EAAE,CAAC;IAClC,CAAC;IAEK,eAAe;;YACnB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;YACvC,OAAO,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC9B,CAAC;KAAA;IAED;;;;OAIG;IAEH,YAAY,CAAC,MAAc;QACzB,OAAO,IAAI,CAAC,GAAG,CAAC,8CAA8C,EAAE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CAAC,CAAC;IACrC,CAAC;CACF;AA1RD,kDA0RC"}
@@ -9,16 +9,29 @@ export default abstract class BaseRestClient {
9
9
  private key;
10
10
  private secret;
11
11
  private clientType;
12
- /** Function that calls exchange API to query & resolve server time, used by time sync */
12
+ /** Function that calls exchange API to query & resolve server time, used by time sync, disabled by default */
13
13
  abstract fetchServerTime(): Promise<number>;
14
- constructor(key: string | undefined, secret: string | undefined, baseUrl: string, options: RestClientOptions | undefined, requestOptions: AxiosRequestConfig | undefined, clientType: RestClientType);
14
+ /** Defines the client type (affecting how requests & signatures behave) */
15
+ abstract getClientType(): RestClientType;
16
+ /**
17
+ * Create an instance of the REST client
18
+ * @param {string} key - your API key
19
+ * @param {string} secret - your API secret
20
+ * @param {boolean} [useLivenet=false]
21
+ * @param {RestClientOptions} [restClientOptions={}] options to configure REST API connectivity
22
+ * @param {AxiosRequestConfig} [requestOptions={}] HTTP networking options for axios
23
+ */
24
+ constructor(key?: string | undefined, secret?: string | undefined, useLivenet?: boolean, options?: RestClientOptions, requestOptions?: AxiosRequestConfig);
15
25
  private isSpotClient;
26
+ private isUSDCClient;
16
27
  get(endpoint: string, params?: any): Promise<any>;
17
28
  post(endpoint: string, params?: any): Promise<any>;
18
29
  getPrivate(endpoint: string, params?: any): Promise<any>;
19
30
  postPrivate(endpoint: string, params?: any): Promise<any>;
20
31
  deletePrivate(endpoint: string, params?: any): Promise<any>;
21
32
  private prepareSignParams;
33
+ /** Returns an axios request object. Handles signing process automatically if this is a private API call */
34
+ private buildRequest;
22
35
  /**
23
36
  * @private Make a HTTP request to a specific endpoint. Private endpoints are automatically signed.
24
37
  */