gateio-api
Version:
Complete & Robust Node.js SDK for Gate.com's REST APIs, WebSockets & WebSocket APIs, with TypeScript declarations.
1,826 lines (1,780 loc) • 328 kB
Plain Text
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/
futures/
getBalances.ts
getOrders.ts
getTickers.ts
submitLimitOrder.ts
submitMarketOrder.ts
testnet.ts
spot/
getBalances.ts
getCandles.ts
getOrders.ts
getTickers.ts
submitLimitOrder.ts
submitMarketOrder.ts
futures-balance-trade.ts
README.md
ws-api-client.ts
ws-private-perp-futures-wsapi.ts
ws-private-perp-futures.ts
ws-private-spot-wsapi.ts
ws-private-spot.ts
ws-public.ts
src/
lib/
websocket/
websocket-util.ts
WsStore.ts
WsStore.types.ts
BaseRestClient.ts
BaseWSClient.ts
logger.ts
misc-util.ts
requestUtils.ts
webCryptoAPI.ts
types/
request/
account.ts
collateralLoan.ts
delivery.ts
earn.ts
earnuni.ts
flashswap.ts
futures.ts
margin.ts
marginuni.ts
multicollateralLoan.ts
options.ts
rebate.ts
spot.ts
subaccount.ts
unified.ts
wallet.ts
withdrawal.ts
response/
account.ts
collateralloan.ts
delivery.ts
earn.ts
earnuni.ts
flashswap.ts
futures.ts
margin.ts
marginuni.ts
multicollateralLoan.ts
options.ts
rebate.ts
spot.ts
subaccount.ts
unified.ts
wallet.ts
withdrawal.ts
websockets/
client.ts
events.ts
requests.ts
wsAPI.ts
shared.ts
index.ts
RestClient.ts
WebsocketAPIClient.ts
WebsocketClient.ts
.eslintrc.cjs
.gitignore
.nvmrc
.prettierrc
jest.config.ts
LICENSE.md
package.json
postBuild.sh
README.md
tea.yaml
tsconfig.cjs.json
tsconfig.esm.json
tsconfig.json
tsconfig.linting.json
================================================================
Files
================================================================
================
File: examples/futures/getBalances.ts
================
import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
⋮----
// Define the account object with API key and secret
⋮----
key: process.env.API_KEY || 'yourApiHere', // Replace 'yourApiHere' with your actual API key
secret: process.env.API_SECRET || 'yourSecretHere', // Replace 'yourSecretHere' with your actual API secret
⋮----
// Initialize the RestClient with the API credentials
⋮----
async function getFuturesBalances()
⋮----
// Fetch the futures account balance for USDT settlement
⋮----
console.log('Response: ', result); // Log the response to the console
⋮----
console.error(`Error in execution: `, e); // Log any errors that occur
⋮----
// Execute the function to get futures balances
================
File: examples/futures/getOrders.ts
================
import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
⋮----
// Define the account object with API key and secret
⋮----
key: process.env.API_KEY || 'yourApiHere', // Replace 'yourApiHere' with your actual API key or use environment variables
secret: process.env.API_SECRET || 'yourSecretHere', // Replace 'yourSecretHere' with your actual API secret or use environment variables
⋮----
// Initialize the RestClient with the API credentials
⋮----
async function getFuturesOrders()
⋮----
// Fetch open futures orders with USDT settlement
⋮----
settle: 'usdt', // Specify the settlement currency
status: 'open', // Specify the status of the orders to fetch
⋮----
console.log('openOrders: ', openOrders); // Log the response to the console
⋮----
// Fetch finished futures orders with USDT settlement
⋮----
settle: 'usdt', // Specify the settlement currency
status: 'finished', // Specify the status of the orders to fetch
⋮----
console.log('finishedOrders: ', finishedOrders); // Log the response to the console
⋮----
console.error(`Error in execution: `, e); // Log any errors that occur
⋮----
// Execute the function to get futures orders
================
File: examples/futures/getTickers.ts
================
import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
⋮----
// Define the account object with API key and secret
⋮----
key: process.env.API_KEY || 'yourApiHere', // Replace 'yourApiHere' with your actual API key
secret: process.env.API_SECRET || 'yourSecretHere', // Replace 'yourSecretHere' with your actual API secret
⋮----
// Initialize the RestClient with the API credentials
⋮----
async function getFuturesTicker()
⋮----
// Fetch all futures tickers with USDT settlement
⋮----
settle: 'usdt', // Specify the settlement currency
⋮----
console.log('allTickers: ', allTickers); // Log the response to the console
⋮----
// Fetch a specific futures ticker with USDT settlement
⋮----
settle: 'usdt', // Specify the settlement currency
contract: 'BTC_USDT', // Specify the contract
⋮----
console.log('ticker: ', ticker); // Log the response to the console
⋮----
console.error(`Error in execution: `, e); // Log any errors that occur
⋮----
// Execute the function to get futures tickers
================
File: examples/futures/submitLimitOrder.ts
================
import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
⋮----
// Define the account object with API key and secret
⋮----
key: process.env.API_KEY || 'yourApiHere', // Replace 'yourApiHere' with your actual API key
secret: process.env.API_SECRET || 'yourSecretHere', // Replace 'yourSecretHere' with your actual API secret
⋮----
// Initialize the RestClient with the API credentials
⋮----
async function submitFuturesOrder()
⋮----
// Submit a limit order for futures trading
⋮----
settle: 'usdt', // Specify the settlement currency
contract: 'BTC_USDT', // Specify the contract
size: 10, // Order size: positive for long, negative for short
price: '45000', // Limit price for the order
tif: 'gtc', // Time in force: 'gtc' (Good Till Cancelled)
⋮----
console.log('Response: ', result); // Log the response to the console
⋮----
console.error(`Error in execution: `, e); // Log any errors that occur
⋮----
// Execute the function to submit a futures order
================
File: examples/futures/submitMarketOrder.ts
================
import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
⋮----
// Define the account object with API key and secret
⋮----
key: process.env.API_KEY || 'yourApiHere', // Replace 'yourApiHere' with your actual API key
secret: process.env.API_SECRET || 'yourSecretHere', // Replace 'yourSecretHere' with your actual API secret
⋮----
// Initialize the RestClient with the API credentials
⋮----
async function submitFuturesOrder()
⋮----
// Submit a market order for futures trading
⋮----
settle: 'usdt', // Specify the settlement currency
contract: 'BTC_USDT', // Specify the contract
size: 20, // Order size: positive for long, negative for short
price: '0', // Market order, so price is set to '0'
tif: 'ioc', // Time in force: 'ioc' (Immediate Or Cancel)
⋮----
console.log('Response: ', result); // Log the response to the console
⋮----
console.error(`Error in execution: `, e); // Log any errors that occur
⋮----
// Execute the function to submit a futures order
================
File: examples/spot/getBalances.ts
================
import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
⋮----
// Define the account object with API key and secret
⋮----
key: process.env.API_KEY || 'yourApiHere', // Replace 'yourApiHere' with your actual API key
secret: process.env.API_SECRET || 'yourSecretHere', // Replace 'yourSecretHere' with your actual API secret
⋮----
// Initialize the RestClient with the API credentials
⋮----
async function getSpotBalances()
⋮----
// Fetch the spot account balances
⋮----
console.log('Response: ', balances); // Log the response to the console
⋮----
console.error(`Error in execution: `, e); // Log any errors that occur
⋮----
// Execute the function to get spot balances
================
File: examples/spot/getCandles.ts
================
import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
⋮----
// Define the account object with API key and secret
⋮----
key: process.env.API_KEY || 'yourApiHere', // Replace 'yourApiHere' with your actual API key
secret: process.env.API_SECRET || 'yourSecretHere', // Replace 'yourSecretHere' with your actual API secret
⋮----
// Initialize the RestClient with the API credentials
⋮----
async function getSpotCandles()
⋮----
// Fetch the spot account balances
⋮----
console.log('Response: ', balances); // Log the response to the console
⋮----
console.error(`Error in execution: `, e); // Log any errors that occur
⋮----
// Execute the function to get spot balances
================
File: examples/spot/getOrders.ts
================
import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
⋮----
// Define the account object with API key and secret
⋮----
key: process.env.API_KEY || 'yourApiHere', // Replace 'yourApiHere' with your actual API key
secret: process.env.API_SECRET || 'yourSecretHere', // Replace 'yourSecretHere' with your actual API secret
⋮----
// Initialize the RestClient with the API credentials
⋮----
async function getSpotOrders()
⋮----
// Fetch open spot orders for the BTC_USDT currency pair
⋮----
currency_pair: 'BTC_USDT', // Specify the currency pair
status: 'open', // Specify the status of the orders to fetch
⋮----
console.log('openOrders: ', openOrders); // Log the response to the console
⋮----
// Fetch finished spot orders for the BTC_USDT currency pair
⋮----
currency_pair: 'BTC_USDT', // Specify the currency pair
status: 'finished', // Specify the status of the orders to fetch
⋮----
console.log('finishedOrders: ', finishedOrders); // Log the response to the console
⋮----
console.error(`Error in execution: `, e); // Log any errors that occur
⋮----
// Execute the function to get spot orders
================
File: examples/spot/getTickers.ts
================
import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
⋮----
// Define the account object with API key and secret
⋮----
key: process.env.API_KEY || 'yourApiHere', // Replace 'yourApiHere' with your actual API key
secret: process.env.API_SECRET || 'yourSecretHere', // Replace 'yourSecretHere' with your actual API secret
⋮----
// Initialize the RestClient with the API credentials
⋮----
async function getSpotTicker()
⋮----
// Fetch the ticker for a specific currency pair (BTC_USDT)
⋮----
currency_pair: 'BTC_USDT', // Specify the currency pair
⋮----
console.log('Response: ', ticker); // Log the response to the console
⋮----
// Fetch all tickers
⋮----
console.log('Response: ', allTickers); // Log the response to the console
⋮----
console.error(`Error in execution: `, e); // Log any errors that occur
⋮----
// Execute the function to get spot tickers
================
File: examples/spot/submitLimitOrder.ts
================
import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
⋮----
// Define the account object with API key and secret
⋮----
key: process.env.API_KEY || 'yourApiHere', // Replace 'yourApiHere' with your actual API key
secret: process.env.API_SECRET || 'yourSecretHere', // Replace 'yourSecretHere' with your actual API secret
⋮----
// Initialize the RestClient with the API credentials
⋮----
async function submitSpotOrder()
⋮----
// Submit a limit order for spot trading
⋮----
currency_pair: 'BTC_USDT', // Specify the currency pair
side: 'buy', // Specify the order side: 'buy' or 'sell'
type: 'limit', // Specify the order type: 'limit'
amount: '0.001', // Specify the amount to buy
price: '45000', // Specify the limit price
time_in_force: 'gtc', // Time in force: 'gtc' (Good Till Cancelled)
⋮----
console.log('Response: ', result); // Log the response to the console
⋮----
console.error(`Error in execution: `, e); // Log any errors that occur
⋮----
// Execute the function to submit a spot order
================
File: examples/spot/submitMarketOrder.ts
================
import { RestClient } from '../../src/index.js'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
⋮----
// Define the account object with API key and secret
⋮----
key: process.env.API_KEY || 'yourApiHere', // Replace 'yourApiHere' with your actual API key
secret: process.env.API_SECRET || 'yourSecretHere', // Replace 'yourSecretHere' with your actual API secret
⋮----
// Initialize the RestClient with the API credentials
⋮----
async function submitSpotOrder()
⋮----
// Submit a market order for spot trading
⋮----
currency_pair: 'BTC_USDT', // Specify the currency pair
side: 'buy', // Specify the order side: 'buy' or 'sell'
type: 'market', // Specify the order type: 'market'
amount: '10', // Specify the amount to buy
time_in_force: 'ioc', // Time in force: 'ioc' (Immediate Or Cancel)
⋮----
console.log('Response: ', result); // Log the response to the console
⋮----
console.error(`Error in execution: `, e); // Log any errors that occur
⋮----
// Execute the function to submit a spot order
================
File: examples/futures-balance-trade.ts
================
/**
* This example demonstrates a simple commented workflow of:
* - initialising the RestClient and WebsocketClient for Gate.io exchange
* - connecting to an account’s private websockets (to receive updates asynchronously)
* - checking if connection is successful
* - fetching available futures balance
* - placing an order using 50% of the available balance
**/
⋮----
// Import the RestClient and WebsocketClient from the published version of this SDK, installed via NPM (npm install gateio-api)
import { RestClient, WebsocketClient } from 'gateio-api';
⋮----
// Define the account object with API key and secret
⋮----
// Replace 'yourApiHere' with your actual API key or use environment variables
⋮----
// Replace 'yourSecretHere' with your actual API secret or use environment variables
⋮----
// Initialize the RestClient with the API credentials
⋮----
// initialise websocket client - if you want only public data, you can initialise the client without the apiKey and apiSecret, just WebsocketClient()
⋮----
// Data received
⋮----
async function subscribePrivateWs()
⋮----
// Enter your user ID here
⋮----
//sub to balances updates
⋮----
//sub to trades updates
⋮----
/**
* Either send one topic (with params) at a time
*/
// client.subscribe({
// topic: 'futures.usertrades',
// payload: [myUserID, '!all'],
// }, 'perpFuturesUSDTV4');
⋮----
/**
* Or send multiple topics in a batch (grouped by ws connection (WsKey))
* You can also use strings for topics that don't have any parameters, even if you mix multiple requests into one function call:
*/
⋮----
async function main()
⋮----
// Get futures account balance via REST
⋮----
// total usdt balance
⋮----
// available usdt balance
⋮----
// submit market order with 50% of the balance
⋮----
// Submit a market order with 50% of the balance
⋮----
settle: 'usdt', // Specify the settlement currency
contract: 'BTC_USDT', // Specify the contract
size: orderAmount, // Order size: positive for long, negative for short, in USDT
price: '0', // Market order, so price is set to '0'
tif: 'ioc', // Time in force: 'ioc' (Immediate Or Cancel)
⋮----
// for more detailed ws connection, you can use a lot more listeners like below:
⋮----
// Something happened, attempting to reconnect
⋮----
// Reconnect successful
⋮----
// Connection closed. If unexpected, expect reconnect -> reconnected.
⋮----
// Reply to a request, e.g. "subscribe"/"unsubscribe"/"authenticate"
================
File: examples/README.md
================
# Examples
These samples can be executed using `ts-node` or `tsx`:
```
ts-node ./examples/ws-public.ts
```
Most examples also have minimal typescript, so if you rename them to "js" they should execute fine with just node. TypeScript is recommended but completely optional:
```
node ./examples/spot/getTickers.js
```
================
File: src/lib/misc-util.ts
================
export function neverGuard(x: never, msg: string): Error
================
File: src/lib/webCryptoAPI.ts
================
import { neverGuard } from './misc-util.js';
⋮----
function bufferToB64(buffer: ArrayBuffer): string
⋮----
export type SignEncodeMethod = 'hex' | 'base64';
export type SignAlgorithm = 'SHA-256' | 'SHA-512';
⋮----
/**
* Similar to node crypto's `createHash()` function
*/
export async function hashMessage(
message: string,
method: SignEncodeMethod,
algorithm: SignAlgorithm,
): Promise<string>
⋮----
/**
* Sign a message, with a secret, using the Web Crypto API
*/
export async function signMessage(
message: string,
secret: string,
method: SignEncodeMethod,
algorithm: SignAlgorithm,
): Promise<string>
================
File: src/types/request/account.ts
================
/**==========================================================================================================================
* ACCOUNT
* ==========================================================================================================================
*/
⋮----
export interface CreateStpGroupReq {
name: string;
id?: number;
creator_id?: number;
create_time?: number;
}
================
File: src/types/request/collateralLoan.ts
================
/**==========================================================================================================================
* COLLATERAL LOAN
* ==========================================================================================================================
*/
⋮----
export interface SubmitLoanOrderReq {
collateral_amount: string;
collateral_currency: string;
borrow_amount: string;
borrow_currency: string;
}
⋮----
export interface GetLoanOrdersReq {
page?: number;
limit?: number;
collateral_currency?: string;
borrow_currency?: string;
}
⋮----
export interface GetLoanRepaymentHistoryReq {
source: 'repay' | 'liquidate';
borrow_currency?: string;
collateral_currency?: string;
page?: number;
limit?: number;
from?: number;
to?: number;
}
⋮----
export interface UpdateLoanCollateralReq {
order_id: number;
collateral_currency: string;
collateral_amount: string;
type: 'append' | 'redeem';
}
⋮----
export interface GetLoanCollateralRecordsReq {
page?: number;
limit?: number;
from?: number;
to?: number;
borrow_currency?: string;
collateral_currency?: string;
}
================
File: src/types/request/delivery.ts
================
/**==========================================================================================================================
* DELIVERY
* ==========================================================================================================================
*/
⋮----
export interface GetDeliveryOrderBookReq {
settle: 'usdt';
contract: string;
interval?: '0' | '0.1' | '0.01';
limit?: number;
with_id?: boolean;
}
⋮----
export interface GetDeliveryTradesReq {
settle: 'usdt';
contract: string;
limit?: number;
last_id?: string;
from?: number;
to?: number;
}
⋮----
export interface GetDeliveryCandlesReq {
settle: 'usdt';
contract: string;
from?: number;
to?: number;
limit?: number;
interval?:
| '10s'
| '30s'
| '1m'
| '5m'
| '15m'
| '30m'
| '1h'
| '2h'
| '4h'
| '6h'
| '8h'
| '12h'
| '1d'
| '7d'
| '1w'
| '30d';
}
⋮----
export interface GetDeliveryBookReq {
settle: 'usdt';
limit?: number;
from?: number;
to?: number;
type?:
| 'dnw'
| 'pnl'
| 'fee'
| 'refr'
| 'fund'
| 'point_dnw'
| 'point_fee'
| 'point_refr'
| 'bonus_offset';
}
⋮----
export interface SubmitDeliveryFuturesOrderReq {
settle: 'usdt';
contract: string;
size: number;
iceberg?: number;
price?: string;
close?: boolean;
reduce_only?: boolean;
tif?: string;
text?: string;
auto_size?: string;
stp_act?: string;
}
⋮----
export interface GetDeliveryOrdersReq {
settle: 'usdt';
contract?: string;
status: 'open' | 'finished';
limit?: number;
offset?: number;
last_id?: string;
count_total?: 0 | 1;
}
⋮----
export interface GetDeliveryTradingHistoryReq {
settle: 'usdt';
contract?: string;
order?: number;
limit?: number;
offset?: number;
last_id?: string;
count_total?: 0 | 1;
}
⋮----
export interface GetDeliveryClosedPositionsReq {
settle: 'usdt';
contract?: string;
limit?: number;
}
⋮----
export interface GetDeliveryLiquidationHistoryReq {
settle: 'usdt';
contract?: string;
limit?: number;
at?: number;
}
⋮----
export interface GetDeliverySettlementHistoryReq {
settle: 'usdt';
contract?: string;
limit?: number;
at?: number;
}
export interface GetDeliveryAutoOrdersReq {
settle: 'usdt';
status: 'open' | 'finished';
contract?: string;
limit?: number;
offset?: number;
}
================
File: src/types/request/earn.ts
================
/**==========================================================================================================================
* EARN
* ==========================================================================================================================
*/
⋮----
export interface GetStructuredProductListReq {
status: string;
type?: string;
page?: number;
limit?: number;
}
⋮----
export interface GetStructuredProductOrdersReq {
from?: number;
to?: number;
page?: number;
limit?: number;
}
================
File: src/types/request/earnuni.ts
================
/**==========================================================================================================================
* EARN UNI
* ==========================================================================================================================
*/
⋮----
export interface SubmitLendOrRedeemReq {
currency: string;
amount: string;
type: 'lend' | 'redeem';
min_rate?: string;
}
⋮----
export interface GetLendingOrdersReq {
currency?: string;
page?: number;
limit?: number;
}
⋮----
export interface GetLendingRecordsReq {
currency?: string;
page?: number;
limit?: number;
from?: number;
to?: number;
type?: 'lend' | 'redeem';
}
⋮----
export interface GetLendingInterestRecordsReq {
currency?: string;
page?: number;
limit?: number;
from?: number;
to?: number;
}
================
File: src/types/request/flashswap.ts
================
/**==========================================================================================================================
* FLASH SWAP
* ==========================================================================================================================
*/
⋮----
export interface SubmitFlashSwapOrderReq {
preview_id: string;
sell_currency: string;
sell_amount: string;
buy_currency: string;
buy_amount: string;
}
⋮----
export interface GetFlashSwapOrdersReq {
status?: number;
sell_currency?: string;
buy_currency?: string;
reverse?: boolean;
limit?: number;
page?: number;
}
⋮----
export interface GetFlashSwapOrderReq {
order_id: number;
}
⋮----
export interface SubmitFlashSwapOrderPreviewReq {
sell_currency: string;
sell_amount?: string;
buy_currency: string;
buy_amount?: string;
}
================
File: src/types/request/margin.ts
================
/**==========================================================================================================================
* MARGIN
* ==========================================================================================================================
*/
⋮----
export interface GetMarginBalanceHistoryReq {
currency?: string;
currency_pair?: string;
type?: string;
from?: number;
to?: number;
page?: number;
limit?: number;
}
⋮----
export interface GetCrossMarginAccountHistoryReq {
currency?: string;
from?: number;
to?: number;
page?: number;
limit?: number;
type?: string;
}
⋮----
export interface SubmitCrossMarginBorrowLoanReq {
currency: string;
amount: string;
text?: string;
}
⋮----
export interface GetCrossMarginBorrowHistoryReq {
status: number;
currency?: string;
limit?: number;
offset?: number;
reverse?: boolean;
}
⋮----
export interface GetCrossMarginRepaymentsReq {
currency?: string;
loan_id?: string;
limit?: number;
offset?: number;
reverse?: boolean;
}
⋮----
export interface GetCrossMarginInterestRecordsReq {
currency?: string;
page?: number;
limit?: number;
from?: number;
to?: number;
}
================
File: src/types/request/marginuni.ts
================
/**==========================================================================================================================
* MARGIN UNI
* ==========================================================================================================================
*/
⋮----
export interface GetMarginUNILoansReq {
currency_pair?: string;
currency?: string;
page?: number;
limit?: number;
}
⋮----
export interface GetMarginUNILoanRecordsReq {
type?: 'borrow' | 'repay';
currency?: string;
currency_pair?: string;
page?: number;
limit?: number;
}
⋮----
export interface GetMarginUNIInterestRecordsReq {
currency_pair?: string;
currency?: string;
page?: number;
limit?: number;
from?: number;
to?: number;
}
⋮----
export interface GetMarginUNIMaxBorrowReq {
currency: string;
currency_pair: string;
}
================
File: src/types/request/multicollateralLoan.ts
================
/**==========================================================================================================================
* MULTI COLLATERAL LOAN
* ==========================================================================================================================
*/
⋮----
export interface SubmitMultiLoanOrderReq {
order_id?: string;
order_type?: string;
fixed_type?: string;
fixed_rate?: string;
auto_renew?: boolean;
auto_repay?: boolean;
borrow_currency: string;
borrow_amount: string;
collateral_currencies?: {
currency?: string;
amount?: string;
}[];
}
export interface GetMultiLoanOrdersReq {
page?: number;
limit?: number;
sort?: string;
order_type?: string;
}
⋮----
export interface RepayMultiLoanReq {
order_id: number;
repay_items: {
currency?: string;
amount?: string;
repaid_all?: boolean;
}[];
}
⋮----
export interface GetMultiLoanRepayRecordsReq {
type: 'repay' | 'liquidate';
borrow_currency?: string;
page?: number;
limit?: number;
from?: number;
to?: number;
}
⋮----
export interface UpdateMultiLoanReq {
order_id: number;
type: 'append' | 'redeem';
collaterals?: {
currency?: string;
amount?: string;
}[];
}
⋮----
export interface GetMultiLoanAdjustmentRecordsReq {
page?: number;
limit?: number;
from?: number;
to?: number;
collateral_currency?: string;
}
================
File: src/types/request/options.ts
================
/**==========================================================================================================================
* OPTIONS
* ==========================================================================================================================
*/
export interface GetOptionsSettlementHistoryReq {
underlying: string;
limit?: number;
offset?: number;
from?: number;
to?: number;
}
export interface GetOptionsMySettlementsReq {
underlying: string;
contract?: string;
limit?: number;
offset?: number;
from?: number;
to?: number;
}
⋮----
export interface GetOptionsOrderBookReq {
contract: string;
interval?: '0' | '0.1' | '0.01';
limit?: number;
with_id?: boolean;
}
⋮----
export interface GetOptionsCandlesReq {
contract: string;
limit?: number;
from?: number;
to?: number;
interval?: '1m' | '5m' | '15m' | '30m' | '1h';
}
⋮----
export interface GetOptionsUnderlyingCandlesReq {
underlying: string;
limit?: number;
from?: number;
to?: number;
interval?: '1m' | '5m' | '15m' | '30m' | '1h';
}
⋮----
export interface GetOptionsTradesReq {
contract?: string;
type?: 'C' | 'P';
limit?: number;
offset?: number;
from?: number;
to?: number;
}
⋮----
export interface GetOptionsAccountChangeReq {
limit?: number;
offset?: number;
from?: number;
to?: number;
type?: 'dnw' | 'prem' | 'fee' | 'refr' | 'set';
}
⋮----
export interface SubmitOptionsOrderReq {
contract: string;
size: number;
iceberg?: number;
price?: string;
close?: boolean;
reduce_only?: boolean;
tif?: 'gtc' | 'ioc' | 'poc';
text?: string;
}
⋮----
export interface GetOptionsOrdersReq {
contract?: string;
underlying?: string;
status: 'open' | 'finished';
limit?: number;
offset?: number;
from?: number;
to?: number;
}
⋮----
export interface GetOptionsPersonalHistoryReq {
underlying: string;
contract?: string;
limit?: number;
offset?: number;
from?: number;
to?: number;
}
⋮----
export interface OptionsMMPSettingsReq {
underlying: string;
window: number; // Time window in milliseconds, between 1-5000, 0 to disable MMP
frozen_period: number; // Frozen period in milliseconds, 0 to freeze indefinitely until reset API is called
qty_limit: string; // Maximum transaction volume (positive number, up to 2 decimal places)
delta_limit: string; // Maximum net delta value (positive number, up to 2 decimal places)
}
⋮----
window: number; // Time window in milliseconds, between 1-5000, 0 to disable MMP
frozen_period: number; // Frozen period in milliseconds, 0 to freeze indefinitely until reset API is called
qty_limit: string; // Maximum transaction volume (positive number, up to 2 decimal places)
delta_limit: string; // Maximum net delta value (positive number, up to 2 decimal places)
================
File: src/types/request/rebate.ts
================
export interface GetAgencyTransactionHistoryReq {
currency_pair?: string;
user_id?: number;
from?: number;
to?: number;
limit?: number;
offset?: number;
}
⋮----
export interface GetAgencyCommissionHistoryReq {
currency?: string;
user_id?: number;
from?: number;
to?: number;
limit?: number;
offset?: number;
}
⋮----
export interface GetPartnerSubordinateListReq {
user_id?: number;
limit?: number;
offset?: number;
}
⋮----
export interface GetBrokerCommissionHistoryReq {
limit?: number;
offset?: number;
user_id?: number;
from?: number;
to?: number;
}
⋮----
export interface GetBrokerTransactionHistoryReq {
limit?: number;
offset?: number;
user_id?: number;
from?: number;
to?: number;
}
⋮----
// Interfaces for request and response
export interface PartnerTransactionReq {
currency_pair?: string;
user_id?: number;
from?: number;
to?: number;
limit?: number;
offset?: number;
}
================
File: src/types/request/subaccount.ts
================
export interface CreateSubAccountReq {
login_name: string;
remark?: string;
password?: string;
email?: string;
}
⋮----
export interface CreateSubAccountApiKeyReq {
user_id: number;
mode?: number; // Mode: 1 - classic, 2 - portfolio account
name?: string; // API key name
perms?: {
name?:
| 'wallet'
| 'spot'
| 'futures'
| 'delivery'
| 'earn'
| 'options'
| 'account'
| 'unified'
| 'loan'; // Permission name
read_only?: boolean; // Read only
}[];
ip_whitelist?: string[]; // IP white list
}
⋮----
mode?: number; // Mode: 1 - classic, 2 - portfolio account
name?: string; // API key name
⋮----
| 'loan'; // Permission name
read_only?: boolean; // Read only
⋮----
ip_whitelist?: string[]; // IP white list
⋮----
export type UpdateSubAccountApiKeyReq = {
key: string;
} & CreateSubAccountApiKeyReq;
================
File: src/types/request/withdrawal.ts
================
/**================================================================================================================================
* WITHDRAW
* ==========================================================================================================================
*/
⋮----
export interface SubmitWithdrawalReq {
amount: string;
currency: string;
chain: string;
withdraw_order_id?: string;
address?: string;
memo?: string;
}
================
File: src/types/response/collateralloan.ts
================
/**==========================================================================================================================
* COLLATERAL LOAN
* ==========================================================================================================================
*/
⋮----
export interface LoanOrder {
order_id: number;
collateral_currency: string;
collateral_amount: string;
borrow_currency: string;
borrow_amount: string;
repaid_amount: string;
repaid_principal: string;
repaid_interest: string;
init_ltv: string;
current_ltv: string;
liquidate_ltv: string;
status: string;
borrow_time: number;
left_repay_total: string;
left_repay_principal: string;
left_repay_interest: string;
}
⋮----
export interface LoanRepaymentHistoryRecord {
order_id: number;
record_id: number;
repaid_amount: string;
borrow_currency: string;
collateral_currency: string;
init_ltv: string;
borrow_time: number;
repay_time: number;
total_interest: string;
before_left_principal: string;
after_left_principal: string;
before_left_collateral: string;
after_left_collateral: string;
}
⋮----
export interface LoanCollateralRecord {
order_id: number;
record_id: number;
borrow_currency: string;
borrow_amount: string;
collateral_currency: string;
before_collateral: string;
after_collateral: string;
before_ltv: string;
after_ltv: string;
operate_time: number;
}
⋮----
export interface LoanCollateralRatio {
collateral_currency: string;
borrow_currency: string;
init_ltv: string;
alert_ltv: string;
liquidate_ltv: string;
min_borrow_amount: string;
left_borrowable_amount: string;
}
================
File: src/types/response/earnuni.ts
================
/**==========================================================================================================================
* EARN UNI
* ==========================================================================================================================
*/
⋮----
export interface LendingCurrency {
currency: string;
min_lend_amount: string;
max_lend_amount: string;
max_rate: string;
min_rate: string;
}
⋮----
export interface LendingOrder {
currency: string;
current_amount: string;
amount: string;
lent_amount: string;
frozen_amount: string;
min_rate: string;
interest_status: string;
reinvest_left_amount: string;
create_time: number;
update_time: number;
}
⋮----
export interface LendingRecord {
currency: string;
amount: string;
last_wallet_amount: string;
last_lent_amount: string;
last_frozen_amount: string;
type: 'lend' | 'redeem';
create_time: number;
}
⋮----
export interface LendingInterestRecord {
status: number;
currency: string;
actual_rate: string;
interest: string;
interest_status: string;
create_time: number;
}
================
File: src/types/response/flashswap.ts
================
/**==========================================================================================================================
* FLASH SWAP
* ==========================================================================================================================
*/
⋮----
export interface FlashSwapCurrencyPair {
currency_pair: string;
sell_currency: string;
buy_currency: string;
sell_min_amount: string;
sell_max_amount: string;
buy_min_amount: string;
buy_max_amount: string;
}
⋮----
export interface FlashSwapOrder {
id: number;
create_time: number;
user_id: number;
sell_currency: string;
sell_amount: string;
buy_currency: string;
buy_amount: string;
price: string;
status: number;
}
⋮----
export interface SubmitFlashSwapOrderPreviewResp {
preview_id: string;
sell_currency: string;
sell_amount: string;
buy_currency: string;
buy_amount: string;
price: string;
}
================
File: src/types/response/marginuni.ts
================
/**==========================================================================================================================
* MARGIN UNI
* ==========================================================================================================================
*/
⋮----
export interface LendingMarket {
currency_pair: string;
base_min_borrow_amount: string;
quote_min_borrow_amount: string;
leverage: string;
}
⋮----
export interface MarginUNILoan {
currency: string;
currency_pair: string;
amount: string;
type: string;
create_time: number;
update_time: number;
}
⋮----
export interface MarginUNILoanRecord {
type: string;
currency_pair: string;
currency: string;
amount: string;
create_time: number;
}
⋮----
export interface MarginUNIInterestRecord {
currency: string;
currency_pair: string;
actual_rate: string;
interest: string;
status: number;
type: string;
create_time: number;
}
⋮----
export interface MarginUNIMaxBorrowable {
currency: string;
currency_pair: string;
borrowable: string;
}
================
File: src/types/response/multicollateralLoan.ts
================
/**==========================================================================================================================
* MULTI COLLATERAL LOAN
* ==========================================================================================================================
*/
⋮----
export interface MultiLoanOrder {
order_id: string;
order_type: string;
fixed_type: string;
fixed_rate: string;
expire_time: number;
auto_renew: boolean;
auto_repay: boolean;
current_ltv: string;
status: string;
borrow_time: number;
total_left_repay_usdt: string;
total_left_collateral_usdt: string;
borrow_currencies: {
currency: string;
index_price: string;
left_repay_principal: string;
left_repay_interest: string;
left_repay_usdt: string;
}[];
collateral_currencies: {
currency: string;
index_price: string;
left_collateral: string;
left_collateral_usdt: string;
}[];
}
⋮----
export interface RepayMultiLoanResp {
order_id: number;
repaid_currencies: {
succeeded: boolean;
label?: string;
message?: string;
currency: string;
repaid_principal: string;
repaid_interest: string;
}[];
}
⋮----
export interface MultiLoanRepayRecord {
order_id: number;
record_id: number;
init_ltv: string;
before_ltv: string;
after_ltv: string;
borrow_time: number;
repay_time: number;
borrow_currencies: {
currency: string;
index_price: string;
before_amount: string;
before_amount_usdt: string;
after_amount: string;
after_amount_usdt: string;
}[];
collateral_currencies: {
currency: string;
index_price: string;
before_amount: string;
before_amount_usdt: string;
after_amount: string;
after_amount_usdt: string;
}[];
repaid_currencies: {
currency: string;
index_price: string;
repaid_amount: string;
repaid_principal: string;
repaid_interest: string;
repaid_amount_usdt: string;
}[];
total_interest_list: {
currency: string;
index_price: string;
amount: string;
amount_usdt: string;
}[];
left_repay_interest_list: {
currency: string;
index_price: string;
before_amount: string;
before_amount_usdt: string;
after_amount: string;
after_amount_usdt: string;
}[];
}
⋮----
export interface UpdateMultiLoanResp {
order_id: number;
collateral_currencies: {
succeeded: boolean;
label?: string;
message?: string;
currency: string;
amount: string;
}[];
}
⋮----
export interface MultiLoanAdjustmentRecord {
order_id: number;
record_id: number;
before_ltv: string;
after_ltv: string;
operate_time: number;
borrow_currencies: {
currency: string;
index_price: string;
before_amount: string;
before_amount_usdt: string;
after_amount: string;
after_amount_usdt: string;
}[];
collateral_currencies: {
currency: string;
index_price: string;
before_amount: string;
before_amount_usdt: string;
after_amount: string;
after_amount_usdt: string;
}[];
}
⋮----
export interface MultiLoanCurrencyQuota {
currency: string;
index_price: string;
min_quota: string;
left_quota: string;
left_quote_usdt: string;
}
⋮----
export interface MultiLoanSupportedCurrencies {
loan_currencies: {
currency: string;
price: string;
}[];
collateral_currencies: {
currency: string;
index_price: string;
discount: string;
}[];
}
⋮----
export interface MultiLoanRatio {
init_ltv: string;
alert_ltv: string;
liquidate_ltv: string;
}
⋮----
export interface MultiLoanFixedRate {
currency: string;
rate_7d: string;
rate_30d: string;
update_time: number;
}
================
File: src/types/response/options.ts
================
/**==========================================================================================================================
* OPTIONS
* ==========================================================================================================================
*/
⋮----
export interface OptionsContract {
name: string;
tag: string;
create_time: number;
expiration_time: number;
is_call: boolean;
strike_price: string;
last_price: string;
mark_price: string;
orderbook_id: number;
trade_id: number;
trade_size: number;
position_size: number;
underlying: string;
underlying_price: string;
multiplier: string;
order_price_round: string;
mark_price_round: string;
maker_fee_rate: string;
taker_fee_rate: string;
price_limit_fee_rate: string;
ref_discount_rate: string;
ref_rebate_rate: string;
order_price_deviate: string;
order_size_min: number;
order_size_max: number;
orders_limit: number;
}
⋮----
export interface OptionsSettlementHistoryRecord {
time: number;
contract: string;
profit: string;
fee: string;
strike_price: string;
settle_price: string;
}
⋮----
export interface OptionsUserSettlement {
time: number;
underlying: string;
contract: string;
strike_price: string;
settle_price: string;
size: number;
settle_profit: string;
fee: string;
realised_pnl: string;
}
⋮----
export interface OptionsOrderBook {
id?: number;
current: number;
update: number;
asks: { p: string; s: number }[];
bids: { p: string; s: number }[];
}
⋮----
export interface OptionsTicker {
name: string;
last_price: string;
mark_price: string;
index_price: string;
ask1_size: number;
ask1_price: string;
bid1_size: number;
bid1_price: string;
position_size: number;
mark_iv: string;
bid_iv: string;
ask_iv: string;
leverage: string;
delta: string;
gamma: string;
vega: string;
theta: string;
rho: string;
}
⋮----
export interface OptionsCandle {
t: number;
v?: number;
c: string;
h: string;
l: string;
o: string;
}
⋮----
export interface OptionsUnderlyingCandle {
t: number;
v?: number;
c: string;
h: string;
l: string;
o: string;
sum: string;
}
⋮----
export interface OptionsTrade {
id: number;
create_time: number;
create_time_ms: number;
contract: string;
size: number;
price: string;
is_internal?: boolean;
}
⋮----
export interface OptionsAccount {
user: number;
total: string;
short_enabled: boolean;
unrealised_pnl: string;
init_margin: string;
maint_margin: string;
order_margin: string;
available: string;
point: string;
currency: string;
}
export interface OptionsAccountChangeRecord {
time: number;
change: string;
balance: string;
type: 'dnw' | 'prem' | 'fee' | 'refr' | 'set';
text: string;
}
⋮----
export interface OptionsPositionsUnderlying {
user: number;
underlying: string;
underlying_price: string;
contract: string;
size: number;
entry_price: string;
mark_price: string;
mark_iv: string;
realised_pnl: string;
unrealised_pnl: string;
pending_orders: number;
close_order: {
id: number;
price: string;
is_liq: boolean;
} | null;
delta: string;
gamma: string;
vega: string;
theta: string;
}
⋮----
export interface GetOptionsLiquidationResp {
time: number;
contract: string;
side: 'long' | 'short';
pnl: string;
text: string;
settle_size: string;
}
⋮----
export interface SubmitOptionsOrderResp {
id: number;
user: number;
create_time: number;
finish_time: number;
finish_as:
| 'filled'
| 'cancelled'
| 'liquidated'
| 'ioc'
| 'auto_deleveraged'
| 'reduce_only'
| 'position_closed';
status: 'open' | 'finished';
contract: string;
size: number;
iceberg: number;
price: string;
is_close: boolean;
is_reduce_only: boolean;
is_liq: boolean;
tif: 'gtc' | 'ioc' | 'poc';
left: number;
fill_price: string;
text: string;
tkfr: string;
mkfr: string;
refu: number;
refr: string;
}
⋮----
export interface OptionsUserHistoryRecord {
id: number;
create_time: number;
contract: string;
order_id: number;
size: number;
price: string;
underlying_price: string