Skip to content

Latest commit

 

History

History
1509 lines (1024 loc) · 60.3 KB

SpotApi.md

File metadata and controls

1509 lines (1024 loc) · 60.3 KB

SpotApi

All URIs are relative to https://api.gateio.ws/api/v4

Method HTTP request Description
listCurrencies GET /spot/currencies List all currencies' details
getCurrency GET /spot/currencies/{currency} Get details of a specific currency
listCurrencyPairs GET /spot/currency_pairs List all currency pairs supported
getCurrencyPair GET /spot/currency_pairs/{currency_pair} Get details of a specifc currency pair
listTickers GET /spot/tickers Retrieve ticker information
listOrderBook GET /spot/order_book Retrieve order book
listTrades GET /spot/trades Retrieve market trades
listCandlesticks GET /spot/candlesticks Market candlesticks
getFee GET /spot/fee Query user trading fee rates
getBatchSpotFee GET /spot/batch_fee Query a batch of user trading fee rates
listSpotAccounts GET /spot/accounts List spot accounts
listSpotAccountBook GET /spot/account_book Query account book
createBatchOrders POST /spot/batch_orders Create a batch of orders
listAllOpenOrders GET /spot/open_orders List all open orders
createCrossLiquidateOrder POST /spot/cross_liquidate_orders close position when cross-currency is disabled
listOrders GET /spot/orders List orders
createOrder POST /spot/orders Create an order
cancelOrders DELETE /spot/orders Cancel all `open` orders in specified currency pair
cancelBatchOrders POST /spot/cancel_batch_orders Cancel a batch of orders with an ID list
getOrder GET /spot/orders/{order_id} Get a single order
cancelOrder DELETE /spot/orders/{order_id} Cancel a single order
amendOrder PATCH /spot/orders/{order_id} Amend an order
listMyTrades GET /spot/my_trades List personal trading history
getSystemTime GET /spot/time Get server current time
countdownCancelAllSpot POST /spot/countdown_cancel_all Countdown cancel orders
amendBatchOrders POST /spot/amend_batch_orders Batch modification of orders
listSpotPriceTriggeredOrders GET /spot/price_orders Retrieve running auto order list
createSpotPriceTriggeredOrder POST /spot/price_orders Create a price-triggered order
cancelSpotPriceTriggeredOrderList DELETE /spot/price_orders Cancel all open orders
getSpotPriceTriggeredOrder GET /spot/price_orders/{order_id} Get a price-triggered order
cancelSpotPriceTriggeredOrder DELETE /spot/price_orders/{order_id} cancel a price-triggered order

listCurrencies

Promise<{ response: http.IncomingMessage; body: Array; }> listCurrencies()

List all currencies&#39; details

Currency has two forms: 1. Only currency name, e.g., BTC, USDT 2. `<currency><chain>`, e.g., `HT_ETH` The latter one occurs when one currency has multiple chains. Currency detail contains a `chain` field whatever the form is. To retrieve all chains of one currency, you can use use all the details which has the name of the currency or name starting with `<currency>`.

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"

const api = new GateApi.SpotApi(client);
api.listCurrencies()
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

This endpoint does not need any parameter.

Return type

Promise<{ response: AxiosResponse; body: Array; }> Currency

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

getCurrency

Promise<{ response: http.IncomingMessage; body: Currency; }> getCurrency(currency)

Get details of a specific currency

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"

const api = new GateApi.SpotApi(client);
const currency = "GT"; // string | Currency name
api.getCurrency(currency)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
currency string Currency name [default to undefined]

Return type

Promise<{ response: AxiosResponse; body: Currency; }> Currency

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

listCurrencyPairs

Promise<{ response: http.IncomingMessage; body: Array; }> listCurrencyPairs()

List all currency pairs supported

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"

const api = new GateApi.SpotApi(client);
api.listCurrencyPairs()
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

This endpoint does not need any parameter.

Return type

Promise<{ response: AxiosResponse; body: Array; }> CurrencyPair

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

getCurrencyPair

Promise<{ response: http.IncomingMessage; body: CurrencyPair; }> getCurrencyPair(currencyPair)

Get details of a specifc currency pair

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"

const api = new GateApi.SpotApi(client);
const currencyPair = "ETH_BTC"; // string | Currency pair
api.getCurrencyPair(currencyPair)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
currencyPair string Currency pair [default to undefined]

Return type

Promise<{ response: AxiosResponse; body: CurrencyPair; }> CurrencyPair

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

listTickers

Promise<{ response: http.IncomingMessage; body: Array; }> listTickers(opts)

Retrieve ticker information

Return only related data if `currency_pair` is specified; otherwise return all of them

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"

const api = new GateApi.SpotApi(client);
const opts = {
  'currencyPair': "BTC_USDT", // string | Currency pair
  'timezone': "utc0" // 'utc0' | 'utc8' | 'all' | Timezone
};
api.listTickers(opts)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
currencyPair string Currency pair [optional] [default to undefined]
timezone Timezone Timezone [optional] [default to undefined]

Return type

Promise<{ response: AxiosResponse; body: Array; }> Ticker

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

listOrderBook

Promise<{ response: http.IncomingMessage; body: OrderBook; }> listOrderBook(currencyPair, opts)

Retrieve order book

Order book will be sorted by price from high to low on bids; low to high on asks

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"

const api = new GateApi.SpotApi(client);
const currencyPair = "BTC_USDT"; // string | Currency pair
const opts = {
  'interval': '0', // string | Order depth. 0 means no aggregation is applied. default to 0
  'limit': 10, // number | Maximum number of order depth data in asks or bids
  'withId': false // boolean | Return order book ID
};
api.listOrderBook(currencyPair, opts)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
currencyPair string Currency pair [default to undefined]
interval string Order depth. 0 means no aggregation is applied. default to 0 [optional] [default to '0']
limit number Maximum number of order depth data in asks or bids [optional] [default to 10]
withId boolean Return order book ID [optional] [default to undefined]

Return type

Promise<{ response: AxiosResponse; body: OrderBook; }> OrderBook

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

listTrades

Promise<{ response: http.IncomingMessage; body: Array; }> listTrades(currencyPair, opts)

Retrieve market trades

You can use `from` and `to` to query by time range, or use `last_id` by scrolling page. The default behavior is by time range. Scrolling query using `last_id` is not recommended any more. If `last_id` is specified, time range query parameters will be ignored.

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"

const api = new GateApi.SpotApi(client);
const currencyPair = "BTC_USDT"; // string | Currency pair
const opts = {
  'limit': 100, // number | Maximum number of records to be returned in a single list.  Default: 100, Minimum: 1, Maximum: 1000
  'lastId': "12345", // string | Specify list staring point using the `id` of last record in previous list-query results
  'reverse': true, // boolean | Whether the id of records to be retrieved should be less than the last_id specified. Default to false.  When `last_id` is specified. Set `reverse` to `true` to trace back trading history; `false` to retrieve latest tradings.  No effect if `last_id` is not specified.
  'from': 1627706330, // number | Start timestamp of the query
  'to': 1635329650, // number | Time range ending, default to current time
  'page': 1 // number | Page number
};
api.listTrades(currencyPair, opts)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
currencyPair string Currency pair [default to undefined]
limit number Maximum number of records to be returned in a single list. Default: 100, Minimum: 1, Maximum: 1000 [optional] [default to 100]
lastId string Specify list staring point using the `id` of last record in previous list-query results [optional] [default to undefined]
reverse boolean Whether the id of records to be retrieved should be less than the last_id specified. Default to false. When `last_id` is specified. Set `reverse` to `true` to trace back trading history; `false` to retrieve latest tradings. No effect if `last_id` is not specified. [optional] [default to undefined]
from number Start timestamp of the query [optional] [default to undefined]
to number Time range ending, default to current time [optional] [default to undefined]
page number Page number [optional] [default to 1]

Return type

Promise<{ response: AxiosResponse; body: Array; }> Trade

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

listCandlesticks

Promise<{ response: http.IncomingMessage; body: Array<Array>; }> listCandlesticks(currencyPair, opts)

Market candlesticks

Maximum of 1000 points can be returned in a query. Be sure not to exceed the limit when specifying from, to and interval

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"

const api = new GateApi.SpotApi(client);
const currencyPair = "BTC_USDT"; // string | Currency pair
const opts = {
  'limit': 100, // number | Maximum recent data points to return. `limit` is conflicted with `from` and `to`. If either `from` or `to` is specified, request will be rejected.
  'from': 1546905600, // number | Start time of candlesticks, formatted in Unix timestamp in seconds. Default to`to - 100 * interval` if not specified
  'to': 1546935600, // number | End time of candlesticks, formatted in Unix timestamp in seconds. Default to current time
  'interval': '30m' // '10s' | '1m' | '5m' | '15m' | '30m' | '1h' | '4h' | '8h' | '1d' | '7d' | '30d' | Interval time between data points. Note that `30d` means 1 natual month, not 30 days
};
api.listCandlesticks(currencyPair, opts)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
currencyPair string Currency pair [default to undefined]
limit number Maximum recent data points to return. `limit` is conflicted with `from` and `to`. If either `from` or `to` is specified, request will be rejected. [optional] [default to 100]
from number Start time of candlesticks, formatted in Unix timestamp in seconds. Default to`to - 100 * interval` if not specified [optional] [default to undefined]
to number End time of candlesticks, formatted in Unix timestamp in seconds. Default to current time [optional] [default to undefined]
interval Interval Interval time between data points. Note that `30d` means 1 natual month, not 30 days [optional] [default to '30m']

Return type

Promise<{ response: AxiosResponse; body: Array<Array>; }> Array

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

getFee

Promise<{ response: http.IncomingMessage; body: TradeFee; }> getFee(opts)

Query user trading fee rates

This API is deprecated in favour of new fee retrieving API `/wallet/fee`.

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const opts = {
  'currencyPair': "BTC_USDT" // string | Specify a currency pair to retrieve precise fee rate  This field is optional. In most cases, the fee rate is identical among all currency pairs
};
api.getFee(opts)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
currencyPair string Specify a currency pair to retrieve precise fee rate This field is optional. In most cases, the fee rate is identical among all currency pairs [optional] [default to undefined]

Return type

Promise<{ response: AxiosResponse; body: TradeFee; }> TradeFee

Authorization

apiv4

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

getBatchSpotFee

Promise<{ response: http.IncomingMessage; body: { [key: string]: SpotFee; }; }> getBatchSpotFee(currencyPairs)

Query a batch of user trading fee rates

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const currencyPairs = "BTC_USDT,ETH_USDT"; // string | A request can only query up to 50 currency pairs
api.getBatchSpotFee(currencyPairs)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
currencyPairs string A request can only query up to 50 currency pairs [default to undefined]

Return type

Promise<{ response: AxiosResponse; body: { [key: string]: SpotFee; }; }> SpotFee

Authorization

apiv4

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

listSpotAccounts

Promise<{ response: http.IncomingMessage; body: Array; }> listSpotAccounts(opts)

List spot accounts

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const opts = {
  'currency': "BTC" // string | Retrieve data of the specified currency
};
api.listSpotAccounts(opts)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
currency string Retrieve data of the specified currency [optional] [default to undefined]

Return type

Promise<{ response: AxiosResponse; body: Array; }> SpotAccount

Authorization

apiv4

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

listSpotAccountBook

Promise<{ response: http.IncomingMessage; body: Array; }> listSpotAccountBook(opts)

Query account book

Record time range cannot exceed 30 days

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const opts = {
  'currency': "BTC", // string | Retrieve data of the specified currency
  'from': 1627706330, // number | Start timestamp of the query
  'to': 1635329650, // number | Time range ending, default to current time
  'page': 1, // number | Page number
  'limit': 100, // number | Maximum number of records to be returned in a single list
  'type': "lend" // string | Only retrieve changes of the specified type. All types will be returned if not specified.
};
api.listSpotAccountBook(opts)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
currency string Retrieve data of the specified currency [optional] [default to undefined]
from number Start timestamp of the query [optional] [default to undefined]
to number Time range ending, default to current time [optional] [default to undefined]
page number Page number [optional] [default to 1]
limit number Maximum number of records to be returned in a single list [optional] [default to 100]
type string Only retrieve changes of the specified type. All types will be returned if not specified. [optional] [default to undefined]

Return type

Promise<{ response: AxiosResponse; body: Array; }> SpotAccountBook

Authorization

apiv4

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

createBatchOrders

Promise<{ response: http.IncomingMessage; body: Array; }> createBatchOrders(order)

Create a batch of orders

Batch orders requirements: 1. custom order field `text` is required 2. At most 4 currency pairs, maximum 10 orders each, are allowed in one request 3. No mixture of spot orders and margin orders, i.e. `account` must be identical for all orders

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const order = [new Order()]; // Array<Order> | 
api.createBatchOrders(order)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
order Array<Order>

Return type

Promise<{ response: AxiosResponse; body: Array; }> BatchOrder

Authorization

apiv4

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

listAllOpenOrders

Promise<{ response: http.IncomingMessage; body: Array; }> listAllOpenOrders(opts)

List all open orders

List open orders in all currency pairs. Note that pagination parameters affect record number in each currency pair&#39;s open order list. No pagination is applied to the number of currency pairs returned. All currency pairs with open orders will be returned. Spot,portfolio and margin orders are returned by default. To list cross margin orders, `account` must be set to `cross_margin`

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const opts = {
  'page': 1, // number | Page number
  'limit': 100, // number | Maximum number of records returned in one page in each currency pair
  'account': "cross_margin" // string | Specify operation account. Default to spot ,portfolio and margin account if not specified. Set to `cross_margin` to operate against margin account.  Portfolio margin account must set to `cross_margin` only
};
api.listAllOpenOrders(opts)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
page number Page number [optional] [default to 1]
limit number Maximum number of records returned in one page in each currency pair [optional] [default to 100]
account string Specify operation account. Default to spot ,portfolio and margin account if not specified. Set to `cross_margin` to operate against margin account. Portfolio margin account must set to `cross_margin` only [optional] [default to undefined]

Return type

Promise<{ response: AxiosResponse; body: Array; }> OpenOrders

Authorization

apiv4

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

createCrossLiquidateOrder

Promise<{ response: http.IncomingMessage; body: Order; }> createCrossLiquidateOrder(liquidateOrder)

close position when cross-currency is disabled

Currently, only cross-margin accounts are supported to close position when cross currencies are disabled. Maximum buy quantity = (unpaid principal and interest - currency balance - the amount of the currency in the order book) / 0.998

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const liquidateOrder = new LiquidateOrder(); // LiquidateOrder | 
api.createCrossLiquidateOrder(liquidateOrder)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
liquidateOrder LiquidateOrder

Return type

Promise<{ response: AxiosResponse; body: Order; }> Order

Authorization

apiv4

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

listOrders

Promise<{ response: http.IncomingMessage; body: Array; }> listOrders(currencyPair, status, opts)

List orders

Spot, portfolio and margin orders are returned by default. If cross margin orders are needed, `account` must be set to `cross_margin` When `status` is `open`, i.e., listing open orders, only pagination parameters `page` and `limit` are supported and `limit` cannot be larger than 100. Query by `side` and time range parameters `from` and `to` are not supported. When `status` is `finished`, i.e., listing finished orders, pagination parameters, time range parameters `from` and `to`, and `side` parameters are all supported. Time range parameters are handled as order finish time.

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const currencyPair = "BTC_USDT"; // string | Retrieve results with specified currency pair. It is required for open orders, but optional for finished ones.
const status = "open"; // 'open' | 'finished' | List orders based on status  `open` - order is waiting to be filled `finished` - order has been filled or cancelled 
const opts = {
  'page': 1, // number | Page number
  'limit': 100, // number | Maximum number of records to be returned. If `status` is `open`, maximum of `limit` is 100
  'account': "cross_margin", // string | Specify operation account. Default to spot ,portfolio and margin account if not specified. Set to `cross_margin` to operate against margin account.  Portfolio margin account must set to `cross_margin` only
  'from': 1627706330, // number | Start timestamp of the query
  'to': 1635329650, // number | Time range ending, default to current time
  'side': "sell" // 'buy' | 'sell' | All bids or asks. Both included if not specified
};
api.listOrders(currencyPair, status, opts)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
currencyPair string Retrieve results with specified currency pair. It is required for open orders, but optional for finished ones. [default to undefined]
status Status List orders based on status `open` - order is waiting to be filled `finished` - order has been filled or cancelled [default to undefined]
page number Page number [optional] [default to 1]
limit number Maximum number of records to be returned. If `status` is `open`, maximum of `limit` is 100 [optional] [default to 100]
account string Specify operation account. Default to spot ,portfolio and margin account if not specified. Set to `cross_margin` to operate against margin account. Portfolio margin account must set to `cross_margin` only [optional] [default to undefined]
from number Start timestamp of the query [optional] [default to undefined]
to number Time range ending, default to current time [optional] [default to undefined]
side Side All bids or asks. Both included if not specified [optional] [default to undefined]

Return type

Promise<{ response: AxiosResponse; body: Array; }> Order

Authorization

apiv4

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

createOrder

Promise<{ response: http.IncomingMessage; body: Order; }> createOrder(order)

Create an order

You can place orders with spot, portfolio, margin or cross margin account through setting the `account `field. It defaults to `spot`, which means spot account is used to place orders. If the user is using unified account, it defaults to the unified account. When margin account is used, i.e., `account` is `margin`, `auto_borrow` field can be set to `true` to enable the server to borrow the amount lacked using `POST /margin/loans` when your account&#39;s balance is not enough. Whether margin orders&#39; fill will be used to repay margin loans automatically is determined by the auto repayment setting in your margin account, which can be updated or queried using `/margin/auto_repay` API. When cross margin account is used, i.e., `account` is `cross_margin`, `auto_borrow` can also be enabled to achieve borrowing the insufficient amount automatically if cross account&#39;s balance is not enough. But it differs from margin account that automatic repayment is determined by order&#39;s `auto_repay` field and only current order&#39;s fill will be used to repay cross margin loans. Automatic repayment will be triggered when the order is finished, i.e., its status is either `cancelled` or `closed`. Order status An order waiting to be filled is `open`, and it stays `open` until it is filled totally. If fully filled, order is finished and its status turns to `closed`.If the order is cancelled before it is totally filled, whether or not partially filled, its status is `cancelled`. Iceberg order `iceberg` field can be used to set the amount shown. Set to `-1` to hide the order completely. Note that the hidden part&#39;s fee will be charged using taker&#39;s fee rate. Self Trade Prevention - Set `stp_act` to decide the strategy of self-trade prevention. For detailed usage, refer to the `stp_act` parameter in request body

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const order = new Order(); // Order | 
api.createOrder(order)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
order Order

Return type

Promise<{ response: AxiosResponse; body: Order; }> Order

Authorization

apiv4

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

cancelOrders

Promise<{ response: http.IncomingMessage; body: Array; }> cancelOrders(currencyPair, opts)

Cancel all `open` orders in specified currency pair

If `account` is not set, all open orders, including spot, portfolio, margin and cross margin ones, will be cancelled. You can set `account` to cancel only orders within the specified account

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const currencyPair = "BTC_USDT"; // string | Currency pair
const opts = {
  'side': "sell", // 'buy' | 'sell' | All bids or asks. Both included if not specified
  'account': "spot" // 'spot' | 'margin' | 'cross_margin' | Specify account type  - classic account:Default to all account types being included   - portfolio margin account:`cross_margin` only
};
api.cancelOrders(currencyPair, opts)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
currencyPair string Currency pair [default to undefined]
side Side All bids or asks. Both included if not specified [optional] [default to undefined]
account Account Specify account type - classic account:Default to all account types being included - portfolio margin account:`cross_margin` only [optional] [default to undefined]

Return type

Promise<{ response: AxiosResponse; body: Array; }> Order

Authorization

apiv4

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

cancelBatchOrders

Promise<{ response: http.IncomingMessage; body: Array; }> cancelBatchOrders(cancelBatchOrder)

Cancel a batch of orders with an ID list

Multiple currency pairs can be specified, but maximum 20 orders are allowed per request

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const cancelBatchOrder = [new CancelBatchOrder()]; // Array<CancelBatchOrder> | 
api.cancelBatchOrders(cancelBatchOrder)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
cancelBatchOrder Array<CancelBatchOrder>

Return type

Promise<{ response: AxiosResponse; body: Array; }> CancelOrderResult

Authorization

apiv4

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

getOrder

Promise<{ response: http.IncomingMessage; body: Order; }> getOrder(orderId, currencyPair, opts)

Get a single order

Spot, portfolio and margin orders are queried by default. If cross margin orders are needed or portfolio margin account are used, account must be set to cross_margin.

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const orderId = "12345"; // string | Order ID returned, or user custom ID(i.e., `text` field). Operations based on custom ID can only be checked when the order is in orderbook.  When the order is finished, it can be checked within 1 hour after the end of the order.  After that, only order ID is accepted.
const currencyPair = "BTC_USDT"; // string | Currency pair
const opts = {
  'account': "cross_margin" // string | Specify operation account. Default to spot ,portfolio and margin account if not specified. Set to `cross_margin` to operate against margin account.  Portfolio margin account must set to `cross_margin` only
};
api.getOrder(orderId, currencyPair, opts)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
orderId string Order ID returned, or user custom ID(i.e., `text` field). Operations based on custom ID can only be checked when the order is in orderbook. When the order is finished, it can be checked within 1 hour after the end of the order. After that, only order ID is accepted. [default to undefined]
currencyPair string Currency pair [default to undefined]
account string Specify operation account. Default to spot ,portfolio and margin account if not specified. Set to `cross_margin` to operate against margin account. Portfolio margin account must set to `cross_margin` only [optional] [default to undefined]

Return type

Promise<{ response: AxiosResponse; body: Order; }> Order

Authorization

apiv4

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

cancelOrder

Promise<{ response: http.IncomingMessage; body: Order; }> cancelOrder(orderId, currencyPair, opts)

Cancel a single order

Spot,portfolio and margin orders are cancelled by default. If trying to cancel cross margin orders or portfolio margin account are used, account must be set to cross_margin

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const orderId = "12345"; // string | Order ID returned, or user custom ID(i.e., `text` field). Operations based on custom ID can only be checked when the order is in orderbook.  When the order is finished, it can be checked within 1 hour after the end of the order.  After that, only order ID is accepted.
const currencyPair = "BTC_USDT"; // string | Currency pair
const opts = {
  'account': "cross_margin" // string | Specify operation account. Default to spot ,portfolio and margin account if not specified. Set to `cross_margin` to operate against margin account.  Portfolio margin account must set to `cross_margin` only
};
api.cancelOrder(orderId, currencyPair, opts)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
orderId string Order ID returned, or user custom ID(i.e., `text` field). Operations based on custom ID can only be checked when the order is in orderbook. When the order is finished, it can be checked within 1 hour after the end of the order. After that, only order ID is accepted. [default to undefined]
currencyPair string Currency pair [default to undefined]
account string Specify operation account. Default to spot ,portfolio and margin account if not specified. Set to `cross_margin` to operate against margin account. Portfolio margin account must set to `cross_margin` only [optional] [default to undefined]

Return type

Promise<{ response: AxiosResponse; body: Order; }> Order

Authorization

apiv4

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

amendOrder

Promise<{ response: http.IncomingMessage; body: Order; }> amendOrder(orderId, currencyPair, orderPatch, opts)

Amend an order

By default, the orders of spot, portfolio and margin account are updated. If you need to modify orders of the `cross-margin` account, you must specify account as `cross_margin`. For portfolio margin account, only `cross_margin` account is supported. Currently, only supports modification of `price` or `amount` fields. Regarding rate limiting: modify order and create order sharing rate limiting rules. Regarding matching priority: Only reducing the quantity without modifying the priority of matching, altering the price or increasing the quantity will adjust the priority to the new price at the end Note: If the modified amount is less than the fill amount, the order will be cancelled.

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const orderId = "12345"; // string | Order ID returned, or user custom ID(i.e., `text` field). Operations based on custom ID can only be checked when the order is in orderbook.  When the order is finished, it can be checked within 1 hour after the end of the order.  After that, only order ID is accepted.
const currencyPair = "BTC_USDT"; // string | Currency pair
const orderPatch = new OrderPatch(); // OrderPatch | 
const opts = {
  'account': "cross_margin" // string | Specify operation account. Default to spot ,portfolio and margin account if not specified. Set to `cross_margin` to operate against margin account.  Portfolio margin account must set to `cross_margin` only
};
api.amendOrder(orderId, currencyPair, orderPatch, opts)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
orderId string Order ID returned, or user custom ID(i.e., `text` field). Operations based on custom ID can only be checked when the order is in orderbook. When the order is finished, it can be checked within 1 hour after the end of the order. After that, only order ID is accepted. [default to undefined]
currencyPair string Currency pair [default to undefined]
orderPatch OrderPatch
account string Specify operation account. Default to spot ,portfolio and margin account if not specified. Set to `cross_margin` to operate against margin account. Portfolio margin account must set to `cross_margin` only [optional] [default to undefined]

Return type

Promise<{ response: AxiosResponse; body: Order; }> Order

Authorization

apiv4

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

listMyTrades

Promise<{ response: http.IncomingMessage; body: Array; }> listMyTrades(opts)

List personal trading history

Spot,portfolio and margin trades are queried by default. If cross margin trades are needed, `account` must be set to `cross_margin` You can also set `from` and(or) `to` to query by time range. If you don&#39;t specify `from` and/or `to` parameters, only the last 7 days of data will be retured. The range of `from` and `to` is not alloed to exceed 30 days. Time range parameters are handled as order finish time.

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const opts = {
  'currencyPair': "BTC_USDT", // string | Retrieve results with specified currency pair
  'limit': 100, // number | Maximum number of records to be returned in a single list
  'page': 1, // number | Page number
  'orderId': "12345", // string | Filter trades with specified order ID. `currency_pair` is also required if this field is present
  'account': "cross_margin", // string | Specify operation account. Default to spot ,portfolio and margin account if not specified. Set to `cross_margin` to operate against margin account.  Portfolio margin account must set to `cross_margin` only
  'from': 1627706330, // number | Start timestamp of the query
  'to': 1635329650 // number | Time range ending, default to current time
};
api.listMyTrades(opts)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
currencyPair string Retrieve results with specified currency pair [optional] [default to undefined]
limit number Maximum number of records to be returned in a single list [optional] [default to 100]
page number Page number [optional] [default to 1]
orderId string Filter trades with specified order ID. `currency_pair` is also required if this field is present [optional] [default to undefined]
account string Specify operation account. Default to spot ,portfolio and margin account if not specified. Set to `cross_margin` to operate against margin account. Portfolio margin account must set to `cross_margin` only [optional] [default to undefined]
from number Start timestamp of the query [optional] [default to undefined]
to number Time range ending, default to current time [optional] [default to undefined]

Return type

Promise<{ response: AxiosResponse; body: Array; }> Trade

Authorization

apiv4

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

getSystemTime

Promise<{ response: http.IncomingMessage; body: SystemTime; }> getSystemTime()

Get server current time

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"

const api = new GateApi.SpotApi(client);
api.getSystemTime()
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

This endpoint does not need any parameter.

Return type

Promise<{ response: AxiosResponse; body: SystemTime; }> SystemTime

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

countdownCancelAllSpot

Promise<{ response: http.IncomingMessage; body: TriggerTime; }> countdownCancelAllSpot(countdownCancelAllSpotTask)

Countdown cancel orders

When the timeout set by the user is reached, if there is no cancel or set a new countdown, the related pending orders will be automatically cancelled. This endpoint can be called repeatedly to set a new countdown or cancel the countdown. For example, call this endpoint at 30s intervals, each countdown`timeout` is set to 30s. If this endpoint is not called again within 30 seconds, all pending orders on the specified `market` will be automatically cancelled, if no `market` is specified, all market pending orders will be cancelled. If the `timeout` is set to 0 within 30 seconds, the countdown timer will expire and the cacnel function will be cancelled.

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const countdownCancelAllSpotTask = new CountdownCancelAllSpotTask(); // CountdownCancelAllSpotTask | 
api.countdownCancelAllSpot(countdownCancelAllSpotTask)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
countdownCancelAllSpotTask CountdownCancelAllSpotTask

Return type

Promise<{ response: AxiosResponse; body: TriggerTime; }> TriggerTime

Authorization

apiv4

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

amendBatchOrders

Promise<{ response: http.IncomingMessage; body: Array; }> amendBatchOrders(batchAmendItem)

Batch modification of orders

Default modification of orders for spot, portfolio, and margin accounts. To modify orders for a cross margin account, the `account` parameter must be specified as `cross_margin`. For portfolio margin accounts, the `account` parameter can only be specified as `cross_margin`. Currently, only modifications to price or quantity (choose one) are supported. When modifying unfinished orders, a maximum of 5 orders can be batch-modified in one request. The request parameters should be passed in an array format. During batch modification, if one order modification fails, the modification process will continue with the next order. After execution, the response will include corresponding failure information for the failed orders. The sequence of calling for batch order modification should be consistent with the order in the order list. The response content order for batch order modification will also be consistent with the order in the order list.

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const batchAmendItem = [new BatchAmendItem()]; // Array<BatchAmendItem> | 
api.amendBatchOrders(batchAmendItem)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
batchAmendItem Array<BatchAmendItem>

Return type

Promise<{ response: AxiosResponse; body: Array; }> AmendOrderResult

Authorization

apiv4

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

listSpotPriceTriggeredOrders

Promise<{ response: http.IncomingMessage; body: Array; }> listSpotPriceTriggeredOrders(status, opts)

Retrieve running auto order list

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const status = "status_example"; // 'open' | 'finished' | Only list the orders with this status
const opts = {
  'market': "BTC_USDT", // string | Currency pair
  'account': "account_example", // 'normal' | 'margin' | 'cross_margin' | Trading account type.  Portfolio margin account must set to `cross_margin`
  'limit': 100, // number | Maximum number of records to be returned in a single list
  'offset': 0 // number | List offset, starting from 0
};
api.listSpotPriceTriggeredOrders(status, opts)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
status Status Only list the orders with this status [default to undefined]
market string Currency pair [optional] [default to undefined]
account Account Trading account type. Portfolio margin account must set to `cross_margin` [optional] [default to undefined]
limit number Maximum number of records to be returned in a single list [optional] [default to 100]
offset number List offset, starting from 0 [optional] [default to 0]

Return type

Promise<{ response: AxiosResponse; body: Array; }> SpotPriceTriggeredOrder

Authorization

apiv4

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

createSpotPriceTriggeredOrder

Promise<{ response: http.IncomingMessage; body: TriggerOrderResponse; }> createSpotPriceTriggeredOrder(spotPriceTriggeredOrder)

Create a price-triggered order

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const spotPriceTriggeredOrder = new SpotPriceTriggeredOrder(); // SpotPriceTriggeredOrder | 
api.createSpotPriceTriggeredOrder(spotPriceTriggeredOrder)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
spotPriceTriggeredOrder SpotPriceTriggeredOrder

Return type

Promise<{ response: AxiosResponse; body: TriggerOrderResponse; }> TriggerOrderResponse

Authorization

apiv4

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

cancelSpotPriceTriggeredOrderList

Promise<{ response: http.IncomingMessage; body: Array; }> cancelSpotPriceTriggeredOrderList(opts)

Cancel all open orders

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const opts = {
  'market': "BTC_USDT", // string | Currency pair
  'account': "account_example" // 'normal' | 'margin' | 'cross_margin' | Trading account type.  Portfolio margin account must set to `cross_margin`
};
api.cancelSpotPriceTriggeredOrderList(opts)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
market string Currency pair [optional] [default to undefined]
account Account Trading account type. Portfolio margin account must set to `cross_margin` [optional] [default to undefined]

Return type

Promise<{ response: AxiosResponse; body: Array; }> SpotPriceTriggeredOrder

Authorization

apiv4

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

getSpotPriceTriggeredOrder

Promise<{ response: http.IncomingMessage; body: SpotPriceTriggeredOrder; }> getSpotPriceTriggeredOrder(orderId)

Get a price-triggered order

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const orderId = "orderId_example"; // string | Retrieve the data of the order with the specified ID
api.getSpotPriceTriggeredOrder(orderId)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
orderId string Retrieve the data of the order with the specified ID [default to undefined]

Return type

Promise<{ response: AxiosResponse; body: SpotPriceTriggeredOrder; }> SpotPriceTriggeredOrder

Authorization

apiv4

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

cancelSpotPriceTriggeredOrder

Promise<{ response: http.IncomingMessage; body: SpotPriceTriggeredOrder; }> cancelSpotPriceTriggeredOrder(orderId)

cancel a price-triggered order

Example

const GateApi = require('gate-api');
const client = new GateApi.ApiClient();
// uncomment the next line to change base path
// client.basePath = "https://some-other-host"
// Configure Gate APIv4 key authentication:
client.setApiKeySecret("YOUR_API_KEY", "YOUR_API_SECRET");

const api = new GateApi.SpotApi(client);
const orderId = "orderId_example"; // string | Retrieve the data of the order with the specified ID
api.cancelSpotPriceTriggeredOrder(orderId)
   .then(value => console.log('API called successfully. Returned data: ', value.body),
         error => console.error(error));

Parameters

Name Type Description Notes
orderId string Retrieve the data of the order with the specified ID [default to undefined]

Return type

Promise<{ response: AxiosResponse; body: SpotPriceTriggeredOrder; }> SpotPriceTriggeredOrder

Authorization

apiv4

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json