### Node.js SDK Installation Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/sdk-examples.md Install the Node.js SDK using npm. ```bash npm install '@gateio/gate-api' ``` -------------------------------- ### Get Contracts Response Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/market.md Example JSON response for the Get Contracts endpoint, showing a list of options contracts. ```json [ { "name": "BTC_USDT-20230630-30000-C", "underlying": "BTC_USDT", "strike_price": "30000", "expiration": 1625097600, "type": "call", "multiplier": "0.01", "is_active": true } ] ``` -------------------------------- ### Python SDK Installation Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/sdk-examples.md Install the Python SDK using pip. ```bash pip install gate-api ``` -------------------------------- ### Get Order Book Response Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/market.md Example JSON response for the Get Order Book endpoint, showing the asks and bids for an options contract. ```json { "contract": "BTC_USDT-20230630-30000-C", "asks": [ ["2010", "1.0"], ["2015", "2.0"] ], "bids": [ ["1990", "1.5"], ["1985", "2.5"] ] } ``` -------------------------------- ### Get Options Statistics Response Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/market.md Example JSON response for the Get Options Statistics endpoint, showing market statistics for an underlying asset. ```json { "underlying": "BTC_USDT", "total_calls_volume": "1000", "total_puts_volume": "800", "total_calls_amount": "2000000", "total_puts_amount": "1600000", "put_call_ratio": "0.8", "index_price": "29000", "volatility": "0.65" } ``` -------------------------------- ### Get Recent Trades Response Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/market.md Example JSON response for the Get Recent Trades endpoint, listing recent trades for an options contract. ```json [ { "id": 123456, "create_time": 1623456789, "contract": "BTC_USDT-20230630-30000-C", "size": "1.0", "price": "2000" } ] ``` -------------------------------- ### Get Contracts Response Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/market.md Example response for retrieving a list of all futures contracts. ```json { "name": "BTC_USDT", "type": "direct", "quanto_multiplier": "0.0001", "leverage_min": "1", "leverage_max": "100", "maintenance_rate": "0.005", "mark_type": "index", "maker_fee_rate": "-0.00025", "taker_fee_rate": "0.00075", "order_price_round": "0.1", "mark_price_round": "0.1", "funding_rate": "0.002", "order_size_min": 1 } ``` -------------------------------- ### Get Tickers Response Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/market.md Example JSON response for the Get Tickers endpoint, providing market ticker information for an options contract. ```json { "name": "BTC_USDT-20230630-30000-C", "last": "2000", "mark_price": "2005", "index_price": "29000", "bid1_price": "1990", "bid1_size": "1.0", "ask1_price": "2010", "ask1_size": "1.0", "volume_24h": "100", "volume_24h_usd": "200000", "delta": "0.65", "gamma": "0.0001", "vega": "10", "theta": "-5" } ``` -------------------------------- ### Get Funding Rate Response Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/market.md Example response for retrieving funding rate for a specific futures contract. ```json { "funding_rate": "0.002", "funding_time": 1623456789 } ``` -------------------------------- ### Get Account Balance Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/spot/account.md Example JSON response for retrieving spot account balances. ```json [ { "currency": "BTC", "available": "1.23456789", "locked": "0.12345678" } ] ``` -------------------------------- ### Python SDK Spot Trading Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/sdk-examples.md Example of how to perform spot trading operations using the Python SDK. ```python from gate_api import ApiClient, Configuration, Order, SpotApi # Initialize API client config = Configuration( key='your_api_key', secret='your_api_secret' ) spot_api = SpotApi(ApiClient(config)) # Get currency pair info currency_pair = "BTC_USDT" pair = spot_api.get_currency_pair(currency_pair) min_amount = pair.min_base_amount # Get last price tickers = spot_api.list_tickers(currency_pair=currency_pair) last_price = tickers[0].last # Check account balance accounts = spot_api.list_spot_accounts(currency=currency_pair.split("_")[1]) available = accounts[0].available # Place order order = Order( amount=min_amount * 2, price=last_price, side='buy', currency_pair=currency_pair ) created = spot_api.create_order(order) # Check and cancel order if needed if created.status == 'open': order_result = spot_api.get_order(created.id, currency_pair) if order_result.left > 0: # if order not fully filled result = spot_api.cancel_order(order_result.id, currency_pair) ``` -------------------------------- ### Python SDK Futures Trading Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/sdk-examples.md Example of how to perform futures trading operations using the Python SDK. ```python from gate_api import ApiClient, Configuration, FuturesApi, FuturesOrder # Initialize API client config = Configuration( key='your_api_key', secret='your_api_secret' ) futures_api = FuturesApi(ApiClient(config)) # Set up futures trading settle = "usdt" contract = "BTC_USDT" # Set leverage leverage = "3" futures_api.update_position_leverage(settle, contract, leverage) # Get position try: position = futures_api.get_position(settle, contract) position_size = position.size except GateApiException as ex: if ex.label != "POSITION_NOT_FOUND": raise ex # Get contract details futures_contract = futures_api.get_futures_contract(settle, contract) order_size = max(10, futures_contract.order_size_min) # Update risk limit risk_limit = futures_contract.risk_limit_base + futures_contract.risk_limit_step futures_api.update_position_risk_limit(settle, contract, str(risk_limit)) # Place futures order order = FuturesOrder( contract=contract, size=order_size, price=price, tif='gtc' # good till cancelled ) created = futures_api.create_futures_order(settle, order) ``` -------------------------------- ### Get Currency Pairs Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/spot/market.md Example response for retrieving a list of all supported currency pairs for spot trading. ```json [ { "id": "BTC_USDT", "base": "BTC", "quote": "USDT", "fee": "0.2", "min_base_amount": "0.0001", "min_quote_amount": "1", "amount_precision": 4, "precision": 2, "trade_status": "tradable" } ] ``` -------------------------------- ### Node.js SDK Basic Usage Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/sdk-examples.md Example of basic usage for the Node.js SDK, including setting API keys and making a spot API call. ```javascript const GateApi = require('@gateio/gate-api'); const client = new GateApi.ApiClient(); client.setApiKeySecret('YOUR_API_KEY', 'YOUR_API_SECRET'); // Spot API example const spotApi = new GateApi.SpotApi(client); const currencyPair = 'BTC_USDT'; // Get market info spotApi.listTickers(currencyPair) .then(tickers => { console.log(`Last price: ${tickers[0].last}`); }) .catch(err => console.log(err)); // Place order const order = new GateApi.Order(); order.currencyPair = currencyPair; order.amount = '0.01'; order.price = '10000'; order.side = 'buy'; spotApi.createOrder(order) .then(response => { console.log(`Order created: ${response.id}`); }) .catch(err => console.log(err)); ``` -------------------------------- ### Get Position Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/trading.md Example JSON response for retrieving current options positions. ```json { "contract": "BTC_USDT-20230630-30000-C", "size": "1.0", "entry_price": "2000", "mark_price": "2100", "realised_pnl": "0", "unrealised_pnl": "100", "pending_orders": 0 } ``` -------------------------------- ### Get Open Orders Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/trading.md Example JSON response for retrieving all open options orders. ```json [ { "id": "123456789", "contract": "BTC_USDT-20230630-30000-C", "create_time": 1623456789, "size": "1.0", "price": "2000", "fill_price": "0", "status": "open", "tif": "gtc", "text": "custom_tag" } ] ``` -------------------------------- ### Get Account History Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/spot/account.md Example JSON response for retrieving spot account history. ```json [ { "id": "12345", "currency": "BTC", "type": "trade", "amount": "0.1", "time": "1548000000" } ] ``` -------------------------------- ### Go Authentication Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/authentication.md Example of how to sign a request using Go for Gate.io API v4 authentication. ```go package main import ( "crypto/hmac" "crypto/sha512" "encoding/hex" "fmt" "strconv" "time" "github.com/gateio/gateapi-go/v6" ) func signRequest(method, path, queryString, body string) map[string]string { timestamp := strconv.FormatInt(time.Now().Unix(), 10) stringToSign := fmt.Sprintf("%s|%s|%s|%s|%s", method, path, queryString, timestamp, body) h := sha512.New() h.Write([]byte(stringToSign)) mac := hmac.New(sha512.New, []byte(apiSecret)) mac.Write(h.Sum(nil)) sign := hex.EncodeToString(mac.Sum(nil)) return map[string]string{ "KEY": apiKey, "Timestamp": timestamp, "SIGN": sign, } } // Usage example client := gateapi.NewAPIClient(gateapi.NewConfiguration()) client.SetApiKeySecret("your_api_key", "your_api_secret") ``` -------------------------------- ### Get Recent Trades Response Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/market.md Example response for retrieving recent trades for a specific futures contract. ```json [ { "id": 123456, "create_time": 1623456789, "contract": "BTC_USDT", "size": 0.1, "price": "8600.0", "side": "buy" } ] ``` -------------------------------- ### Get Tickers Response Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/market.md Example response for retrieving ticker information for futures contracts. ```json { "contract": "BTC_USDT", "last": "8600.0", "change_percentage": "3.5", "volume": "10.5", "low_24h": "8200.0", "high_24h": "8800.0", "mark_price": "8500.0", "funding_rate": "0.002", "index_price": "8500.0" } ``` -------------------------------- ### Get Account Information Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/account.md Example JSON response for retrieving options account information and balances. ```json { "total": "10000", "unrealized_pnl": "500", "option_value": "2000", "short_positions": "3", "long_positions": "2", "available": "7500", "currency": "USDT", "margin_ratio": "0.2" } ``` -------------------------------- ### Get Order Book Response Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/market.md Example response for retrieving order book data for a specific futures contract. ```json { "asks": [ ["8700.0", "0.1"], ["8701.0", "0.2"] ], "bids": [ ["8699.0", "0.3"], ["8698.0", "0.4"] ] } ``` -------------------------------- ### Get Order Book Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/spot/market.md Example response for retrieving the order book for a specific currency pair. ```json { "id": 123456789, "current": 1627544100, "update": 1627544099, "asks": [ ["45001.00", "0.5000"], ["45002.00", "0.3000"] ], "bids": [ ["44999.00", "0.4000"], ["44998.00", "0.2000"] ] } ``` -------------------------------- ### Get Tickers Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/spot/market.md Example response for retrieving ticker information for all currency pairs or a specific pair. ```json [ { "currency_pair": "BTC_USDT", "last": "45000.00", "lowest_24h": "44000.00", "highest_24h": "46000.00", "change_percentage": "2.5", "base_volume": "1000.0000", "quote_volume": "45000000.00" } ] ``` -------------------------------- ### Get Recent Trades Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/spot/market.md Example response for retrieving recent trades for a specific currency pair. ```json [ { "id": "123456789", "create_time": 1627544100, "create_time_ms": "1627544100123", "side": "buy", "currency_pair": "BTC_USDT", "amount": "0.0100", "price": "45000.00" } ] ``` -------------------------------- ### Python Authentication Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/authentication.md Example of how to sign a request using Python for Gate.io API v4 authentication. ```python import time import hmac import hashlib import requests from gate_api import ApiClient, Configuration def sign_request(method: str, path: str, query_string: str = '', body: str = ''): t = time.time() m = hashlib.sha512() m.update((method + '|' + path + '|' + query_string + '|' + str(t) + '|' + body).encode('utf-8')) sign = hmac.new(api_secret.encode('utf-8'), m.digest(), hashlib.sha512).hexdigest() return { 'KEY': api_key, 'Timestamp': str(t), 'SIGN': sign } # Usage example config = Configuration(key='your_api_key', secret='your_api_secret') client = ApiClient(config) ``` -------------------------------- ### Get Position Risk Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/account.md Example JSON response for retrieving risk metrics for options positions. ```json { "total_delta": "0.5", "total_gamma": "0.001", "total_vega": "20", "total_theta": "-10", "margin_occupied": "2000", "margin_required": "1500", "effective_leverage": "2.5", "portfolio_var": "1000", "positions": [ { "contract": "BTC_USDT-20230630-30000-C", "size": "1.0", "delta": "0.6", "gamma": "0.0005", "vega": "10", "theta": "-5" } ] } ``` -------------------------------- ### Place Order Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/unified/trading.md Example JSON response for placing a new order in a unified trading market. ```json { "id": "123456789", "product": "spot", "contract": "BTC_USDT", "size": "1.0", "price": "50000", "filled_size": "0", "filled_price": "0", "status": "open", "type": "limit", "tif": "gtc", "create_time": 1234567890, "finish_time": 0 } ``` -------------------------------- ### Get Position Risk Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/account.md Example response for retrieving risk metrics for all positions. ```json [ { "contract": "BTC_USDT", "size": 1, "leverage": "10", "risk_limit": "100", "margin": "5.2", "entry_price": "8500.0", "liq_price": "7800.0", "mark_price": "8600.0", "unrealized_pnl": "0.1", "maintenance_rate": "0.005" } ] ``` -------------------------------- ### Get Account Info Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/account.md Example response for retrieving futures account information. ```json { "user": 1234, "total": "10.5", "unrealized_pnl": "0.1", "margin": "5.2", "available": "5.2", "point": "0.0", "currency": "USDT" } ``` -------------------------------- ### Place Order Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/spot/trading.md Example response structure for a successful spot trading order creation. ```json { "id": "123456789", "text": "custom_tag", "create_time": "1548000000", "update_time": "1548000100", "currency_pair": "BTC_USDT", "status": "open", "type": "limit", "account": "spot", "side": "buy", "amount": "1", "price": "4000", "filled_amount": "0", "filled_price": "0", "fee": "0", "fee_currency": "USDT", "point_fee": "0", "gt_fee": "0", "gt_discount": false, "rebated_fee": "0", "rebated_fee_currency": "USDT" } ``` -------------------------------- ### Place Order Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/trading.md Example JSON response when placing an options order. ```json { "id": "123456789", "contract": "BTC_USDT-20230630-30000-C", "create_time": 1623456789, "size": "1.0", "price": "2000", "fill_price": "0", "status": "open", "tif": "gtc", "text": "custom_tag" } ``` -------------------------------- ### Get Account History Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/account.md Example JSON response for retrieving options account history. ```json [ { "time": 1623456789, "type": "premium", "contract": "BTC_USDT-20230630-30000-C", "size": "1.0", "amount": "2000", "currency": "USDT" } ] ``` -------------------------------- ### Get Position Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/unified/trading.md Example JSON response for retrieving current position information in a unified trading market. ```json { "product": "futures", "contract": "BTC_USDT", "size": "1.0", "leverage": "2", "entry_price": "50000", "mark_price": "51000", "realised_pnl": "0", "unrealised_pnl": "1000", "margin_requirement": "5000", "maintenance_margin": "2500", "risk_level": "low" } ``` -------------------------------- ### Get Account Book Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/account.md Example response for retrieving account balance change history. ```json [ { "time": 1623456789, "change": "0.1", "balance": "10.5", "type": "pnl", "text": "Trading profit" } ] ``` -------------------------------- ### Get Candlestick Data Response Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/market.md Example response for retrieving candlestick (k-line) data for a specific futures contract. ```json [ [ 1623456789, // timestamp "8500.0", // open "8600.0", // close "8700.0", // high "8400.0", // low "100.0" // volume ] ] ``` -------------------------------- ### Error Handling Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/unified/ws-user.md Example JSON object for handling authentication or subscription errors. ```json { "time": 1234567890, "channel": "unified.orders", "event": "error", "message": "Authentication failed", "code": 401 } ``` -------------------------------- ### Get Order History Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/trading.md Example JSON response for retrieving historical options orders. ```json [ { "id": "123456789", "contract": "BTC_USDT-20230630-30000-C", "create_time": 1623456789, "finish_time": 1623456799, "size": "1.0", "price": "2000", "fill_price": "2000", "status": "finished", "tif": "gtc", "text": "custom_tag" } ] ``` -------------------------------- ### Get Funding History Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/account.md Example response for retrieving funding payment history. ```json [ { "contract": "BTC_USDT", "funding_time": 1623456789, "funding_rate": "0.002", "amount": "0.1" } ] ``` -------------------------------- ### Reduce-Only Order Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/trading.md Example of a reduce-only futures order. ```json { "contract": "BTC_USDT", "size": -1, "price": "50000", "reduce_only": true } ``` -------------------------------- ### Node.js Authentication Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/authentication.md Example of how to sign a request using Node.js for Gate.io API v4 authentication. ```javascript const crypto = require('crypto'); const GateApi = require('@gateio/gate-api'); function signRequest(method, path, queryString = '', body = '') { const timestamp = Math.floor(Date.now() / 1000); const stringToSign = `${method}|${path}|${queryString}|${timestamp}|${body}`; const hash = crypto.createHash('sha512') .update(stringToSign) .digest(); const signature = crypto.createHmac('sha512', apiSecret) .update(hash) .digest('hex'); return { 'KEY': apiKey, 'Timestamp': timestamp.toString(), 'SIGN': signature }; } // Usage example const client = new GateApi.ApiClient(); client.setApiKeySecret('your_api_key', 'your_api_secret'); ``` -------------------------------- ### Take Profit Order Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/trading.md Example of a take-profit futures order. ```json { "contract": "BTC_USDT", "size": -1, "price": "55000", "stop": "profit", "stop_price": "54000" } ``` -------------------------------- ### Get Order Status Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/trading.md Example JSON response for retrieving the status of a specific options order. ```json { "id": "123456789", "contract": "BTC_USDT-20230630-30000-C", "create_time": 1623456789, "size": "1.0", "price": "2000", "fill_price": "2000", "status": "closed", "tif": "gtc", "text": "custom_tag" } ``` -------------------------------- ### Get Settlement History Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/account.md Example JSON response for retrieving options settlement history. ```json [ { "time": 1625097600, "contract": "BTC_USDT-20230630-30000-C", "strike_price": "30000", "settlement_price": "35000", "profit": "5000", "fee": "10", "currency": "USDT" } ] ``` -------------------------------- ### Error Handling Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/ws-market.md Example JSON response indicating an error occurred during a subscription or data retrieval. ```json { "time": 1234567890, "channel": "options.tickers", "event": "error", "message": "Invalid subscription format", "code": 1 } ``` -------------------------------- ### Error Handling Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/ws-user.md Example JSON response for authentication or subscription errors. ```json { "time": 1234567890, "channel": "futures.orders", "event": "error", "message": "Authentication failed", "code": 401 } ``` -------------------------------- ### Get Position Risk Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/unified/account.md Get risk metrics for all positions. ```json { "total_risk": "10000", "total_margin_requirement": "5000", "margin_ratio": "0.2", "liquidation_price": "25000", "positions": [ { "product": "spot", "currency_pair": "BTC_USDT", "size": "1.0", "value": "30000", "leverage": "2", "risk_weight": "0.1", "margin_requirement": "3000" } ] } ``` -------------------------------- ### Get Candlestick Data Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/spot/market.md Example response for retrieving candlestick/kline data for a specific currency pair. ```json [ [ "1627544100", // timestamp "45000.00", // open "45100.00", // high "44900.00", // low "45050.00", // close "100.0000", // volume "4505000.00" // quote volume ] ] ``` -------------------------------- ### Account Balance Update Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/spot/ws-user.md Example of a WebSocket response detailing account balance changes. ```json { "time": 1234567890, "channel": "spot.balances", "event": "update", "result": { "timestamp": "1234567890123", "currency": "BTC", "available": "1.23456789", "locked": "0.12345678" } } ``` -------------------------------- ### Get Account Balance Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/unified/account.md Get detailed balance information for each asset. ```json [ { "currency": "BTC", "available": "1.0", "locked": "0.5", "borrowed": "0.2", "interest": "0.0001", "total": "1.5", "value_in_usd": "45000", "value_in_btc": "1.5" } ] ``` -------------------------------- ### Account Updates Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/ws-user.md Example JSON response detailing account balance updates. ```json { "time": 1234567890, "channel": "options.balances", "event": "update", "result": { "total": "10000", "unrealized_pnl": "500", "option_value": "2000", "short_positions": "3", "long_positions": "2", "available": "7500", "currency": "USDT", "margin_ratio": "0.2" } } ``` -------------------------------- ### Stop Loss Order Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/trading.md Example of a stop-loss futures order. ```json { "contract": "BTC_USDT", "size": -1, "price": "45000", "stop": "loss", "stop_price": "46000" } ``` -------------------------------- ### Portfolio Risk Updates Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/ws-user.md Example JSON response detailing portfolio risk metrics. ```json { "time": 1234567890, "channel": "options.portfolio", "event": "update", "result": { "total_delta": "0.5", "total_gamma": "0.001", "total_vega": "20", "total_theta": "-10", "margin_occupied": "2000", "margin_required": "1500", "effective_leverage": "2.5", "portfolio_var": "1000" } } ``` -------------------------------- ### Get Borrowing Info Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/unified/account.md Get borrowing information for margin positions. ```json [ { "currency": "BTC", "borrowable": "10.0", "interest_rate": "0.0002", "min_borrow_amount": "0.01", "borrow_ceiling": "100" } ] ``` -------------------------------- ### Get Unified Account Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/unified/account.md Get unified account information and balances. ```json { "user_id": 123456, "total_equity": "100000", "total_liability": "20000", "total_margin_balance": "80000", "total_initial_margin": "10000", "total_maintenance_margin": "5000", "total_available_margin": "70000", "total_unrealized_pnl": "1000", "margin_level": "8.0", "portfolio_margin_total_equity": "100000", "portfolio_margin_total_liability": "20000", "currency": "USDT" } ``` -------------------------------- ### Position Risk Calculation Metrics Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/account.md Example JSON object for position risk calculation metrics. ```json { "position_risk": { "var_99": "10000", "expected_shortfall": "15000", "stress_test_loss": "20000" } } ``` -------------------------------- ### Authentication Signature Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/unified/ws-user.md This JSON object demonstrates the structure for signing a WebSocket connection for authentication purposes. ```json { "time": 1234567890, "channel": "unified.orders", "event": "subscribe", "auth": { "method": "api_key", "KEY": "your_api_key", "SIGN": "calculated_signature" } } ``` -------------------------------- ### Personal Trading Updates Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/spot/ws-user.md Example of a WebSocket response detailing personal trade information. ```json { "time": 1234567890, "channel": "spot.usertrades", "event": "update", "result": { "id": "12345", "create_time": "1234567890", "create_time_ms": "1234567890123", "currency_pair": "BTC_USDT", "side": "buy", "role": "taker", "amount": "1.0", "price": "50000", "order_id": "123456789", "fee": "0.1", "fee_currency": "USDT", "point_fee": "0", "gt_fee": "0" } } ``` -------------------------------- ### Subscribe to Funding Rate Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/ws-market.md Example response structure for real-time funding rate updates. ```json { "time": 1234567890, "channel": "futures.funding_rate", "event": "update", "result": { "contract": "BTC_USDT", "funding_rate": "0.0001", "funding_rate_indicative": "0.0002", "funding_time": 1234567890 } } ``` -------------------------------- ### Error Handling Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/ws-market.md Example JSON structure for an error message received from the WebSocket. ```json { "time": 1234567890, "channel": "futures.tickers", "event": "error", "message": "Invalid subscription format", "code": 1 } ``` -------------------------------- ### Position Updates Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/ws-user.md Example JSON response detailing position updates. ```json { "time": 1234567890, "channel": "options.positions", "event": "update", "result": { "contract": "BTC_USDT-20230630-30000-C", "size": "1.0", "entry_price": "2000", "mark_price": "2100", "realised_pnl": "0", "unrealised_pnl": "100", "delta": "0.65", "gamma": "0.0001", "vega": "10", "theta": "-5" } } ``` -------------------------------- ### Order Status Update Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/spot/ws-user.md Example of a WebSocket response detailing changes in order status. ```json { "time": 1234567890, "channel": "spot.orders", "event": "update", "result": { "id": "123456789", "user": "1234", "text": "custom_tag", "create_time": "1234567890", "update_time": "1234567890", "currency_pair": "BTC_USDT", "status": "open", "type": "limit", "account": "spot", "side": "buy", "amount": "1", "price": "50000", "filled_amount": "0.5", "filled_price": "49999", "fee": "0.1", "fee_currency": "USDT", "point_fee": "0", "gt_fee": "0", "gt_discount": false, "rebated_fee": "0", "rebated_fee_currency": "USDT" } } ``` -------------------------------- ### Subscribe to Trades Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/ws-market.md Example JSON response containing real-time trade updates for an options contract. ```json { "time": 1234567890, "channel": "options.trades", "event": "update", "result": { "id": 123456, "create_time": 1234567890, "create_time_ms": 1234567890123, "contract": "BTC_USDT-20230630-30000-C", "size": "1.0", "price": "2000" } } ``` -------------------------------- ### Account Updates Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/unified/ws-user.md Example response structure for unified account balance updates. ```json { "time": 1234567890, "channel": "unified.balances", "event": "update", "result": { "total_equity": "100000", "total_liability": "20000", "total_margin_balance": "80000", "total_initial_margin": "10000", "total_maintenance_margin": "5000", "total_available_margin": "70000", "total_unrealized_pnl": "1000", "margin_level": "8.0", "currency": "USDT", "update_time": 1234567890 } } ``` -------------------------------- ### Order Updates Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/ws-user.md Example JSON response detailing order status updates. ```json { "time": 1234567890, "channel": "options.orders", "event": "update", "result": { "id": "123456789", "contract": "BTC_USDT-20230630-30000-C", "size": "1.0", "price": "2000", "fill_price": "2000", "status": "closed", "type": "limit", "tif": "gtc", "create_time": 1234567890, "finish_time": 1234567890 } } ``` -------------------------------- ### Risk Updates Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/unified/ws-user.md Example response structure for unified portfolio risk updates. ```json { "time": 1234567890, "channel": "unified.risk", "event": "update", "result": { "total_risk": "10000", "total_margin_requirement": "5000", "margin_ratio": "0.2", "liquidation_risk": "low", "largest_position_risk": "3000", "portfolio_var": "2000", "update_time": 1234567890 } } ``` -------------------------------- ### WebSocket Error Handling Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/spot/ws-user.md JSON structure for WebSocket errors, indicating authentication or subscription failures. ```json { "time": 1234567890, "channel": "spot.orders", "event": "error", "message": "Authentication failed", "code": 401 } ``` -------------------------------- ### Error Handling Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/ws-user.md JSON payload indicating an authentication or subscription error. ```json { "time": 1234567890, "channel": "options.orders", "event": "error", "message": "Authentication failed", "code": 401 } ``` -------------------------------- ### Subscribe to Trades Request Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/ws-market.md Example JSON request to subscribe to real-time trade updates for a specific options contract. ```json { "time": 1234567890, "channel": "options.trades", "event": "subscribe", "payload": ["BTC_USDT-20230630-30000-C"] } ``` -------------------------------- ### Subscribe to Trades Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/ws-market.md Example response structure for real-time trade updates. ```json { "time": 1234567890, "channel": "futures.trades", "event": "update", "result": { "id": 123456, "create_time": 1234567890, "create_time_ms": 1234567890123, "contract": "BTC_USDT", "size": 1.0, "price": "50000" } } ``` -------------------------------- ### Position Updates Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/unified/ws-user.md Example response structure for unified position updates. ```json { "time": 1234567890, "channel": "unified.positions", "event": "update", "result": { "product": "futures", "contract": "BTC_USDT", "size": "1.0", "leverage": "2", "entry_price": "50000", "mark_price": "51000", "realised_pnl": "0", "unrealised_pnl": "1000", "margin_requirement": "5000", "maintenance_margin": "2500", "risk_level": "low", "update_time": 1234567890 } } ``` -------------------------------- ### Subscribe to Greeks Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/ws-market.md Example JSON response containing real-time Greeks updates for an options contract. ```json { "time": 1234567890, "channel": "options.greeks", "event": "update", "result": { "contract": "BTC_USDT-20230630-30000-C", "delta": "0.65", "gamma": "0.0001", "vega": "10", "theta": "-5", "implied_volatility": "0.5" } } ``` -------------------------------- ### Subscribe to Greeks Request Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/ws-market.md Example JSON request to subscribe to real-time Greeks updates for a specific options contract. ```json { "time": 1234567890, "channel": "options.greeks", "event": "subscribe", "payload": ["BTC_USDT-20230630-30000-C"] } ``` -------------------------------- ### Account Updates Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/ws-user.md Example JSON response for account balance updates. ```json { "time": 1234567890, "channel": "futures.balances", "event": "update", "result": { "total": "10000", "unrealised_pnl": "100", "position_margin": "1000", "order_margin": "500", "available": "8500", "point_value": "0", "currency": "USDT" } } ``` -------------------------------- ### Subscribe to Order Book Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/ws-market.md Example JSON response containing real-time order book updates for an options contract. ```json { "time": 1234567890, "channel": "options.order_book", "event": "update", "result": { "t": 1234567890123, "s": "BTC_USDT-20230630-30000-C", "bids": [["1990", "1.5"], ["1985", "2.0"]], "asks": [["2010", "1.0"], ["2015", "2.5"]] } } ``` -------------------------------- ### Subscribe to Tickers Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/ws-market.md Example JSON response containing real-time price updates for an options contract. ```json { "time": 1234567890, "channel": "options.tickers", "event": "update", "result": { "name": "BTC_USDT-20230630-30000-C", "last": "2000", "mark_price": "2005", "index_price": "29000", "bid1_price": "1990", "bid1_size": "1.0", "ask1_price": "2010", "ask1_size": "1.0", "volume_24h": "100", "volume_24h_usd": "200000", "delta": "0.65", "gamma": "0.0001", "vega": "10", "theta": "-5" } } ``` -------------------------------- ### Subscribe to Tickers Request Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/options/ws-market.md Example JSON request to subscribe to real-time price updates for a specific options contract. ```json { "time": 1234567890, "channel": "options.tickers", "event": "subscribe", "payload": ["BTC_USDT-20230630-30000-C"] } ``` -------------------------------- ### Subscribe to Order Book Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/ws-market.md Example response structure for real-time order book updates. ```json { "time": 1234567890, "channel": "futures.order_book", "event": "update", "result": { "t": 1234567890123, "s": "BTC_USDT", "bids": [["50000", "1.5"], ["49999", "2.0"]], "asks": [["50001", "1.0"], ["50002", "2.5"]] } } ``` -------------------------------- ### WebSocket Authentication Example Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/spot/ws-user.md This JSON object demonstrates the structure required for authenticating a WebSocket connection, including API key and signature. ```json { "time": 1234567890, "channel": "spot.balances", "event": "subscribe", "auth": { "method": "api_key", "KEY": "your_api_key", "SIGN": "calculated_signature" } } ``` -------------------------------- ### Place Order Request Parameters Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/spot/trading.md Defines the parameters required for placing a new order in spot trading. ```json { "currency_pair": "BTC_USDT", "side": "buy", "type": "limit", "account": "spot", "amount": "1", "price": "4000", "time_in_force": "gtc", "iceberg": "0", "auto_borrow": false, "text": "custom_tag" } ``` -------------------------------- ### Subscribe to Order Book Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/spot/ws-market.md Example response for order book updates, showing timestamp, currency pair, and lists of bids and asks with price and amount. ```json { "time": 1234567890, "channel": "spot.order_book", "event": "update", "result": { "t": 1234567890123, "s": "BTC_USDT", "bids": [["50000", "1.5"], ["49999", "2.0"]], "asks": [["50001", "1.0"], ["50002", "2.5"]] } } ``` -------------------------------- ### Subscribe to Trades Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/spot/ws-market.md Example response for trade updates, including trade ID, timestamp, side, currency pair, amount, and price. ```json { "time": 1234567890, "channel": "spot.trades", "event": "update", "result": { "id": 123456, "create_time": 1234567890, "create_time_ms": 1234567890123, "side": "buy", "currency_pair": "BTC_USDT", "amount": "1.0", "price": "50000" } } ``` -------------------------------- ### Insurance Fund Statistics Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/account.md Example JSON object for insurance fund statistics. ```json { "total_balance": "1000000", "daily_income": "5000", "daily_usage": "2000", "currency": "USDT" } ``` -------------------------------- ### Error Handling Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/spot/ws-market.md Example of an error message received through the WebSocket stream. ```json { "time": 1234567890, "channel": "spot.tickers", "event": "error", "message": "Invalid subscription format", "code": 1 } ``` -------------------------------- ### Liquidation Updates Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/ws-user.md Example JSON response for liquidation warnings. ```json { "time": 1234567890, "channel": "futures.liquidates", "event": "update", "result": { "contract": "BTC_USDT", "leverage": "10", "liq_price": "45000", "risk_level": "high" } } ``` -------------------------------- ### Order Updates Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/ws-user.md Example JSON response for order updates. ```json { "time": 1234567890, "channel": "futures.orders", "event": "update", "result": { "id": "123456789", "contract": "BTC_USDT", "size": 1.0, "price": "50000", "fill_price": "49999", "status": "closed", "tif": "gtc", "create_time": 1234567890, "finish_time": 1234567890 } } ``` -------------------------------- ### Position Updates Response Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/ws-user.md Example JSON response for position updates. ```json { "time": 1234567890, "channel": "futures.positions", "event": "update", "result": { "contract": "BTC_USDT", "size": 1.0, "entry_price": "50000", "mark_price": "50100", "realised_pnl": "100", "unrealised_pnl": "100", "leverage": "10", "mode": "single" } } ``` -------------------------------- ### Authentication Payload Source: https://github.com/suenot/gateio-docs-markdown/blob/main/docs/futures/ws-user.md Example JSON payload for authenticating a WebSocket connection. ```json { "time": 1234567890, "channel": "futures.orders", "event": "subscribe", "auth": { "method": "api_key", "KEY": "your_api_key", "SIGN": "calculated_signature" } } ```