feat:Support multiply trigger TP
This commit is contained in:
parent
068c63d5c5
commit
422ee7ec8b
|
|
@ -1,11 +1,11 @@
|
|||
from .client import Client
|
||||
from .okxclient import OkxClient
|
||||
from .consts import *
|
||||
|
||||
|
||||
class AccountAPI(Client):
|
||||
class AccountAPI(OkxClient):
|
||||
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True,proxy = None,timeout = 30):
|
||||
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy,timeout)
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True,proxy = None):
|
||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||
|
||||
# Get Positions
|
||||
def get_position_risk(self, instType=''):
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
from .client import Client
|
||||
from .okxclient import OkxClient
|
||||
from .consts import *
|
||||
|
||||
|
||||
class BlockTradingAPI(Client):
|
||||
class BlockTradingAPI(OkxClient):
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None):
|
||||
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||
|
||||
def counterparties(self):
|
||||
params = {}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
from .client import Client
|
||||
from .okxclient import OkxClient
|
||||
from .consts import *
|
||||
|
||||
|
||||
class ConvertAPI(Client):
|
||||
class ConvertAPI(OkxClient):
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True,proxy = None):
|
||||
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||
|
||||
def get_currencies(self):
|
||||
params = {}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
from .client import Client
|
||||
from .okxclient import OkxClient
|
||||
from .consts import *
|
||||
|
||||
|
||||
class CopyTradingAPI(Client):
|
||||
class CopyTradingAPI(OkxClient):
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1',
|
||||
domain='https://www.okx.com', debug=True, proxy=None):
|
||||
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,
|
||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,
|
||||
proxy=proxy)
|
||||
|
||||
# Get existing leading positions
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
from .client import Client
|
||||
from .okxclient import OkxClient
|
||||
from .consts import *
|
||||
|
||||
|
||||
class EarningAPI(Client):
|
||||
class EarningAPI(OkxClient):
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None):
|
||||
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||
|
||||
def get_offers(self,productId = '',protocolType = '',ccy = ''):
|
||||
params = {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
from .client import Client
|
||||
from .okxclient import OkxClient
|
||||
from .consts import *
|
||||
|
||||
|
||||
class FDBrokerAPI(Client):
|
||||
class FDBrokerAPI(OkxClient):
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None):
|
||||
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||
|
||||
def generate_rebate_details_download_link(self, begin ='', end = ''):
|
||||
params = {'begin': begin, 'end': end}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
from .client import Client
|
||||
from .okxclient import OkxClient
|
||||
from .consts import *
|
||||
|
||||
|
||||
class FundingAPI(Client):
|
||||
class FundingAPI(OkxClient):
|
||||
|
||||
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None):
|
||||
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||
|
||||
# Get Deposit Address
|
||||
def get_deposit_address(self, ccy):
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
from .client import Client
|
||||
from .okxclient import OkxClient
|
||||
from .consts import *
|
||||
|
||||
|
||||
class GridAPI(Client):
|
||||
class GridAPI(OkxClient):
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None):
|
||||
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||
|
||||
def grid_order_algo(self, instId='', algoOrdType='', maxPx='', minPx='', gridNum='', runType='', tpTriggerPx='',
|
||||
slTriggerPx='', tag='', quoteSz='', baseSz='', sz='', direction='', lever='', basePos=''):
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
from .client import Client
|
||||
from .okxclient import OkxClient
|
||||
from .consts import *
|
||||
|
||||
|
||||
class MarketAPI(Client):
|
||||
class MarketAPI(OkxClient):
|
||||
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None):
|
||||
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||
|
||||
|
||||
# Get Tickers
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
from .client import Client
|
||||
from .okxclient import OkxClient
|
||||
from .consts import *
|
||||
class NDBrokerAPI(Client):
|
||||
class NDBrokerAPI(OkxClient):
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None):
|
||||
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||
|
||||
#GET /api/v5/broker/nd/info
|
||||
def get_broker_info(self):
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
from .client import Client
|
||||
from .okxclient import OkxClient
|
||||
from .consts import *
|
||||
|
||||
|
||||
class PublicAPI(Client):
|
||||
class PublicAPI(OkxClient):
|
||||
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None):
|
||||
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||
|
||||
# Get Instruments
|
||||
def get_instruments(self, instType, uly='', instId='',instFamily = ''):
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
from .client import Client
|
||||
from .okxclient import OkxClient
|
||||
from .consts import *
|
||||
|
||||
|
||||
class SpreadTradingAPI(Client):
|
||||
class SpreadTradingAPI(OkxClient):
|
||||
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None):
|
||||
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||
|
||||
# Place Order
|
||||
def place_order(self, sprdId='', clOrdId='', tag='', side='', ordType='', sz='', px=''):
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
from .client import Client
|
||||
from .okxclient import OkxClient
|
||||
from .consts import *
|
||||
|
||||
|
||||
class StatusAPI(Client):
|
||||
class StatusAPI(OkxClient):
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None):
|
||||
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||
|
||||
def status(self, state=''):
|
||||
params = {'state': state}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
from .client import Client
|
||||
from .okxclient import OkxClient
|
||||
from .consts import *
|
||||
|
||||
|
||||
class SubAccountAPI(Client):
|
||||
class SubAccountAPI(OkxClient):
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None):
|
||||
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||
|
||||
def get_account_balance(self, subAcct):
|
||||
params = {"subAcct": subAcct}
|
||||
|
|
|
|||
28
okx/Trade.py
28
okx/Trade.py
|
|
@ -1,21 +1,26 @@
|
|||
from .client import Client
|
||||
import json
|
||||
|
||||
from .okxclient import OkxClient
|
||||
from .consts import *
|
||||
|
||||
|
||||
class TradeAPI(Client):
|
||||
class TradeAPI(OkxClient):
|
||||
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None):
|
||||
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1',
|
||||
domain='https://www.okx.com', debug=True, proxy=None):
|
||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||
|
||||
# Place Order
|
||||
def place_order(self, instId, tdMode, side, ordType, sz, ccy='', clOrdId='', tag='', posSide='', px='',
|
||||
reduceOnly='', tgtCcy='', tpTriggerPx='', tpOrdPx='', slTriggerPx='', slOrdPx='',
|
||||
tpTriggerPxType='', slTriggerPxType='', quickMgnType='', stpId='', stpMode=''):
|
||||
tpTriggerPxType='', slTriggerPxType='', quickMgnType='', stpId='', stpMode='',
|
||||
attachAlgoOrds=None):
|
||||
params = {'instId': instId, 'tdMode': tdMode, 'side': side, 'ordType': ordType, 'sz': sz, 'ccy': ccy,
|
||||
'clOrdId': clOrdId, 'tag': tag, 'posSide': posSide, 'px': px, 'reduceOnly': reduceOnly,
|
||||
'tgtCcy': tgtCcy, 'tpTriggerPx': tpTriggerPx, 'tpOrdPx': tpOrdPx, 'slTriggerPx': slTriggerPx,
|
||||
'slOrdPx': slOrdPx, 'tpTriggerPxType': tpTriggerPxType, 'slTriggerPxType': slTriggerPxType,
|
||||
'quickMgnType': quickMgnType, 'stpId': stpId, 'stpMode': stpMode}
|
||||
params['attachAlgoOrds'] = attachAlgoOrds
|
||||
return self._request_with_params(POST, PLACR_ORDER, params)
|
||||
|
||||
# Place Multiple Orders
|
||||
|
|
@ -33,11 +38,13 @@ class TradeAPI(Client):
|
|||
|
||||
# Amend Order
|
||||
def amend_order(self, instId, cxlOnFail='', ordId='', clOrdId='', reqId='', newSz='', newPx='', newTpTriggerPx='',
|
||||
newTpOrdPx='', newSlTriggerPx='', newSlOrdPx='', newTpTriggerPxType='', newSlTriggerPxType=''):
|
||||
newTpOrdPx='', newSlTriggerPx='', newSlOrdPx='', newTpTriggerPxType='', newSlTriggerPxType='',
|
||||
attachAlgoOrds=''):
|
||||
params = {'instId': instId, 'cxlOnFailc': cxlOnFail, 'ordId': ordId, 'clOrdId': clOrdId, 'reqId': reqId,
|
||||
'newSz': newSz, 'newPx': newPx, 'newTpTriggerPx': newTpTriggerPx, 'newTpOrdPx': newTpOrdPx,
|
||||
'newSlTriggerPx': newSlTriggerPx, 'newSlOrdPx': newSlOrdPx, 'newTpTriggerPxType': newTpTriggerPxType,
|
||||
'newSlTriggerPxType': newSlTriggerPxType}
|
||||
params['attachAlgoOrds'] = attachAlgoOrds
|
||||
return self._request_with_params(POST, AMEND_ORDER, params)
|
||||
|
||||
# Amend Multiple Orders
|
||||
|
|
@ -56,7 +63,8 @@ class TradeAPI(Client):
|
|||
return self._request_with_params(GET, ORDER_INFO, params)
|
||||
|
||||
# Get Order List
|
||||
def get_order_list(self, instType='', uly='', instId='', ordType='', state='', after='', before='', limit='',instFamily = ''):
|
||||
def get_order_list(self, instType='', uly='', instId='', ordType='', state='', after='', before='', limit='',
|
||||
instFamily=''):
|
||||
params = {'instType': instType, 'uly': uly, 'instId': instId, 'ordType': ordType, 'state': state,
|
||||
'after': after, 'before': before, 'limit': limit, 'instFamily': instFamily}
|
||||
return self._request_with_params(GET, ORDERS_PENDING, params)
|
||||
|
|
@ -99,7 +107,8 @@ class TradeAPI(Client):
|
|||
'timeInterval': timeInterval,
|
||||
'pxSpread': pxSpread, 'tpTriggerPxType': tpTriggerPxType, 'slTriggerPxType': slTriggerPxType,
|
||||
'callbackRatio': callbackRatio, 'callbackSpread': callbackSpread, 'activePx': activePx,
|
||||
'tag':tag,'triggerPxType':triggerPxType,'closeFraction':closeFraction,'quickMgnType':quickMgnType,'algoClOrdId':algoClOrdId}
|
||||
'tag': tag, 'triggerPxType': triggerPxType, 'closeFraction': closeFraction,
|
||||
'quickMgnType': quickMgnType, 'algoClOrdId': algoClOrdId}
|
||||
return self._request_with_params(POST, PLACE_ALGO_ORDER, params)
|
||||
|
||||
# Cancel Algo Order
|
||||
|
|
@ -111,7 +120,8 @@ class TradeAPI(Client):
|
|||
return self._request_with_params(POST, Cancel_Advance_Algos, params)
|
||||
|
||||
# Get Algo Order List
|
||||
def order_algos_list(self, ordType='', algoId='', instType='', instId='', after='', before='', limit='',algoClOrdId=''):
|
||||
def order_algos_list(self, ordType='', algoId='', instType='', instId='', after='', before='', limit='',
|
||||
algoClOrdId=''):
|
||||
params = {'ordType': ordType, 'algoId': algoId, 'instType': instType, 'instId': instId, 'after': after,
|
||||
'before': before, 'limit': limit, 'algoClOrdId': algoClOrdId}
|
||||
return self._request_with_params(GET, ORDERS_ALGO_OENDING, params)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
from .client import Client
|
||||
from .okxclient import OkxClient
|
||||
from .consts import *
|
||||
|
||||
|
||||
class TradingDataAPI(Client):
|
||||
class TradingDataAPI(OkxClient):
|
||||
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1', domain = 'https://www.okx.com',debug = True, proxy=None):
|
||||
Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug,proxy)
|
||||
OkxClient.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag, domain, debug, proxy)
|
||||
|
||||
|
||||
def get_support_coin(self):
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@
|
|||
Python SDK for the OKX API v5
|
||||
|
||||
"""
|
||||
__version__="0.2.6"
|
||||
__version__="0.2.7"
|
||||
|
|
@ -6,7 +6,7 @@ from httpx import Client
|
|||
from . import consts as c, utils, exceptions
|
||||
|
||||
|
||||
class Client(Client):
|
||||
class OkxClient(Client):
|
||||
|
||||
def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_server_time=False, flag='1',base_api=c.API_URL, debug='True', proxy=None):
|
||||
super().__init__(base_url=base_api, http2=True, proxy=proxy)
|
||||
|
|
@ -1,18 +1,20 @@
|
|||
|
||||
import unittest
|
||||
|
||||
from okx import Account
|
||||
|
||||
|
||||
class AccountTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
proxy = "http://125.106.203.126:10423";
|
||||
api_key = 'aee24256-7393-422f-90d9-47cc4028ce39'
|
||||
api_secret_key = 'FF517E627F6A702E2BF50F311F245D2A'
|
||||
passphrase = 'hylHYL950525,.'
|
||||
self.AccountAPI = Account.AccountAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag='1',proxy=proxy,timeout=30)
|
||||
proxy = "http://43.152.113.72:19206"
|
||||
api_key = 'your_apiKey'
|
||||
api_secret_key = 'your_secretKey'
|
||||
passphrase = 'your_secretKey'
|
||||
self.AccountAPI = Account.AccountAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag='1', proxy=proxy)
|
||||
|
||||
# '''
|
||||
POSITIONS_HISTORY = '/api/v5/account/positions-history' #need add
|
||||
GET_PM_LIMIT = '/api/v5/account/position-tiers' #need add
|
||||
ACCOUNT_RISK = '/api/v5/account/risk-state' #need add
|
||||
# POSITIONS_HISTORY = '/api/v5/account/positions-history' #need add
|
||||
# GET_PM_LIMIT = '/api/v5/account/position-tiers' #need add
|
||||
# ACCOUNT_RISK = '/api/v5/account/risk-state' #need add
|
||||
# def test_account_risk(self):
|
||||
# print(self.AccountAPI.get_account_risk())
|
||||
#
|
||||
|
|
@ -21,58 +23,58 @@ class AccountTest(unittest.TestCase):
|
|||
# positions-history
|
||||
def test_get_positions_history(self):
|
||||
print(self.AccountAPI.get_positions_history())
|
||||
def test_get_user_config(self):
|
||||
print(self.AccountAPI.get_account_config())
|
||||
def test_get_positions(self):
|
||||
print(self.AccountAPI.get_positions("SWAP"))
|
||||
def test_get_balance(self):
|
||||
print(self.AccountAPI.get_account())
|
||||
def test_get_positions_risk(self):
|
||||
print(self.AccountAPI.get_position_risk("SWAP"))
|
||||
def test_get_bills(self):
|
||||
print(self.AccountAPI.get_bills_detail())
|
||||
|
||||
def test_get_bills_arch(self):
|
||||
print(self.AccountAPI.get_bills_details())
|
||||
def test_set_position_mode(self):
|
||||
print(self.AccountAPI.set_position_mode("long_short_mode"))
|
||||
def test_set_leverage(self):
|
||||
print(self.AccountAPI.set_leverage(instId="BTC-USDT",lever="5",mgnMode="isolated"))
|
||||
def test_get_max_avaliable_size(self):
|
||||
print(self.AccountAPI.get_max_avail_size(instId="BTC-USDT",tdMode="cash"))
|
||||
def test_get_max_size(self):
|
||||
print(self.AccountAPI.get_maximum_trade_size(instId="BTC-USDT",tdMode="cash"))
|
||||
def test_get_positions(self):
|
||||
print(self.AccountAPI.get_positions("MARGIN"))
|
||||
def test_set_margin_balance(self):
|
||||
print(self.AccountAPI.Adjustment_margin(instId="BTC-USDT",posSide="net",type="add",amt="1"))
|
||||
def test_get_lev_info(self):
|
||||
print(self.AccountAPI.get_leverage("BTC-USDT","cross"));
|
||||
def test_get_max_loan(self):
|
||||
print(self.AccountAPI.get_max_loan("BTC-USDT","cross","USDT"))
|
||||
def test_get_trade_fee(self):
|
||||
print(self.AccountAPI.get_fee_rates("SPOT"))
|
||||
def test_get_insterested_accrued(self):
|
||||
print(self.AccountAPI.get_interest_accrued())
|
||||
def test_get_interestred_rate(self):
|
||||
print(self.AccountAPI.get_interest_rate())
|
||||
def test_set_greeks(self):
|
||||
print(self.AccountAPI.set_greeks("BS"))
|
||||
|
||||
def test_set_isolated_mode(self):
|
||||
print(self.AccountAPI.set_isolated_mode("automatic","MARGIN"))
|
||||
def test_set_max_withdraw(self):
|
||||
print(self.AccountAPI.get_max_withdrawal("USDT"))
|
||||
def test_borrow_repay(self):
|
||||
print(self.AccountAPI.borrow_repay("BTC","borrow","1.0"))
|
||||
def test_borrow_repay_history(self):
|
||||
print(self.AccountAPI.get_borrow_repay_history())
|
||||
def test_get_interest_limits(self):
|
||||
print(self.AccountAPI.get_interest_limits())
|
||||
def test_simulated_margin(self):
|
||||
print(self.AccountAPI.get_simulated_margin())
|
||||
def test_get_greeks(self):
|
||||
print(self.AccountAPI.get_greeks())
|
||||
# def test_get_user_config(self):
|
||||
# print(self.AccountAPI.get_account_config())
|
||||
# def test_get_positions(self):
|
||||
# print(self.AccountAPI.get_positions("SWAP"))
|
||||
# def test_get_balance(self):
|
||||
# print(self.AccountAPI.get_account())
|
||||
# def test_get_positions_risk(self):
|
||||
# print(self.AccountAPI.get_position_risk("SWAP"))
|
||||
# def test_get_bills(self):
|
||||
# print(self.AccountAPI.get_bills_detail())
|
||||
#
|
||||
# def test_get_bills_arch(self):
|
||||
# print(self.AccountAPI.get_bills_details())
|
||||
# def test_set_position_mode(self):
|
||||
# print(self.AccountAPI.set_position_mode("long_short_mode"))
|
||||
# def test_set_leverage(self):
|
||||
# print(self.AccountAPI.set_leverage(instId="BTC-USDT",lever="5",mgnMode="isolated"))
|
||||
# def test_get_max_avaliable_size(self):
|
||||
# print(self.AccountAPI.get_max_avail_size(instId="BTC-USDT",tdMode="cash"))
|
||||
# def test_get_max_size(self):
|
||||
# print(self.AccountAPI.get_maximum_trade_size(instId="BTC-USDT",tdMode="cash"))
|
||||
# def test_get_positions(self):
|
||||
# print(self.AccountAPI.get_positions("MARGIN"))
|
||||
# def test_set_margin_balance(self):
|
||||
# print(self.AccountAPI.Adjustment_margin(instId="BTC-USDT",posSide="net",type="add",amt="1"))
|
||||
# def test_get_lev_info(self):
|
||||
# print(self.AccountAPI.get_leverage("BTC-USDT","cross"));
|
||||
# def test_get_max_loan(self):
|
||||
# print(self.AccountAPI.get_max_loan("BTC-USDT","cross","USDT"))
|
||||
# def test_get_trade_fee(self):
|
||||
# print(self.AccountAPI.get_fee_rates("SPOT"))
|
||||
# def test_get_insterested_accrued(self):
|
||||
# print(self.AccountAPI.get_interest_accrued())
|
||||
# def test_get_interestred_rate(self):
|
||||
# print(self.AccountAPI.get_interest_rate())
|
||||
# def test_set_greeks(self):
|
||||
# print(self.AccountAPI.set_greeks("BS"))
|
||||
#
|
||||
# def test_set_isolated_mode(self):
|
||||
# print(self.AccountAPI.set_isolated_mode("automatic","MARGIN"))
|
||||
# def test_set_max_withdraw(self):
|
||||
# print(self.AccountAPI.get_max_withdrawal("USDT"))
|
||||
# def test_borrow_repay(self):
|
||||
# print(self.AccountAPI.borrow_repay("BTC","borrow","1.0"))
|
||||
# def test_borrow_repay_history(self):
|
||||
# print(self.AccountAPI.get_borrow_repay_history())
|
||||
# def test_get_interest_limits(self):
|
||||
# print(self.AccountAPI.get_interest_limits())
|
||||
# def test_simulated_margin(self):
|
||||
# print(self.AccountAPI.get_simulated_margin())
|
||||
# def test_get_greeks(self):
|
||||
# print(self.AccountAPI.get_greeks())
|
||||
# '''
|
||||
# def test_simulated_margin(self):
|
||||
# print(self.AccountAPI.get_simulated_margin())
|
||||
|
|
@ -103,7 +105,9 @@ class AccountTest(unittest.TestCase):
|
|||
# def test_borrow_repay(self):
|
||||
# print(self.AccountAPI.borrow_repay("BTC", "borrow", "1.0"))
|
||||
|
||||
def test_simulated_margin(self):
|
||||
print(self.AccountAPI.get_simulated_margin(spotOffsetType='3'))
|
||||
# def test_simulated_margin(self):
|
||||
# print(self.AccountAPI.get_simulated_margin(spotOffsetType='3'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
@ -1,115 +1,169 @@
|
|||
import unittest
|
||||
|
||||
from okx import Trade
|
||||
|
||||
|
||||
class TradeTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
api_key = 'your_apiKey'
|
||||
api_secret_key = 'your_secretKey'
|
||||
passphrase = 'your_secretKey'
|
||||
self.tradeApi = Trade.TradeAPI(api_key, api_secret_key, passphrase, False, '1')
|
||||
"""
|
||||
def test_place_order(self):
|
||||
print(self.tradeApi.place_order("BTC-USDT",tdMode="cross",clOrdId="asCai1",side="buy",ordType="limit",sz="0.01",px="18000"))
|
||||
def test_cancel_order(self):
|
||||
print(self.tradeApi.cancel_order(instId="ETH-USDT",ordId="480702180748558336"))
|
||||
|
||||
def test_batch_order(self):
|
||||
orderData = [ {
|
||||
"instId":"ETH-USDT",
|
||||
"tdMode":"cross",
|
||||
"clOrdId":"b151121",
|
||||
"side":"buy",
|
||||
"ordType":"limit",
|
||||
"px":"2.15",
|
||||
"sz":"2"
|
||||
},
|
||||
{
|
||||
"instId":"BTC-USDT",
|
||||
"tdMode":"cross",
|
||||
"clOrdId":"b152233",
|
||||
"side":"buy",
|
||||
"ordType":"limit",
|
||||
"px":"2.15",
|
||||
"sz":"2"
|
||||
}]
|
||||
print(self.tradeApi.place_multiple_orders(orderData))
|
||||
# # """
|
||||
# def test_place_order(self):
|
||||
# attachAlgoOrds = [{'tpTriggerPx': '49000.0', 'tpOrdPx': '-1', 'sz': '1', 'tpTriggerPxType': 'last'}];
|
||||
# print(self.tradeApi.place_order(
|
||||
# "BTC-USDT-SWAP", tdMode="isolated", clOrdId="asCai1234", side='buy', posSide="long", ordType="limit",
|
||||
# sz="1",
|
||||
# px="30000.0",
|
||||
# attachAlgoOrds=attachAlgoOrds)
|
||||
# );
|
||||
#
|
||||
# attachAlgoOrds = [{'slTriggerPx': '25000.0', 'slOrdPx': '-1', 'sz': '1', 'slTriggerPxType': 'last'}];
|
||||
# print(self.tradeApi.place_order(
|
||||
# "BTC-USDT-SWAP", tdMode="isolated", clOrdId="asCai1234", side='buy', posSide="long", ordType="limit",
|
||||
# sz="1",
|
||||
# px="30000.0",
|
||||
# attachAlgoOrds=attachAlgoOrds)
|
||||
# );
|
||||
#
|
||||
# attachAlgoOrds = [
|
||||
# {
|
||||
# "tpTriggerPxType": "last",
|
||||
# "tpOrdPx": "-1",
|
||||
# "tpTriggerPx": "34000",
|
||||
# "sz": "1"
|
||||
# },
|
||||
# {
|
||||
# "tpTriggerPxType": "last",
|
||||
# "tpOrdPx": "-1",
|
||||
# "tpTriggerPx": "35000",
|
||||
# "sz": "1"
|
||||
# },
|
||||
# {
|
||||
# "slTriggerPxType": "last",
|
||||
# "slOrdPx": "-1",
|
||||
# "slTriggerPx": "20000",
|
||||
# "sz": "3"
|
||||
# }
|
||||
# ]
|
||||
# print(self.tradeApi.place_order(
|
||||
# "BTC-USDT-SWAP", tdMode="isolated", clOrdId="asCai1234", side='buy', posSide="long", ordType="limit",
|
||||
# sz="1",
|
||||
# px="30000.0",
|
||||
# attachAlgoOrds=attachAlgoOrds)
|
||||
# );
|
||||
|
||||
# def test_cancel_order(self):
|
||||
# print(self.tradeApi.cancel_order(instId="ETH-USDT",ordId="480702180748558336"))
|
||||
|
||||
# def test_batch_order(self):
|
||||
# orderData = [{
|
||||
# "instId": "BTC-USDT-SWAP",
|
||||
# "tdMode": "isolated",
|
||||
# "clOrdId": "b15112122",
|
||||
# "side": "buy",
|
||||
# "posSide": "long",
|
||||
# "ordType": "limit",
|
||||
# "px": "30000.0",
|
||||
# "sz": "2",
|
||||
# "attachAlgoOrds": [{'tpTriggerPx': '50000.0', 'tpOrdPx': '-1', 'sz': '1', 'tpTriggerPxType': 'last'}]
|
||||
# },
|
||||
# {
|
||||
# "instId": "BTC-USDT-SWAP",
|
||||
# "tdMode": "isolated",
|
||||
# "clOrdId": "b15112111",
|
||||
# "side": "buy",
|
||||
# "posSide": "long",
|
||||
# "ordType": "limit",
|
||||
# "px": "31000.0",
|
||||
# "sz": "2",
|
||||
# "attachAlgoOrds": [{'tpTriggerPx': '51000.0', 'tpOrdPx': '-1', 'sz': '1', 'tpTriggerPxType': 'last'}]
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
# print(self.tradeApi.place_multiple_orders(orderData))
|
||||
|
||||
# 480702180748558336
|
||||
def test_cancel_batch_orders(self):
|
||||
data=[
|
||||
{
|
||||
'instId':"ETH-USDT",
|
||||
'ordId':"480702885353881600"
|
||||
},
|
||||
{
|
||||
'instId':"BTC-USDT",
|
||||
'ordId':'480702885353881601'
|
||||
}
|
||||
]
|
||||
print(self.tradeApi.cancel_multiple_orders(data))
|
||||
def test_amend_order(self):
|
||||
print(self.tradeApi.amend_order("BTC-USDT",ordId="480706017781743616",newSz="0.03"))
|
||||
def test_amend_order_batch(self):
|
||||
orderData = [
|
||||
{
|
||||
'instId':'ETH-USDT',
|
||||
'ordId':'480707205436669952',
|
||||
'newSz':'0.02'
|
||||
},
|
||||
{
|
||||
'instId':'BTC-USDT',
|
||||
'ordId':'480707205436669953',
|
||||
'newPx':'3.0'
|
||||
}
|
||||
]
|
||||
print(self.tradeApi.amend_multiple_orders(orderData))
|
||||
def test_close_all_positions(self):
|
||||
print(self.tradeApi.close_positions("BTC-USDT",mgnMode="cross"))
|
||||
def test_get_order_info(self):
|
||||
print(self.tradeApi.get_orders("ETH-USDT","480707205436669952"))
|
||||
def test_get_order_pending(self):
|
||||
print(self.tradeApi.get_order_list("SPOT"))
|
||||
def test_get_order_history(self):
|
||||
print(self.tradeApi.get_orders_history("SPOT"))
|
||||
def test_get_order_histry_archive(self):
|
||||
print(self.tradeApi.orders_history_archive("SPOT"))
|
||||
def test_get_fills(self):
|
||||
print(self.tradeApi.get_fills("SPOT"))
|
||||
def test_get_fills_history(self):
|
||||
print(self.tradeApi.get_fills_history("SPOT"))
|
||||
def test_get_order_algo_pending(self):
|
||||
print(self.tradeApi.order_algos_list('oco'))
|
||||
def test_order_algo(self):
|
||||
print(self.tradeApi.place_algo_order('BTC-USDT-SWAP', 'cross', side='buy', ordType='trigger', posSide='long',
|
||||
sz='100', triggerPx='22000', triggerPxType ='index', orderPx='-1'))
|
||||
def test_cancel_algos(self):
|
||||
params = [{
|
||||
'algoId': '485903392536264704',
|
||||
'instId': 'BTC-USDT-SWAP'
|
||||
}]
|
||||
# def test_cancel_batch_orders(self):
|
||||
# data=[
|
||||
# {
|
||||
# 'instId':"ETH-USDT",
|
||||
# 'ordId':"480702885353881600"
|
||||
# },
|
||||
# {
|
||||
# 'instId':"BTC-USDT",
|
||||
# 'ordId':'480702885353881601'
|
||||
# }
|
||||
# ]
|
||||
# print(self.tradeApi.cancel_multiple_orders(data))
|
||||
# def test_amend_order(self):
|
||||
# attachAlgoOrds = [{'attachAlgoId': '672081789170569217', 'newTpTriggerPx': '55000.0'}];
|
||||
# print(self.tradeApi.amend_order("BTC-USDT-SWAP", ordId="672081789170569216", newSz="1",
|
||||
# attachAlgoOrds=attachAlgoOrds))
|
||||
|
||||
# def test_amend_order_batch(self):
|
||||
# orderData = [
|
||||
# {
|
||||
# 'instId': 'BTC-USDT-SWAP',
|
||||
# 'ordId': '672081789170569216',
|
||||
# 'newSz': '1',
|
||||
# "attachAlgoOrds": [{'attachAlgoId': '672081789170569217', 'newTpTriggerPx': '53000.0'}]
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
# print(self.tradeApi.amend_multiple_orders(orderData))
|
||||
|
||||
print(self.tradeApi.cancel_algo_order(params))
|
||||
def test_cancel_adv_algos(self):
|
||||
params = [{
|
||||
'algoId': '485936482235191296',
|
||||
'instId': 'BTC-USDT-SWAP'
|
||||
}]
|
||||
|
||||
print(self.tradeApi.cancel_advance_algos(params)))
|
||||
def test_orders_algo_pending(self):
|
||||
print(self.tradeApi.order_algos_list(ordType='iceberg'))
|
||||
def test_algo_order_history(self):
|
||||
print(self.tradeApi.order_algos_history(algoId='485903392536264704',ordType='conditional'))
|
||||
def test_get_easy_convert_list(self):
|
||||
print(self.tradeApi.get_easy_convert_currency_list())
|
||||
def test_easy_convert(self):
|
||||
print(self.tradeApi.easy_convert(fromCcy=['BTC'],toCcy='OKB'))
|
||||
def test_get_convert_history(self):
|
||||
print(self.tradeApi.get_easy_convert_history())
|
||||
def test_get_oneclick_repay_support_list(self):
|
||||
print(self.tradeApi.get_oneclick_repay_list('cross'))
|
||||
def test_oneclick_repay(self):
|
||||
print(self.tradeApi.oneclick_repay(['BTC'],'USDT'))
|
||||
"""
|
||||
# def test_close_all_positions(self):
|
||||
# print(self.tradeApi.close_positions("BTC-USDT",mgnMode="cross"))
|
||||
# def test_get_order_info(self):
|
||||
# print(self.tradeApi.get_orders("ETH-USDT","480707205436669952"))
|
||||
# def test_get_order_pending(self):
|
||||
# print(self.tradeApi.get_order_list("SPOT"))
|
||||
# def test_get_order_history(self):
|
||||
# print(self.tradeApi.get_orders_history("SPOT"))
|
||||
# def test_get_order_histry_archive(self):
|
||||
# print(self.tradeApi.orders_history_archive("SPOT"))
|
||||
# def test_get_fills(self):
|
||||
# print(self.tradeApi.get_fills("SPOT"))
|
||||
# def test_get_fills_history(self):
|
||||
# print(self.tradeApi.get_fills_history("SPOT"))
|
||||
# def test_get_order_algo_pending(self):
|
||||
# print(self.tradeApi.order_algos_list('oco'))
|
||||
# def test_order_algo(self):
|
||||
# print(self.tradeApi.place_algo_order('BTC-USDT-SWAP', 'cross', side='buy', ordType='trigger', posSide='long',
|
||||
# sz='100', triggerPx='22000', triggerPxType ='index', orderPx='-1'))
|
||||
# def test_cancel_algos(self):
|
||||
# params = [{
|
||||
# 'algoId': '485903392536264704',
|
||||
# 'instId': 'BTC-USDT-SWAP'
|
||||
# }]
|
||||
#
|
||||
#
|
||||
# print(self.tradeApi.cancel_algo_order(params))
|
||||
# def test_cancel_adv_algos(self):
|
||||
# params = [{
|
||||
# 'algoId': '485936482235191296',
|
||||
# 'instId': 'BTC-USDT-SWAP'
|
||||
# }]
|
||||
#
|
||||
# print(self.tradeApi.cancel_advance_algos(params)))
|
||||
# def test_orders_algo_pending(self):
|
||||
# print(self.tradeApi.order_algos_list(ordType='iceberg'))
|
||||
# def test_algo_order_history(self):
|
||||
# print(self.tradeApi.order_algos_history(algoId='485903392536264704',ordType='conditional'))
|
||||
# def test_get_easy_convert_list(self):
|
||||
# print(self.tradeApi.get_easy_convert_currency_list())
|
||||
# def test_easy_convert(self):
|
||||
# print(self.tradeApi.easy_convert(fromCcy=['BTC'],toCcy='OKB'))
|
||||
# def test_get_convert_history(self):
|
||||
# print(self.tradeApi.get_easy_convert_history())
|
||||
# def test_get_oneclick_repay_support_list(self):
|
||||
# print(self.tradeApi.get_oneclick_repay_list('cross'))
|
||||
# def test_oneclick_repay(self):
|
||||
# print(self.tradeApi.oneclick_repay(['BTC'],'USDT'))
|
||||
# """
|
||||
# 485903392536264704
|
||||
# 485936482235191296
|
||||
# def test_oneclick_repay_history(self):
|
||||
|
|
@ -179,13 +233,15 @@ class TradeTest(unittest.TestCase):
|
|||
# print(self.tradeApi.place_algo_order(instId='BTC-USDT-SWAP', tdMode='cross', side='buy', ordType='conditional', \
|
||||
# tpTriggerPx='15', tpOrdPx='18', sz='2',algoClOrdId='7678687',quickMgnType='manual'))
|
||||
|
||||
def test_order_algos_list(self):
|
||||
print(self.tradeApi.order_algos_list(ordType='conditional'))
|
||||
# def test_order_algos_list(self):
|
||||
# print(self.tradeApi.order_algos_list(ordType='conditional'))
|
||||
|
||||
# def test_order_algo(self):
|
||||
# print(self.tradeApi.place_order(instId='BTC-USDT-SWAP', tdMode='cross', side='buy',px='121',sz='2',
|
||||
# clOrdId='234234565535',ordType='market'))
|
||||
# def test_close_all_positions(self):
|
||||
# print(self.tradeApi.close_positions(instId="BTC-USDT-SWAP", mgnMode="cross",clOrdId='1213124'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Reference in New Issue