Skip to content

Latest commit

 

History

History
1368 lines (1030 loc) · 52.4 KB

StockApi.md

File metadata and controls

1368 lines (1030 loc) · 52.4 KB

gate_api.StockApi

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

Method HTTP request Description
query_stock_user_assets GET /stock/users/assets Query user assets
set_stock_margin_feature PUT /stock/users/margin-feature Set margin financing availability
query_stock_symbols GET /stock/symbols Query symbol list
query_stock_symbol_detail GET /stock/symbols/detail Query symbol details
query_stock_order_book GET /stock/market/{symbol}/orderbook Query market order book
query_stock_order_list GET /stock/orders Query open order list
create_stock_order POST /stock/orders Create order
delete_all_stock_orders DELETE /stock/orders Cancel all open orders
query_stock_order_history GET /stock/orders/history Query historical order list
query_stock_order_deals GET /stock/orders/deals Query order trade records
update_stock_order PUT /stock/orders/{order_id} Modify order
delete_stock_order DELETE /stock/orders/{order_id} Cancel order
query_stock_positions GET /stock/positions Query current position list
close_stock_position POST /stock/positions/close Close position
query_stock_transactions GET /stock/transactions Query transaction records
create_stock_transaction POST /stock/transactions Fund transfer
query_stock_balance_records GET /stock/users/balance-records Query user balance records
query_stock_exchanges GET /stock/exchanges Query supported exchanges
query_stock_fee_rate GET /stock/fee-rate Query fee rates for Japanese and Korean stocks

query_stock_user_assets

UserAssetResp2 query_stock_user_assets(pnl_calc_type=pnl_calc_type, pnl_calc_price=pnl_calc_price)

Query user assets

Rate limit: 5 qps.

Example

  • Api Key Authentication (apiv4):
from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure APIv4 key authorization
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4",
    key = "YOU_API_KEY",
    secret = "YOUR_API_SECRET"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)
pnl_calc_type = 1 # int | PnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price) (optional)
pnl_calc_price = 1 # int | PnL calculation price type. Defaults to intraday price when omitted (1 = intraday price, 2 = latest extended-hours price) (optional)

try:
    # Query user assets
    api_response = api_instance.query_stock_user_assets(pnl_calc_type=pnl_calc_type, pnl_calc_price=pnl_calc_price)
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->query_stock_user_assets: %s\n" % e)

Parameters

Name Type Description Notes
pnl_calc_type int PnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price) [optional]
pnl_calc_price int PnL calculation price type. Defaults to intraday price when omitted (1 = intraday price, 2 = latest extended-hours price) [optional]

Return type

UserAssetResp2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Request success -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]

set_stock_margin_feature

SetMarginFeature set_stock_margin_feature(trad_fi_spot_set_margin_feature_request)

Set margin financing availability

Rate limit: 5 requests per second. Enable or disable margin financing for the user.

Example

  • Api Key Authentication (apiv4):
from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure APIv4 key authorization
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4",
    key = "YOU_API_KEY",
    secret = "YOUR_API_SECRET"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)
trad_fi_spot_set_margin_feature_request = gate_api.TradFiSpotSetMarginFeatureRequest() # TradFiSpotSetMarginFeatureRequest | 

try:
    # Set margin financing availability
    api_response = api_instance.set_stock_margin_feature(trad_fi_spot_set_margin_feature_request)
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->set_stock_margin_feature: %s\n" % e)

Parameters

Name Type Description Notes
trad_fi_spot_set_margin_feature_request TradFiSpotSetMarginFeatureRequest

Return type

SetMarginFeature

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Request success -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]

query_stock_symbols

Symbols2 query_stock_symbols(symbols=symbols, exchange=exchange, with_desc_i18n=with_desc_i18n, page=page, page_size=page_size)

Query symbol list

Rate limit: 5 qps.

Example

from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)
symbols = 'AAPL,TSLA' # str | Symbol list, multiple separated by commas (optional)
exchange = 'us' # str | Trading market code. - us: US stocks. - hk: Hong Kong stocks. - kr: South Korean stocks. - jp: Japanese stocks. (optional)
with_desc_i18n = true # bool | Whether to return multilingual symbol description (optional)
page = 1 # int | Page number, defaults to 1 (optional)
page_size = 100 # int | Page size, defaults to 10, max 500; server caps at 500 (optional)

try:
    # Query symbol list
    api_response = api_instance.query_stock_symbols(symbols=symbols, exchange=exchange, with_desc_i18n=with_desc_i18n, page=page, page_size=page_size)
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->query_stock_symbols: %s\n" % e)

Parameters

Name Type Description Notes
symbols str Symbol list, multiple separated by commas [optional]
exchange str Trading market code. - us: US stocks. - hk: Hong Kong stocks. - kr: South Korean stocks. - jp: Japanese stocks. [optional]
with_desc_i18n bool Whether to return multilingual symbol description [optional]
page int Page number, defaults to 1 [optional]
page_size int Page size, defaults to 10, max 500; server caps at 500 [optional]

Return type

Symbols2

Authorization

No authorization required

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Request success -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]

query_stock_symbol_detail

SymbolDetail query_stock_symbol_detail(symbols=symbols, exchange=exchange, page=page, page_size=page_size)

Query symbol details

Rate limit: 5 qps.

Example

from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)
symbols = 'AAPL,TSLA' # str | Symbol list, multiple separated by commas (optional)
exchange = 'us' # str | Exchange. - us: US stocks. - hk: Hong Kong stocks. - kr: Korean stocks. - jp: Japanese stocks. (optional)
page = 1 # int | Page number, defaults to 1 (optional)
page_size = 100 # int | Page size, defaults to 10, max 500; server caps at 500 (optional)

try:
    # Query symbol details
    api_response = api_instance.query_stock_symbol_detail(symbols=symbols, exchange=exchange, page=page, page_size=page_size)
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->query_stock_symbol_detail: %s\n" % e)

Parameters

Name Type Description Notes
symbols str Symbol list, multiple separated by commas [optional]
exchange str Exchange. - us: US stocks. - hk: Hong Kong stocks. - kr: Korean stocks. - jp: Japanese stocks. [optional]
page int Page number, defaults to 1 [optional]
page_size int Page size, defaults to 10, max 500; server caps at 500 [optional]

Return type

SymbolDetail

Authorization

No authorization required

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Request success -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]

query_stock_order_book

OrderBook2 query_stock_order_book(symbol)

Query market order book

Rate limit: 5 qps.

Example

from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)
symbol = 'AAPL' # str | Symbol

try:
    # Query market order book
    api_response = api_instance.query_stock_order_book(symbol)
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->query_stock_order_book: %s\n" % e)

Parameters

Name Type Description Notes
symbol str Symbol

Return type

OrderBook2

Authorization

No authorization required

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Request success -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]

query_stock_order_list

OrderList2 query_stock_order_list(symbol=symbol)

Query open order list

Rate limit: 5 qps.

Example

  • Api Key Authentication (apiv4):
from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure APIv4 key authorization
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4",
    key = "YOU_API_KEY",
    secret = "YOUR_API_SECRET"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)
symbol = 'AAPL' # str | Symbol (optional)

try:
    # Query open order list
    api_response = api_instance.query_stock_order_list(symbol=symbol)
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->query_stock_order_list: %s\n" % e)

Parameters

Name Type Description Notes
symbol str Symbol [optional]

Return type

OrderList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Request success -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]

create_stock_order

CreateOrder2 create_stock_order(trad_fi_spot_order_request)

Create order

Rate limit: 5 qps.

Example

  • Api Key Authentication (apiv4):
from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure APIv4 key authorization
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4",
    key = "YOU_API_KEY",
    secret = "YOUR_API_SECRET"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)
trad_fi_spot_order_request = gate_api.TradFiSpotOrderRequest() # TradFiSpotOrderRequest | 

try:
    # Create order
    api_response = api_instance.create_stock_order(trad_fi_spot_order_request)
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->create_stock_order: %s\n" % e)

Parameters

Name Type Description Notes
trad_fi_spot_order_request TradFiSpotOrderRequest

Return type

CreateOrder2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Order placed successfully -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]

delete_all_stock_orders

DeleteOrder delete_all_stock_orders()

Cancel all open orders

Rate limit: 5 qps.

Example

  • Api Key Authentication (apiv4):
from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure APIv4 key authorization
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4",
    key = "YOU_API_KEY",
    secret = "YOUR_API_SECRET"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)

try:
    # Cancel all open orders
    api_response = api_instance.delete_all_stock_orders()
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->delete_all_stock_orders: %s\n" % e)

Parameters

This endpoint does not need any parameter.

Return type

DeleteOrder

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Request success -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]

query_stock_order_history

OrderHistoryList2 query_stock_order_history(symbol=symbol, order_ids=order_ids, begin_time=begin_time, end_time=end_time, side=side, page=page, page_size=page_size)

Query historical order list

Rate limit: 5 qps.

Example

  • Api Key Authentication (apiv4):
from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure APIv4 key authorization
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4",
    key = "YOU_API_KEY",
    secret = "YOUR_API_SECRET"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)
symbol = 'AAPL' # str | Symbol (optional)
order_ids = '123456,123457' # str | Order ID list, multiple separated by commas; max 20, each must be a positive integer (optional)
begin_time = 1769378400 # int | Start time (Unix timestamp, seconds). When both begin_time and end_time are provided, end_time must be >= begin_time, query range must not exceed 3 months. (optional)
end_time = 1769464800 # int | End time (Unix timestamp, seconds). When both begin_time and end_time are provided, end_time must be >= begin_time, query range must not exceed 3 months. (optional)
side = 2 # int | Side (1=sell, 2=buy) (optional)
page = 1 # int | Page number, defaults to 1 (optional)
page_size = 100 # int | Page size, defaults to 10, max 500; server caps at 500 (optional)

try:
    # Query historical order list
    api_response = api_instance.query_stock_order_history(symbol=symbol, order_ids=order_ids, begin_time=begin_time, end_time=end_time, side=side, page=page, page_size=page_size)
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->query_stock_order_history: %s\n" % e)

Parameters

Name Type Description Notes
symbol str Symbol [optional]
order_ids str Order ID list, multiple separated by commas; max 20, each must be a positive integer [optional]
begin_time int Start time (Unix timestamp, seconds). When both begin_time and end_time are provided, end_time must be >= begin_time, query range must not exceed 3 months. [optional]
end_time int End time (Unix timestamp, seconds). When both begin_time and end_time are provided, end_time must be >= begin_time, query range must not exceed 3 months. [optional]
side int Side (1=sell, 2=buy) [optional]
page int Page number, defaults to 1 [optional]
page_size int Page size, defaults to 10, max 500; server caps at 500 [optional]

Return type

OrderHistoryList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Request success -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]

query_stock_order_deals

OrderDealList query_stock_order_deals(order_id, page=page, page_size=page_size)

Query order trade records

Rate limit: 5 requests per second. Query the current user's trade records by order ID. price, value, and fee are denominated in the instrument trading currency (for example, USD for US stocks, HKD for Hong Kong stocks, JPY for Japanese stocks, and KRW for Korean stocks). role returns maker or taker.

Example

  • Api Key Authentication (apiv4):
from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure APIv4 key authorization
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4",
    key = "YOU_API_KEY",
    secret = "YOUR_API_SECRET"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)
order_id = 123456 # int | Order ID
page = 1 # int | Page number, defaults to 1 (optional)
page_size = 20 # int | Records per page. Defaults to 10, maximum 100. The server caps values greater than 100 at 100. (optional)

try:
    # Query order trade records
    api_response = api_instance.query_stock_order_deals(order_id, page=page, page_size=page_size)
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->query_stock_order_deals: %s\n" % e)

Parameters

Name Type Description Notes
order_id int Order ID
page int Page number, defaults to 1 [optional]
page_size int Records per page. Defaults to 10, maximum 100. The server caps values greater than 100 at 100. [optional]

Return type

OrderDealList

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Request success -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]

update_stock_order

UpdateOrder2 update_stock_order(order_id, trad_fi_spot_order_update_request)

Modify order

Rate limit: 5 qps.

Example

  • Api Key Authentication (apiv4):
from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure APIv4 key authorization
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4",
    key = "YOU_API_KEY",
    secret = "YOUR_API_SECRET"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)
order_id = 123456 # int | Order ID
trad_fi_spot_order_update_request = gate_api.TradFiSpotOrderUpdateRequest() # TradFiSpotOrderUpdateRequest | 

try:
    # Modify order
    api_response = api_instance.update_stock_order(order_id, trad_fi_spot_order_update_request)
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->update_stock_order: %s\n" % e)

Parameters

Name Type Description Notes
order_id int Order ID
trad_fi_spot_order_update_request TradFiSpotOrderUpdateRequest

Return type

UpdateOrder2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Request success -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]

delete_stock_order

DeleteOrder delete_stock_order(order_id)

Cancel order

Rate limit: 5 qps.

Example

  • Api Key Authentication (apiv4):
from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure APIv4 key authorization
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4",
    key = "YOU_API_KEY",
    secret = "YOUR_API_SECRET"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)
order_id = 123456 # int | Order ID

try:
    # Cancel order
    api_response = api_instance.delete_stock_order(order_id)
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->delete_stock_order: %s\n" % e)

Parameters

Name Type Description Notes
order_id int Order ID

Return type

DeleteOrder

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Request success -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]

query_stock_positions

PositionList2 query_stock_positions(pnl_calc_type=pnl_calc_type, pnl_calc_price=pnl_calc_price, symbol=symbol, exchange=exchange)

Query current position list

Rate limit: 5 qps.

Example

  • Api Key Authentication (apiv4):
from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure APIv4 key authorization
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4",
    key = "YOU_API_KEY",
    secret = "YOUR_API_SECRET"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)
pnl_calc_type = 1 # int | PnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price) (optional)
pnl_calc_price = 1 # int | PnL calculation price type. Defaults to intraday price when omitted (1 = intraday price, 2 = latest extended-hours price) (optional)
symbol = 'AAPL' # str | Symbol (optional)
exchange = 'us' # str | Exchange. - us: US stocks. - hk: Hong Kong stocks. - kr: Korean stocks. - jp: Japanese stocks. (optional)

try:
    # Query current position list
    api_response = api_instance.query_stock_positions(pnl_calc_type=pnl_calc_type, pnl_calc_price=pnl_calc_price, symbol=symbol, exchange=exchange)
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->query_stock_positions: %s\n" % e)

Parameters

Name Type Description Notes
pnl_calc_type int PnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price) [optional]
pnl_calc_price int PnL calculation price type. Defaults to intraday price when omitted (1 = intraday price, 2 = latest extended-hours price) [optional]
symbol str Symbol [optional]
exchange str Exchange. - us: US stocks. - hk: Hong Kong stocks. - kr: Korean stocks. - jp: Japanese stocks. [optional]

Return type

PositionList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Request success -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]

close_stock_position

ClosePosition close_stock_position(trad_fi_spot_close_position_request)

Close position

Rate limit: 5 qps.

Example

  • Api Key Authentication (apiv4):
from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure APIv4 key authorization
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4",
    key = "YOU_API_KEY",
    secret = "YOUR_API_SECRET"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)
trad_fi_spot_close_position_request = gate_api.TradFiSpotClosePositionRequest() # TradFiSpotClosePositionRequest | 

try:
    # Close position
    api_response = api_instance.close_stock_position(trad_fi_spot_close_position_request)
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->close_stock_position: %s\n" % e)

Parameters

Name Type Description Notes
trad_fi_spot_close_position_request TradFiSpotClosePositionRequest

Return type

ClosePosition

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Request success -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]

query_stock_transactions

TransactionList2 query_stock_transactions(begin_time=begin_time, end_time=end_time, ref_id=ref_id, type=type, page=page, page_size=page_size)

Query transaction records

Rate limit: 5 qps. Query stock account transaction records, including fund transfers, trades, fees, dividends, rewards, and stock transfers.

Example

  • Api Key Authentication (apiv4):
from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure APIv4 key authorization
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4",
    key = "YOU_API_KEY",
    secret = "YOUR_API_SECRET"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)
begin_time = 1769378400 # int | Start time (Unix timestamp, seconds). When both begin_time and end_time are provided, end_time must be >= begin_time, query range must not exceed 3 months. (optional)
end_time = 1769464800 # int | End time (Unix timestamp, seconds). When both begin_time and end_time are provided, end_time must be >= begin_time, query range must not exceed 3 months. (optional)
ref_id = 'transfer-202607070001' # str | Business idempotent ID. When ref_id is provided, the server queries by ref_id, ignoring other parameters such as begin_time, end_time, type, page, page_size (optional)
type = 'deposit' # str | 流水类型。 - deposit: 资金转入,从现货账户转入到股票账户。 - withdraw: 资金转出,从股票账户转出到现货账户。 - fee: 交易手续费。 - dividend: 分红派息。 - sell: 卖出股票入账。 - buy: 买入股票出账。 - award: 空投奖励。 - stock_transfer_in: 股票转入。 - stock_transfer_out: 股票转出。 (optional)
page = 1 # int | Page number, defaults to 1 (optional)
page_size = 100 # int | Page size, defaults to 10, max 500; server caps at 500 (optional)

try:
    # Query transaction records
    api_response = api_instance.query_stock_transactions(begin_time=begin_time, end_time=end_time, ref_id=ref_id, type=type, page=page, page_size=page_size)
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->query_stock_transactions: %s\n" % e)

Parameters

Name Type Description Notes
begin_time int Start time (Unix timestamp, seconds). When both begin_time and end_time are provided, end_time must be >= begin_time, query range must not exceed 3 months. [optional]
end_time int End time (Unix timestamp, seconds). When both begin_time and end_time are provided, end_time must be >= begin_time, query range must not exceed 3 months. [optional]
ref_id str Business idempotent ID. When ref_id is provided, the server queries by ref_id, ignoring other parameters such as begin_time, end_time, type, page, page_size [optional]
type str 流水类型。 - deposit: 资金转入,从现货账户转入到股票账户。 - withdraw: 资金转出,从股票账户转出到现货账户。 - fee: 交易手续费。 - dividend: 分红派息。 - sell: 卖出股票入账。 - buy: 买入股票出账。 - award: 空投奖励。 - stock_transfer_in: 股票转入。 - stock_transfer_out: 股票转出。 [optional]
page int Page number, defaults to 1 [optional]
page_size int Page size, defaults to 10, max 500; server caps at 500 [optional]

Return type

TransactionList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Request success -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]

create_stock_transaction

CreateTransaction2 create_stock_transaction(trad_fi_spot_transaction_request)

Fund transfer

Rate limit: 5 qps. Fund transfer moves USDT between the spot account and the stock account. - deposit: transfer from the spot account to the stock account. - withdraw: transfer from the stock account to the spot account.

Example

  • Api Key Authentication (apiv4):
from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure APIv4 key authorization
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4",
    key = "YOU_API_KEY",
    secret = "YOUR_API_SECRET"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)
trad_fi_spot_transaction_request = gate_api.TradFiSpotTransactionRequest() # TradFiSpotTransactionRequest | 

try:
    # Fund transfer
    api_response = api_instance.create_stock_transaction(trad_fi_spot_transaction_request)
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->create_stock_transaction: %s\n" % e)

Parameters

Name Type Description Notes
trad_fi_spot_transaction_request TradFiSpotTransactionRequest

Return type

CreateTransaction2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Request success -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]

query_stock_balance_records

BalanceRecordList query_stock_balance_records(type=type, business=business, symbol=symbol, begin_time=begin_time, end_time=end_time, start_id=start_id, sort_direction=sort_direction, include_detail=include_detail, page=page, page_size=page_size)

Query user balance records

Rate limit: 5 requests per second. Query the current user's raw balance records. User scope is derived from the request headers; a query parameter user_id is not supported. - type and business support multiple comma-separated values. - begin_time and end_time filter record creation time in seconds. When both are provided, end_time must be greater than begin_time. - Results are always sorted by primary key id; sort_direction accepts asc or desc. The default is id desc. With start_id and no sort_direction, the order is id asc, and only records with id > start_id are returned for incremental retrieval. - detail is omitted by default and returned only when include_detail=true. - stock_change is parsed from detail.amount for stock quantity records; balance is a cash balance snapshot, not a stock position balance.

Example

  • Api Key Authentication (apiv4):
from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure APIv4 key authorization
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4",
    key = "YOU_API_KEY",
    secret = "YOUR_API_SECRET"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)
type = 'deposit,fee' # str | Record types, separated by commas (optional)
business = 'transfer,trade' # str | Business identifiers, separated by commas (optional)
symbol = 'AAPL' # str | Symbol (optional)
begin_time = 1769378400 # int | Start time (Unix timestamp in seconds). When both begin_time and end_time are provided, end_time must be greater than begin_time. (optional)
end_time = 1769464800 # int | End time (Unix timestamp in seconds). When both begin_time and end_time are provided, end_time must be greater than begin_time. (optional)
start_id = 1000 # int | Starting primary key ID for incremental queries. Only records with a greater id are returned. (optional)
sort_direction = 'desc' # str | Sort direction by primary key id. - asc: Ascending. - desc: Descending. When omitted, defaults to desc without start_id, or asc with start_id. (optional)
include_detail = false # bool | Whether to return the raw detail field; defaults to false when omitted (optional)
page = 1 # int | Page number, defaults to 1 (optional)
page_size = 20 # int | Records per page. Defaults to 10, maximum 100. The server caps values greater than 100 at 100. (optional)

try:
    # Query user balance records
    api_response = api_instance.query_stock_balance_records(type=type, business=business, symbol=symbol, begin_time=begin_time, end_time=end_time, start_id=start_id, sort_direction=sort_direction, include_detail=include_detail, page=page, page_size=page_size)
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->query_stock_balance_records: %s\n" % e)

Parameters

Name Type Description Notes
type str Record types, separated by commas [optional]
business str Business identifiers, separated by commas [optional]
symbol str Symbol [optional]
begin_time int Start time (Unix timestamp in seconds). When both begin_time and end_time are provided, end_time must be greater than begin_time. [optional]
end_time int End time (Unix timestamp in seconds). When both begin_time and end_time are provided, end_time must be greater than begin_time. [optional]
start_id int Starting primary key ID for incremental queries. Only records with a greater id are returned. [optional]
sort_direction str Sort direction by primary key id. - asc: Ascending. - desc: Descending. When omitted, defaults to desc without start_id, or asc with start_id. [optional]
include_detail bool Whether to return the raw detail field; defaults to false when omitted [optional]
page int Page number, defaults to 1 [optional]
page_size int Records per page. Defaults to 10, maximum 100. The server caps values greater than 100 at 100. [optional]

Return type

BalanceRecordList

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Request success -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]

query_stock_exchanges

Exchanges query_stock_exchanges()

Query supported exchanges

Query stock spot supported exchanges and whether stock transfers are supported. Rate limit: 5 qps.

Example

from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)

try:
    # Query supported exchanges
    api_response = api_instance.query_stock_exchanges()
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->query_stock_exchanges: %s\n" % e)

Parameters

This endpoint does not need any parameter.

Return type

Exchanges

Authorization

No authorization required

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Request success -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]

query_stock_fee_rate

FeeRate query_stock_fee_rate()

Query fee rates for Japanese and Korean stocks

Query fee rates for Japanese and Korean stocks. Rate limit: 5 qps.

Example

from __future__ import print_function
import gate_api
from gate_api.exceptions import ApiException, GateApiException
# Defining the host is optional and defaults to https://api.gateio.ws/api/v4
# See configuration.py for a list of all supported configuration parameters.
configuration = gate_api.Configuration(
    host = "https://api.gateio.ws/api/v4"
)

api_client = gate_api.ApiClient(configuration)
# Create an instance of the API class
api_instance = gate_api.StockApi(api_client)

try:
    # Query fee rates for Japanese and Korean stocks
    api_response = api_instance.query_stock_fee_rate()
    print(api_response)
except GateApiException as ex:
    print("Gate api exception, label: %s, message: %s\n" % (ex.label, ex.message))
except ApiException as e:
    print("Exception when calling StockApi->query_stock_fee_rate: %s\n" % e)

Parameters

This endpoint does not need any parameter.

Return type

FeeRate

Authorization

No authorization required

HTTP request headers

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

HTTP response details

Status code Description Response headers
200 Request success -
400 Request failed -

[Back to top] [Back to API list] [Back to Model list] [Back to README]