Skip to content

Commit

Permalink
PYTHON UPDATE
Browse files Browse the repository at this point in the history
  • Loading branch information
jane-cloud committed Jul 26, 2024
1 parent 9eb36c0 commit bc9fb28
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 14 deletions.
24 changes: 19 additions & 5 deletions okx-python-sdk-api-v5/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
# result = accountAPI.set_account_level(acctLv='')
# 仓位创建器 POST /api/v5/account/position-builder
# result = accountAPI.position_builder()
# 设置现货对冲占用 POST /api/v5/account/set-riskOffset-amt
result = accountAPI.set_riskOffset_amt(ccy = 'BTC', clSpotInUseAmt = '0.01')



Expand Down Expand Up @@ -274,10 +276,20 @@
tradingDataAPI = TradingData.TradingDataAPI(api_key, secret_key, passphrase, False, flag)
# 获取支持币种 Get support coin
# result = tradingDataAPI.get_support_coin()
# 获取获取合约持仓量历史
# result = tradingDataAPI.get_open_interest_history(instId = 'BTC-USDT-SWAP', period = '5m', end = '1597027383085', begin = '1597027383085', limit = '')
# 获取币币或衍生品主动买入/卖出情况 Get taker volume
# result = tradingDataAPI.get_taker_volume(ccy='BTC', instType='SPOT')
# 获取合约主动买入/卖出情况
# result = tradingDataAPI.get_taker_volume_contract(instId = 'BTC-USDT-SWAP')
# 获取杠杆多空比 Get Margin lending ratio
# result = tradingDataAPI.get_margin_lending_ratio('BTC')
# 获取精英交易员合约多空持仓人数比
# result = tradingDataAPI.get_long_short_account_ratio_contract_top_trader(instId = 'BTC-USDT-SWAP', period = '', end = '', begin = '', limit = '')
# 获取精英交易员合约多空持仓仓位比
# result = tradingDataAPI.get_long_short_position_ratio_contract_top_trader(instId = 'BTC-USDT-SWAP', period = '', end = '', begin = '', limit = '')
# 获取合约多空持仓人数比
# result = tradingDataAPI.get_long_short_account_ratio_contract(instId = 'BTC-USDT-SWAP', period = '', end = '', begin = '', limit = '')
# 获取多空持仓人数比 Get Long/Short ratio
# result = tradingDataAPI.get_long_short_ratio('BTC')
# 获取持仓总量及交易量 Get contracts open interest and volume
Expand Down Expand Up @@ -372,7 +384,7 @@
# 撤销 MMP 订单
# result =tradeAPI.mass_cancel()
# 倒计时全部撤单
# result = tradeAPI.cancel_all_after()
# result = tradeAPI.cancel_all_after(timeOut = '10', tag = '')
# 申请成交明细(近两年) POST /api/v5/trade/fills-archive
# result = tradeAPI.fills_archive()
# 获取成交明细(近两年) GET /api/v5/trade/fills-archive
Expand All @@ -381,7 +393,7 @@
# result = accountAPI.account_rate_limit()


#价差撮合交易 SprdAPI
# 价差撮合交易 SprdAPI
sprdAPI = Sprd.SprdAPI(api_key, secret_key, passphrase, False, flag)
# 下单 POST /api/v5/sprd/order
# result = sprdAPI.place(sprdId='',clOrdId='',tag='',side='',ordType='',sz='',px='')
Expand Down Expand Up @@ -409,6 +421,8 @@
# result = sprdAPI.ticker(sprdId='')
# 获取公共成交数据(公共)GET /api/v5/sprd/public-trades
# result = sprdAPI.public_trades(sprdId='')
# 倒计时全部撤单 POST /api/v5/sprd/cancel-all-after
# result = sprdAPI.sprd_cancel_all_after(timeOut='10')

# 子账户API subAccount
subAccountAPI = SubAccount.SubAccountAPI(api_key, secret_key, passphrase, False, flag)
Expand Down Expand Up @@ -532,7 +546,7 @@
# 获取大宗交易公共成交数据
# result = RfqAPI.get_public_trades(beginId = '', endId = '', limit = '')
# 倒计时全部撤单 POST /api/v5/rfq/cancel-all-after
# result = RfqAPI.cancel_all_after()
# result = RfqAPI.tag()



Expand Down Expand Up @@ -619,9 +633,9 @@
# 获取定期简单赚币订单信息 GET /api/v5/finance/fixed-loan/lending-orders-list
# result = Finance.fixed_loan_lending_orders_list(ordId = '', ccy ='', state ='', after = '', before = '', limit = '')
# 获取定期简单赚币子订单信息
result = Finance.fixed_loan_lending_sub_orders(ordId = '', state ='', after = '', before = '', limit = '')

# result = Finance.fixed_loan_lending_sub_orders(ordId = '', state ='', after = '', before = '', limit = '')

# 跟单
Copytrading = Copytrading.CopytradingAPI(api_key, secret_key, passphrase, False, flag)
# 交易员获取当前带单
# result = Copytrading.current_subpositions(instId='', after='', before='', limit='')
Expand Down
8 changes: 7 additions & 1 deletion okx-python-sdk-api-v5/okx/Account_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,10 @@ def position_builder(self,inclRealPosAndEq='',spotOffsetType='',simPos='',simAss
greeksType='',):
params = {'acctLv': acctLv, 'spotOffsetType': spotOffsetType, 'simPos': simPos, 'simAsset': simAsset,
'greeksType': greeksType, }
return self._request_with_params(POST, POSITION_BUILDER, params)
return self._request_with_params(POST, POSITION_BUILDER, params)


# POST /api/v5/account/set-riskOffset-amt
def set_riskOffset_amt(self,ccy = '', clSpotInUseAmt = ''):
params = {'ccy': ccy, 'clSpotInUseAmt': clSpotInUseAmt}
return self._request_with_params(POST, SET_RISKOFFSET_AMT, params)
6 changes: 3 additions & 3 deletions okx-python-sdk-api-v5/okx/Rfq_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def get_public_trades(self, beginId = '', endId = '', limit = ''):
return self._request_with_params(GET, GET_PUBLIC_TRADES, params)


def cancel_all_after(self, timeOut = ''):
params = {'timeOut': timeOut, }
return self._request_with_params(POST, CANCEL_ALL_AFTER, params)
def rfq_cancel_all_after(self, timeOut = ''):
params = {'timeOut': timeOut}
return self._request_with_params(POST, RFQ_CANCEL_ALL_AFTER, params)

def maker_instrument_settings(self, instType='', data=[]):
params = [{'instType': instType, 'data': data}]
Expand Down
5 changes: 5 additions & 0 deletions okx-python-sdk-api-v5/okx/SprdApi_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,9 @@ def public_trades(self,sprdId=''):
params = {'sprdId': sprdId}
return self._request_with_params(GET, SPRD_PUBLIC_TRADES, params)

# POST /api/v5/sprd/cancel-all-after
def sprd_cancel_all_after(self,timeOut=''):
params = {'timeOut':timeOut }
return self._request_with_params(POST, SPRD_CANCEL_ALL_AFTER, params)


4 changes: 2 additions & 2 deletions okx-python-sdk-api-v5/okx/Trade_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ def mass_cancel(self,instType,instFamily):
params = {'instType':instType, 'instFamily':instFamily}
return self._request_with_params(POST, MASS_CANCEL, params)

def cancel_all_after(self,timeOut):
params = {'timeOut': timeOut,}
def cancel_all_after(self,timeOut= '', tag = ''):
params = {'timeOut': timeOut, 'tag': tag}
return self._request_with_params(POST, CANCEL_ALL_AFTER, params)

# POST / api / v5 / trade / fills - archive
Expand Down
27 changes: 25 additions & 2 deletions okx-python-sdk-api-v5/okx/TradingData_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,39 @@ def __init__(self, api_key, api_secret_key, passphrase, use_server_time=False, f
def get_support_coin(self):
return self._request_without_params(GET, SUPPORT_COIN)

# GET /api/v5/rubik/stat/contracts/open-interest-history
def get_open_interest_history(self, instId = '', period = '', end = '', begin = '', limit = ''):
params = {'instId': instId, 'period': period, 'end': end, 'begin': begin, 'limit': limit}
return self._request_with_params(GET, GET_OPEN_INTEREST_HISTORY, params)

def get_taker_volume(self, ccy, instType, begin='', end='', period=''):
params = {'ccy': ccy, 'instType': instType, 'begin': begin, 'end': end, 'period': period}
return self._request_with_params(GET, TAKER_VOLUME, params)

# GET /api/v5/rubik/stat/taker-volume-contract
def get_taker_volume_contract(self, instId, period = '', unit='', end='', begin='', limit = ''):
params = {'instId': instId, 'period': period, 'unit': unit, 'end': end, 'begin': begin,'limit':limit}
return self._request_with_params(GET, GET_TAKER_VOLUME_CONTRACT, params)

def get_margin_lending_ratio(self, ccy, begin='', end='', period=''):
params = {'ccy': ccy, 'begin': begin, 'end': end, 'period': period}
return self._request_with_params(GET, MARGIN_LENDING_RATIO, params)

# GET /api/v5/rubik/stat/contracts/long-short-account-ratio-contract-top-trader
def get_long_short_account_ratio_contract_top_trader(self, instId = '', period = '', end = '', begin = '', limit = ''):
params = {'instId': instId, 'period': period, 'end': end, 'begin': begin,'limit':limit}
return self._request_with_params(GET, GET_LONG_SHORT_ACCOUNT_RADIO_CONTRACT_TOP_TRADER, params)

# GET /api/v5/rubik/stat/contracts/long-short-position-ratio-contract-top-trader
def get_long_short_position_ratio_contract_top_trader(self, instId = '', period = '', end = '', begin = '', limit = ''):
params = {'instId': instId, 'period': period, 'end': end, 'begin': begin,'limit':limit}
return self._request_with_params(GET, GET_LONG_SHORT_POSTION_RADIO_CONTRACT_TOP_TRADER, params)

# GET /api/v5/rubik/stat/contracts/long-short-account-ratio-contract
def get_long_short_account_ratio_contract(self, instId = '', period = '', end = '', begin = '', limit = ''):
params = {'instId': instId, 'period': period, 'end': end, 'begin': begin,'limit':limit}
return self._request_with_params(GET, GET_LONG_SHORT_ACCOUNT_RADIO_CONTRACT, params)

def get_long_short_ratio(self, ccy, begin='', end='', period=''):
params = {'ccy': ccy, 'begin': begin, 'end': end, 'period': period}
return self._request_with_params(GET, LONG_SHORT_RATIO, params)
Expand Down Expand Up @@ -50,5 +75,3 @@ def get_taker_flow(self, ccy, period=''):





Binary file modified okx-python-sdk-api-v5/okx/__pycache__/Account_api.cpython-38.pyc
Binary file not shown.
Binary file modified okx-python-sdk-api-v5/okx/__pycache__/Finance_api.cpython-38.pyc
Binary file not shown.
Binary file modified okx-python-sdk-api-v5/okx/__pycache__/Rfq_api.cpython-38.pyc
Binary file not shown.
Binary file modified okx-python-sdk-api-v5/okx/__pycache__/SprdApi_api.cpython-38.pyc
Binary file not shown.
Binary file modified okx-python-sdk-api-v5/okx/__pycache__/Trade_api.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified okx-python-sdk-api-v5/okx/__pycache__/consts.cpython-38.pyc
Binary file not shown.
9 changes: 8 additions & 1 deletion okx-python-sdk-api-v5/okx/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
SET_RISKOFFSET_TYPE = '/api/v5/account/set-riskOffset-type'
SET_AUTO_LOAN = '/api/v5/account/set-auto-loan'
MMP_RESET = '/api/v5/account/mmp-reset'
SET_RISKOFFSET_AMT = '/api/v5/account/set-riskOffset-amt'

# funding
DEPOSIT_ADDRESS = '/api/v5/asset/deposit-address'
Expand Down Expand Up @@ -142,6 +143,11 @@
OPEN_INTEREST_VOLUME_EXPIRY = '/api/v5/rubik/stat/option/open-interest-volume-expiry'
INTEREST_VOLUME_STRIKE = '/api/v5/rubik/stat/option/open-interest-volume-strike'
TAKER_FLOW = '/api/v5/rubik/stat/option/taker-block-volume'
GET_OPEN_INTEREST_HISTORY = '/api/v5/rubik/stat/contracts/open-interest-history'
GET_TAKER_VOLUME_CONTRACT = '/api/v5/rubik/stat/taker-volume-contract'
GET_LONG_SHORT_ACCOUNT_RADIO_CONTRACT_TOP_TRADER = '/api/v5/rubik/stat/contracts/long-short-account-ratio-contract-top-trader'
GET_LONG_SHORT_POSTION_RADIO_CONTRACT_TOP_TRADER = '/api/v5/rubik/stat/contracts/long-short-position-ratio-contract-top-trader'
GET_LONG_SHORT_ACCOUNT_RADIO_CONTRACT = '/api/v5/rubik/stat/contracts/long-short-account-ratio-contract'

# TRADE
PLACR_ORDER = '/api/v5/trade/order'
Expand Down Expand Up @@ -190,6 +196,7 @@
SPRD_BOOKS = '/api/v5/sprd/books'
SPRD_TICKER = '/api/v5/sprd/ticker'
SPRD_PUBLIC_TRADES = '/api/v5/sprd/public-trades'
SPRD_CANCEL_ALL_AFTER = '/api/v5/sprd/cancel-all-after'



Expand Down Expand Up @@ -259,7 +266,7 @@
GET_QUOTES = '/api/v5/rfq/quotes'
GET_RFQ_TRADES = '/api/v5/rfq/trades'
GET_PUBLIC_TRADES = '/api/v5/rfq/public-trades'
CANCEL_ALL_AFTER = '/api/v5/rfq/cancel-all-after'
RFQ_CANCEL_ALL_AFTER = '/api/v5/rfq/cancel-all-after'
MARKET_INSTRUMENT_SETTINGS = '/api/v5/rfq/maker-instrument-settings'
MMP_RESET = '/api/v5/rfq/mmp-reset'
MMP_CONFIG = '/api/v5/rfq/mmp-config'
Expand Down

0 comments on commit bc9fb28

Please sign in to comment.