UNPKG

bybit-api

Version:

Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.

2,154 lines (2,118 loc) 395 kB
This file is a merged representation of a subset of the codebase, containing files not matching ignore patterns, combined into a single document by Repomix. The content has been processed where content has been compressed (code blocks are separated by ⋮---- delimiter). ================================================================ File Summary ================================================================ Purpose: -------- This file contains a packed representation of a subset of the repository's contents that is considered the most important context. It is designed to be easily consumable by AI systems for analysis, code review, or other automated processes. File Format: ------------ The content is organized as follows: 1. This summary section 2. Repository information 3. Directory structure 4. Repository files (if enabled) 5. Multiple file entries, each consisting of: a. A separator line (================) b. The file path (File: path/to/file) c. Another separator line d. The full contents of the file e. A blank line Usage Guidelines: ----------------- - This file should be treated as read-only. Any changes should be made to the original repository files, not this packed version. - When processing this file, use the file path to distinguish between different files in the repository. - Be aware that this file may contain sensitive information. Handle it with the same level of security as you would the original repository. Notes: ------ - Some files may have been excluded based on .gitignore rules and Repomix's configuration - Binary files are not included in this packed representation. Please refer to the Repository Structure section for a complete list of file paths, including binary files - Files matching these patterns are excluded: .github/, examples/apidoc/, docs/images/, docs/endpointFunctionList.md, test/, src/util/ - Files matching patterns in .gitignore are excluded - Files matching default ignore patterns are excluded - Content has been compressed - code blocks are separated by ⋮---- delimiter - Files are sorted by Git change count (files with more changes are at the bottom) ================================================================ Directory Structure ================================================================ examples/ deprecated/ README.md demo-trading.ts fasterHmacSign.ts README.md rest-v5-all.ts rest-v5-custom-url.ts rest-v5-next-cursor.ts rest-v5-p2p.ts rest-v5-private.ts rest-v5-proxies.ts rest-v5-proxies2.ts rest-v5-public.ts RSA-sign.md RSA-sign.ts ws-api-client.ts ws-api-raw-events.ts ws-api-raw-promises.ts ws-private-v5.ts ws-public-allLiquidations.ts ws-public-v5.ts src/ constants/ enum.ts types/ request/ account-asset.ts contract.ts copy-trading.ts index.ts inverse.ts linear.ts unified-margin.ts usdc-options.ts usdc-perp.ts usdc-shared.ts v5-account.ts v5-asset.ts v5-broker.ts v5-crypto-loan.ts v5-earn.ts v5-market.ts v5-p2p-trading.ts v5-position.ts v5-pre-upgrade.ts v5-rfq.ts v5-spot-leverage-token.ts v5-spreadtrading.ts v5-trade.ts v5-user.ts response/ account-asset.ts contract.ts index.ts shared.ts spot.ts unified-margin.ts usdt-perp.ts v5-account.ts v5-asset.ts v5-broker.ts v5-crypto-loan.ts v5-earn.ts v5-market.ts v5-p2p-trading.ts v5-position.ts v5-preupgrade.ts v5-rfq.ts v5-spot-leverage-token.ts v5-spreadtrading.ts v5-trade.ts v5-user.ts websockets/ index.ts ws-api.ts ws-confirmations.ts ws-events.ts ws-general.ts index.ts shared-v5.ts shared.ts index.ts rest-client-v5.ts spot-client-v3.ts websocket-api-client.ts websocket-client.ts webpack/ webpack.config.js .eslintrc.cjs .gitignore .jshintrc .nvmrc .prettierrc index.js jest.config.ts jsconfig.json LICENSE.md package.json README.md tea.yaml tsconfig.build.json tsconfig.examples.json tsconfig.json tsconfig.linting.json tsconfig.test.json ================================================================ Files ================================================================ ================ File: examples/deprecated/README.md ================ # Deprecated Examples The examples in this folder use old/deprecated/obsolete APIs. They should all have a modern alternative. As of December 2023, use the V5 APIs & WebSockets. ================ File: examples/demo-trading.ts ================ import { DefaultLogger, RestClientV5, WebsocketClient } from '../src/index'; ⋮---- // or // import { RestClientV5 } from 'bybit-api'; ⋮---- /** * * * This example demonstrates how to use Bybit's demo trading functionality, both for REST and WS. * * Refer to the API docs for more information: https://bybit-exchange.github.io/docs/v5/demo * * */ ⋮---- /** * Set this to true to enable demo trading: */ ⋮---- // Optional, uncomment the "trace" override to log a lot more info about what the WS client is doing ⋮---- // trace: (...params) => console.log('trace', ...params), ⋮---- /** * Set this to true to enable demo trading for the private account data WS * Topics: order,execution,position,wallet,greeks */ ⋮---- function setWsClientEventListeners( websocketClient: WebsocketClient, accountRef: string, ): Promise<void> ⋮---- // console.log('raw message received ', JSON.stringify(data, null, 2)); ⋮---- // Simple promise to ensure we're subscribed before trying anything else ⋮---- // Start trading ⋮---- /** Simple examples for private REST API calls with bybit's V5 REST APIs */ ⋮---- // Trade USDT linear perps ================ File: examples/README.md ================ # Examples These samples can be executed using `ts-node`: ``` ts-node ./examples/rest-spot-public.ts ``` ================ File: examples/rest-v5-all.ts ================ import { RestClientV5 } from '../src/index'; ⋮---- // or // import { RestClientV5 } from 'bybit-api'; ⋮---- /** * If you don't plan on making any private api calls, * you can instance the REST client without any parameters: * * const client = new RestClientV5(); */ ================ File: examples/rest-v5-custom-url.ts ================ import { RestClientV5 } from '../src/index'; ⋮---- // or // import { RestClientV5 } from 'bybit-api'; ⋮---- /** * The first parameter of the REST client allows you to pass any configuration parameters supported by the SDK. * * These include API keys, if you wish to use private endpoints, but also expose other features such as * setting a custom base URL (e.g. for Turkish users). * * Refer to the API documentation for a complete list of domains: https://bybit-exchange.github.io/docs/v5/guide#authentication */ ⋮---- /** * You can pass a completely custom base URL, * e.g. if you're trying to use a domain that hasn't been added yet (please let us know) */ // baseUrl: 'https://api5.bybit.com', // // /** * * There are also predefined API regions, which you can easily use with the "apiRegion" property: * */ // // // default: routes to api.bybit.com // apiRegion: 'default', // // // bytick: routes to api.bytick.com // apiRegion: 'bytick', // // // NL: routes to api.bybit.nl (for Netherland users) // apiRegion: 'NL', // // // HK: routes to api.byhkbit.com (for Hong Kong users) // apiRegion: 'HK', // // // TK: routes to api.bybit-tr.com (for Turkey users) // apiRegion: 'TK', ================ File: examples/rest-v5-next-cursor.ts ================ import { RestClientV5, UniversalTransferRecordV5 } from '../src/index'; ⋮---- // or // import { RestClientV5 } from 'bybit-api'; ⋮---- async function getAllUniversalTransfers() ⋮---- limit: 50, // Maximum page size per request cursor: nextCursor || undefined, // Only send cursor if we have one ⋮---- // Optional: Add a small delay to avoid rate limits ================ File: examples/rest-v5-proxies.ts ================ import { RestClientV5 } from '../src/index'; ⋮---- // or // import { RestClientV5 } from 'bybit-api'; ⋮---- // Sometimes using a proxy introduces recv timestamp errors (due to the extra latency) // If that happens, you can try increasing the recv window (which is 5000ms by default) // recv_window: 10000, ⋮---- /** * Axios has a native way of supporting http/https proxies. It works for most proxy services but not all. * If you have issues making any proxied requests this way, take a look at the rest-v5-proxies2.ts example using the https-proxy-agent. */ ⋮---- protocol: 'http', // or 'https' ⋮---- // const orders = await client.batchSubmitOrders('linear', [ // { // symbol: 'ETHUSDT', // orderType: 'Limit', // side: 'Buy', // qty: '1', // orderIv: '6', // timeInForce: 'GTC', // orderLinkId: 'option-test-001', // mmp: false, // reduceOnly: false, // }, // { // symbol: 'ETHUSDT', // orderType: 'Limit', // side: 'Sell', // qty: '2', // price: '700', // timeInForce: 'GTC', // orderLinkId: 'option-test-001', // mmp: false, // reduceOnly: false, // }, // ]); ⋮---- // console.log('orders: ', JSON.stringify(orders, null, 2)); ================ File: examples/rest-v5-proxies2.ts ================ // @ts-ignore import { HttpsProxyAgent } from 'https-proxy-agent'; ⋮---- import { RestClientV5 } from '../src/index'; ⋮---- // or // import { RestClientV5 } from 'bybit-api'; ⋮---- /** * Some proxy services don't work with the proxy configuration that axios supports. * * For these, you can try using HttpsProxyAgent or SocksProxyAgent (depending on your proxy type, HTTP or SOCKS). * * The following example uses the HttpsProxyAgent (via the npm module https-proxy-agent). */ ⋮---- // Sometimes using a proxy introduces recv timestamp errors (due to the extra latency) // If that happens, you can try increasing the recv window (which is 5000ms by default) // recv_window: 10000, ================ File: examples/rest-v5-public.ts ================ import { RestClientV5 } from '../src/index'; ⋮---- // or // import { RestClientV5 } from 'bybit-api'; ⋮---- /** * If you don't plan on making any private api calls, * you can instance the REST client without any parameters */ ⋮---- // const klineResult = await client.getKline({ // category: 'linear', // interval: '15', // symbol: 'BTCUSDT', // }); // console.log('klineResult: ', klineResult); ⋮---- // const markPriceKlineResult = await client.getMarkPriceKline({ // category: 'linear', // interval: '15', // symbol: 'BTCUSDT', // }); // console.log('markPriceKlineResult: ', markPriceKlineResult); ⋮---- // const indexPriceKline = await client.getIndexPriceKline({ // category: 'linear', // interval: '15', // symbol: 'BTCUSDT', // }); // console.log('indexPriceKline: ', indexPriceKline); ⋮---- // const openInterest = await client.getOpenInterest({ // category: 'linear', // symbol: 'BTCUSDT', // intervalTime: '5min', // }); ⋮---- // console.log( // JSON.stringify( // tickers.result.list.map((ticker) => ticker.symbol), // null, // 2, // ), // ); ⋮---- // openInterest.result.list.forEach((row) => { // console.log('int: ', { // timestamp: row.timestamp, // value: row.openInterest, // }); // }); // console.log('openInterest: ', openInterest.result.list); ================ File: examples/ws-api-client.ts ================ import { DefaultLogger, WebsocketAPIClient } from '../src'; ⋮---- // or // import { DefaultLogger, WebsocketAPIClient } from 'bybit-api'; // const { DefaultLogger, WebsocketAPIClient } = require('bybit-api'); ⋮---- // function attachEventHandlers<TWSClient extends WebsocketClient>( // wsClient: TWSClient, // ): void { // wsClient.on('update', (data) => { // console.log('raw message received ', JSON.stringify(data)); // }); // wsClient.on('open', (data) => { // console.log('ws connected', data.wsKey); // }); // wsClient.on('reconnect', ({ wsKey }) => { // console.log('ws automatically reconnecting.... ', wsKey); // }); // wsClient.on('reconnected', (data) => { // console.log('ws has reconnected ', data?.wsKey); // }); // wsClient.on('authenticated', (data) => { // console.log('ws has authenticated ', data?.wsKey); // }); // } ⋮---- async function main() ⋮---- // Optional ⋮---- // For a more detailed view of the WebsocketClient, enable the `trace` level by uncommenting the below line: // trace: (...params) => console.log('trace', ...params), ⋮---- // testnet: true, // Whether to use the testnet environment: https://testnet.bybit.com/app/user/api-management ⋮---- // Whether to use the livenet demo trading environment // Note: As of Jan 2025, demo trading only supports consuming events, it does // NOT support the WS API. // demoTrading: false, ⋮---- // If you want your own event handlers instead of the default ones with logs, // disable this setting and see the `attachEventHandlers` example below: // attachEventListeners: false ⋮---- logger, // Optional: inject a custom logger ⋮---- // Optional, see above "attachEventListeners". Attach basic event handlers, so nothing is left unhandled // attachEventHandlers(wsClient.getWSClient()); ⋮---- // Optional, if you see RECV Window errors, you can use this to manage time issues. // ! However, make sure you sync your system clock first! // https://github.com/tiagosiebler/awesome-crypto-examples/wiki/Timestamp-for-this-request-is-outside-of-the-recvWindow // wsClient.setTimeOffsetMs(-5000); ⋮---- // Optional: prepare the WebSocket API connection in advance. // This happens automatically but you can do this early before making any API calls, to prevent delays from a cold start. // await wsClient.getWSClient().connectWSAPI(); ================ File: src/constants/enum.ts ================ /** Full take profit/stop loss mode (a single TP order and a single SL order can be placed, covering the entire position) */ ⋮---- /** Partial take profit/stop loss mode (multiple TP and SL orders can be placed, covering portions of the position) */ ⋮---- /** This could mean bad request, incorrect value types or even incorrect/missing values */ ⋮---- /** API key requires specific whitelisted IPs, and this IP was not in the list */ ⋮---- /** Account not unified margin, update required */ ⋮---- /** Seen when placing an order */ ⋮---- /** Seen if a conditional order is too large */ ⋮---- /** E.g. trying to change position margin while on cross */ ⋮---- /** E.g. USDC Options trading, trying to access a symbol that is no longer active */ ⋮---- /** E.g. USDC Options trading when the account hasn't been opened for USDC Options yet */ ⋮---- /** * Position idx, used to identify positions in different position modes. * Required if you are under One-Way Mode: */ export enum LinearPositionIdx { OneWayMode = 0, BuySide = 1, SellSide = 2, } ================ File: src/types/request/account-asset.ts ================ export type TransferAccountType = | 'CONTRACT' | 'SPOT' | 'INVESTMENT' | 'OPTION' | 'UNIFIED'; ⋮---- export type TransferType = 'IN' | 'OUT'; ⋮---- export type TransferStatus = 'SUCCESS' | 'PENDING' | 'FAILED'; ⋮---- export type PageDirection = 'Prev' | 'Next'; ⋮---- export interface InternalTransferRequest { transfer_id: string; coin: string; amount: string; from_account_type: TransferAccountType; to_account_type: TransferAccountType; } ⋮---- export interface InternalTransferRequestV3 { transferId: string; coin: string; amount: string; fromAccountType: string; toAccountType: string; } ⋮---- export interface QueryInternalTransfersRequestV3 { transferId?: string; coin: string; status?: string; startTime?: number; endTime?: number; limit?: number; cursor?: string; } ⋮---- export interface SubAccountTransferRequest { transfer_id: string; coin: string; amount: string; sub_user_id: string; type: TransferType; } ⋮---- export interface SubAccountTransferRequestV3 { transferId?: string; coin?: string; status?: string; startTime?: number; endTime?: number; limit?: number; cursor?: string; } ⋮---- export interface TransferQueryRequest { transfer_id?: string; coin?: string; status?: TransferStatus; start_time?: number; end_time?: number; direction?: PageDirection; limit?: number; cursor?: string; } ⋮---- export interface EnableUniversalTransferRequest { /** A comma-separated list of subaccount UIDs, for example "123,45,14,26,46" */ transferable_sub_ids?: string; } ⋮---- /** A comma-separated list of subaccount UIDs, for example "123,45,14,26,46" */ ⋮---- export interface UniversalTransferRequest { transfer_id: string; coin: string; amount: string; from_member_id: string; to_member_id: string; from_account_type: TransferAccountType; to_account_type: TransferAccountType; } export interface SupportedDepositListRequest { coin?: string; chain?: string; page_index?: number; page_size?: number; } ⋮---- export interface DepositRecordsRequest { start_time?: number; end_time?: number; coin?: string; cursor?: string; direction?: PageDirection; limit?: number; } ⋮---- export interface WithdrawalRecordsRequest { withdraw_id?: number; start_time?: number; end_time?: number; coin?: string; cursor?: string; direction?: PageDirection; limit?: number; } ⋮---- export interface AccountAssetInformationRequest { /** Account type. Default value: ACCOUNT_TYPE_SPOT */ account_type?: string; coin?: string; } ⋮---- /** Account type. Default value: ACCOUNT_TYPE_SPOT */ ⋮---- export interface WithdrawalRequest { address: string; amount: string; coin: string; chain: string; tag?: string; } ⋮---- export interface UniversalTransferRequestV3 { transferId: string; coin: string; amount: string; fromMemberId: string; toMemberId: string; fromAccountType: TransferAccountType; toAccountType: TransferAccountType; } ⋮---- export interface UniversalTransferListRequestV3 { transferId?: string; coin: string; status?: string; startTime?: number; endTime?: number; limit?: number; cursor?: string; } ⋮---- export interface TransferCoinListRequestV3 { fromAccountType: TransferAccountType; toAccountType: TransferAccountType; } ⋮---- export interface SingleAccountCoinBalanceRequestV3 { memberId?: string; accountType: TransferAccountType; coin: string; withBonus?: '0' | '1'; } ⋮---- export interface AccountCoinBalancesRequestV3 { memberId?: string; accountType: TransferAccountType; coin?: string; withBonus?: '0' | '1'; } ⋮---- export interface AssetInfoRequestV3 { accountType?: TransferAccountType; coin?: string; } ⋮---- export interface SupportedDepositListRequestV3 { coin?: string; chain?: string; cursor?: string; limit?: number; } ⋮---- export interface DepositRecordQueryRequestV3 { startTime?: number; endTime?: number; coin?: string; cursor?: string; limit?: number; } ⋮---- export interface SubDepositRecordQueryRequestV3 { subMemberId: number; startTime?: number; endTime?: number; coin?: string; cursor?: string; limit?: number; } ⋮---- export interface WithdrawRecordQueryRequestV3 { withdrawID?: number; startTime?: number; endTime?: number; coin?: string; withdrawType?: string; cursor?: string; limit?: number; } ⋮---- export interface WithdrawCreateRequestV3 { coin: string; chain: string; address: string; tag?: string; amount: string; timestamp: number; forceChain?: 0 | 1; } ⋮---- export interface QueryDepositAddressRequestV3 { coin?: string; chainType?: string; } ⋮---- export interface QuerySubAccountDepositAddressRequestV3 { coin?: string; chainType?: string; subMemberId: string; } ⋮---- export interface CreateSubMemberRequestV3 { username: string; memberType: 1 | 6; switch?: 0 | 1; note?: string; } ⋮---- export interface CreateSubAPIKeyRequestV3 { subuid: string; note?: string; readOnly: 0 | 1; ips?: string[]; permissions: { ContractTrade?: string[]; Spot?: string[]; Wallet?: string[]; Options?: string[]; Derivatives?: string[]; Exchange?: string[]; }; } ⋮---- export interface ModifyAPIKeyRequestV3 { readOnly: number; ips?: string[]; permissions: { ContractTrade?: string[]; Spot?: string[]; Wallet?: string[]; Options?: string[]; Derivatives?: string[]; CopyTrading?: string[]; BlockTrade?: string[]; Exchange?: string[]; NFT?: string[]; }; } ================ File: src/types/request/contract.ts ================ import { OrderSide } from '../shared'; import { UMOrderType } from './unified-margin'; import { USDCOrderFilter, USDCTimeInForce } from './usdc-shared'; ⋮---- export interface ContractOrderRequest { symbol: string; side: OrderSide; orderType: UMOrderType; qty: string; timeInForce: USDCTimeInForce; price?: string; triggerDirection?: '1' | '2'; triggerPrice?: string; triggerBy?: string; positionIdx?: '0' | '1' | '2'; orderLinkId?: string; takeProfit?: string; stopLoss?: string; tpTriggerBy?: string; slTriggerBy?: string; reduceOnly?: boolean; closeOnTrigger?: boolean; tpslMode?: 'Partial' | 'Full'; tpOrderType?: UMOrderType; slOrderType?: UMOrderType; } ⋮---- export interface ContractHistoricOrdersRequest { orderId?: string; orderLinkId?: string; symbol: string; orderStatus?: string; orderFilter?: USDCOrderFilter; limit?: number; cursor?: string; } ⋮---- export interface ContractCancelOrderRequest { symbol: string; orderId?: string; orderLinkId?: string; } ⋮---- export interface ContractModifyOrderRequest { symbol: string; orderId?: string; orderLinkId?: string; price?: string; qty?: string; triggerPrice?: string; takeProfit?: string; stopLoss?: string; tpTriggerBy?: string; slTriggerBy?: string; triggerBy?: string; tpLimitPrice?: string; slLimitPrice?: string; } ⋮---- export interface ContractActiveOrdersRequest { symbol?: string; orderId?: string; orderLinkId?: string; settleCoin?: string; orderFilter?: USDCOrderFilter; limit?: number; } ⋮---- export interface ContractPositionsRequest { symbol?: string; settleCoin?: string; dataFilter?: string; } ⋮---- export interface ContractSetAutoAddMarginRequest { symbol: string; side: 'Buy' | 'Sell'; autoAddMargin: 1 | 0; positionIdx?: 0 | 1 | 2; } ⋮---- export interface ContractSetMarginSwitchRequest { symbol: string; tradeMode: 0 | 1; buyLeverage: string; sellLeverage: string; } ⋮---- export interface ContractSetPositionModeRequest { symbol?: string; coin?: string; mode: 0 | 3; } ⋮---- export interface ContractSetTPSLRequest { symbol: string; takeProfit?: string; stopLoss?: string; tpslMode?: 'Full' | 'Partial'; tpSize?: string; slSize?: string; tpTriggerBy?: string; slTriggerBy?: string; trailingStop?: string; activePrice?: string; tpLimitPrice?: string; slLimitPrice?: string; tpOrderType?: UMOrderType; slOrderType?: UMOrderType; /** 0-one-way, 1-buy side, 2-sell side */ positionIdx?: 0 | 1 | 2; } ⋮---- /** 0-one-way, 1-buy side, 2-sell side */ ⋮---- export interface ContractUserExecutionHistoryRequest { symbol: string; orderId?: string; startTime?: number; endTime?: number; execType?: 'Trade' | 'AdlTrade' | 'Funding' | 'BustTrade'; limit?: number; cursor?: string; } ⋮---- export interface ContractClosedPNLRequest { symbol: string; startTime?: number; endTime?: number; limit?: number; cursor?: string; } ⋮---- export interface ContractWalletFundRecordRequest { startTime?: string; endTime?: string; coin?: string; walletFundType?: string; limit?: string; cursor?: string; } ================ File: src/types/request/copy-trading.ts ================ import { OrderSide } from '../shared'; import { USDCOrderType } from './usdc-shared'; ⋮---- export interface CopyTradingOrderRequest { side: OrderSide; symbol: string; orderType: USDCOrderType; price: string; qty: string; takeProfit?: string; stopLoss?: string; tpTriggerBy?: string; slTriggerBy?: string; orderLinkId?: string; } ⋮---- export interface CopyTradingTradingStopRequest { symbol: string; parentOrderId: string; takeProfit?: string; stopLoss?: string; tpTriggerBy?: string; slTriggerBy?: string; parentOrderLinkId?: string; } ⋮---- export interface CopyTradingOrderListRequest { symbol?: string; orderId?: string; orderLinkId?: string; copyTradeOrderType?: string; } ⋮---- export interface CopyTradingCancelOrderRequest { symbol: string; orderId?: string; orderLinkId?: string; } ⋮---- export interface CopyTradingCloseOrderRequest { symbol: string; orderLinkId?: string; parentOrderId?: string; parentOrderLinkId?: string; } ⋮---- export interface CopyTradingTransferRequest { transferId: string; coin: string; amount: string; fromAccountType: string; toAccountType: string; } ================ File: src/types/request/inverse.ts ================ export interface InverseOrderRequest { side: string; symbol: string; order_type: string; qty: number; price?: number; time_in_force: string; take_profit?: number; stop_loss?: number; reduce_only?: boolean; tp_trigger_by?: 'LastPrice' | 'MarkPrice' | 'IndexPrice'; sl_trigger_by?: 'LastPrice' | 'MarkPrice' | 'IndexPrice'; close_on_trigger?: boolean; order_link_id?: string; } ⋮---- export interface InverseActiveOrdersRequest { symbol: string; order_status?: string; direction?: string; limit?: number; cursor?: string; } ⋮---- export interface InverseCancelOrderRequest { symbol: string; order_id?: string; order_link_id?: string; } ⋮---- export interface InverseReplaceOrderRequest { order_id?: string; order_link_id?: string; symbol: string; p_r_qty?: number; p_r_price?: string; take_profit?: number; stop_loss?: number; tp_trigger_by?: string; sl_trigger_by?: string; } ⋮---- export interface InverseGetOrderRequest { order_id?: string; order_link_id?: string; symbol: string; } ⋮---- export interface InverseConditionalOrderRequest { side: string; symbol: string; order_type: string; qty: string; price?: string; base_price: string; stop_px: string; time_in_force: string; trigger_by?: string; close_on_trigger?: boolean; order_link_id?: string; } ⋮---- export interface InverseActiveConditionalOrderRequest { symbol: string; stop_order_status?: string; direction?: string; limit?: number; cursor?: string; } ⋮---- export interface InverseCancelConditionalOrderRequest { symbol: string; stop_order_id?: string; order_link_id?: string; } ⋮---- export interface InverseReplaceConditionalOrderRequest { stop_order_id?: string; order_link_id?: string; symbol: string; p_r_qty?: number; p_r_price?: string; p_r_trigger_price?: string; } ⋮---- export interface InverseChangePositionMarginRequest { symbol: string; margin: string; } ⋮---- export interface InverseSetTradingStopRequest { symbol: string; take_profit?: number; stop_loss?: number; trailing_stop?: number; tp_trigger_by?: string; sl_trigger_by?: string; new_trailing_active?: number; } ⋮---- export interface InverseSetLeverageRequest { symbol: string; leverage: number; leverage_only?: boolean; } ⋮---- export interface InverseGetTradeRecordsRequest { order_id?: string; symbol: string; start_time?: number; page?: number; limit?: number; order?: string; } ⋮---- export interface InverseGetClosedPnlRequest { symbol: string; start_time?: number; end_time?: number; exec_type?: string; page?: number; limit?: number; } ⋮---- export interface InverseSetSlTpPositionModeRequest { symbol: string; tp_sl_mode: 'Full' | 'Partial'; } ⋮---- export interface InverseSetMarginTypeRequest { symbol: string; is_isolated: boolean; buy_leverage: number; sell_leverage: number; } ================ File: src/types/request/linear.ts ================ import { LinearPositionIdx, linearPositionModeEnum, positionTpSlModeEnum, } from '../../constants/enum'; import { OrderSide } from '../shared'; ⋮---- export interface LinearGetOrdersRequest { order_id?: string; order_link_id?: string; symbol: string; order?: string; page?: number; limit?: number; order_status?: string; } ⋮---- export interface LinearCancelOrderRequest { symbol: string; order_id?: string; order_link_id?: string; } ⋮---- export interface LinearReplaceOrderRequest { order_id?: string; order_link_id?: string; symbol: string; p_r_qty?: number; p_r_price?: number; take_profit?: number; stop_loss?: number; tp_trigger_by?: string; sl_trigger_by?: string; } ⋮---- export interface LinearGetOrderRequest { order_id?: string; order_link_id?: string; symbol: string; } ⋮---- export type LinearOrderType = 'Limit' | 'Market'; ⋮---- export type LinearTimeInForce = | 'GoodTillCancel' | 'ImmediateOrCancel' | 'FillOrKill' | 'PostOnly'; ⋮---- export interface NewLinearOrder { side: OrderSide; symbol: string; order_type: LinearOrderType; qty: number; price?: number; time_in_force: LinearTimeInForce; take_profit?: number; stop_loss?: number; tp_trigger_by?: string; sl_trigger_by?: string; reduce_only: boolean; close_on_trigger: boolean; order_link_id?: string; position_idx?: LinearPositionIdx; } ⋮---- export interface LinearConditionalOrderRequest { side: string; symbol: string; order_type: string; qty: number; price?: number; base_price: number; stop_px: number; time_in_force: string; trigger_by?: string; close_on_trigger?: boolean; order_link_id?: string; reduce_only: boolean; take_profit?: number; stop_loss?: number; tp_trigger_by?: string; sl_trigger_by?: string; } ⋮---- export interface LinearGetConditionalOrderRequest { stop_order_id?: string; order_link_id?: string; symbol: string; stop_order_status?: string; order?: string; page?: number; limit?: number; } ⋮---- export interface LinearCancelConditionalOrderRequest { symbol: string; stop_order_id?: string; order_link_id?: string; } ⋮---- export interface LinearReplaceConditionalOrderRequest { stop_order_id?: string; order_link_id?: string; symbol: string; p_r_qty?: number; p_r_price?: number; p_r_trigger_price?: number; take_profit?: number; stop_loss?: number; tp_trigger_by?: string; sl_trigger_by?: string; } ⋮---- export interface LinearQueryConditionalOrderRequest { symbol: string; stop_order_id?: string; order_link_id?: string; } ⋮---- export interface LinearSetAutoAddMarginRequest { symbol: string; side: string; auto_add_margin: boolean; } ⋮---- export interface LinearSetMarginSwitchRequest { symbol: string; is_isolated: boolean; buy_leverage: number; sell_leverage: number; } ⋮---- export interface LinearSetPositionModeRequest { symbol: string; mode: (typeof linearPositionModeEnum)[keyof typeof linearPositionModeEnum]; } ⋮---- export interface LinearSetPositionTpSlModeRequest { symbol: string; tp_sl_mode: (typeof positionTpSlModeEnum)[keyof typeof positionTpSlModeEnum]; } ⋮---- export interface LinearSetAddReduceMarginRequest { symbol: string; side: string; margin: number; } ⋮---- export interface LinearSetUserLeverageRequest { symbol: string; buy_leverage: number; sell_leverage: number; } ⋮---- export interface LinearSetTradingStopRequest { symbol: string; side: string; take_profit?: number; stop_loss?: number; trailing_stop?: number; tp_trigger_by?: string; sl_trigger_by?: string; sl_size?: number; tp_size?: number; position_idx?: 0 | 1 | 2; } ⋮---- export interface LinearGetTradeRecordsRequest { symbol: string; start_time?: number; end_time?: number; exec_type?: string; page?: number; limit?: number; } ⋮---- export interface LinearGetHistoryTradeRecordsRequest { symbol: string; start_time?: number; end_time?: number; exec_type?: string; page?: number; limit?: number; page_token?: string; } ⋮---- export interface LinearGetClosedPnlRequest { symbol: string; start_time?: number; end_time?: number; exec_type?: string; page?: number; limit?: number; } ⋮---- export interface LinearSetRiskLimitRequest { symbol: string; side: string; risk_id: number; } ================ File: src/types/request/unified-margin.ts ================ import { KlineIntervalV3, OrderSide } from '../shared'; import { USDCOrderFilter, USDCTimeInForce } from './usdc-shared'; ⋮---- export type UMCategory = 'linear' | 'inverse' | 'option'; export type UMOrderType = 'Limit' | 'Market'; export type UMDirection = 'prev' | 'next'; ⋮---- export interface UMCandlesRequest { category: UMCategory; symbol: string; interval: KlineIntervalV3; start: number; end: number; limit?: number; } ⋮---- export interface UMInstrumentInfoRequest { category: UMCategory; symbol?: string; baseCoin?: string; limit?: string; cursor?: string; } ⋮---- export interface UMFundingRateHistoryRequest { category: UMCategory; symbol: string; startTime?: number; endTime?: number; limit?: number; } ⋮---- export interface UMOptionDeliveryPriceRequest { category: UMCategory; symbol?: string; baseCoin?: string; direction?: UMDirection; limit?: string; cursor?: string; } ⋮---- export interface UMPublicTradesRequest { category: UMCategory; symbol: string; baseCoin?: string; optionType?: 'Call' | 'Put'; limit?: string; } ⋮---- export interface UMOpenInterestRequest { category: UMCategory; symbol: string; interval: '5min' | '15min' | '30min' | '1h' | '4h' | '1d'; startTime?: number; endTime?: number; limit?: number; } ⋮---- export interface UMOrderRequest { category: UMCategory; symbol: string; side: OrderSide; positionIdx?: '0' | '1' | '2'; orderType: UMOrderType; qty: string; price?: string; basePrice?: string; triggerPrice?: string; triggerBy?: string; iv?: string; timeInForce: USDCTimeInForce; orderLinkId?: string; takeProfit?: number; stopLoss?: number; tpTriggerBy?: string; slTriggerBy?: string; reduceOnly?: boolean; closeOnTrigger?: boolean; mmp?: boolean; } ⋮---- export interface UMModifyOrderRequest { category: UMCategory; symbol: string; orderId?: string; orderLinkId?: string; iv?: string; triggerPrice?: string; qty?: string; price?: string; takeProfit?: number; stopLoss?: number; tpTriggerBy?: string; slTriggerBy?: string; triggerBy?: string; } ⋮---- export interface UMCancelOrderRequest { category: UMCategory; symbol: string; orderId?: string; orderLinkId?: string; orderFilter?: USDCOrderFilter; } ⋮---- export interface UMActiveOrdersRequest { category: UMCategory; symbol?: string; baseCoin?: string; orderId?: string; orderLinkId?: string; orderFilter?: USDCOrderFilter; direction?: UMDirection; limit?: number; cursor?: string; } ⋮---- export interface UMHistoricOrdersRequest { category: UMCategory; symbol?: string; baseCoin?: string; orderId?: string; orderLinkId?: string; orderStatus?: string; orderFilter?: USDCOrderFilter; direction?: UMDirection; limit?: number; cursor?: string; } ⋮---- export interface UMBatchOrder { symbol: string; side: OrderSide; positionIdx?: '0'; orderType: UMOrderType; qty: string; price?: string; iv?: string; timeInForce: USDCTimeInForce; orderLinkId?: string; reduceOnly?: boolean; closeOnTrigger?: boolean; mmp?: boolean; } ⋮---- export interface UMBatchOrderReplace { symbol: string; orderId?: string; orderLinkId?: string; iv?: string; qty?: string; price?: string; } ⋮---- export interface UMBatchOrderCancel { symbol: string; orderId?: string; orderLinkId?: string; } ⋮---- export interface UMCancelAllOrdersRequest { category: UMCategory; baseCoin?: string; settleCoin?: string; symbol?: string; orderFilter?: USDCOrderFilter; } ⋮---- export interface UMPositionsRequest { category: UMCategory; symbol?: string; baseCoin?: string; direction?: UMDirection; limit?: number; cursor?: string; } ⋮---- export interface UMSetTPSLRequest { category: UMCategory; symbol: string; takeProfit?: string; stopLoss?: string; trailingStop?: string; tpTriggerBy?: string; slTriggerBy?: string; activePrice?: string; slSize?: string; tpSize?: string; positionIdx?: '0'; } ⋮---- export interface UM7DayTradingHistoryRequest { category: UMCategory; symbol: string; baseCoin?: string; orderId?: string; orderLinkId?: string; startTime?: number; endTime?: number; direction?: UMDirection; limit?: number; cursor?: string; execType?: string; } ⋮---- export interface UMOptionsSettlementHistoryRequest { category: UMCategory; symbol?: string; expDate?: string; direction?: UMDirection; limit?: number; cursor?: string; } ⋮---- export interface UMPerpSettlementHistoryRequest { category: UMCategory; symbol?: string; direction?: UMDirection; limit?: number; cursor?: string; } ⋮---- export interface UMTransactionLogRequest { category: UMCategory; currency: string; baseCoin?: string; type?: string; startTime?: number; endTime?: number; direction?: UMDirection; limit?: number; cursor?: string; } ⋮---- export interface UMExchangeCoinsRequest { fromCoin?: string; toCoin?: string; } ⋮---- export interface UMBorrowHistoryRequest { currency: string; startTime?: number; endTime?: number; direction?: UMDirection; limit?: number; cursor?: string; } ================ File: src/types/request/usdc-options.ts ================ import { OrderSide } from '../shared'; import { USDCAPICategory, USDCOrderType, USDCTimeInForce } from './usdc-shared'; ⋮---- export interface USDCOptionsContractInfoRequest { symbol?: string; status?: 'WAITING_ONLINE' | 'ONLINE' | 'DELIVERING' | 'OFFLINE'; baseCoin?: string; direction?: string; limit?: string; cursor?: string; } ⋮---- export interface USDCOptionsDeliveryPriceRequest { symbol?: string; baseCoin?: string; direction?: string; limit?: string; cursor?: string; } ⋮---- export interface USDCOptionsRecentTradesRequest { category: USDCAPICategory; symbol?: string; baseCoin?: string; optionType?: 'Call' | 'Put'; limit?: string; } ⋮---- export interface USDCOptionsHistoricalVolatilityRequest { baseCoin?: string; period?: string; startTime?: string; endTime?: string; } ⋮---- export interface USDCOptionsOrderRequest { symbol: string; orderType: USDCOrderType; side: OrderSide; orderPrice?: string; orderQty: string; iv?: string; timeInForce?: USDCTimeInForce; orderLinkId?: string; reduceOnly?: boolean; } ⋮---- export interface USDCOptionsModifyOrderRequest { symbol: string; orderId?: string; orderLinkId?: string; orderPrice?: string; orderQty?: string; iv?: string; } ⋮---- export interface USDCOptionsCancelOrderRequest { symbol: string; orderId?: string; orderLinkId?: string; } ⋮---- export interface USDCOptionsCancelAllOrdersRequest { symbol?: string; baseCoin?: string; } ⋮---- export interface USDCOptionsActiveOrdersRealtimeRequest { orderId?: string; orderLinkId?: string; symbol?: string; baseCoin?: string; direction?: string; limit?: number; cursor?: string; } ⋮---- export interface USDCOptionsActiveOrdersRequest { category: 'OPTION'; symbol?: string; baseCoin?: string; orderId?: string; orderLinkId?: string; direction?: string; limit?: number; cursor?: string; } ⋮---- export interface USDCOptionsHistoricOrdersRequest { category: 'OPTION'; symbol?: string; baseCoin?: string; orderId?: string; orderLinkId?: string; orderStatus?: string; direction?: string; limit?: number; cursor?: string; } ⋮---- export interface USDCOptionsOrderExecutionRequest { category: 'OPTION'; symbol?: string; baseCoin?: string; orderId?: string; orderLinkId?: string; startTime?: string; direction?: string; limit?: number; cursor?: string; } ⋮---- export interface USDCOptionsDeliveryHistoryRequest { symbol: string; expDate?: string; direction?: string; limit?: string; cursor?: string; } ⋮---- export interface USDCOptionsPositionsInfoExpiryRequest { expDate?: string; direction?: string; limit?: string; cursor?: string; } ⋮---- export interface USDCOptionsModifyMMPRequest { currency: string; windowMs: number; frozenPeriodMs: number; qtyLimit: string; deltaLimit: string; } ================ File: src/types/request/usdc-perp.ts ================ import { OrderSide } from '../shared'; import { USDCAPICategory, USDCOrderFilter, USDCOrderType, USDCTimeInForce, } from './usdc-shared'; ⋮---- export interface USDCOpenInterestRequest { symbol: string; period: string; limit?: number; } ⋮---- export interface USDCLast500TradesRequest { category: USDCAPICategory; symbol?: string; baseCoin?: string; limit?: string; } ⋮---- export interface USDCSymbolDirectionLimit { symbol?: string; direction?: string; limit?: string; } ⋮---- export interface USDCSymbolDirectionLimitCursor { symbol?: string; direction?: string; limit?: string; cursor?: string; } ⋮---- export interface USDCPerpOrderRequest { symbol: string; orderType: USDCOrderType; orderFilter: USDCOrderFilter; side: OrderSide; orderPrice?: string; orderQty: string; timeInForce?: USDCTimeInForce; orderLinkId?: string; reduceOnly?: boolean; closeOnTrigger?: boolean; takeProfit?: string; stopLoss?: string; tptriggerby?: string; slTriggerBy?: string; basePrice?: string; triggerPrice?: string; triggerBy?: string; mmp?: boolean; } ⋮---- export interface USDCPerpModifyOrderRequest { symbol: string; orderFilter: USDCOrderFilter; orderId?: string; orderLinkId?: string; orderPrice?: string; orderQty?: string; takeProfit?: string; stopLoss?: string; tptriggerby?: string; slTriggerBy?: string; triggerPrice?: string; } ⋮---- export interface USDCPerpCancelOrderRequest { symbol: string; orderFilter: USDCOrderFilter; orderId?: string; orderLinkId?: string; } ⋮---- export interface USDCPerpActiveOrdersRequest { category: 'PERPETUAL'; symbol?: string; baseCoin?: string; orderId?: string; orderLinkId?: string; orderFilter?: USDCOrderFilter; direction?: string; limit?: number; cursor?: string; } ⋮---- export interface USDCPerpHistoricOrdersRequest { category: 'PERPETUAL'; symbol?: string; baseCoin?: string; orderId?: string; orderLinkId?: string; orderStatus?: string; orderFilter?: USDCOrderFilter; direction?: string; limit?: number; cursor?: string; } ================ File: src/types/request/usdc-shared.ts ================ export type USDCAPICategory = 'PERPETUAL' | 'OPTION'; ⋮---- export type USDCOrderType = 'Limit' | 'Market'; ⋮---- export type USDCTimeInForce = | 'GoodTillCancel' | 'ImmediateOrCancel' | 'FillOrKill' | 'PostOnly'; ⋮---- export type USDCOrderFilter = 'Order' | 'StopOrder'; ⋮---- export interface USDCKlineRequest { symbol: string; period: string; startTime: number; limit?: string; } ⋮---- export interface USDCTransactionLogRequest { type: string; baseCoin?: string; startTime?: string; endTime?: string; direction?: string; limit?: string; cursor?: string; category?: USDCAPICategory; } ⋮---- export interface USDCPositionsRequest { category: USDCAPICategory; symbol?: string; baseCoin?: string; expDate?: string; direction?: string; limit?: string; cursor?: string; } ================ File: src/types/request/v5-broker.ts ================ export interface GetExchangeBrokerEarningsParamsV5 { bizType?: 'SPOT' | 'DERIVATIVES' | 'OPTIONS' | 'CONVERT'; begin?: string; end?: string; uid?: string; limit?: number; cursor?: string; } ⋮---- export interface GetBrokerSubAccountDepositsV5 { id?: string; txID?: string; subMemberId?: string; coin?: string; startTime?: number; endTime?: number; limit?: number; cursor?: string; } ⋮---- export interface IssueVoucherParamsV5 { accountId: string; awardId: string; specCode: string; amount: string; brokerId: string; } ⋮---- export interface GetBrokerIssuedVoucherParamsV5 { accountId: string; awardId: string; specCode: string; withUsedAmount?: boolean; } ================ File: src/types/request/v5-p2p-trading.ts ================ export interface GetP2PAccountCoinsBalanceParamsV5 { memberId?: string; accountType: string; coin?: string; withBonus?: 0 | 1; } ⋮---- export interface GetP2POnlineAdsParamsV5 { tokenId: string; currencyId: string; side: '0' | '1'; // 0: buy; 1: sell page?: string; size?: string; } ⋮---- side: '0' | '1'; // 0: buy; 1: sell ⋮---- export interface P2PTradingPreferenceSetV5 { hasUnPostAd?: 0 | 1; isKyc?: 0 | 1; isEmail?: 0 | 1; isMobile?: 0 | 1; hasRegisterTime?: 0 | 1; registerTimeThreshold?: number; orderFinishNumberDay30?: number; completeRateDay30?: string; nationalLimit?: string; hasOrderFinishNumberDay30?: 0 | 1; hasCompleteRateDay30?: 0 | 1; hasNationalLimit?: 0 | 1; } ⋮---- export interface CreateP2PAdParamsV5 { tokenId: string; currencyId: string; side: '0' | '1'; // 0: buy; 1: sell priceType: '0' | '1'; // 0: fixed rate; 1: floating rate premium: string; price: string; minAmount: string; maxAmount: string; remark: string; tradingPreferenceSet: P2PTradingPreferenceSetV5; paymentIds: string[]; quantity: string; paymentPeriod: string; itemType: 'ORIGIN' | 'BULK'; } ⋮---- side: '0' | '1'; // 0: buy; 1: sell priceType: '0' | '1'; // 0: fixed rate; 1: floating rate ⋮---- export interface UpdateP2PAdParamsV5 { id: string; priceType: '0' | '1'; // 0: fixed rate; 1: floating rate premium: string; price: string; minAmount: string; maxAmount: string; remark: string; tradingPreferenceSet: P2PTradingPreferenceSetV5; paymentIds: string[]; actionType: 'MODIFY' | 'ACTIVE'; // MODIFY: modify adv; ACTIVE: reonline adv quantity: string; paymentPeriod: string; itemType?: 'ORIGIN' | 'BULK'; subsidyAd?: boolean; securityRiskToken?: string; } ⋮---- priceType: '0' | '1'; // 0: fixed rate; 1: floating rate ⋮---- actionType: 'MODIFY' | 'ACTIVE'; // MODIFY: modify adv; ACTIVE: reonline adv ⋮---- export interface GetP2PPersonalAdsParamsV5 { itemId?: string; status?: '1' | '2'; // 1: Sold Out; 2: Available side?: '0' | '1'; // 0: buy; 1: sell tokenId?: string; page?: string; size?: string; currencyId?: string; } ⋮---- status?: '1' | '2'; // 1: Sold Out; 2: Available side?: '0' | '1'; // 0: buy; 1: sell ⋮---- export interface GetP2POrdersParamsV5 { status?: number; beginTime?: string; endTime?: string; tokenId?: string; side?: number[]; page: number; size: number; } ⋮---- export interface GetP2PPendingOrdersParamsV5 { status?: number; beginTime?: string; endTime?: string; tokenId?: string; side?: number[]; page: number; size: number; } ⋮---- export interface MarkP2POrderAsPaidParamsV5 { orderId: string; paymentType: string; paymentId: string; } ⋮---- export interface SendP2POrderMessageParamsV5 { message: string; contentType: string; orderId: string; msgUuid?: string; fileName?: string; } ⋮---- export interface GetP2POrderMessagesParamsV5 { orderId: string; currentPage?: string; size: string; } ⋮---- export interface GetP2PCounterpartyUserInfoParamsV5 { originalUid: string; orderId: string; } ================ File: src/types/request/v5-pre-upgrade.ts ================ import { ExecTypeV5 } from '../shared-v5'; ⋮---- export interface GetPreUpgradeOrderHistoryParamsV5 { category: 'linear' | 'inverse'; symbol?: string; baseCoin?: string; orderId?: string; orderLinkId?: string; orderFilter?: 'Order' | 'StopOrder'; orderStatus?: string; startTime?: number; endTime?: number; limit?: number; cursor?: string; } ⋮---- export interface GetPreUpgradeTradeHistoryParamsV5 { category: 'linear' | 'inverse'; symbol?: string; orderId?: string; orderLinkId?: string; baseCoin?: string; startTime?: number; endTime?: number; execType?: ExecTypeV5; limit?: number; cursor?: string; } ⋮---- export interface GetPreUpgradeClosedPnlParamsV5 { category: 'linear' | 'inverse'; symbol: string; startTime?: number; endTime?: number; limit?: number; cursor?: string; } ⋮---- export interface GetPreUpgradeTransactionLogParamsV5 { category: 'linear' | 'option'; baseCoin?: string; type?: string; startTime?: number; endTime?: number; limit?: number; cursor?: string; } ⋮---- export interface GetPreUpgradeOptionDeliveryRecordParamsV5 { category: 'option'; symbol?: string; expDate?: string; limit?: number; cursor?: string; } ⋮---- export interface GetPreUpgradeUSDCSessionParamsV5 { category: 'linear'; symbol?: string; limit?: number; cursor?: string; } ================ File: src/types/request/v5-spreadtrading.ts ================ export interface GetSpreadInstrumentsInfoParamsV5 { symbol?: string; baseCoin?: string; limit?: number; cursor?: string; } ⋮---- export interface SubmitSpreadOrderParamsV5 { symbol: string; side: 'Buy' | 'Sell'; orderType: 'Limit' | 'Market'; qty: string; price: string; orderLinkId: string; timeInForce: 'IOC' | 'FOK' | 'GTC' | 'PostOnly'; } ⋮---- export interface AmendSpreadOrderParamsV5 { symbol: string; orderId?: string; orderLinkId?: string; qty?: string; price?: string; } ⋮---- export interface GetSpreadOpenOrdersParamsV5 { symbol?: string; baseCoin?: string; orderId?: string; orderLinkId?: string; limit?: number; cursor?: string; } export interface GetSpreadOrderHistoryParamsV5 { symbol?: string; baseCoin?: string; orderId?: string; orderLinkId?: string;