Skip to content

Latest commit

History

History
1131 lines (848 loc) · 39.9 KB

File metadata and controls

1131 lines (848 loc) · 39.9 KB

gate_api.StockApi

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

MethodHTTP requestDescription
query_stock_user_assetsGET /stock/users/assetsQuery user assets
query_stock_symbolsGET /stock/symbolsQuery symbol list
query_stock_symbol_detailGET /stock/symbols/detailQuery symbol details
query_stock_order_bookGET /stock/market/{symbol}/orderbookQuery market order book
query_stock_order_listGET /stock/ordersQuery open order list
create_stock_orderPOST /stock/ordersCreate order
delete_all_stock_ordersDELETE /stock/ordersCancel all open orders
query_stock_order_historyGET /stock/orders/historyQuery historical order list
update_stock_orderPUT /stock/orders/{order_id}Modify order
delete_stock_orderDELETE /stock/orders/{order_id}Cancel order
query_stock_positionsGET /stock/positionsQuery current position list
close_stock_positionPOST /stock/positions/closeClose position
query_stock_transactionsGET /stock/transactionsQuery transaction records
create_stock_transactionPOST /stock/transactionsFund transfer
query_stock_exchangesGET /stock/exchangesQuery supported exchanges
query_stock_fee_rateGET /stock/fee-rateQuery 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 assetsapi_response=api_instance.query_stock_user_assets(pnl_calc_type=pnl_calc_type, pnl_calc_price=pnl_calc_price)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_user_assets: %s\n"%e)

Parameters

NameTypeDescriptionNotes
pnl_calc_typeintPnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price)[optional]
pnl_calc_priceintPnL 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbols='AAPL,TSLA'# str | Symbol list, multiple separated by commas (optional)exchange='us'# str | Exchange, supports us, hk, and kr (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 listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_symbols: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolsstrSymbol list, multiple separated by commas[optional]
exchangestrExchange, supports us, hk, and kr[optional]
with_desc_i18nboolWhether to return multilingual symbol description[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbols='AAPL,TSLA'# str | Symbol list, multiple separated by commas (optional)exchange='us'# str | Exchange, supports us, hk, and kr (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 detailsapi_response=api_instance.query_stock_symbol_detail(symbols=symbols, exchange=exchange, page=page, page_size=page_size)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_symbol_detail: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolsstrSymbol list, multiple separated by commas[optional]
exchangestrExchange, supports us, hk, and kr[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbol='AAPL'# str | Symboltry:
# Query market order bookapi_response=api_instance.query_stock_order_book(symbol)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_book: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol

Return type

OrderBook2

Authorization

No authorization required

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
symbol='AAPL'# str | Symbol (optional)try:
# Query open order listapi_response=api_instance.query_stock_order_list(symbol=symbol)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_list: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol[optional]

Return type

OrderList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_order_request=gate_api.TradFiSpotOrderRequest() # TradFiSpotOrderRequest | try:
# Create orderapi_response=api_instance.create_stock_order(trad_fi_spot_order_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->create_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_order_requestTradFiSpotOrderRequest

Return type

CreateOrder2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Order placed successfully-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
try:
# Cancel all open ordersapi_response=api_instance.delete_all_stock_orders()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_history: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol[optional]
order_idsstrOrder ID list, multiple separated by commas; max 20, each must be a positive integer[optional]
begin_timeintStart 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_timeintEnd 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]
sideintSide (1=sell, 2=buy)[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
order_id=123456# int | Order IDtrad_fi_spot_order_update_request=gate_api.TradFiSpotOrderUpdateRequest() # TradFiSpotOrderUpdateRequest | try:
# Modify orderapi_response=api_instance.update_stock_order(order_id, trad_fi_spot_order_update_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->update_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
order_idintOrder ID
trad_fi_spot_order_update_requestTradFiSpotOrderUpdateRequest

Return type

UpdateOrder2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
order_id=123456# int | Order IDtry:
# Cancel orderapi_response=api_instance.delete_stock_order(order_id)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->delete_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
order_idintOrder ID

Return type

DeleteOrder

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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, supports us, hk, and kr (optional)try:
# Query current position listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_positions: %s\n"%e)

Parameters

NameTypeDescriptionNotes
pnl_calc_typeintPnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price)[optional]
pnl_calc_priceintPnL calculation price type. Defaults to intraday price when omitted (1 = intraday price, 2 = latest extended-hours price)[optional]
symbolstrSymbol[optional]
exchangestrExchange, supports us, hk, and kr[optional]

Return type

PositionList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_close_position_request=gate_api.TradFiSpotClosePositionRequest() # TradFiSpotClosePositionRequest | try:
# Close positionapi_response=api_instance.close_stock_position(trad_fi_spot_close_position_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->close_stock_position: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_close_position_requestTradFiSpotClosePositionRequest

Return type

ClosePosition

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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.

Example

  • Api Key Authentication (apiv4):
from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 | Transaction type (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 recordsapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_transactions: %s\n"%e)

Parameters

NameTypeDescriptionNotes
begin_timeintStart 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_timeintEnd 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_idstrBusiness 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]
typestrTransaction type[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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.

Example

  • Api Key Authentication (apiv4):
from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_transaction_request=gate_api.TradFiSpotTransactionRequest() # TradFiSpotTransactionRequest | try:
# Fund transferapi_response=api_instance.create_stock_transaction(trad_fi_spot_transaction_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->create_stock_transaction: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_transaction_requestTradFiSpotTransactionRequest

Return type

CreateTransaction2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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

Example

from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
try:
# Query supported exchangesapi_response=api_instance.query_stock_exchanges()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
try:
# Query fee rates for Japanese and Korean stocksapi_response=api_instance.query_stock_fee_rate()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request failed-

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

, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
gateapi-python/docs/StockApi.md at master · gate/gateapi-python · GitHub
Skip to content

Latest commit

History

History
1131 lines (848 loc) · 39.9 KB

File metadata and controls

1131 lines (848 loc) · 39.9 KB

gate_api.StockApi

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

MethodHTTP requestDescription
query_stock_user_assetsGET /stock/users/assetsQuery user assets
query_stock_symbolsGET /stock/symbolsQuery symbol list
query_stock_symbol_detailGET /stock/symbols/detailQuery symbol details
query_stock_order_bookGET /stock/market/{symbol}/orderbookQuery market order book
query_stock_order_listGET /stock/ordersQuery open order list
create_stock_orderPOST /stock/ordersCreate order
delete_all_stock_ordersDELETE /stock/ordersCancel all open orders
query_stock_order_historyGET /stock/orders/historyQuery historical order list
update_stock_orderPUT /stock/orders/{order_id}Modify order
delete_stock_orderDELETE /stock/orders/{order_id}Cancel order
query_stock_positionsGET /stock/positionsQuery current position list
close_stock_positionPOST /stock/positions/closeClose position
query_stock_transactionsGET /stock/transactionsQuery transaction records
create_stock_transactionPOST /stock/transactionsFund transfer
query_stock_exchangesGET /stock/exchangesQuery supported exchanges
query_stock_fee_rateGET /stock/fee-rateQuery 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 assetsapi_response=api_instance.query_stock_user_assets(pnl_calc_type=pnl_calc_type, pnl_calc_price=pnl_calc_price)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_user_assets: %s\n"%e)

Parameters

NameTypeDescriptionNotes
pnl_calc_typeintPnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price)[optional]
pnl_calc_priceintPnL 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbols='AAPL,TSLA'# str | Symbol list, multiple separated by commas (optional)exchange='us'# str | Exchange, supports us, hk, and kr (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 listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_symbols: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolsstrSymbol list, multiple separated by commas[optional]
exchangestrExchange, supports us, hk, and kr[optional]
with_desc_i18nboolWhether to return multilingual symbol description[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbols='AAPL,TSLA'# str | Symbol list, multiple separated by commas (optional)exchange='us'# str | Exchange, supports us, hk, and kr (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 detailsapi_response=api_instance.query_stock_symbol_detail(symbols=symbols, exchange=exchange, page=page, page_size=page_size)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_symbol_detail: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolsstrSymbol list, multiple separated by commas[optional]
exchangestrExchange, supports us, hk, and kr[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbol='AAPL'# str | Symboltry:
# Query market order bookapi_response=api_instance.query_stock_order_book(symbol)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_book: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol

Return type

OrderBook2

Authorization

No authorization required

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
symbol='AAPL'# str | Symbol (optional)try:
# Query open order listapi_response=api_instance.query_stock_order_list(symbol=symbol)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_list: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol[optional]

Return type

OrderList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_order_request=gate_api.TradFiSpotOrderRequest() # TradFiSpotOrderRequest | try:
# Create orderapi_response=api_instance.create_stock_order(trad_fi_spot_order_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->create_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_order_requestTradFiSpotOrderRequest

Return type

CreateOrder2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Order placed successfully-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
try:
# Cancel all open ordersapi_response=api_instance.delete_all_stock_orders()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_history: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol[optional]
order_idsstrOrder ID list, multiple separated by commas; max 20, each must be a positive integer[optional]
begin_timeintStart 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_timeintEnd 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]
sideintSide (1=sell, 2=buy)[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
order_id=123456# int | Order IDtrad_fi_spot_order_update_request=gate_api.TradFiSpotOrderUpdateRequest() # TradFiSpotOrderUpdateRequest | try:
# Modify orderapi_response=api_instance.update_stock_order(order_id, trad_fi_spot_order_update_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->update_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
order_idintOrder ID
trad_fi_spot_order_update_requestTradFiSpotOrderUpdateRequest

Return type

UpdateOrder2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
order_id=123456# int | Order IDtry:
# Cancel orderapi_response=api_instance.delete_stock_order(order_id)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->delete_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
order_idintOrder ID

Return type

DeleteOrder

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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, supports us, hk, and kr (optional)try:
# Query current position listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_positions: %s\n"%e)

Parameters

NameTypeDescriptionNotes
pnl_calc_typeintPnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price)[optional]
pnl_calc_priceintPnL calculation price type. Defaults to intraday price when omitted (1 = intraday price, 2 = latest extended-hours price)[optional]
symbolstrSymbol[optional]
exchangestrExchange, supports us, hk, and kr[optional]

Return type

PositionList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_close_position_request=gate_api.TradFiSpotClosePositionRequest() # TradFiSpotClosePositionRequest | try:
# Close positionapi_response=api_instance.close_stock_position(trad_fi_spot_close_position_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->close_stock_position: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_close_position_requestTradFiSpotClosePositionRequest

Return type

ClosePosition

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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.

Example

  • Api Key Authentication (apiv4):
from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 | Transaction type (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 recordsapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_transactions: %s\n"%e)

Parameters

NameTypeDescriptionNotes
begin_timeintStart 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_timeintEnd 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_idstrBusiness 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]
typestrTransaction type[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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.

Example

  • Api Key Authentication (apiv4):
from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_transaction_request=gate_api.TradFiSpotTransactionRequest() # TradFiSpotTransactionRequest | try:
# Fund transferapi_response=api_instance.create_stock_transaction(trad_fi_spot_transaction_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->create_stock_transaction: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_transaction_requestTradFiSpotTransactionRequest

Return type

CreateTransaction2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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

Example

from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
try:
# Query supported exchangesapi_response=api_instance.query_stock_exchanges()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
try:
# Query fee rates for Japanese and Korean stocksapi_response=api_instance.query_stock_fee_rate()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request failed-

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

, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' gateapi-python/docs/StockApi.md at master · gate/gateapi-python · GitHub
Skip to content

Latest commit

History

History
1131 lines (848 loc) · 39.9 KB

File metadata and controls

1131 lines (848 loc) · 39.9 KB

gate_api.StockApi

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

MethodHTTP requestDescription
query_stock_user_assetsGET /stock/users/assetsQuery user assets
query_stock_symbolsGET /stock/symbolsQuery symbol list
query_stock_symbol_detailGET /stock/symbols/detailQuery symbol details
query_stock_order_bookGET /stock/market/{symbol}/orderbookQuery market order book
query_stock_order_listGET /stock/ordersQuery open order list
create_stock_orderPOST /stock/ordersCreate order
delete_all_stock_ordersDELETE /stock/ordersCancel all open orders
query_stock_order_historyGET /stock/orders/historyQuery historical order list
update_stock_orderPUT /stock/orders/{order_id}Modify order
delete_stock_orderDELETE /stock/orders/{order_id}Cancel order
query_stock_positionsGET /stock/positionsQuery current position list
close_stock_positionPOST /stock/positions/closeClose position
query_stock_transactionsGET /stock/transactionsQuery transaction records
create_stock_transactionPOST /stock/transactionsFund transfer
query_stock_exchangesGET /stock/exchangesQuery supported exchanges
query_stock_fee_rateGET /stock/fee-rateQuery 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 assetsapi_response=api_instance.query_stock_user_assets(pnl_calc_type=pnl_calc_type, pnl_calc_price=pnl_calc_price)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_user_assets: %s\n"%e)

Parameters

NameTypeDescriptionNotes
pnl_calc_typeintPnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price)[optional]
pnl_calc_priceintPnL 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbols='AAPL,TSLA'# str | Symbol list, multiple separated by commas (optional)exchange='us'# str | Exchange, supports us, hk, and kr (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 listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_symbols: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolsstrSymbol list, multiple separated by commas[optional]
exchangestrExchange, supports us, hk, and kr[optional]
with_desc_i18nboolWhether to return multilingual symbol description[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbols='AAPL,TSLA'# str | Symbol list, multiple separated by commas (optional)exchange='us'# str | Exchange, supports us, hk, and kr (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 detailsapi_response=api_instance.query_stock_symbol_detail(symbols=symbols, exchange=exchange, page=page, page_size=page_size)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_symbol_detail: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolsstrSymbol list, multiple separated by commas[optional]
exchangestrExchange, supports us, hk, and kr[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbol='AAPL'# str | Symboltry:
# Query market order bookapi_response=api_instance.query_stock_order_book(symbol)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_book: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol

Return type

OrderBook2

Authorization

No authorization required

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
symbol='AAPL'# str | Symbol (optional)try:
# Query open order listapi_response=api_instance.query_stock_order_list(symbol=symbol)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_list: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol[optional]

Return type

OrderList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_order_request=gate_api.TradFiSpotOrderRequest() # TradFiSpotOrderRequest | try:
# Create orderapi_response=api_instance.create_stock_order(trad_fi_spot_order_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->create_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_order_requestTradFiSpotOrderRequest

Return type

CreateOrder2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Order placed successfully-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
try:
# Cancel all open ordersapi_response=api_instance.delete_all_stock_orders()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_history: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol[optional]
order_idsstrOrder ID list, multiple separated by commas; max 20, each must be a positive integer[optional]
begin_timeintStart 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_timeintEnd 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]
sideintSide (1=sell, 2=buy)[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
order_id=123456# int | Order IDtrad_fi_spot_order_update_request=gate_api.TradFiSpotOrderUpdateRequest() # TradFiSpotOrderUpdateRequest | try:
# Modify orderapi_response=api_instance.update_stock_order(order_id, trad_fi_spot_order_update_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->update_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
order_idintOrder ID
trad_fi_spot_order_update_requestTradFiSpotOrderUpdateRequest

Return type

UpdateOrder2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
order_id=123456# int | Order IDtry:
# Cancel orderapi_response=api_instance.delete_stock_order(order_id)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->delete_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
order_idintOrder ID

Return type

DeleteOrder

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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, supports us, hk, and kr (optional)try:
# Query current position listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_positions: %s\n"%e)

Parameters

NameTypeDescriptionNotes
pnl_calc_typeintPnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price)[optional]
pnl_calc_priceintPnL calculation price type. Defaults to intraday price when omitted (1 = intraday price, 2 = latest extended-hours price)[optional]
symbolstrSymbol[optional]
exchangestrExchange, supports us, hk, and kr[optional]

Return type

PositionList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_close_position_request=gate_api.TradFiSpotClosePositionRequest() # TradFiSpotClosePositionRequest | try:
# Close positionapi_response=api_instance.close_stock_position(trad_fi_spot_close_position_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->close_stock_position: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_close_position_requestTradFiSpotClosePositionRequest

Return type

ClosePosition

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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.

Example

  • Api Key Authentication (apiv4):
from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 | Transaction type (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 recordsapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_transactions: %s\n"%e)

Parameters

NameTypeDescriptionNotes
begin_timeintStart 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_timeintEnd 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_idstrBusiness 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]
typestrTransaction type[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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.

Example

  • Api Key Authentication (apiv4):
from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_transaction_request=gate_api.TradFiSpotTransactionRequest() # TradFiSpotTransactionRequest | try:
# Fund transferapi_response=api_instance.create_stock_transaction(trad_fi_spot_transaction_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->create_stock_transaction: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_transaction_requestTradFiSpotTransactionRequest

Return type

CreateTransaction2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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

Example

from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
try:
# Query supported exchangesapi_response=api_instance.query_stock_exchanges()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
try:
# Query fee rates for Japanese and Korean stocksapi_response=api_instance.query_stock_fee_rate()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request failed-

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

, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' gateapi-python/docs/StockApi.md at master · gate/gateapi-python · GitHub
Skip to content

Latest commit

History

History
1131 lines (848 loc) · 39.9 KB

File metadata and controls

1131 lines (848 loc) · 39.9 KB

gate_api.StockApi

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

MethodHTTP requestDescription
query_stock_user_assetsGET /stock/users/assetsQuery user assets
query_stock_symbolsGET /stock/symbolsQuery symbol list
query_stock_symbol_detailGET /stock/symbols/detailQuery symbol details
query_stock_order_bookGET /stock/market/{symbol}/orderbookQuery market order book
query_stock_order_listGET /stock/ordersQuery open order list
create_stock_orderPOST /stock/ordersCreate order
delete_all_stock_ordersDELETE /stock/ordersCancel all open orders
query_stock_order_historyGET /stock/orders/historyQuery historical order list
update_stock_orderPUT /stock/orders/{order_id}Modify order
delete_stock_orderDELETE /stock/orders/{order_id}Cancel order
query_stock_positionsGET /stock/positionsQuery current position list
close_stock_positionPOST /stock/positions/closeClose position
query_stock_transactionsGET /stock/transactionsQuery transaction records
create_stock_transactionPOST /stock/transactionsFund transfer
query_stock_exchangesGET /stock/exchangesQuery supported exchanges
query_stock_fee_rateGET /stock/fee-rateQuery 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 assetsapi_response=api_instance.query_stock_user_assets(pnl_calc_type=pnl_calc_type, pnl_calc_price=pnl_calc_price)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_user_assets: %s\n"%e)

Parameters

NameTypeDescriptionNotes
pnl_calc_typeintPnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price)[optional]
pnl_calc_priceintPnL 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbols='AAPL,TSLA'# str | Symbol list, multiple separated by commas (optional)exchange='us'# str | Exchange, supports us, hk, and kr (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 listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_symbols: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolsstrSymbol list, multiple separated by commas[optional]
exchangestrExchange, supports us, hk, and kr[optional]
with_desc_i18nboolWhether to return multilingual symbol description[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbols='AAPL,TSLA'# str | Symbol list, multiple separated by commas (optional)exchange='us'# str | Exchange, supports us, hk, and kr (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 detailsapi_response=api_instance.query_stock_symbol_detail(symbols=symbols, exchange=exchange, page=page, page_size=page_size)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_symbol_detail: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolsstrSymbol list, multiple separated by commas[optional]
exchangestrExchange, supports us, hk, and kr[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbol='AAPL'# str | Symboltry:
# Query market order bookapi_response=api_instance.query_stock_order_book(symbol)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_book: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol

Return type

OrderBook2

Authorization

No authorization required

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
symbol='AAPL'# str | Symbol (optional)try:
# Query open order listapi_response=api_instance.query_stock_order_list(symbol=symbol)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_list: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol[optional]

Return type

OrderList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_order_request=gate_api.TradFiSpotOrderRequest() # TradFiSpotOrderRequest | try:
# Create orderapi_response=api_instance.create_stock_order(trad_fi_spot_order_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->create_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_order_requestTradFiSpotOrderRequest

Return type

CreateOrder2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Order placed successfully-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
try:
# Cancel all open ordersapi_response=api_instance.delete_all_stock_orders()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_history: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol[optional]
order_idsstrOrder ID list, multiple separated by commas; max 20, each must be a positive integer[optional]
begin_timeintStart 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_timeintEnd 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]
sideintSide (1=sell, 2=buy)[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
order_id=123456# int | Order IDtrad_fi_spot_order_update_request=gate_api.TradFiSpotOrderUpdateRequest() # TradFiSpotOrderUpdateRequest | try:
# Modify orderapi_response=api_instance.update_stock_order(order_id, trad_fi_spot_order_update_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->update_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
order_idintOrder ID
trad_fi_spot_order_update_requestTradFiSpotOrderUpdateRequest

Return type

UpdateOrder2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
order_id=123456# int | Order IDtry:
# Cancel orderapi_response=api_instance.delete_stock_order(order_id)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->delete_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
order_idintOrder ID

Return type

DeleteOrder

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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, supports us, hk, and kr (optional)try:
# Query current position listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_positions: %s\n"%e)

Parameters

NameTypeDescriptionNotes
pnl_calc_typeintPnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price)[optional]
pnl_calc_priceintPnL calculation price type. Defaults to intraday price when omitted (1 = intraday price, 2 = latest extended-hours price)[optional]
symbolstrSymbol[optional]
exchangestrExchange, supports us, hk, and kr[optional]

Return type

PositionList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_close_position_request=gate_api.TradFiSpotClosePositionRequest() # TradFiSpotClosePositionRequest | try:
# Close positionapi_response=api_instance.close_stock_position(trad_fi_spot_close_position_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->close_stock_position: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_close_position_requestTradFiSpotClosePositionRequest

Return type

ClosePosition

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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.

Example

  • Api Key Authentication (apiv4):
from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 | Transaction type (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 recordsapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_transactions: %s\n"%e)

Parameters

NameTypeDescriptionNotes
begin_timeintStart 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_timeintEnd 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_idstrBusiness 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]
typestrTransaction type[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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.

Example

  • Api Key Authentication (apiv4):
from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_transaction_request=gate_api.TradFiSpotTransactionRequest() # TradFiSpotTransactionRequest | try:
# Fund transferapi_response=api_instance.create_stock_transaction(trad_fi_spot_transaction_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->create_stock_transaction: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_transaction_requestTradFiSpotTransactionRequest

Return type

CreateTransaction2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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

Example

from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
try:
# Query supported exchangesapi_response=api_instance.query_stock_exchanges()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
try:
# Query fee rates for Japanese and Korean stocksapi_response=api_instance.query_stock_fee_rate()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request failed-

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

, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' gateapi-python/docs/StockApi.md at master · gate/gateapi-python · GitHub
Skip to content

Latest commit

History

History
1131 lines (848 loc) · 39.9 KB

File metadata and controls

1131 lines (848 loc) · 39.9 KB

gate_api.StockApi

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

MethodHTTP requestDescription
query_stock_user_assetsGET /stock/users/assetsQuery user assets
query_stock_symbolsGET /stock/symbolsQuery symbol list
query_stock_symbol_detailGET /stock/symbols/detailQuery symbol details
query_stock_order_bookGET /stock/market/{symbol}/orderbookQuery market order book
query_stock_order_listGET /stock/ordersQuery open order list
create_stock_orderPOST /stock/ordersCreate order
delete_all_stock_ordersDELETE /stock/ordersCancel all open orders
query_stock_order_historyGET /stock/orders/historyQuery historical order list
update_stock_orderPUT /stock/orders/{order_id}Modify order
delete_stock_orderDELETE /stock/orders/{order_id}Cancel order
query_stock_positionsGET /stock/positionsQuery current position list
close_stock_positionPOST /stock/positions/closeClose position
query_stock_transactionsGET /stock/transactionsQuery transaction records
create_stock_transactionPOST /stock/transactionsFund transfer
query_stock_exchangesGET /stock/exchangesQuery supported exchanges
query_stock_fee_rateGET /stock/fee-rateQuery 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 assetsapi_response=api_instance.query_stock_user_assets(pnl_calc_type=pnl_calc_type, pnl_calc_price=pnl_calc_price)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_user_assets: %s\n"%e)

Parameters

NameTypeDescriptionNotes
pnl_calc_typeintPnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price)[optional]
pnl_calc_priceintPnL 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbols='AAPL,TSLA'# str | Symbol list, multiple separated by commas (optional)exchange='us'# str | Exchange, supports us, hk, and kr (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 listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_symbols: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolsstrSymbol list, multiple separated by commas[optional]
exchangestrExchange, supports us, hk, and kr[optional]
with_desc_i18nboolWhether to return multilingual symbol description[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbols='AAPL,TSLA'# str | Symbol list, multiple separated by commas (optional)exchange='us'# str | Exchange, supports us, hk, and kr (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 detailsapi_response=api_instance.query_stock_symbol_detail(symbols=symbols, exchange=exchange, page=page, page_size=page_size)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_symbol_detail: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolsstrSymbol list, multiple separated by commas[optional]
exchangestrExchange, supports us, hk, and kr[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbol='AAPL'# str | Symboltry:
# Query market order bookapi_response=api_instance.query_stock_order_book(symbol)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_book: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol

Return type

OrderBook2

Authorization

No authorization required

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
symbol='AAPL'# str | Symbol (optional)try:
# Query open order listapi_response=api_instance.query_stock_order_list(symbol=symbol)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_list: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol[optional]

Return type

OrderList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_order_request=gate_api.TradFiSpotOrderRequest() # TradFiSpotOrderRequest | try:
# Create orderapi_response=api_instance.create_stock_order(trad_fi_spot_order_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->create_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_order_requestTradFiSpotOrderRequest

Return type

CreateOrder2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Order placed successfully-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
try:
# Cancel all open ordersapi_response=api_instance.delete_all_stock_orders()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_history: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol[optional]
order_idsstrOrder ID list, multiple separated by commas; max 20, each must be a positive integer[optional]
begin_timeintStart 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_timeintEnd 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]
sideintSide (1=sell, 2=buy)[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
order_id=123456# int | Order IDtrad_fi_spot_order_update_request=gate_api.TradFiSpotOrderUpdateRequest() # TradFiSpotOrderUpdateRequest | try:
# Modify orderapi_response=api_instance.update_stock_order(order_id, trad_fi_spot_order_update_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->update_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
order_idintOrder ID
trad_fi_spot_order_update_requestTradFiSpotOrderUpdateRequest

Return type

UpdateOrder2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
order_id=123456# int | Order IDtry:
# Cancel orderapi_response=api_instance.delete_stock_order(order_id)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->delete_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
order_idintOrder ID

Return type

DeleteOrder

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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, supports us, hk, and kr (optional)try:
# Query current position listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_positions: %s\n"%e)

Parameters

NameTypeDescriptionNotes
pnl_calc_typeintPnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price)[optional]
pnl_calc_priceintPnL calculation price type. Defaults to intraday price when omitted (1 = intraday price, 2 = latest extended-hours price)[optional]
symbolstrSymbol[optional]
exchangestrExchange, supports us, hk, and kr[optional]

Return type

PositionList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_close_position_request=gate_api.TradFiSpotClosePositionRequest() # TradFiSpotClosePositionRequest | try:
# Close positionapi_response=api_instance.close_stock_position(trad_fi_spot_close_position_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->close_stock_position: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_close_position_requestTradFiSpotClosePositionRequest

Return type

ClosePosition

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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.

Example

  • Api Key Authentication (apiv4):
from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 | Transaction type (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 recordsapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_transactions: %s\n"%e)

Parameters

NameTypeDescriptionNotes
begin_timeintStart 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_timeintEnd 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_idstrBusiness 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]
typestrTransaction type[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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.

Example

  • Api Key Authentication (apiv4):
from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_transaction_request=gate_api.TradFiSpotTransactionRequest() # TradFiSpotTransactionRequest | try:
# Fund transferapi_response=api_instance.create_stock_transaction(trad_fi_spot_transaction_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->create_stock_transaction: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_transaction_requestTradFiSpotTransactionRequest

Return type

CreateTransaction2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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

Example

from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
try:
# Query supported exchangesapi_response=api_instance.query_stock_exchanges()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
try:
# Query fee rates for Japanese and Korean stocksapi_response=api_instance.query_stock_fee_rate()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request failed-

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

, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' gateapi-python/docs/StockApi.md at master · gate/gateapi-python · GitHub
Skip to content

Latest commit

History

History
1131 lines (848 loc) · 39.9 KB

File metadata and controls

1131 lines (848 loc) · 39.9 KB

gate_api.StockApi

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

MethodHTTP requestDescription
query_stock_user_assetsGET /stock/users/assetsQuery user assets
query_stock_symbolsGET /stock/symbolsQuery symbol list
query_stock_symbol_detailGET /stock/symbols/detailQuery symbol details
query_stock_order_bookGET /stock/market/{symbol}/orderbookQuery market order book
query_stock_order_listGET /stock/ordersQuery open order list
create_stock_orderPOST /stock/ordersCreate order
delete_all_stock_ordersDELETE /stock/ordersCancel all open orders
query_stock_order_historyGET /stock/orders/historyQuery historical order list
update_stock_orderPUT /stock/orders/{order_id}Modify order
delete_stock_orderDELETE /stock/orders/{order_id}Cancel order
query_stock_positionsGET /stock/positionsQuery current position list
close_stock_positionPOST /stock/positions/closeClose position
query_stock_transactionsGET /stock/transactionsQuery transaction records
create_stock_transactionPOST /stock/transactionsFund transfer
query_stock_exchangesGET /stock/exchangesQuery supported exchanges
query_stock_fee_rateGET /stock/fee-rateQuery 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 assetsapi_response=api_instance.query_stock_user_assets(pnl_calc_type=pnl_calc_type, pnl_calc_price=pnl_calc_price)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_user_assets: %s\n"%e)

Parameters

NameTypeDescriptionNotes
pnl_calc_typeintPnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price)[optional]
pnl_calc_priceintPnL 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbols='AAPL,TSLA'# str | Symbol list, multiple separated by commas (optional)exchange='us'# str | Exchange, supports us, hk, and kr (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 listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_symbols: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolsstrSymbol list, multiple separated by commas[optional]
exchangestrExchange, supports us, hk, and kr[optional]
with_desc_i18nboolWhether to return multilingual symbol description[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbols='AAPL,TSLA'# str | Symbol list, multiple separated by commas (optional)exchange='us'# str | Exchange, supports us, hk, and kr (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 detailsapi_response=api_instance.query_stock_symbol_detail(symbols=symbols, exchange=exchange, page=page, page_size=page_size)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_symbol_detail: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolsstrSymbol list, multiple separated by commas[optional]
exchangestrExchange, supports us, hk, and kr[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbol='AAPL'# str | Symboltry:
# Query market order bookapi_response=api_instance.query_stock_order_book(symbol)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_book: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol

Return type

OrderBook2

Authorization

No authorization required

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
symbol='AAPL'# str | Symbol (optional)try:
# Query open order listapi_response=api_instance.query_stock_order_list(symbol=symbol)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_list: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol[optional]

Return type

OrderList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_order_request=gate_api.TradFiSpotOrderRequest() # TradFiSpotOrderRequest | try:
# Create orderapi_response=api_instance.create_stock_order(trad_fi_spot_order_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->create_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_order_requestTradFiSpotOrderRequest

Return type

CreateOrder2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Order placed successfully-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
try:
# Cancel all open ordersapi_response=api_instance.delete_all_stock_orders()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_history: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol[optional]
order_idsstrOrder ID list, multiple separated by commas; max 20, each must be a positive integer[optional]
begin_timeintStart 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_timeintEnd 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]
sideintSide (1=sell, 2=buy)[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
order_id=123456# int | Order IDtrad_fi_spot_order_update_request=gate_api.TradFiSpotOrderUpdateRequest() # TradFiSpotOrderUpdateRequest | try:
# Modify orderapi_response=api_instance.update_stock_order(order_id, trad_fi_spot_order_update_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->update_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
order_idintOrder ID
trad_fi_spot_order_update_requestTradFiSpotOrderUpdateRequest

Return type

UpdateOrder2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
order_id=123456# int | Order IDtry:
# Cancel orderapi_response=api_instance.delete_stock_order(order_id)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->delete_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
order_idintOrder ID

Return type

DeleteOrder

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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, supports us, hk, and kr (optional)try:
# Query current position listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_positions: %s\n"%e)

Parameters

NameTypeDescriptionNotes
pnl_calc_typeintPnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price)[optional]
pnl_calc_priceintPnL calculation price type. Defaults to intraday price when omitted (1 = intraday price, 2 = latest extended-hours price)[optional]
symbolstrSymbol[optional]
exchangestrExchange, supports us, hk, and kr[optional]

Return type

PositionList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_close_position_request=gate_api.TradFiSpotClosePositionRequest() # TradFiSpotClosePositionRequest | try:
# Close positionapi_response=api_instance.close_stock_position(trad_fi_spot_close_position_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->close_stock_position: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_close_position_requestTradFiSpotClosePositionRequest

Return type

ClosePosition

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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.

Example

  • Api Key Authentication (apiv4):
from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 | Transaction type (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 recordsapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_transactions: %s\n"%e)

Parameters

NameTypeDescriptionNotes
begin_timeintStart 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_timeintEnd 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_idstrBusiness 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]
typestrTransaction type[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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.

Example

  • Api Key Authentication (apiv4):
from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_transaction_request=gate_api.TradFiSpotTransactionRequest() # TradFiSpotTransactionRequest | try:
# Fund transferapi_response=api_instance.create_stock_transaction(trad_fi_spot_transaction_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->create_stock_transaction: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_transaction_requestTradFiSpotTransactionRequest

Return type

CreateTransaction2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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

Example

from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
try:
# Query supported exchangesapi_response=api_instance.query_stock_exchanges()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
try:
# Query fee rates for Japanese and Korean stocksapi_response=api_instance.query_stock_fee_rate()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request failed-

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

, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' gateapi-python/docs/StockApi.md at master · gate/gateapi-python · GitHub
Skip to content

Latest commit

History

History
1131 lines (848 loc) · 39.9 KB

File metadata and controls

1131 lines (848 loc) · 39.9 KB

gate_api.StockApi

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

MethodHTTP requestDescription
query_stock_user_assetsGET /stock/users/assetsQuery user assets
query_stock_symbolsGET /stock/symbolsQuery symbol list
query_stock_symbol_detailGET /stock/symbols/detailQuery symbol details
query_stock_order_bookGET /stock/market/{symbol}/orderbookQuery market order book
query_stock_order_listGET /stock/ordersQuery open order list
create_stock_orderPOST /stock/ordersCreate order
delete_all_stock_ordersDELETE /stock/ordersCancel all open orders
query_stock_order_historyGET /stock/orders/historyQuery historical order list
update_stock_orderPUT /stock/orders/{order_id}Modify order
delete_stock_orderDELETE /stock/orders/{order_id}Cancel order
query_stock_positionsGET /stock/positionsQuery current position list
close_stock_positionPOST /stock/positions/closeClose position
query_stock_transactionsGET /stock/transactionsQuery transaction records
create_stock_transactionPOST /stock/transactionsFund transfer
query_stock_exchangesGET /stock/exchangesQuery supported exchanges
query_stock_fee_rateGET /stock/fee-rateQuery 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 assetsapi_response=api_instance.query_stock_user_assets(pnl_calc_type=pnl_calc_type, pnl_calc_price=pnl_calc_price)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_user_assets: %s\n"%e)

Parameters

NameTypeDescriptionNotes
pnl_calc_typeintPnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price)[optional]
pnl_calc_priceintPnL 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbols='AAPL,TSLA'# str | Symbol list, multiple separated by commas (optional)exchange='us'# str | Exchange, supports us, hk, and kr (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 listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_symbols: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolsstrSymbol list, multiple separated by commas[optional]
exchangestrExchange, supports us, hk, and kr[optional]
with_desc_i18nboolWhether to return multilingual symbol description[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbols='AAPL,TSLA'# str | Symbol list, multiple separated by commas (optional)exchange='us'# str | Exchange, supports us, hk, and kr (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 detailsapi_response=api_instance.query_stock_symbol_detail(symbols=symbols, exchange=exchange, page=page, page_size=page_size)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_symbol_detail: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolsstrSymbol list, multiple separated by commas[optional]
exchangestrExchange, supports us, hk, and kr[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbol='AAPL'# str | Symboltry:
# Query market order bookapi_response=api_instance.query_stock_order_book(symbol)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_book: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol

Return type

OrderBook2

Authorization

No authorization required

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
symbol='AAPL'# str | Symbol (optional)try:
# Query open order listapi_response=api_instance.query_stock_order_list(symbol=symbol)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_list: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol[optional]

Return type

OrderList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_order_request=gate_api.TradFiSpotOrderRequest() # TradFiSpotOrderRequest | try:
# Create orderapi_response=api_instance.create_stock_order(trad_fi_spot_order_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->create_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_order_requestTradFiSpotOrderRequest

Return type

CreateOrder2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Order placed successfully-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
try:
# Cancel all open ordersapi_response=api_instance.delete_all_stock_orders()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_history: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol[optional]
order_idsstrOrder ID list, multiple separated by commas; max 20, each must be a positive integer[optional]
begin_timeintStart 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_timeintEnd 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]
sideintSide (1=sell, 2=buy)[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
order_id=123456# int | Order IDtrad_fi_spot_order_update_request=gate_api.TradFiSpotOrderUpdateRequest() # TradFiSpotOrderUpdateRequest | try:
# Modify orderapi_response=api_instance.update_stock_order(order_id, trad_fi_spot_order_update_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->update_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
order_idintOrder ID
trad_fi_spot_order_update_requestTradFiSpotOrderUpdateRequest

Return type

UpdateOrder2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
order_id=123456# int | Order IDtry:
# Cancel orderapi_response=api_instance.delete_stock_order(order_id)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->delete_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
order_idintOrder ID

Return type

DeleteOrder

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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, supports us, hk, and kr (optional)try:
# Query current position listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_positions: %s\n"%e)

Parameters

NameTypeDescriptionNotes
pnl_calc_typeintPnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price)[optional]
pnl_calc_priceintPnL calculation price type. Defaults to intraday price when omitted (1 = intraday price, 2 = latest extended-hours price)[optional]
symbolstrSymbol[optional]
exchangestrExchange, supports us, hk, and kr[optional]

Return type

PositionList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_close_position_request=gate_api.TradFiSpotClosePositionRequest() # TradFiSpotClosePositionRequest | try:
# Close positionapi_response=api_instance.close_stock_position(trad_fi_spot_close_position_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->close_stock_position: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_close_position_requestTradFiSpotClosePositionRequest

Return type

ClosePosition

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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.

Example

  • Api Key Authentication (apiv4):
from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 | Transaction type (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 recordsapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_transactions: %s\n"%e)

Parameters

NameTypeDescriptionNotes
begin_timeintStart 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_timeintEnd 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_idstrBusiness 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]
typestrTransaction type[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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.

Example

  • Api Key Authentication (apiv4):
from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_transaction_request=gate_api.TradFiSpotTransactionRequest() # TradFiSpotTransactionRequest | try:
# Fund transferapi_response=api_instance.create_stock_transaction(trad_fi_spot_transaction_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->create_stock_transaction: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_transaction_requestTradFiSpotTransactionRequest

Return type

CreateTransaction2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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

Example

from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
try:
# Query supported exchangesapi_response=api_instance.query_stock_exchanges()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
try:
# Query fee rates for Japanese and Korean stocksapi_response=api_instance.query_stock_fee_rate()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request failed-

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

, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); gateapi-python/docs/StockApi.md at master · gate/gateapi-python · GitHub
Skip to content

Latest commit

History

History
1131 lines (848 loc) · 39.9 KB

File metadata and controls

1131 lines (848 loc) · 39.9 KB

gate_api.StockApi

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

MethodHTTP requestDescription
query_stock_user_assetsGET /stock/users/assetsQuery user assets
query_stock_symbolsGET /stock/symbolsQuery symbol list
query_stock_symbol_detailGET /stock/symbols/detailQuery symbol details
query_stock_order_bookGET /stock/market/{symbol}/orderbookQuery market order book
query_stock_order_listGET /stock/ordersQuery open order list
create_stock_orderPOST /stock/ordersCreate order
delete_all_stock_ordersDELETE /stock/ordersCancel all open orders
query_stock_order_historyGET /stock/orders/historyQuery historical order list
update_stock_orderPUT /stock/orders/{order_id}Modify order
delete_stock_orderDELETE /stock/orders/{order_id}Cancel order
query_stock_positionsGET /stock/positionsQuery current position list
close_stock_positionPOST /stock/positions/closeClose position
query_stock_transactionsGET /stock/transactionsQuery transaction records
create_stock_transactionPOST /stock/transactionsFund transfer
query_stock_exchangesGET /stock/exchangesQuery supported exchanges
query_stock_fee_rateGET /stock/fee-rateQuery 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 assetsapi_response=api_instance.query_stock_user_assets(pnl_calc_type=pnl_calc_type, pnl_calc_price=pnl_calc_price)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_user_assets: %s\n"%e)

Parameters

NameTypeDescriptionNotes
pnl_calc_typeintPnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price)[optional]
pnl_calc_priceintPnL 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbols='AAPL,TSLA'# str | Symbol list, multiple separated by commas (optional)exchange='us'# str | Exchange, supports us, hk, and kr (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 listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_symbols: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolsstrSymbol list, multiple separated by commas[optional]
exchangestrExchange, supports us, hk, and kr[optional]
with_desc_i18nboolWhether to return multilingual symbol description[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbols='AAPL,TSLA'# str | Symbol list, multiple separated by commas (optional)exchange='us'# str | Exchange, supports us, hk, and kr (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 detailsapi_response=api_instance.query_stock_symbol_detail(symbols=symbols, exchange=exchange, page=page, page_size=page_size)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_symbol_detail: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolsstrSymbol list, multiple separated by commas[optional]
exchangestrExchange, supports us, hk, and kr[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
symbol='AAPL'# str | Symboltry:
# Query market order bookapi_response=api_instance.query_stock_order_book(symbol)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_book: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol

Return type

OrderBook2

Authorization

No authorization required

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
symbol='AAPL'# str | Symbol (optional)try:
# Query open order listapi_response=api_instance.query_stock_order_list(symbol=symbol)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_list: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol[optional]

Return type

OrderList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_order_request=gate_api.TradFiSpotOrderRequest() # TradFiSpotOrderRequest | try:
# Create orderapi_response=api_instance.create_stock_order(trad_fi_spot_order_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->create_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_order_requestTradFiSpotOrderRequest

Return type

CreateOrder2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Order placed successfully-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
try:
# Cancel all open ordersapi_response=api_instance.delete_all_stock_orders()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_order_history: %s\n"%e)

Parameters

NameTypeDescriptionNotes
symbolstrSymbol[optional]
order_idsstrOrder ID list, multiple separated by commas; max 20, each must be a positive integer[optional]
begin_timeintStart 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_timeintEnd 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]
sideintSide (1=sell, 2=buy)[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
order_id=123456# int | Order IDtrad_fi_spot_order_update_request=gate_api.TradFiSpotOrderUpdateRequest() # TradFiSpotOrderUpdateRequest | try:
# Modify orderapi_response=api_instance.update_stock_order(order_id, trad_fi_spot_order_update_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->update_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
order_idintOrder ID
trad_fi_spot_order_update_requestTradFiSpotOrderUpdateRequest

Return type

UpdateOrder2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
order_id=123456# int | Order IDtry:
# Cancel orderapi_response=api_instance.delete_stock_order(order_id)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->delete_stock_order: %s\n"%e)

Parameters

NameTypeDescriptionNotes
order_idintOrder ID

Return type

DeleteOrder

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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, supports us, hk, and kr (optional)try:
# Query current position listapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_positions: %s\n"%e)

Parameters

NameTypeDescriptionNotes
pnl_calc_typeintPnL calculation cost type. Defaults to average cost price when omitted (1 = average cost price, 2 = diluted cost price)[optional]
pnl_calc_priceintPnL calculation price type. Defaults to intraday price when omitted (1 = intraday price, 2 = latest extended-hours price)[optional]
symbolstrSymbol[optional]
exchangestrExchange, supports us, hk, and kr[optional]

Return type

PositionList2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_close_position_request=gate_api.TradFiSpotClosePositionRequest() # TradFiSpotClosePositionRequest | try:
# Close positionapi_response=api_instance.close_stock_position(trad_fi_spot_close_position_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->close_stock_position: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_close_position_requestTradFiSpotClosePositionRequest

Return type

ClosePosition

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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.

Example

  • Api Key Authentication (apiv4):
from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_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 | Transaction type (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 recordsapi_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)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->query_stock_transactions: %s\n"%e)

Parameters

NameTypeDescriptionNotes
begin_timeintStart 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_timeintEnd 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_idstrBusiness 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]
typestrTransaction type[optional]
pageintPage number, defaults to 1[optional]
page_sizeintPage 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 codeDescriptionResponse headers
200Request success-
400Request 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.

Example

  • Api Key Authentication (apiv4):
from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 authorizationconfiguration=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 classapi_instance=gate_api.StockApi(api_client)
trad_fi_spot_transaction_request=gate_api.TradFiSpotTransactionRequest() # TradFiSpotTransactionRequest | try:
# Fund transferapi_response=api_instance.create_stock_transaction(trad_fi_spot_transaction_request)
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
print("Exception when calling StockApi->create_stock_transaction: %s\n"%e)

Parameters

NameTypeDescriptionNotes
trad_fi_spot_transaction_requestTradFiSpotTransactionRequest

Return type

CreateTransaction2

Authorization

apiv4

HTTP request headers

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

HTTP response details

Status codeDescriptionResponse headers
200Request success-
400Request 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

Example

from __future__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
try:
# Query supported exchangesapi_response=api_instance.query_stock_exchanges()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request 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__ importprint_functionimportgate_apifromgate_api.exceptionsimportApiException, 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 classapi_instance=gate_api.StockApi(api_client)
try:
# Query fee rates for Japanese and Korean stocksapi_response=api_instance.query_stock_fee_rate()
print(api_response)
exceptGateApiExceptionasex:
print("Gate api exception, label: %s, message: %s\n"% (ex.label, ex.message))
exceptApiExceptionase:
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 codeDescriptionResponse headers
200Request success-
400Request failed-

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