# Broker API v1.1.1

    Scroll down for code samples, example requests and responses. Select a language for code samples from the tabs above or the mobile navigation menu.

    The broker API

    # Changelog

    v1.1.0

    2021-03-13

    • New optional parameters of futures trading fee rate range added.

    v1.0.0

    2020-12-21

    • First Version

    # API General Info

    Broker API's format is in accordance with APIv4's format. Except the seperate permission group for authentication, please refer to APIv4 General Info for other information .

    # Authentication

    Broker API's authentication method is in accordance with APIv4's,The differences are that API paths of Broker operations all start with '/broker', and there is a seperate access option in the APIv4's permission management. Before using Broker API, please make sure:

    1. You have a Gate.io account
    2. The administrator has enabled the broker function for the account

    Log in and enter the APIv4 Key management page of the your personal Gate account page, and choose to create a new APIv4 key or edit one that is already in use. Enabling the broker's permission function, then you can use the APIv4 Key to operate.

    # Introduction of Broker API Functions

    The Broker API interconnects with the Gate Account based on the minimum access principle, so the scope of the interface only covers the core access-related functions. The deposit and transaction after account enabling Broker API use existing interface of APIv4 for docking

    1. Confirm Broker's Configuration Information

      GET /broker/info returns broker's relevant configuration information including commission setting, the number of accounts allowed to be accessed, and the range of trading fee rates that can be configured for the account, etc.

    2. Access Account

      Each accessed account corresponds to a sub-account. Create a subaccount by POST /broker/sub_accounts.

      When creating the subaccount, you need to set the trading fee rate configuration of the subaccount. The specific rules are determined by the broker. Gate is only responsible for calculating the trading fees when the account is traded according to the rate set by the broker. Brokers can set the rate of each access account according to the internal established user level rules.

      After the account is created, you need to create an APIv4 key pair for the accessed account through POST /broker/sub_account_keys. This key pair is used for its account's subsequent deposit and trading. The broker needs to properly maintain and save the key pair information, the secret of the key pair. The broker needs to properly maintain and save the key pair information, and the Secret of the key pair should not be stored in plain text. When creating a trading pair, you can enable the corresponding APIv4 function permission.

      Note: /broker interface can only be operated using a key pair with Broker permissions enabled. Deposits and transactions of the accessed account can only use the key pairs generated by the account itself.

    3. Deposits and Transactions

      After creating an APIv4 key pair for the accessed account and granting the corresponding wallet permission, there are two ways to deposit.

      • The broker uses its own key pair and calls the Broker API "POST /broker/sub_account_transfers" to transfer its own funds to the account
      • The broker calls APIv4 wallet interface with the account's key pair to obtain the deposit address, and make the account deposit funds to this address by itself.

      After the deposit, the broker needs to use the key of the accessed account to perform trading operations on the trading interfaces such as spot and contract of APIv4.

    # Broker

    Broker API

    # Get the broker info

    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 = '/broker/info'
    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="/broker/info"
    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 /broker/info

    Get the broker info

    Example responses

    200 Response

    {
      "id": 10001,
      "commission_rate": "0.3",
      "status": "enabled",
      "min_taker_rate": "0.001",
      "max_taker_rate": "0.002",
      "min_maker_rate": "0.00005",
      "max_maker_rate": "0.001",
      "futures_min_taker_rate": "0.001",
      "futures_max_taker_rate": "0.002",
      "futures_min_maker_rate": "-0.0005",
      "futures_max_maker_rate": "0",
      "max_sub_accounts": 100000,
      "used_sub_accounts": 10000
    }
    

    Responses

    Status Meaning Description Schema
    200 OK (opens new window) Broker detail Broker

    WARNING

    To perform this operation, you must be authenticated by API key and secret

    # Create sub-account

    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 = '/broker/sub_accounts'
    query_param = ''
    body='{"id":"my-sample-user-id","name":"bob","maker_rate":"0.002","taker_rate":"0.002","futures_maker_rate":"-0.0001","futures_taker_rate":"0.002","gt_discount":false,"gt_taker_rate":"0","gt_maker_rate":"0","point_type":1}'
    # 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="/broker/sub_accounts"
    query_param=""
    body_param='{"id":"my-sample-user-id","name":"bob","maker_rate":"0.002","taker_rate":"0.002","futures_maker_rate":"-0.0001","futures_taker_rate":"0.002","gt_discount":false,"gt_taker_rate":"0","gt_maker_rate":"0","point_type":1}'
    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 /broker/sub_accounts

    Create sub-account

    Body parameter

    {
      "id": "my-sample-user-id",
      "name": "bob",
      "maker_rate": "0.002",
      "taker_rate": "0.002",
      "futures_maker_rate": "-0.0001",
      "futures_taker_rate": "0.002",
      "gt_discount": false,
      "gt_taker_rate": "0",
      "gt_maker_rate": "0",
      "point_type": 1
    }
    

    Parameters

    Name In Type Required Description
    body body BrokerSubAccount true none
    » id body string true The unique identifier of the sub-account. This field is only used for record display. Any operations to the sub-account needs to use the user ID generated inside the Gate.`
    » name body string false name
    » maker_rate body string true maker fee of the sub-account
    » taker_rate body string true taker fee of the sub-account
    » futures_maker_rate body string true Futures trading maker fee of sub account
    » futures_taker_rate body string true Futures trading taker fee of sub account
    » gt_discount body boolean false If GT deduction is enabled
    » gt_taker_rate body string false Taker fee rate if using GT deduction. It will be 0 if GT deduction is disabled
    » gt_maker_rate body string false Maker fee rate if using GT deduction. It will be 0 if GT deduction is disabled
    » point_type body string false Point type. 0 - Initial version. 1 - new version since 202009

    Example responses

    201 Response

    {
      "id": "my-sample-user-id",
      "name": "bob",
      "maker_rate": "0.002",
      "taker_rate": "0.002",
      "futures_maker_rate": "-0.0001",
      "futures_taker_rate": "0.002",
      "gt_discount": false,
      "gt_taker_rate": "0",
      "gt_maker_rate": "0",
      "status": "enabled",
      "point_type": 1,
      "gate_id": 100010
    }
    

    Responses

    Status Meaning Description Schema
    201 Created (opens new window) Sub account detail BrokerSubAccount

    WARNING

    To perform this operation, you must be authenticated by API key and secret

    # List sub-accounts

    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 = '/broker/sub_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="/broker/sub_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 /broker/sub_accounts

    List sub-accounts

    Parameters

    Name In Type Required Description
    limit query integer false Maximum number of records to be returned in a single list
    offset query integer false List offset, starting from 0

    Example responses

    200 Response

    [
      {
        "id": "my-sample-user-id",
        "name": "bob",
        "maker_rate": "0.002",
        "taker_rate": "0.002",
        "futures_maker_rate": "-0.0001",
        "futures_taker_rate": "0.002",
        "gt_discount": false,
        "gt_taker_rate": "0",
        "gt_maker_rate": "0",
        "status": "enabled",
        "point_type": 1,
        "gate_id": 100010
      }
    ]
    

    Responses

    Status Meaning Description Schema
    200 OK (opens new window) List retrieved [BrokerSubAccount]

    WARNING

    To perform this operation, you must be authenticated by API key and secret

    # Get the sub-account

    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 = '/broker/sub_accounts/100010'
    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="/broker/sub_accounts/100010"
    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 /broker/sub_accounts/{sub_account_id}

    Get the sub-account

    Parameters

    Name In Type Required Description
    sub_account_id path integer(int64) true Gate user ID returned when sub account created

    Example responses

    200 Response

    {
      "id": "my-sample-user-id",
      "name": "bob",
      "maker_rate": "0.002",
      "taker_rate": "0.002",
      "futures_maker_rate": "-0.0001",
      "futures_taker_rate": "0.002",
      "gt_discount": false,
      "gt_taker_rate": "0",
      "gt_maker_rate": "0",
      "status": "enabled",
      "point_type": 1,
      "gate_id": 100010
    }
    

    Responses

    Status Meaning Description Schema
    200 OK (opens new window) Sub account detail BrokerSubAccount

    WARNING

    To perform this operation, you must be authenticated by API key and secret

    # Update the sub-account

    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 = '/broker/sub_accounts/100010'
    query_param = ''
    body='{"id":"my-sample-user-id","name":"bob","maker_rate":"0.002","taker_rate":"0.002","futures_maker_rate":"-0.0001","futures_taker_rate":"0.002","gt_discount":false,"gt_taker_rate":"0","gt_maker_rate":"0","point_type":1}'
    # for `gen_sign` implementation, refer to section `Authentication` above
    sign_headers = gen_sign('PUT', prefix + url, query_param, body)
    headers.update(sign_headers)
    r = requests.request('PUT', 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="PUT"
    url="/broker/sub_accounts/100010"
    query_param=""
    body_param='{"id":"my-sample-user-id","name":"bob","maker_rate":"0.002","taker_rate":"0.002","futures_maker_rate":"-0.0001","futures_taker_rate":"0.002","gt_discount":false,"gt_taker_rate":"0","gt_maker_rate":"0","point_type":1}'
    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"
    
    

    PUT /broker/sub_accounts/{sub_account_id}

    Update the sub-account

    Body parameter

    {
      "id": "my-sample-user-id",
      "name": "bob",
      "maker_rate": "0.002",
      "taker_rate": "0.002",
      "futures_maker_rate": "-0.0001",
      "futures_taker_rate": "0.002",
      "gt_discount": false,
      "gt_taker_rate": "0",
      "gt_maker_rate": "0",
      "point_type": 1
    }
    

    Parameters

    Name In Type Required Description
    body body BrokerSubAccount true none
    » id body string true The unique identifier of the sub-account. This field is only used for record display. Any operations to the sub-account needs to use the user ID generated inside the Gate.`
    » name body string false name
    » maker_rate body string true maker fee of the sub-account
    » taker_rate body string true taker fee of the sub-account
    » futures_maker_rate body string true Futures trading maker fee of sub account
    » futures_taker_rate body string true Futures trading taker fee of sub account
    » gt_discount body boolean false If GT deduction is enabled
    » gt_taker_rate body string false Taker fee rate if using GT deduction. It will be 0 if GT deduction is disabled
    » gt_maker_rate body string false Maker fee rate if using GT deduction. It will be 0 if GT deduction is disabled
    » point_type body string false Point type. 0 - Initial version. 1 - new version since 202009
    sub_account_id path integer(int64) true Gate user ID returned when sub account created

    Example responses

    200 Response

    {
      "id": "my-sample-user-id",
      "name": "bob",
      "maker_rate": "0.002",
      "taker_rate": "0.002",
      "futures_maker_rate": "-0.0001",
      "futures_taker_rate": "0.002",
      "gt_discount": false,
      "gt_taker_rate": "0",
      "gt_maker_rate": "0",
      "status": "enabled",
      "point_type": 1,
      "gate_id": 100010
    }
    

    Responses

    Status Meaning Description Schema
    200 OK (opens new window) Sub account detail BrokerSubAccount

    WARNING

    To perform this operation, you must be authenticated by API key and secret

    # Disable the sub-account

    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 = '/broker/sub_accounts/100010/disable'
    query_param = ''
    # 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, headers=headers)
    print(r.json())
    
    
    key="YOUR_API_KEY"
    secret="YOUR_API_SECRET"
    host="https://api.gateio.ws"
    prefix="/api/v4"
    method="POST"
    url="/broker/sub_accounts/100010/disable"
    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"
    
    

    POST /broker/sub_accounts/{sub_account_id}/disable

    Disable the sub-account

    Parameters

    Name In Type Required Description
    sub_account_id path integer(int64) true Gate user ID returned when sub account created

    Responses

    Status Meaning Description Schema
    204 No Content (opens new window) Success None

    WARNING

    To perform this operation, you must be authenticated by API key and secret

    # Enable the sub-account

    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 = '/broker/sub_accounts/100010/enable'
    query_param = ''
    # 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, headers=headers)
    print(r.json())
    
    
    key="YOUR_API_KEY"
    secret="YOUR_API_SECRET"
    host="https://api.gateio.ws"
    prefix="/api/v4"
    method="POST"
    url="/broker/sub_accounts/100010/enable"
    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"
    
    

    POST /broker/sub_accounts/{sub_account_id}/enable

    Enable the sub-account

    Parameters

    Name In Type Required Description
    sub_account_id path integer(int64) true Gate user ID returned when sub account created

    Responses

    Status Meaning Description Schema
    204 No Content (opens new window) Success None

    WARNING

    To perform this operation, you must be authenticated by API key and secret

    # Create the API Key of the sub-account

    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 = '/broker/sub_account_keys'
    query_param = ''
    body='{"user_id":"10001","name":"现货读写","type":1,"perms":[{"name":"spot","read_only":false}],"ip_whitelist":["8.8.8.8"]}'
    # 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="/broker/sub_account_keys"
    query_param=""
    body_param='{"user_id":"10001","name":"现货读写","type":1,"perms":[{"name":"spot","read_only":false}],"ip_whitelist":["8.8.8.8"]}'
    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 /broker/sub_account_keys

    Create the API Key of the sub-account

    Body parameter

    {
      "user_id": "10001",
      "name": "现货读写",
      "type": 1,
      "perms": [
        {
          "name": "spot",
          "read_only": false
        }
      ],
      "ip_whitelist": [
        "8.8.8.8"
      ]
    }
    

    Parameters

    Name In Type Required Description
    body body object false none
    » user_id body string false User ID
    » name body string false API key name
    » perms body array false none
    »» name body string false The permission name
    »» read_only body boolean false read only
    » type body integer(int32) false Type: 1 - Main Account 2 - sub-account 3 - Managed Account
    » ip_whitelist body array false ip white list

    # Detailed descriptions

    »» name: The permission name

    • wallet: wallet
    • spot: spot/margin
    • futures: futures
    • delivery: delivery
    • withdraw: withdraw

    # Enumerated Values

    Parameter Value
    »» name wallet
    »» name spot
    »» name futures
    »» name delivery
    »» name withdraw

    Example responses

    201 Response

    {
      "user_id": "10001",
      "name": "spot",
      "type": 1,
      "mode": 1,
      "perms": [
        {
          "name": "spot",
          "read_only": false
        }
      ],
      "key": "bfc5f289273ea47b7cd41d9ce7e27a0d",
      "secret": "bfc5f289273ea47b7cd41d9ce7e27a0dbfc5f289273ea47b7cd41d9ce7e27a0d",
      "ip_whitelist": [
        "8.8.8.8"
      ],
      "created_at": "1583827286",
      "updated_at": "1583827286"
    }
    

    Responses

    Status Meaning Description Schema
    201 Created (opens new window) API Key detail Inline

    Response Schema

    Status Code 201

    Name Type Description
    » user_id string User ID
    » name string API key name
    » perms array none
    »» name string The permission name

    - wallet: wallet
    - spot: spot/margin
    - futures: futures
    - delivery: delivery
    - withdraw: withdraw
    »» read_only boolean read only
    » key string API Key
    » secret string API Secret
    » type integer(int32) Type: 1 - Main Account 2 - sub-account 3 - Managed Account
    » mode integer(int32) Mode: 1 - Classic Account 2 - Portfolio Margin Account
    » ip_whitelist array ip white list
    » created_at string Creation time
    » updated_at string Last update time

    # Enumerated Values

    Property Value
    name wallet
    name spot
    name futures
    name delivery
    name withdraw

    WARNING

    To perform this operation, you must be authenticated by API key and secret

    # List the API Keys of the sub-account

    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 = '/broker/sub_account_keys/100010'
    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="/broker/sub_account_keys/100010"
    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 /broker/sub_account_keys/{sub_account_id}

    List the API Keys of the sub-account

    Parameters

    Name In Type Required Description
    sub_account_id path integer(int64) true Gate user ID returned when sub account created

    Example responses

    200 Response

    [
      {
        "user_id": "10001",
        "name": "spot",
        "type": 1,
        "mode": 1,
        "perms": [
          {
            "name": "spot",
            "read_only": false
          }
        ],
        "key": "bfc5f289273ea47b7cd41d9ce7e27a0d",
        "ip_whitelist": [
          "8.8.8.8"
        ],
        "created_at": "1583827286",
        "updated_at": "1583827286"
      }
    ]
    

    Responses

    Status Meaning Description Schema
    200 OK (opens new window) List retrieved [Inline]

    Response Schema

    Status Code 200

    Name Type Description
    » user_id string User ID
    » name string API key name
    » perms array none
    »» name string The permission name

    - wallet: wallet
    - spot: spot/margin
    - futures: futures
    - delivery: delivery
    - withdraw: withdraw
    »» read_only boolean read only
    » key string API Key
    » type integer(int32) Type: 1 - Main Account 2 - sub-account 3 - Managed Account
    » mode integer(int32) Mode: 1 - Classic Account 2 - Portfolio Margin Account
    » ip_whitelist array ip white list
    » created_at string Creation time
    » updated_at string Last update time

    # Enumerated Values

    Property Value
    name wallet
    name spot
    name futures
    name delivery
    name withdraw

    WARNING

    To perform this operation, you must be authenticated by API key and secret

    # Get the API Key

    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 = '/broker/sub_account_keys/100010/bfc5f289273ea47b7cd41d9ce7e27a0d'
    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="/broker/sub_account_keys/100010/bfc5f289273ea47b7cd41d9ce7e27a0d"
    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 /broker/sub_account_keys/{sub_account_id}/{key}

    Get the API Key

    Parameters

    Name In Type Required Description
    sub_account_id path integer(int64) true Gate user ID returned when sub account created
    key path string true The API Key

    Example responses

    200 Response

    {
      "user_id": "10001",
      "name": "spot",
      "type": 1,
      "mode": 1,
      "perms": [
        {
          "name": "spot",
          "read_only": false
        }
      ],
      "key": "bfc5f289273ea47b7cd41d9ce7e27a0d",
      "ip_whitelist": [
        "8.8.8.8"
      ],
      "created_at": "1583827286",
      "updated_at": "1583827286"
    }
    

    Responses

    Status Meaning Description Schema
    200 OK (opens new window) API Key detail Inline

    Response Schema

    Status Code 200

    Name Type Description
    » user_id string User ID
    » name string API key name
    » perms array none
    »» name string The permission name

    - wallet: wallet
    - spot: spot/margin
    - futures: futures
    - delivery: delivery
    - withdraw: withdraw
    »» read_only boolean read only
    » key string API Key
    » type integer(int32) Type: 1 - Main Account 2 - sub-account 3 - Managed Account
    » mode integer(int32) Mode: 1 - Classic Account 2 - Portfolio Margin Account
    » ip_whitelist array ip white list
    » created_at string Creation time
    » updated_at string Last update time

    # Enumerated Values

    Property Value
    name wallet
    name spot
    name futures
    name delivery
    name withdraw

    WARNING

    To perform this operation, you must be authenticated by API key and secret

    # Delete the API key

    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 = '/broker/sub_account_keys/100010/bfc5f289273ea47b7cd41d9ce7e27a0d'
    query_param = ''
    # for `gen_sign` implementation, refer to section `Authentication` above
    sign_headers = gen_sign('DELETE', prefix + url, query_param)
    headers.update(sign_headers)
    r = requests.request('DELETE', 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="DELETE"
    url="/broker/sub_account_keys/100010/bfc5f289273ea47b7cd41d9ce7e27a0d"
    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"
    
    

    DELETE /broker/sub_account_keys/{sub_account_id}/{key}

    Delete the API key

    Parameters

    Name In Type Required Description
    sub_account_id path integer(int64) true Gate user ID returned when sub account created
    key path string true The API Key

    Responses

    Status Meaning Description Schema
    204 No Content (opens new window) Delete successfully None

    WARNING

    To perform this operation, you must be authenticated by API key and secret

    # Update the API key

    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 = '/broker/sub_account_keys/100010/bfc5f289273ea47b7cd41d9ce7e27a0d'
    query_param = ''
    body='{"user_id":"10001","name":"spot","type":1,"perms":[{"name":"spot","read_only":false}],"ip_whitelist":["8.8.8.8"]}'
    # for `gen_sign` implementation, refer to section `Authentication` above
    sign_headers = gen_sign('PUT', prefix + url, query_param, body)
    headers.update(sign_headers)
    r = requests.request('PUT', 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="PUT"
    url="/broker/sub_account_keys/100010/bfc5f289273ea47b7cd41d9ce7e27a0d"
    query_param=""
    body_param='{"user_id":"10001","name":"spot","type":1,"perms":[{"name":"spot","read_only":false}],"ip_whitelist":["8.8.8.8"]}'
    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"
    
    

    PUT /broker/sub_account_keys/{sub_account_id}/{key}

    Update the API key

    Body parameter

    {
      "user_id": "10001",
      "name": "spot",
      "type": 1,
      "perms": [
        {
          "name": "spot",
          "read_only": false
        }
      ],
      "ip_whitelist": [
        "8.8.8.8"
      ]
    }
    

    Parameters

    Name In Type Required Description
    body body object false none
    » user_id body string false User ID
    » name body string false API key name
    » perms body array false none
    »» name body string false The permission name
    »» read_only body boolean false read only
    » type body integer(int32) false Type: 1 - Main Account 2 - sub-account 3 - Managed Account
    » ip_whitelist body array false ip white list
    sub_account_id path integer(int64) true Gate user ID returned when sub account created
    key path string true The API Key

    # Detailed descriptions

    »» name: The permission name

    • wallet: wallet
    • spot: spot/margin
    • futures: futures
    • delivery: delivery
    • withdraw: withdraw

    # Enumerated Values

    Parameter Value
    »» name wallet
    »» name spot
    »» name futures
    »» name delivery
    »» name withdraw

    Responses

    Status Meaning Description Schema
    204 No Content (opens new window) Success None

    WARNING

    To perform this operation, you must be authenticated by API key and secret

    # Transfer to sub accounts

    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 = '/broker/sub_account_transfers'
    query_param = ''
    body='{"client_order_id":"da3ce7a088c8b0372b741419c7829033","currency":"BTC","sub_account":"10002","direction":"to","amount":"1","sub_account_type":"spot"}'
    # 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="/broker/sub_account_transfers"
    query_param=""
    body_param='{"client_order_id":"da3ce7a088c8b0372b741419c7829033","currency":"BTC","sub_account":"10002","direction":"to","amount":"1","sub_account_type":"spot"}'
    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 /broker/sub_account_transfers

    Transfer to sub accounts

    Body parameter

    {
      "client_order_id": "da3ce7a088c8b0372b741419c7829033",
      "currency": "BTC",
      "sub_account": "10002",
      "direction": "to",
      "amount": "1",
      "sub_account_type": "spot"
    }
    

    Parameters

    Name In Type Required Description
    body body object true none
    » currency body string true Transfer currency name
    » sub_account body string true Sub account user ID
    » direction body string true Transfer direction. to - transfer into sub account; from - transfer out from sub account
    » amount body string true Transfer amount
    » client_order_id body string false The custom ID provided by the customer serves as a safeguard against duplicate transfers. It can be a combination of letters (case-sensitive), numbers, hyphens '-', and underscores '_', with a length ranging from 1 to 64 characters.
    » sub_account_type body string false Target sub user's account. spot - spot account, futures - perpetual contract account, cross_margin - cross margin account, delivery - delivery account

    Responses

    Status Meaning Description Schema
    204 No Content (opens new window) Balance transferred None

    WARNING

    To perform this operation, you must be authenticated by API key and secret

    # List broker's transfer history with sub accounts

    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 = '/broker/sub_account_transfers'
    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="/broker/sub_account_transfers"
    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 /broker/sub_account_transfers

    List broker's transfer history with sub accounts

    Record time range cannot exceed 30 days

    Parameters

    Name In Type Required Description
    sub_uid query string false Sub account user ID. Return records related to all sub accounts if not specified
    from query integer(int64) false Time range beginning, default to 7 days before current time
    to query integer(int64) false Time range ending, default to current time
    limit query integer false Maximum number of records to be returned in a single list
    offset query integer false List offset, starting from 0

    Example responses

    200 Response

    [
      {
        "uid": "10001",
        "timest": "1592809000",
        "source": "web",
        "client_order_id": "da3ce7a088c8b0372b741419c7829033",
        "currency": "BTC",
        "sub_account": "10002",
        "direction": "to",
        "amount": "1",
        "sub_account_type": "spot"
      }
    ]
    

    Responses

    Status Meaning Description Schema
    200 OK (opens new window) List retrieved [Inline]

    Response Schema

    Status Code 200

    Name Type Description
    None array none
    » currency string Transfer currency name
    » sub_account string Sub account user ID
    » direction string Transfer direction. to - transfer into sub account; from - transfer out from sub account
    » amount string Transfer amount
    » uid string Main account user ID
    » client_order_id string The custom ID provided by the customer serves as a safeguard against duplicate transfers. It can be a combination of letters (case-sensitive), numbers, hyphens '-', and underscores '_', with a length ranging from 1 to 64 characters.
    » timest string Transfer timestamp
    » source string Where the operation is initiated from
    » sub_account_type string Target sub user's account. spot - spot account, futures - perpetual contract account, cross_margin - cross margin account, delivery - delivery account

    WARNING

    To perform this operation, you must be authenticated by API key and secret

    # Schemas

    # Broker

    {
      "id": 0,
      "commission_rate": "string",
      "status": "enabled",
      "min_taker_rate": "string",
      "max_taker_rate": "string",
      "min_maker_rate": "string",
      "max_maker_rate": "string",
      "futures_min_taker_rate": "string",
      "futures_max_taker_rate": "string",
      "futures_min_maker_rate": "string",
      "futures_max_maker_rate": "string",
      "max_sub_accounts": 0,
      "used_sub_accounts": 0
    }
    
    

    The broker info

    # Properties

    Name Type Required Restrictions Description
    id integer(int64) true none Broker ID
    commission_rate string true none Commission percentage
    status string false read-only Status:

    - enabled: enabled
    - disabled: disabled
    min_taker_rate string true none The minimum taker fee rate allowed to be set for a sub-account
    max_taker_rate string true none The maximum taker fee rate allowed to be set for a sub-account
    min_maker_rate string true none The minimum maker fee rate allowed to be set for a sub-account
    max_maker_rate string true none The maximum maker fee rate allowed to be set for a sub-account
    futures_min_taker_rate string true none The minimum taker fee rate of the futures allowed to be set for a sub-account
    futures_max_taker_rate string true none The maximum taker fee rate of the futures allowed to be set for a sub-account
    futures_min_maker_rate string true none The minimum maker fee rate of the futures allowed to be set for a sub-account
    futures_max_maker_rate string true none The maximum maker fee rate of the futures allowed to be set for a sub-account
    max_sub_accounts integer true none The maximum number of sub-accounts allowed
    used_sub_accounts integer false read-only The number of sub-accounts currently used

    # Enumerated Values

    Property Value
    status enabled
    status disabled

    # BrokerSubAccount

    {
      "id": "string",
      "name": "string",
      "maker_rate": "string",
      "taker_rate": "string",
      "futures_maker_rate": "string",
      "futures_taker_rate": "string",
      "gt_discount": true,
      "gt_taker_rate": "string",
      "gt_maker_rate": "string",
      "status": "string",
      "gate_id": 0,
      "point_type": "string"
    }
    
    

    The broker's sub-account details

    # Properties

    Name Type Required Restrictions Description
    id string true none The unique identifier of the sub-account. This field is only used for record display. Any operations to the sub-account needs to use the user ID generated inside the Gate.`
    name string false none name
    maker_rate string true none maker fee of the sub-account
    taker_rate string true none taker fee of the sub-account
    futures_maker_rate string true none Futures trading maker fee of sub account
    futures_taker_rate string true none Futures trading taker fee of sub account
    gt_discount boolean false none If GT deduction is enabled
    gt_taker_rate string false none Taker fee rate if using GT deduction. It will be 0 if GT deduction is disabled
    gt_maker_rate string false none Maker fee rate if using GT deduction. It will be 0 if GT deduction is disabled
    status string false read-only Sub-account status:

    - enabled: enabled
    - disabled: disabled
    gate_id integer(int64) false read-only User id of the Gate
    point_type string false none Point type. 0 - Initial version. 1 - new version since 202009