Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
0.5.0: updated to new API spec
Browse files Browse the repository at this point in the history
  • Loading branch information
nicelgueta committed Dec 4, 2022
1 parent 8e70503 commit 61372fa
Show file tree
Hide file tree
Showing 9 changed files with 281 additions and 63 deletions.
1 change: 1 addition & 0 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
key = os.getenv('KEY'),
secret = os.getenv('SECRET'),
passphrase = os.getenv('PASSPHRASE'),
test=True # if using the test OKX environment
)

# create a component for the Account API by passing the client dependency
Expand Down
168 changes: 155 additions & 13 deletions pyokx/Account.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ def get_positions_history(
)
return self.request(details)

def get_account_and_position_risk(
self, instType: str = None, use_proxy: bool = False
) -> APIReturn:
def get_account_and_position_risk(self, use_proxy: bool = False) -> APIReturn:
"""
Get account and position risk
Get account and position risk
Expand Down Expand Up @@ -545,6 +543,57 @@ def get_account_risk_state(self, use_proxy: bool = False) -> APIReturn:
)
return self.request(details)

def manual_borrow_and_repay_in_quick_margin_mode(
self, instId: str, ccy: str, side: str, amt: str, use_proxy: bool = False
) -> APIReturn:
"""
Manual borrow and repay in Quick Margin Mode
Rate Limit: 5 requests per 2 seconds
Rate limit rule: UserID
"""
kwargs = {
k: v
for k, v in locals().items()
if k not in ["use_proxy", "self"] and v is not None
}
details = EndpointDetails(
request_path="/api/v5/account/quick-margin-borrow-repay",
method="POST",
body=kwargs,
use_proxy=use_proxy,
)
return self.request(details)

def get_manual_borrow_and_repay_history_in_quick_margin_mode(
self,
instId: str = None,
ccy: str = None,
side: str = None,
after: str = None,
before: str = None,
begin: str = None,
end: str = None,
limit: str = None,
use_proxy: bool = False,
) -> APIReturn:
"""
Get manual borrow and repay history in Quick Margin Mode
Rate Limit: 5 requests per 2 seconds
Rate limit rule: UserID
"""
kwargs = {
k: v
for k, v in locals().items()
if k not in ["use_proxy", "self"] and v is not None
}
details = EndpointDetails(
request_path="/api/v5/account/quick-margin-borrow-repay-history",
method="GET",
params=kwargs,
use_proxy=use_proxy,
)
return self.request(details)

def vip_loans_borrow_and_repay(
self, ccy: str, side: str, amt: str, use_proxy: bool = False
) -> APIReturn:
Expand Down Expand Up @@ -592,6 +641,88 @@ def get_borrow_and_repay_history_for_vip_loans(
)
return self.request(details)

def get_vip_interest_accrued_data(
self,
ccy: str = None,
ordId: str = None,
after: str = None,
before: str = None,
limit: str = None,
use_proxy: bool = False,
) -> APIReturn:
"""
Get VIP interest accrued data
Rate Limit: 5 requests per 2 seconds
Rate limit rule: UserID
"""
kwargs = {
k: v
for k, v in locals().items()
if k not in ["use_proxy", "self"] and v is not None
}
details = EndpointDetails(
request_path="/api/v5/account/vip-interest-accrued",
method="GET",
params=kwargs,
use_proxy=use_proxy,
)
return self.request(details)

def get_vip_loan_order_list(
self,
ordId: str = None,
state: str = None,
ccy: str = None,
after: str = None,
before: str = None,
limit: str = None,
use_proxy: bool = False,
) -> APIReturn:
"""
Get VIP loan order list
Rate Limit: 5次/2s
Rate limit rule: UserID
"""
kwargs = {
k: v
for k, v in locals().items()
if k not in ["use_proxy", "self"] and v is not None
}
details = EndpointDetails(
request_path="/api/v5/account/vip-loan-order-list",
method="GET",
params=kwargs,
use_proxy=use_proxy,
)
return self.request(details)

def get_vip_loan_order_detail(
self,
ordId: str = None,
ccy: str = None,
after: str = None,
before: str = None,
limit: str = None,
use_proxy: bool = False,
) -> APIReturn:
"""
Get VIP loan order detail
Rate Limit: 5次/2s
Rate limit rule: UserID
"""
kwargs = {
k: v
for k, v in locals().items()
if k not in ["use_proxy", "self"] and v is not None
}
details = EndpointDetails(
request_path="/api/v5/account/vip-loan-order-detail",
method="GET",
params=kwargs,
use_proxy=use_proxy,
)
return self.request(details)

def get_borrow_interest_and_limit(
self, type: str = None, ccy: str = None, use_proxy: bool = False
) -> APIReturn:
Expand All @@ -613,16 +744,7 @@ def get_borrow_interest_and_limit(
)
return self.request(details)

def position_builder(
self,
instType: str = None,
inclRealPos: bool = None,
spotOffsetType: str = None,
simPos: list = None,
instId: str = None,
pos: str = None,
use_proxy: bool = False,
) -> APIReturn:
def position_builder(self, use_proxy: bool = False) -> APIReturn:
"""
Position builder
Calculates portfolio margin information for simulated position or current position of the user.
Expand Down Expand Up @@ -688,3 +810,23 @@ def get_pm_limitation(
use_proxy=use_proxy,
)
return self.request(details)

def set_risk_offset_type(self, type: str, use_proxy: bool = False) -> APIReturn:
"""
Set risk offset type
Configure the risk offset type in portfolio margin mode.
Rate Limit: 10 requests per 2 seconds
Rate limit rule: UserID
"""
kwargs = {
k: v
for k, v in locals().items()
if k not in ["use_proxy", "self"] and v is not None
}
details = EndpointDetails(
request_path="/api/v5/account/set-riskOffset-type",
method="POST",
body=kwargs,
use_proxy=use_proxy,
)
return self.request(details)
23 changes: 22 additions & 1 deletion pyokx/Funding.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ def get_balance(self, ccy: str = None, use_proxy: bool = False) -> APIReturn:
)
return self.request(details)

def get_non_tradable_assets(
self, ccy: str = None, use_proxy: bool = False
) -> APIReturn:
"""
Get non-tradable assets
Rate Limit: 6 requests per second
Rate limit rule: UserID
"""
kwargs = {
k: v
for k, v in locals().items()
if k not in ["use_proxy", "self"] and v is not None
}
details = EndpointDetails(
request_path="/api/v5/asset/non-tradable-assets",
method="GET",
params=kwargs,
use_proxy=use_proxy,
)
return self.request(details)

def get_account_asset_valuation(
self, ccy: str = None, use_proxy: bool = False
) -> APIReturn:
Expand Down Expand Up @@ -240,9 +261,9 @@ def withdrawal(
dest: str,
toAddr: str,
fee: str,
clientId: str = None,
chain: str = None,
areaCode: str = None,
clientId: str = None,
use_proxy: bool = False,
) -> APIReturn:
"""
Expand Down
16 changes: 11 additions & 5 deletions pyokx/Gridtrading.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ def place_grid_algo_order(
tpTriggerPx: str = None,
slTriggerPx: str = None,
tag: str = None,
quoteSz: str = None,
baseSz: str = None,
sz: str = None,
direction: str = None,
lever: str = None,
basePos: bool = None,
use_proxy: bool = False,
) -> APIReturn:
"""
Place grid algo order
Rate Limit: 20 requests per 2 seconds
Derivatives rate limit rule: UserID + (instrumentType + underlying)
Spot & Margin rate limit rule: UserID + instrumentID
Rate limit rule (except Options): UserID + Instrument ID
Rate limit rule (Options only): UserID + Instrument Family
"""
kwargs = {
k: v
Expand All @@ -47,7 +53,7 @@ def amend_grid_algo_order(
Amend grid algo order
Supported contract grid algo order amendment.
Rate Limit: 20 requests per 2 seconds
Derivatives rate limit rule: UserID + (instrumentType + underlying)
Rate limit rule: UserID + Instrument ID
"""
kwargs = {
k: v
Expand All @@ -74,8 +80,8 @@ def stop_grid_algo_order(
Stop grid algo order
A maximum of 10 orders can be canceled per request.
Rate Limit: 20 requests per 2 seconds
Derivatives rate limit rule: UserID + (instrumentType + underlying)
Spot & Margin rate limit rule: UserID + instrumentID
Rate limit rule (except Options): UserID + Instrument ID
Rate limit rule (Options only): UserID + Instrument Family
"""
kwargs = {
k: v
Expand Down
20 changes: 20 additions & 0 deletions pyokx/Marketdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,26 @@ def get_trades_history(
)
return self.request(details)

def get_option_trades(self, instFamily: str, use_proxy: bool = False) -> APIReturn:
"""
Get option trades
Retrieve the recent transactions of an instrument under same instFamily. The maximum is 100.
Rate Limit: 20 requests per 2 seconds
Rate limit rule: IP
"""
kwargs = {
k: v
for k, v in locals().items()
if k not in ["use_proxy", "self"] and v is not None
}
details = EndpointDetails(
request_path="/api/v5/market/option/instrument-family-trades",
method="GET",
params=kwargs,
use_proxy=use_proxy,
)
return self.request(details)

def get_24h_total_volume(self, use_proxy: bool = False) -> APIReturn:
"""
Get 24H total volume
Expand Down
2 changes: 1 addition & 1 deletion pyokx/Status.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class Status(APIComponent):
def status(self, state: str = None, use_proxy: bool = False) -> APIReturn:
def status(self, use_proxy: bool = False) -> APIReturn:
"""
Status
Get event status of system upgrade
Expand Down
4 changes: 1 addition & 3 deletions pyokx/SubAccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def reset_the_apikey_of_a_sub_account(
)
return self.request(details)

def get_sub_account_trading_balance(
self, subAcct: str, use_proxy: bool = False
) -> APIReturn:
def get_sub_account_trading_balance(self, use_proxy: bool = False) -> APIReturn:
"""
Get sub-account trading balance
Query detailed balance info of Trading Account of a sub-account via the master account (applies to master accounts only)
Expand Down
Loading

0 comments on commit 61372fa

Please sign in to comment.