# Isolated-Margin
Isolated Margin
# Margin account list
Code samples
# coding: utf-8
import requests
import time
import hashlib
import hmac
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = '/margin/accounts'
query_param = ''
# for `gen_sign` implementation, refer to section `Authentication` above
sign_headers = gen_sign('GET', prefix + url, query_param)
headers.update(sign_headers)
r = requests.request('GET', host + prefix + url, headers=headers)
print(r.json())
key="YOUR_API_KEY"
secret="YOUR_API_SECRET"
host="https://api.gateio.ws"
prefix="/api/v4"
method="GET"
url="/margin/accounts"
query_param=""
body_param=''
timestamp=$(date +%s)
body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}')
sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp"
sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}')
full_url="$host$prefix$url"
curl -X $method $full_url \
-H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign"
GET /margin/accounts
Margin account list
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| currency_pair | query | string | false | Currency pair |
Example responses
200 Response
[
{
"currency_pair": "BTC_USDT",
"account_type": "mmr",
"leverage": "20",
"locked": false,
"risk": "1.3318",
"mmr": "16.5949188975473644",
"base": {
"currency": "BTC",
"available": "0.047060413211",
"locked": "0",
"borrowed": "0.047233",
"interest": "0"
},
"quote": {
"currency": "USDT",
"available": "1234",
"locked": "0",
"borrowed": "0",
"interest": "0"
}
}
]
Responses
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK (opens new window) | List retrieved successfully | [MarginAccount] |
Response Schema
Status Code 200
| Name | Type | Description |
|---|---|---|
| None | array | [Margin account information for a trading pair. base corresponds to base currency account information, quote corresponds to quote currency account information] |
| » None | MarginAccount | Margin account information for a trading pair. base corresponds to base currency account information, quote corresponds to quote currency account information |
| »» currency_pair | string | Currency pair |
| »» account_type | string | Account Type mmr: maintenance margin rate account;inactive: market not activated |
| »» leverage | string | User's current market leverage multiplier |
| »» locked | boolean | Whether the account is locked |
| »» risk | string | Deprecated |
| »» mmr | string | Current Maintenance Margin Rate of the account |
| »» base | MarginAccount/properties/base | Currency account information |
| »»» currency | string | Currency name |
| »»» available | string | Amount available for margin trading, available = margin + borrowed |
| »»» locked | string | Frozen funds, such as amounts already placed in margin market for order trading |
| »»» borrowed | string | Borrowed funds |
| »»» interest | string | Unpaid interest |
| »» quote | MarginAccount/properties/base | Currency account information |
| »»» currency | string | Currency name |
| »»» available | string | Amount available for margin trading, available = margin + borrowed |
| »»» locked | string | Frozen funds, such as amounts already placed in margin market for order trading |
| »»» borrowed | string | Borrowed funds |
| »»» interest | string | Unpaid interest |
WARNING
To perform this operation, you must be authenticated by API key and secret
# Query margin account balance change history
Code samples
# coding: utf-8
import requests
import time
import hashlib
import hmac
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = '/margin/account_book'
query_param = ''
# for `gen_sign` implementation, refer to section `Authentication` above
sign_headers = gen_sign('GET', prefix + url, query_param)
headers.update(sign_headers)
r = requests.request('GET', host + prefix + url, headers=headers)
print(r.json())
key="YOUR_API_KEY"
secret="YOUR_API_SECRET"
host="https://api.gateio.ws"
prefix="/api/v4"
method="GET"
url="/margin/account_book"
query_param=""
body_param=''
timestamp=$(date +%s)
body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}')
sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp"
sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}')
full_url="$host$prefix$url"
curl -X $method $full_url \
-H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign"
GET /margin/account_book
Query margin account balance change history
Currently only provides transfer history to and from margin accounts. Query time range cannot exceed 30 days
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| currency | query | string | false | Query history for specified currency. If currency is specified, currency_pair must also be specified. |
| currency_pair | query | string | false | Specify margin account currency pair. Used in combination with currency. Ignored if currency is not specified |
| type | query | string | false | Query by specified account change type. If not specified, all change types will be included. |
| from | query | integer(int64) | false | Start timestamp Specify start time, time format is Unix timestamp. If not specified, it defaults to (the data start time of the time range actually returned by to and limit) |
| to | query | integer(int64) | false | Termination Timestamp Specify the end time. If not specified, it defaults to the current time, and the time format is a Unix timestamp |
| page | query | integer(int32) | false | Page number |
| limit | query | integer | false | Maximum number of records returned in a single list |
# Detailed descriptions
from: Start timestamp
Specify start time, time format is Unix timestamp. If not specified, it defaults to (the data start time of the time range actually returned by to and limit)
to: Termination Timestamp
Specify the end time. If not specified, it defaults to the current time, and the time format is a Unix timestamp
Example responses
200 Response
[
{
"id": "123456",
"time": "1547633726",
"time_ms": 1547633726123,
"currency": "BTC",
"currency_pair": "BTC_USDT",
"change": "1.03",
"balance": "4.59316525194"
}
]
Responses
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK (opens new window) | List retrieved successfully | [MarginAccountBook] |
Response Schema
Status Code 200
| Name | Type | Description |
|---|---|---|
| None | array | none |
| » id | string | Balance change record ID |
| » time | string | Account change timestamp |
| » time_ms | integer(int64) | The timestamp of the change (in milliseconds) |
| » currency | string | Currency changed |
| » currency_pair | string | Account trading pair |
| » change | string | Amount changed. Positive value means transferring in, while negative out |
| » balance | string | Balance after change |
| » type | string | Account book type. Please refer to account book type for more detail |
WARNING
To perform this operation, you must be authenticated by API key and secret
# Funding account list
Code samples
# coding: utf-8
import requests
import time
import hashlib
import hmac
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = '/margin/funding_accounts'
query_param = ''
# for `gen_sign` implementation, refer to section `Authentication` above
sign_headers = gen_sign('GET', prefix + url, query_param)
headers.update(sign_headers)
r = requests.request('GET', host + prefix + url, headers=headers)
print(r.json())
key="YOUR_API_KEY"
secret="YOUR_API_SECRET"
host="https://api.gateio.ws"
prefix="/api/v4"
method="GET"
url="/margin/funding_accounts"
query_param=""
body_param=''
timestamp=$(date +%s)
body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}')
sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp"
sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}')
full_url="$host$prefix$url"
curl -X $method $full_url \
-H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign"
GET /margin/funding_accounts
Funding account list
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| currency | query | string | false | Query by specified currency name |
Example responses
200 Response
[
{
"currency": "BTC",
"available": "1.238",
"locked": "0",
"lent": "3.32",
"total_lent": "3.32"
}
]
Responses
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK (opens new window) | List retrieved successfully | [FundingAccount] |
Response Schema
Status Code 200
| Name | Type | Description |
|---|---|---|
| None | array | none |
| » currency | string | Currency name |
| » available | string | Available assets to lend, which is identical to spot account available |
| » locked | string | Locked amount. i.e. amount in open loans |
| » lent | string | Outstanding loan amount yet to be repaid |
| » total_lent | string | Amount used for lending. total_lent = lent + locked |
WARNING
To perform this operation, you must be authenticated by API key and secret
# Query user auto repayment settings
Code samples
# coding: utf-8
import requests
import time
import hashlib
import hmac
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = '/margin/auto_repay'
query_param = ''
# for `gen_sign` implementation, refer to section `Authentication` above
sign_headers = gen_sign('GET', prefix + url, query_param)
headers.update(sign_headers)
r = requests.request('GET', host + prefix + url, headers=headers)
print(r.json())
key="YOUR_API_KEY"
secret="YOUR_API_SECRET"
host="https://api.gateio.ws"
prefix="/api/v4"
method="GET"
url="/margin/auto_repay"
query_param=""
body_param=''
timestamp=$(date +%s)
body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}')
sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp"
sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}')
full_url="$host$prefix$url"
curl -X $method $full_url \
-H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign"
GET /margin/auto_repay
Query user auto repayment settings
Example responses
200 Response
{
"status": "on"
}
Responses
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK (opens new window) | User's current auto repayment settings | Inline |
Response Schema
Status Code 200
AutoRepaySetting
| Name | Type | Description |
|---|---|---|
| » status | string | Auto repayment status: on - enabled, off - disabled |
# Enumerated Values
| Property | Value |
|---|---|
| status | on |
| status | off |
WARNING
To perform this operation, you must be authenticated by API key and secret
# Update user auto repayment settings
Code samples
# coding: utf-8
import requests
import time
import hashlib
import hmac
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = '/margin/auto_repay'
query_param = 'status=on'
# for `gen_sign` implementation, refer to section `Authentication` above
sign_headers = gen_sign('POST', prefix + url, query_param)
headers.update(sign_headers)
r = requests.request('POST', host + prefix + url + "?" + query_param, headers=headers)
print(r.json())
key="YOUR_API_KEY"
secret="YOUR_API_SECRET"
host="https://api.gateio.ws"
prefix="/api/v4"
method="POST"
url="/margin/auto_repay"
query_param="status=on"
body_param=''
timestamp=$(date +%s)
body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}')
sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp"
sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}')
full_url="$host$prefix$url?$query_param"
curl -X $method $full_url \
-H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign"
POST /margin/auto_repay
Update user auto repayment settings
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| status | query | string | true | Whether to enable auto repayment: on - enabled, off - disabled |
Example responses
200 Response
{
"status": "on"
}
Responses
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK (opens new window) | User's current auto repayment settings | Inline |
Response Schema
Status Code 200
AutoRepaySetting
| Name | Type | Description |
|---|---|---|
| » status | string | Auto repayment status: on - enabled, off - disabled |
# Enumerated Values
| Property | Value |
|---|---|
| status | on |
| status | off |
WARNING
To perform this operation, you must be authenticated by API key and secret
# Get maximum transferable amount for isolated margin
Code samples
# coding: utf-8
import requests
import time
import hashlib
import hmac
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = '/margin/transferable'
query_param = 'currency=BTC'
# for `gen_sign` implementation, refer to section `Authentication` above
sign_headers = gen_sign('GET', prefix + url, query_param)
headers.update(sign_headers)
r = requests.request('GET', host + prefix + url + "?" + query_param, headers=headers)
print(r.json())
key="YOUR_API_KEY"
secret="YOUR_API_SECRET"
host="https://api.gateio.ws"
prefix="/api/v4"
method="GET"
url="/margin/transferable"
query_param="currency=BTC"
body_param=''
timestamp=$(date +%s)
body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}')
sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp"
sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}')
full_url="$host$prefix$url?$query_param"
curl -X $method $full_url \
-H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign"
GET /margin/transferable
Get maximum transferable amount for isolated margin
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| currency | query | string | true | Query by specified currency name |
| currency_pair | query | string | false | Currency pair |
Example responses
200 Response
{
"currency": "ETH",
"currency_pair": "ETH_USDT",
"amount": "10000"
}
Responses
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK (opens new window) | Query successful | MarginTransferable |
Response Schema
Status Code 200
MarginTransferable
| Name | Type | Description |
|---|---|---|
| » currency | string | Currency detail |
| » currency_pair | string | Currency pair |
| » amount | string | Max transferable amount |
WARNING
To perform this operation, you must be authenticated by API key and secret
# List lending markets
Code samples
# coding: utf-8
import requests
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = '/margin/uni/currency_pairs'
query_param = ''
r = requests.request('GET', host + prefix + url, headers=headers)
print(r.json())
curl -X GET https://api.gateio.ws/api/v4/margin/uni/currency_pairs \
-H 'Accept: application/json'
GET /margin/uni/currency_pairs
List lending markets
Example responses
200 Response
[
{
"currency_pair": "AE_USDT",
"base_min_borrow_amount": "100",
"quote_min_borrow_amount": "100",
"leverage": "3",
"status": "enabled",
"delisted_time": 1786329745
}
]
Responses
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK (opens new window) | Query successful | [UniCurrencyPair] |
Response Schema
Status Code 200
| Name | Type | Description |
|---|---|---|
| None | array | [Currency pair of the loan] |
| » None | UniCurrencyPair | Currency pair of the loan |
| »» currency_pair | string | Currency pair |
| »» base_min_borrow_amount | string | Minimum borrow amount of base currency |
| »» quote_min_borrow_amount | string | Minimum borrow amount of quote currency |
| »» leverage | string | Leverage multiplier |
| »» status | string | Status - enabled: Enabled - disabled: Disabled |
| »» delisted_time | number(int64) | Delisting Time |
# Get lending market details
Code samples
# coding: utf-8
import requests
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = '/margin/uni/currency_pairs/AE_USDT'
query_param = ''
r = requests.request('GET', host + prefix + url, headers=headers)
print(r.json())
curl -X GET https://api.gateio.ws/api/v4/margin/uni/currency_pairs/AE_USDT \
-H 'Accept: application/json'
GET /margin/uni/currency_pairs/{currency_pair}
Get lending market details
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| currency_pair | path | string | true | Currency pair |
Example responses
200 Response
{
"currency_pair": "AE_USDT",
"base_min_borrow_amount": "100",
"quote_min_borrow_amount": "100",
"leverage": "3",
"status": "enabled",
"delisted_time": 1786329745
}
Responses
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK (opens new window) | Query successful | UniCurrencyPair |
Response Schema
Status Code 200
Currency pair of the loan
| Name | Type | Description |
|---|---|---|
| » currency_pair | string | Currency pair |
| » base_min_borrow_amount | string | Minimum borrow amount of base currency |
| » quote_min_borrow_amount | string | Minimum borrow amount of quote currency |
| » leverage | string | Leverage multiplier |
| » status | string | Status - enabled: Enabled - disabled: Disabled |
| » delisted_time | number(int64) | Delisting Time |
# Estimate interest rate for isolated margin currencies
Code samples
# coding: utf-8
import requests
import time
import hashlib
import hmac
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = '/margin/uni/estimate_rate'
query_param = 'currencies=BTC,GT'
# for `gen_sign` implementation, refer to section `Authentication` above
sign_headers = gen_sign('GET', prefix + url, query_param)
headers.update(sign_headers)
r = requests.request('GET', host + prefix + url + "?" + query_param, headers=headers)
print(r.json())
key="YOUR_API_KEY"
secret="YOUR_API_SECRET"
host="https://api.gateio.ws"
prefix="/api/v4"
method="GET"
url="/margin/uni/estimate_rate"
query_param="currencies=BTC,GT"
body_param=''
timestamp=$(date +%s)
body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}')
sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp"
sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}')
full_url="$host$prefix$url?$query_param"
curl -X $method $full_url \
-H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign"
GET /margin/uni/estimate_rate
Estimate interest rate for isolated margin currencies
Interest rates change hourly based on lending depth, so completely accurate rates cannot be provided.
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| currencies | query | array[string] | true | Array of currency names to query, maximum 10 |
Example responses
200 Response
{
"BTC": "0.000002",
"GT": "0.000001"
}
Responses
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK (opens new window) | Query successful | Inline |
Response Schema
Status Code 200
Estimate current hourly lending rates, returned by currency
| Name | Type | Description |
|---|---|---|
| » additionalProperties | string | none |
WARNING
To perform this operation, you must be authenticated by API key and secret
# Query loans
Code samples
# coding: utf-8
import requests
import time
import hashlib
import hmac
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = '/margin/uni/loans'
query_param = ''
# for `gen_sign` implementation, refer to section `Authentication` above
sign_headers = gen_sign('GET', prefix + url, query_param)
headers.update(sign_headers)
r = requests.request('GET', host + prefix + url, headers=headers)
print(r.json())
key="YOUR_API_KEY"
secret="YOUR_API_SECRET"
host="https://api.gateio.ws"
prefix="/api/v4"
method="GET"
url="/margin/uni/loans"
query_param=""
body_param=''
timestamp=$(date +%s)
body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}')
sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp"
sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}')
full_url="$host$prefix$url"
curl -X $method $full_url \
-H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign"
GET /margin/uni/loans
Query loans
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| currency_pair | query | string | false | Currency pair |
| currency | query | string | false | Query by specified currency name |
| page | query | integer(int32) | false | Page number |
| limit | query | integer | false | Maximum number of records returned in a single list |
Example responses
200 Response
[
{
"currency": "USDT",
"currency_pari": "GT_USDT",
"amount": "1",
"type": "margin",
"change_time": 1673247054000,
"create_time": 1673247054000
}
]
Responses
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK (opens new window) | Query successful | [UniLoan] |
Response Schema
Status Code 200
| Name | Type | Description |
|---|---|---|
| None | array | [Borrowing] |
| » None | UniLoan | Borrowing |
| »» currency | string | Currency |
| »» currency_pair | string | Currency pair |
| »» amount | string | Amount to Repay |
| »» type | string | Loan type: platform borrowing - platform, margin borrowing - margin |
| »» create_time | integer(int64) | Created time |
| »» update_time | integer(int64) | Last Update Time |
WARNING
To perform this operation, you must be authenticated by API key and secret
# Borrow or repay
Code samples
# coding: utf-8
import requests
import time
import hashlib
import hmac
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = '/margin/uni/loans'
query_param = ''
body='{"currency":"BTC","amount":"0.1","type":"borrow","currency_pair":"BTC_USDT","repaid_all":false}'
# for `gen_sign` implementation, refer to section `Authentication` above
sign_headers = gen_sign('POST', prefix + url, query_param, body)
headers.update(sign_headers)
r = requests.request('POST', host + prefix + url, headers=headers, data=body)
print(r.json())
key="YOUR_API_KEY"
secret="YOUR_API_SECRET"
host="https://api.gateio.ws"
prefix="/api/v4"
method="POST"
url="/margin/uni/loans"
query_param=""
body_param='{"currency":"BTC","amount":"0.1","type":"borrow","currency_pair":"BTC_USDT","repaid_all":false}'
timestamp=$(date +%s)
body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}')
sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp"
sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}')
full_url="$host$prefix$url"
curl -X $method $full_url -d "$body_param" -H "Content-Type: application/json" \
-H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign"
POST /margin/uni/loans
Borrow or repay
Body parameter
{
"currency": "BTC",
"amount": "0.1",
"type": "borrow",
"currency_pair": "BTC_USDT",
"repaid_all": false
}
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| body | body | CreateUniLoan | true | none |
| » currency | body | string | true | Currency |
| » type | body | string | true | Loan Type margin: margin borrowing |
| » amount | body | string | true | Borrow or repayment amount |
| » repaid_all | body | boolean | false | Full repayment. For repayment operations only. When true, overrides amount and repays the full amount |
| » currency_pair | body | string | true | Currency pair |
# Enumerated Values
| Parameter | Value |
|---|---|
| » type | borrow |
| » type | repay |
Responses
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 204 | No Content (opens new window) | Operation successful | None |
WARNING
To perform this operation, you must be authenticated by API key and secret
# Query loan records
Code samples
# coding: utf-8
import requests
import time
import hashlib
import hmac
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = '/margin/uni/loan_records'
query_param = ''
# for `gen_sign` implementation, refer to section `Authentication` above
sign_headers = gen_sign('GET', prefix + url, query_param)
headers.update(sign_headers)
r = requests.request('GET', host + prefix + url, headers=headers)
print(r.json())
key="YOUR_API_KEY"
secret="YOUR_API_SECRET"
host="https://api.gateio.ws"
prefix="/api/v4"
method="GET"
url="/margin/uni/loan_records"
query_param=""
body_param=''
timestamp=$(date +%s)
body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}')
sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp"
sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}')
full_url="$host$prefix$url"
curl -X $method $full_url \
-H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign"
GET /margin/uni/loan_records
Query loan records
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| type | query | string | false | Type: borrow - borrow, repay - repay |
| currency | query | string | false | Query by specified currency name |
| currency_pair | query | string | false | Currency pair |
| page | query | integer(int32) | false | Page number |
| limit | query | integer | false | Maximum number of records returned in a single list |
# Enumerated Values
| Parameter | Value |
|---|---|
| type | borrow |
| type | repay |
Example responses
200 Response
[
{
"type": "borrow",
"currency_pair": "AE_USDT",
"currency": "USDT",
"amount": "1000",
"create_time": 1673247054000
}
]
Responses
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK (opens new window) | Query successful | [UniLoanRecord] |
Response Schema
Status Code 200
| Name | Type | Description |
|---|---|---|
| None | array | [Borrowing Records] |
| » None | UniLoanRecord | Borrowing Records |
| »» type | string | Type: borrow - borrow, repay - repay |
| »» currency_pair | string | Currency pair |
| »» currency | string | Currency |
| »» amount | string | Borrow or repayment amount |
| »» create_time | integer(int64) | Created time |
WARNING
To perform this operation, you must be authenticated by API key and secret
# Query interest deduction records
Code samples
# coding: utf-8
import requests
import time
import hashlib
import hmac
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = '/margin/uni/interest_records'
query_param = ''
# for `gen_sign` implementation, refer to section `Authentication` above
sign_headers = gen_sign('GET', prefix + url, query_param)
headers.update(sign_headers)
r = requests.request('GET', host + prefix + url, headers=headers)
print(r.json())
key="YOUR_API_KEY"
secret="YOUR_API_SECRET"
host="https://api.gateio.ws"
prefix="/api/v4"
method="GET"
url="/margin/uni/interest_records"
query_param=""
body_param=''
timestamp=$(date +%s)
body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}')
sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp"
sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}')
full_url="$host$prefix$url"
curl -X $method $full_url \
-H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign"
GET /margin/uni/interest_records
Query interest deduction records
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| currency_pair | query | string | false | Currency pair |
| currency | query | string | false | Query by specified currency name |
| page | query | integer(int32) | false | Page number |
| limit | query | integer | false | Maximum number of records returned in a single list |
| from | query | integer(int64) | false | Start timestamp Specify start time, time format is Unix timestamp. If not specified, it defaults to (the data start time of the time range actually returned by to and limit) |
| to | query | integer(int64) | false | Termination Timestamp Specify the end time. If not specified, it defaults to the current time, and the time format is a Unix timestamp |
# Detailed descriptions
from: Start timestamp
Specify start time, time format is Unix timestamp. If not specified, it defaults to (the data start time of the time range actually returned by to and limit)
to: Termination Timestamp
Specify the end time. If not specified, it defaults to the current time, and the time format is a Unix timestamp
Example responses
200 Response
[
{
"status": 1,
"currency_pair": "BTC_USDT",
"currency": "USDT",
"actual_rate": "0.00000236",
"interest": "0.00006136",
"type": "platform",
"create_time": 1673247054000
}
]
Responses
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK (opens new window) | Query successful | [UniLoanInterestRecord] |
Response Schema
Status Code 200
| Name | Type | Description |
|---|---|---|
| None | array | [Interest Deduction Record] |
| » None | UniLoanInterestRecord | Interest Deduction Record |
| »» currency | string | Currency name |
| »» currency_pair | string | Currency pair |
| »» actual_rate | string | Actual Rate |
| »» interest | string | Interest |
| »» status | integer | Status: 0 - fail, 1 - success |
| »» type | string | Loan Type margin: margin borrowing |
| »» create_time | integer(int64) | Created time |
WARNING
To perform this operation, you must be authenticated by API key and secret
# Query maximum borrowable amount by currency
Code samples
# coding: utf-8
import requests
import time
import hashlib
import hmac
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = '/margin/uni/borrowable'
query_param = 'currency=BTC¤cy_pair=BTC_USDT'
# for `gen_sign` implementation, refer to section `Authentication` above
sign_headers = gen_sign('GET', prefix + url, query_param)
headers.update(sign_headers)
r = requests.request('GET', host + prefix + url + "?" + query_param, headers=headers)
print(r.json())
key="YOUR_API_KEY"
secret="YOUR_API_SECRET"
host="https://api.gateio.ws"
prefix="/api/v4"
method="GET"
url="/margin/uni/borrowable"
query_param="currency=BTC¤cy_pair=BTC_USDT"
body_param=''
timestamp=$(date +%s)
body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}')
sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp"
sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}')
full_url="$host$prefix$url?$query_param"
curl -X $method $full_url \
-H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign"
GET /margin/uni/borrowable
Query maximum borrowable amount by currency
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| currency | query | string | true | Query by specified currency name |
| currency_pair | query | string | true | Currency pair |
Example responses
200 Response
{
"currency": "AE",
"borrowable": "1123.344",
"currency_pair": "AE_USDT"
}
Responses
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK (opens new window) | Query successful | MaxUniBorrowable |
Response Schema
Status Code 200
MaxUniBorrowable
| Name | Type | Description |
|---|---|---|
| » currency | string | Currency |
| » currency_pair | string | Currency pair |
| » borrowable | string | Maximum borrowable |
WARNING
To perform this operation, you must be authenticated by API key and secret
# Query user's own leverage lending tiers in current market
Code samples
# coding: utf-8
import requests
import time
import hashlib
import hmac
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = '/margin/user/loan_margin_tiers'
query_param = 'currency_pair=BTC_USDT'
# for `gen_sign` implementation, refer to section `Authentication` above
sign_headers = gen_sign('GET', prefix + url, query_param)
headers.update(sign_headers)
r = requests.request('GET', host + prefix + url + "?" + query_param, headers=headers)
print(r.json())
key="YOUR_API_KEY"
secret="YOUR_API_SECRET"
host="https://api.gateio.ws"
prefix="/api/v4"
method="GET"
url="/margin/user/loan_margin_tiers"
query_param="currency_pair=BTC_USDT"
body_param=''
timestamp=$(date +%s)
body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}')
sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp"
sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}')
full_url="$host$prefix$url?$query_param"
curl -X $method $full_url \
-H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign"
GET /margin/user/loan_margin_tiers
Query user's own leverage lending tiers in current market
Query the borrowing tier margin requirements of a specific spot market.For more details about borrowing tier margin requirements, please refer to Underlying Logic of the New Isolated Margin System(https://www.gate.com/en/help/trade/margin-trading/42357)
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| currency_pair | query | string | true | Currency pair |
Example responses
200 Response
[
{
"tier_amount": "100",
"mmr": "0.9",
"leverage": "1"
}
]
Responses
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK (opens new window) | Query successful | [MarginLeverageTier] |
Response Schema
Status Code 200
| Name | Type | Description |
|---|---|---|
| None | array | [Market gradient information] |
| » None | MarginLeverageTier | Market gradient information |
| »» upper_limit | string | Maximum borrowing limit. Determined by the leverage you set; the lower the leverage, the larger the borrowing limit. |
| »» mmr | string | Maintenance margin rate.Under tiered margin requirements(https://www.gate.com/en/help/trade/margin-trading/42357), the maintenance margin rate is a composite value. |
| »» leverage | string | the maximum permissible leverage given to the current debt level; the higher the debt level, the lower the maximum leverage. |
WARNING
To perform this operation, you must be authenticated by API key and secret
# Query current market leverage lending tiers
Code samples
# coding: utf-8
import requests
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = '/margin/loan_margin_tiers'
query_param = 'currency_pair=BTC_USDT'
r = requests.request('GET', host + prefix + url + "?" + query_param, headers=headers)
print(r.json())
curl -X GET https://api.gateio.ws/api/v4/margin/loan_margin_tiers?currency_pair=BTC_USDT \
-H 'Accept: application/json'
GET /margin/loan_margin_tiers
Query current market leverage lending tiers
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| currency_pair | query | string | true | Currency pair |
Example responses
200 Response
[
{
"tier_amount": "100",
"mmr": "0.9",
"leverage": "1"
}
]
Responses
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK (opens new window) | Query successful | [MarginLeverageTier] |
Response Schema
Status Code 200
| Name | Type | Description |
|---|---|---|
| None | array | [Market gradient information] |
| » None | MarginLeverageTier | Market gradient information |
| »» upper_limit | string | Maximum borrowing limit. Determined by the leverage you set; the lower the leverage, the larger the borrowing limit. |
| »» mmr | string | Maintenance margin rate.Under tiered margin requirements(https://www.gate.com/en/help/trade/margin-trading/42357), the maintenance margin rate is a composite value. |
| »» leverage | string | the maximum permissible leverage given to the current debt level; the higher the debt level, the lower the maximum leverage. |
# Set user market leverage multiplier
Code samples
# coding: utf-8
import requests
import time
import hashlib
import hmac
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = '/margin/leverage/user_market_setting'
query_param = ''
body='{"currency_pair":"BTC_USDT","leverage":"10"}'
# for `gen_sign` implementation, refer to section `Authentication` above
sign_headers = gen_sign('POST', prefix + url, query_param, body)
headers.update(sign_headers)
r = requests.request('POST', host + prefix + url, headers=headers, data=body)
print(r.json())
key="YOUR_API_KEY"
secret="YOUR_API_SECRET"
host="https://api.gateio.ws"
prefix="/api/v4"
method="POST"
url="/margin/leverage/user_market_setting"
query_param=""
body_param='{"currency_pair":"BTC_USDT","leverage":"10"}'
timestamp=$(date +%s)
body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}')
sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp"
sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}')
full_url="$host$prefix$url"
curl -X $method $full_url -d "$body_param" -H "Content-Type: application/json" \
-H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign"
POST /margin/leverage/user_market_setting
Set user market leverage multiplier
Body parameter
{
"currency_pair": "BTC_USDT",
"leverage": "10"
}
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| body | body | MarginMarketLeverage | true | none |
| » currency_pair | body | string | false | Market |
| » leverage | body | string | true | Leverage multiplier |
Responses
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 204 | No Content (opens new window) | Set successfully | None |
WARNING
To perform this operation, you must be authenticated by API key and secret
# Query user's isolated margin account list
Code samples
# coding: utf-8
import requests
import time
import hashlib
import hmac
host = "https://api.gateio.ws"
prefix = "/api/v4"
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
url = '/margin/user/account'
query_param = ''
# for `gen_sign` implementation, refer to section `Authentication` above
sign_headers = gen_sign('GET', prefix + url, query_param)
headers.update(sign_headers)
r = requests.request('GET', host + prefix + url, headers=headers)
print(r.json())
key="YOUR_API_KEY"
secret="YOUR_API_SECRET"
host="https://api.gateio.ws"
prefix="/api/v4"
method="GET"
url="/margin/user/account"
query_param=""
body_param=''
timestamp=$(date +%s)
body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}')
sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp"
sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}')
full_url="$host$prefix$url"
curl -X $method $full_url \
-H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign"
GET /margin/user/account
Query user's isolated margin account list
Supports querying risk ratio isolated accounts and margin ratio isolated accounts
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| currency_pair | query | string | false | Currency pair |
Example responses
200 Response
[
{
"currency_pair": "BTC_USDT",
"account_type": "mmr",
"leverage": "20",
"locked": false,
"risk": "1.3318",
"mmr": "16.5949188975473644",
"base": {
"currency": "BTC",
"available": "0.047060413211",
"locked": "0",
"borrowed": "0.047233",
"interest": "0"
},
"quote": {
"currency": "USDT",
"available": "1234",
"locked": "0",
"borrowed": "0",
"interest": "0"
}
}
]
Responses
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK (opens new window) | List retrieved successfully | [MarginAccount] |
Response Schema
Status Code 200
| Name | Type | Description |
|---|---|---|
| None | array | [Margin account information for a trading pair. base corresponds to base currency account information, quote corresponds to quote currency account information] |
| » None | MarginAccount | Margin account information for a trading pair. base corresponds to base currency account information, quote corresponds to quote currency account information |
| »» currency_pair | string | Currency pair |
| »» account_type | string | Account Type mmr: maintenance margin rate account;inactive: market not activated |
| »» leverage | string | User's current market leverage multiplier |
| »» locked | boolean | Whether the account is locked |
| »» risk | string | Deprecated |
| »» mmr | string | Current Maintenance Margin Rate of the account |
| »» base | MarginAccount/properties/base | Currency account information |
| »»» currency | string | Currency name |
| »»» available | string | Amount available for margin trading, available = margin + borrowed |
| »»» locked | string | Frozen funds, such as amounts already placed in margin market for order trading |
| »»» borrowed | string | Borrowed funds |
| »»» interest | string | Unpaid interest |
| »» quote | MarginAccount/properties/base | Currency account information |
| »»» currency | string | Currency name |
| »»» available | string | Amount available for margin trading, available = margin + borrowed |
| »»» locked | string | Frozen funds, such as amounts already placed in margin market for order trading |
| »»» borrowed | string | Borrowed funds |
| »»» interest | string | Unpaid interest |
WARNING
To perform this operation, you must be authenticated by API key and secret
# Schemas
# MaxUniBorrowable
{
"currency": "string",
"currency_pair": "string",
"borrowable": "string"
}
MaxUniBorrowable
# Properties
| Name | Type | Required | Restrictions | Description |
|---|---|---|---|---|
| currency | string | true | read-only | Currency |
| currency_pair | string | false | read-only | Currency pair |
| borrowable | string | true | read-only | Maximum borrowable |
# MarginLeverageTier
{
"upper_limit": "string",
"mmr": "string",
"leverage": "string"
}
Market gradient information
# Properties
| Name | Type | Required | Restrictions | Description |
|---|---|---|---|---|
| upper_limit | string | false | none | Maximum borrowing limit. Determined by the leverage you set; the lower the leverage, the larger the borrowing limit. |
| mmr | string | false | none | Maintenance margin rate.Under tiered margin requirements(https://www.gate.com/en/help/trade/margin-trading/42357), the maintenance margin rate is a composite value. |
| leverage | string | false | none | the maximum permissible leverage given to the current debt level; the higher the debt level, the lower the maximum leverage. |
# MarginAccountBook
{
"id": "string",
"time": "string",
"time_ms": 0,
"currency": "string",
"currency_pair": "string",
"change": "string",
"balance": "string",
"type": "string"
}
# Properties
| Name | Type | Required | Restrictions | Description |
|---|---|---|---|---|
| id | string | false | none | Balance change record ID |
| time | string | false | none | Account change timestamp |
| time_ms | integer(int64) | false | none | The timestamp of the change (in milliseconds) |
| currency | string | false | none | Currency changed |
| currency_pair | string | false | none | Account trading pair |
| change | string | false | none | Amount changed. Positive value means transferring in, while negative out |
| balance | string | false | none | Balance after change |
| type | string | false | none | Account book type. Please refer to account book type for more detail |
# MarginTransferable
{
"currency": "string",
"currency_pair": "string",
"amount": "string"
}
MarginTransferable
# Properties
| Name | Type | Required | Restrictions | Description |
|---|---|---|---|---|
| currency | string | false | none | Currency detail |
| currency_pair | string | false | none | Currency pair |
| amount | string | false | none | Max transferable amount |
# UniLoanInterestRecord
{
"currency": "string",
"currency_pair": "string",
"actual_rate": "string",
"interest": "string",
"status": 0,
"type": "string",
"create_time": 0
}
Interest Deduction Record
# Properties
| Name | Type | Required | Restrictions | Description |
|---|---|---|---|---|
| currency | string | false | read-only | Currency name |
| currency_pair | string | false | read-only | Currency pair |
| actual_rate | string | false | read-only | Actual Rate |
| interest | string | false | read-only | Interest |
| status | integer | false | read-only | Status: 0 - fail, 1 - success |
| type | string | false | read-only | Loan Type margin: margin borrowing |
| create_time | integer(int64) | false | read-only | Created time |
# UniLoanRecord
{
"type": "string",
"currency_pair": "string",
"currency": "string",
"amount": "string",
"create_time": 0
}
Borrowing Records
# Properties
| Name | Type | Required | Restrictions | Description |
|---|---|---|---|---|
| type | string | false | read-only | Type: borrow - borrow, repay - repay |
| currency_pair | string | false | read-only | Currency pair |
| currency | string | false | read-only | Currency |
| amount | string | false | read-only | Borrow or repayment amount |
| create_time | integer(int64) | false | read-only | Created time |
# CreateUniLoan
{
"currency": "string",
"type": "borrow",
"amount": "string",
"repaid_all": true,
"currency_pair": "string"
}
Borrow or repay
# Properties
| Name | Type | Required | Restrictions | Description |
|---|---|---|---|---|
| currency | string | true | none | Currency |
| type | string | true | none | Loan Type margin: margin borrowing |
| amount | string | true | none | Borrow or repayment amount |
| repaid_all | boolean | false | none | Full repayment. For repayment operations only. When true, overrides amount and repays the full amount |
| currency_pair | string | true | none | Currency pair |
# Enumerated Values
| Property | Value |
|---|---|
| type | borrow |
| type | repay |
# MarginAccount
{
"currency_pair": "string",
"account_type": "string",
"leverage": "string",
"locked": true,
"risk": "string",
"mmr": "string",
"base": {
"currency": "string",
"available": "string",
"locked": "string",
"borrowed": "string",
"interest": "string"
},
"quote": {
"currency": "string",
"available": "string",
"locked": "string",
"borrowed": "string",
"interest": "string"
}
}
Margin account information for a trading pair. base corresponds to base currency account information, quote corresponds to quote currency account information
# Properties
| Name | Type | Required | Restrictions | Description |
|---|---|---|---|---|
| currency_pair | string | false | none | Currency pair |
| account_type | string | false | none | Account Type mmr: maintenance margin rate account;inactive: market not activated |
| leverage | string | false | none | User's current market leverage multiplier |
| locked | boolean | false | none | Whether the account is locked |
| risk | string | false | none | Deprecated |
| mmr | string | false | none | Current Maintenance Margin Rate of the account |
| base | object | false | none | Currency account information |
| » currency | string | false | none | Currency name |
| » available | string | false | none | Amount available for margin trading, available = margin + borrowed |
| » locked | string | false | none | Frozen funds, such as amounts already placed in margin market for order trading |
| » borrowed | string | false | none | Borrowed funds |
| » interest | string | false | none | Unpaid interest |
| quote | MarginAccount/properties/base | false | none | Currency account information |
# UniCurrencyPair
{
"currency_pair": "string",
"base_min_borrow_amount": "string",
"quote_min_borrow_amount": "string",
"leverage": "string",
"status": "string",
"delisted_time": 0
}
Currency pair of the loan
# Properties
| Name | Type | Required | Restrictions | Description |
|---|---|---|---|---|
| currency_pair | string | false | read-only | Currency pair |
| base_min_borrow_amount | string | false | read-only | Minimum borrow amount of base currency |
| quote_min_borrow_amount | string | false | read-only | Minimum borrow amount of quote currency |
| leverage | string | false | read-only | Leverage multiplier |
| status | string | false | none | Status - enabled: Enabled - disabled: Disabled |
| delisted_time | number(int64) | false | none | Delisting Time |
# UniLoan
{
"currency": "string",
"currency_pair": "string",
"amount": "string",
"type": "string",
"create_time": 0,
"update_time": 0
}
Borrowing
# Properties
| Name | Type | Required | Restrictions | Description |
|---|---|---|---|---|
| currency | string | false | read-only | Currency |
| currency_pair | string | false | read-only | Currency pair |
| amount | string | false | read-only | Amount to Repay |
| type | string | false | read-only | Loan type: platform borrowing - platform, margin borrowing - margin |
| create_time | integer(int64) | false | read-only | Created time |
| update_time | integer(int64) | false | read-only | Last Update Time |
# FundingAccount
{
"currency": "string",
"available": "string",
"locked": "string",
"lent": "string",
"total_lent": "string"
}
# Properties
| Name | Type | Required | Restrictions | Description |
|---|---|---|---|---|
| currency | string | false | none | Currency name |
| available | string | false | none | Available assets to lend, which is identical to spot account available |
| locked | string | false | none | Locked amount. i.e. amount in open loans |
| lent | string | false | none | Outstanding loan amount yet to be repaid |
| total_lent | string | false | none | Amount used for lending. total_lent = lent + locked |