diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..0f777f4 --- /dev/null +++ b/.env.example @@ -0,0 +1,10 @@ +# OKX API Credentials +# Copy this file to .env and fill in your actual credentials +# NEVER commit .env to version control! + +OKX_API_KEY=your_api_key_here +OKX_API_SECRET=your_api_secret_here +OKX_PASSPHRASE=your_passphrase_here + +# Optional: Set to '0' for live trading, '1' for demo trading +OKX_FLAG=1 diff --git a/.gitignore b/.gitignore index 10c5a42..41c5c7c 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,9 @@ build/ ### VS Code ### .vscode/ -id_rsa* \ No newline at end of file +id_rsa* + +# Environment files +.env +.env.local +.env.*.local \ No newline at end of file diff --git a/okx/Account.py b/okx/Account.py index e3d316f..a6b182e 100644 --- a/okx/Account.py +++ b/okx/Account.py @@ -102,8 +102,10 @@ def get_instruments(self, instType='', ugly='', instFamily='', instId=''): return self._request_with_params(GET, GET_INSTRUMENTS, params) # Get the maximum loan of isolated MARGIN - def get_max_loan(self, instId, mgnMode, mgnCcy=''): + def get_max_loan(self, instId, mgnMode, mgnCcy='', tradeQuoteCcy=None): params = {'instId': instId, 'mgnMode': mgnMode, 'mgnCcy': mgnCcy} + if tradeQuoteCcy is not None: + params['tradeQuoteCcy'] = tradeQuoteCcy return self._request_with_params(GET, MAX_LOAN, params) # Get Fee Rates diff --git a/okx/Grid.py b/okx/Grid.py index 74b6a9b..d761708 100644 --- a/okx/Grid.py +++ b/okx/Grid.py @@ -7,11 +7,13 @@ def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_serve 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=''): + slTriggerPx='', tag='', quoteSz='', baseSz='', sz='', direction='', lever='', basePos='', tradeQuoteCcy=None): params = {'instId': instId, 'algoOrdType': algoOrdType, 'maxPx': maxPx, 'minPx': minPx, 'gridNum': gridNum, 'runType': runType, 'tpTriggerPx': tpTriggerPx, 'slTriggerPx': slTriggerPx, 'tag': tag, 'quoteSz': quoteSz, 'baseSz': baseSz, 'sz': sz, 'direction': direction, 'lever': lever, 'basePos': basePos} + if tradeQuoteCcy is not None: + params['tradeQuoteCcy'] = tradeQuoteCcy return self._request_with_params(POST, GRID_ORDER_ALGO, params) def grid_amend_order_algo(self, algoId='', instId='', slTriggerPx='', tpTriggerPx=''): @@ -79,11 +81,13 @@ def grid_ai_param(self, algoOrdType='', instId='', direction='', duration=''): # - Place recurring buy order def place_recurring_buy_order(self, stgyName='', recurringList=[], period='', recurringDay='', recurringTime='', - timeZone='', amt='', investmentCcy='', tdMode='', algoClOrdId='', tag=''): + timeZone='', amt='', investmentCcy='', tdMode='', algoClOrdId='', tag='', tradeQuoteCcy=None): params = {'stgyName': stgyName, 'recurringList': recurringList, 'period': period, 'recurringDay': recurringDay, 'recurringTime': recurringTime, 'timeZone': timeZone, 'amt': amt, 'investmentCcy': investmentCcy, 'tdMode': tdMode, 'algoClOrdId': algoClOrdId, 'tag': tag} + if tradeQuoteCcy is not None: + params['tradeQuoteCcy'] = tradeQuoteCcy return self._request_with_params(POST, PLACE_RECURRING_BUY_ORDER, params) # - Amend recurring buy order diff --git a/okx/Trade.py b/okx/Trade.py index db994ae..9d6d9e5 100644 --- a/okx/Trade.py +++ b/okx/Trade.py @@ -12,10 +12,14 @@ def __init__(self, api_key='-1', api_secret_key='-1', passphrase='-1', use_serve # Place Order def place_order(self, instId, tdMode, side, ordType, sz, ccy='', clOrdId='', tag='', posSide='', px='', - reduceOnly='', tgtCcy='', stpMode='', attachAlgoOrds=None, pxUsd='', pxVol='', banAmend='', tradeQuoteCcy=''): + reduceOnly='', tgtCcy='', stpMode='', attachAlgoOrds=None, pxUsd='', pxVol='', banAmend='', tradeQuoteCcy=None, pxAmendType=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, 'stpMode': stpMode, 'pxUsd': pxUsd, 'pxVol': pxVol, 'banAmend': banAmend, 'tradeQuoteCcy': tradeQuoteCcy} + 'tgtCcy': tgtCcy, 'stpMode': stpMode, 'pxUsd': pxUsd, 'pxVol': pxVol, 'banAmend': banAmend} + if tradeQuoteCcy is not None: + params['tradeQuoteCcy'] = tradeQuoteCcy + if pxAmendType is not None: + params['pxAmendType'] = pxAmendType params['attachAlgoOrds'] = attachAlgoOrds return self._request_with_params(POST, PLACR_ORDER, params) @@ -35,11 +39,13 @@ def cancel_multiple_orders(self, orders_data): # Amend Order def amend_order(self, instId, cxlOnFail='', ordId='', clOrdId='', reqId='', newSz='', newPx='', newTpTriggerPx='', newTpOrdPx='', newSlTriggerPx='', newSlOrdPx='', newTpTriggerPxType='', newSlTriggerPxType='', - attachAlgoOrds='', newTriggerPx='', newOrdPx=''): + attachAlgoOrds='', newTriggerPx='', newOrdPx='', pxAmendType=None): params = {'instId': instId, 'cxlOnFail': cxlOnFail, 'ordId': ordId, 'clOrdId': clOrdId, 'reqId': reqId, 'newSz': newSz, 'newPx': newPx, 'newTpTriggerPx': newTpTriggerPx, 'newTpOrdPx': newTpOrdPx, 'newSlTriggerPx': newSlTriggerPx, 'newSlOrdPx': newSlOrdPx, 'newTpTriggerPxType': newTpTriggerPxType, 'newSlTriggerPxType': newSlTriggerPxType, 'newTriggerPx': newTriggerPx, 'newOrdPx': newOrdPx} + if pxAmendType is not None: + params['pxAmendType'] = pxAmendType params['attachAlgoOrds'] = attachAlgoOrds return self._request_with_params(POST, AMEND_ORDER, params) @@ -95,8 +101,8 @@ def place_algo_order(self, instId='', tdMode='', side='', ordType='', sz='', ccy pxSpread='', szLimit='', pxLimit='', timeInterval='', tpTriggerPxType='', slTriggerPxType='', callbackRatio='', callbackSpread='', activePx='', tag='', triggerPxType='', closeFraction='' - , quickMgnType='', algoClOrdId='', tradeQuoteCcy='', tpOrdKind='', cxlOnClosePos='' - , chaseType='', chaseVal='', maxChaseType='', maxChaseVal='', attachAlgoOrds=[]): + , quickMgnType='', algoClOrdId='', tradeQuoteCcy=None, tpOrdKind='', cxlOnClosePos='' + , chaseType='', chaseVal='', maxChaseType='', maxChaseVal='', attachAlgoOrds=[], pxAmendType=None): params = {'instId': instId, 'tdMode': tdMode, 'side': side, 'ordType': ordType, 'sz': sz, 'ccy': ccy, 'posSide': posSide, 'reduceOnly': reduceOnly, 'tpTriggerPx': tpTriggerPx, 'tpOrdPx': tpOrdPx, 'slTriggerPx': slTriggerPx, 'slOrdPx': slOrdPx, 'triggerPx': triggerPx, 'orderPx': orderPx, @@ -105,9 +111,13 @@ def place_algo_order(self, instId='', tdMode='', side='', ordType='', sz='', ccy 'pxSpread': pxSpread, 'tpTriggerPxType': tpTriggerPxType, 'slTriggerPxType': slTriggerPxType, 'callbackRatio': callbackRatio, 'callbackSpread': callbackSpread, 'activePx': activePx, 'tag': tag, 'triggerPxType': triggerPxType, 'closeFraction': closeFraction, - 'quickMgnType': quickMgnType, 'algoClOrdId': algoClOrdId, 'tradeQuoteCcy': tradeQuoteCcy, + 'quickMgnType': quickMgnType, 'algoClOrdId': algoClOrdId, 'tpOrdKind': tpOrdKind, 'cxlOnClosePos': cxlOnClosePos, 'chaseType': chaseType, 'chaseVal': chaseVal, 'maxChaseType': maxChaseType, 'maxChaseVal': maxChaseVal, 'attachAlgoOrds': attachAlgoOrds} + if tradeQuoteCcy is not None: + params['tradeQuoteCcy'] = tradeQuoteCcy + if pxAmendType is not None: + params['pxAmendType'] = pxAmendType return self._request_with_params(POST, PLACE_ALGO_ORDER, params) # Cancel Algo Order diff --git a/test/config.py b/test/config.py new file mode 100644 index 0000000..37fefdb --- /dev/null +++ b/test/config.py @@ -0,0 +1,34 @@ +""" +Test configuration module - loads API credentials from environment variables. + +Usage: + from test.config import get_api_credentials + + api_key, api_secret, passphrase, flag = get_api_credentials() +""" +import os +from pathlib import Path + +# Try to load from .env file if python-dotenv is available +try: + from dotenv import load_dotenv + env_path = Path(__file__).parent.parent / '.env' + load_dotenv(env_path) +except ImportError: + pass # python-dotenv not installed, rely on system environment variables + + +def get_api_credentials(): + """ + Get API credentials from environment variables. + + Returns: + tuple: (api_key, api_secret, passphrase, flag) + """ + api_key = os.getenv('OKX_API_KEY', '') + api_secret = os.getenv('OKX_API_SECRET', '') + passphrase = os.getenv('OKX_PASSPHRASE', '') + flag = os.getenv('OKX_FLAG', '1') # Default to demo trading + + return api_key, api_secret, passphrase, flag + diff --git a/test/AccountTest.py b/test/test_account.py similarity index 93% rename from test/AccountTest.py rename to test/test_account.py index 14793d0..ef71181 100644 --- a/test/AccountTest.py +++ b/test/test_account.py @@ -3,14 +3,13 @@ from loguru import logger from okx import Account +from test.config import get_api_credentials class AccountTest(unittest.TestCase): def setUp(self): - api_key = 'your_apiKey' - api_secret_key = 'your_secretKey' - passphrase = 'your_secretKey' - self.AccountAPI = Account.AccountAPI(api_key, api_secret_key, passphrase, flag='1') + api_key, api_secret_key, passphrase, flag = get_api_credentials() + self.AccountAPI = Account.AccountAPI(api_key, api_secret_key, passphrase, flag=flag) # ''' # POSITIONS_HISTORY = '/api/v5/account/positions-history' #need add @@ -146,8 +145,15 @@ def setUp(self): # logger.info(f'{self.AccountAPI.set_auto_repay(autoRepay=True)}') # def test_spot_borrow_repay_history(self): # logger.debug(self.AccountAPI.spot_borrow_repay_history(ccy="USDT",type="auto_borrow",after="1597026383085")) - def test_set_auto_earn(self): - logger.debug(self.AccountAPI.set_auto_earn(ccy="USDT", action="turn_on", earnType='0')) + # def test_set_auto_earn(self): + # logger.debug(self.AccountAPI.set_auto_earn(ccy="USDT", action="turn_on", earnType='0')) + #def test_get_max_loan_with_trade_quote_ccy(self): + # logger.debug(self.AccountAPI.get_max_loan( + # instId="BTC-USDT", + # mgnMode="isolated", + # mgnCcy="USDT", + # tradeQuoteCcy="USDT" + # )) if __name__ == '__main__': unittest.main() diff --git a/test/BlockTradingTest.py b/test/test_block_trading.py similarity index 93% rename from test/BlockTradingTest.py rename to test/test_block_trading.py index e8b0e88..1c02542 100644 --- a/test/BlockTradingTest.py +++ b/test/test_block_trading.py @@ -1,12 +1,13 @@ import unittest from okx import BlockTrading +from test.config import get_api_credentials + + class BlockTradingTest(unittest.TestCase): def setUp(self): - api_key = 'your_apiKey' - api_secret_key = 'your_secretKey' - passphrase = 'your_secretKey' - self.BlockTradingAPI = BlockTrading.BlockTradingAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag='1') + api_key, api_secret_key, passphrase, flag = get_api_credentials() + self.BlockTradingAPI = BlockTrading.BlockTradingAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag=flag) """ def test_get_counter_parties(self): diff --git a/test/ConvertTest.py b/test/test_convert.py similarity index 83% rename from test/ConvertTest.py rename to test/test_convert.py index aa1d175..fc1f048 100644 --- a/test/ConvertTest.py +++ b/test/test_convert.py @@ -1,11 +1,12 @@ import unittest -from ..okx import Convert +from okx import Convert +from test.config import get_api_credentials + + class ConvertTest(unittest.TestCase): def setUp(self): - api_key = 'your_apiKey' - api_secret_key = 'your_secretKey' - passphrase = 'your_secretKey' - self.ConvertAPI = Convert.ConvertAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag='1') + api_key, api_secret_key, passphrase, flag = get_api_credentials() + self.ConvertAPI = Convert.ConvertAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag=flag) ''' def test_get_currencies(self): diff --git a/test/CopyTradingTest.py b/test/test_copy_trading.py similarity index 88% rename from test/CopyTradingTest.py rename to test/test_copy_trading.py index 95c1739..b516bc5 100644 --- a/test/CopyTradingTest.py +++ b/test/test_copy_trading.py @@ -1,13 +1,13 @@ import unittest from okx import CopyTrading +from test.config import get_api_credentials + class CopyTradingTest(unittest.TestCase): def setUp(self): - api_key = 'your_apiKey' - api_secret_key = 'your_secretKey' - passphrase = 'your_secretKey' + api_key, api_secret_key, passphrase, flag = get_api_credentials() self.StackingAPI = CopyTrading.CopyTradingAPI(api_key, api_secret_key, passphrase, use_server_time=False, - flag='0') + flag=flag) # def test_get_existing_leading_positions(self): # print(self.StackingAPI.get_existing_leading_positions(instId='DOGE-USDT-SWAP')) diff --git a/test/EthStakingTest.py b/test/test_eth_staking.py similarity index 82% rename from test/EthStakingTest.py rename to test/test_eth_staking.py index 3be4860..f280d1d 100644 --- a/test/EthStakingTest.py +++ b/test/test_eth_staking.py @@ -1,12 +1,12 @@ import unittest from okx.Finance import EthStaking +from test.config import get_api_credentials + class EthStakingTest(unittest.TestCase): def setUp(self): - api_key = 'your_apiKey' - api_secret_key = 'your_secretKey' - passphrase = 'your_secretKey' - self.StackingAPI = EthStaking.EthStakingAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag='1') + api_key, api_secret_key, passphrase, flag = get_api_credentials() + self.StackingAPI = EthStaking.EthStakingAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag=flag) def test_eth_product_info(self): print(self.StackingAPI.eth_product_info()) diff --git a/test/FlexibleLoanTest.py b/test/test_flexible_loan.py similarity index 84% rename from test/FlexibleLoanTest.py rename to test/test_flexible_loan.py index b4320a5..517b194 100644 --- a/test/FlexibleLoanTest.py +++ b/test/test_flexible_loan.py @@ -1,12 +1,12 @@ import unittest from okx.Finance import FlexibleLoan +from test.config import get_api_credentials + class FlexibleLoanTest(unittest.TestCase): def setUp(self): - api_key = 'your_apiKey' - api_secret_key = 'your_secretKey' - passphrase = 'your_secretKey' - self.FlexibleLoanAPI = FlexibleLoan.FlexibleLoanAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag='1') + api_key, api_secret_key, passphrase, flag = get_api_credentials() + self.FlexibleLoanAPI = FlexibleLoan.FlexibleLoanAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag=flag) def test_borrow_currencies(self): print(self.FlexibleLoanAPI.borrow_currencies()) diff --git a/test/FundingTest.py b/test/test_funding.py similarity index 95% rename from test/FundingTest.py rename to test/test_funding.py index f9fb0c6..3247f65 100644 --- a/test/FundingTest.py +++ b/test/test_funding.py @@ -1,13 +1,13 @@ import unittest from okx import Funding +from test.config import get_api_credentials + class FundingTest(unittest.TestCase): def setUp(self): - api_key = 'your_apiKey' - api_secret_key = 'your_secretKey' - passphrase = 'your_secretKey' - self.FundingAPI = Funding.FundingAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag='0') + api_key, api_secret_key, passphrase, flag = get_api_credentials() + self.FundingAPI = Funding.FundingAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag=flag) """ CANCEL_WITHDRAWAL = '/api/v5/asset/cancel-withdrawal' #need add CONVERT_DUST_ASSETS = '/api/v5/asset/convert-dust-assets' #need add diff --git a/test/GridTest.py b/test/test_grid.py similarity index 77% rename from test/GridTest.py rename to test/test_grid.py index 6e8f7da..fb14c95 100644 --- a/test/GridTest.py +++ b/test/test_grid.py @@ -1,13 +1,13 @@ import unittest from okx import Grid +from test.config import get_api_credentials + class GridTest(unittest.TestCase): def setUp(self): - api_key = 'your_apiKey' - api_secret_key = 'your_secretKey' - passphrase = 'your_secretKey' - self.GridAPI = Grid.GridAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag='1', debug=False) + api_key, api_secret_key, passphrase, flag = get_api_credentials() + self.GridAPI = Grid.GridAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag=flag, debug=False) """ GRID_COMPUTE_MARIGIN_BALANCE = '/api/v5/tradingBot/grid/compute-margin-balance' GRID_MARGIN_BALANCE = '/api/v5/tradingBot/grid/margin-balance' @@ -79,7 +79,31 @@ def test_withdrawl_profits(self): # def test_get_recurring_buy_sub_orders(self): # print(self.GridAPI.get_recurring_buy_sub_orders(algoId="581191143417970688")) - #581191143417970688 + #def test_grid_order_algo_with_trade_quote_ccy(self): + # print(self.GridAPI.grid_order_algo( + # instId="BTC-USDT", + # algoOrdType="grid", + # maxPx="45000", + # minPx="20000", + # gridNum="100", + # runType="1", + # quoteSz="50", + # tradeQuoteCcy="USDT" + # )) + + #def test_place_recurring_buy_order_with_trade_quote_ccy(self): + # print(self.GridAPI.place_recurring_buy_order( + # stgyName="test_strategy", + # recurringList=[{'ccy': 'ETH', 'ratio': '1'}], + # period="daily", + # recurringDay='1', + # recurringTime='0', + # timeZone='8', + # amt='100', + # investmentCcy='USDT', + # tdMode='cash', + # tradeQuoteCcy="USDT" + # )) if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/test/MarketTest.py b/test/test_market.py similarity index 93% rename from test/MarketTest.py rename to test/test_market.py index 2a45d7f..f3b6acf 100644 --- a/test/MarketTest.py +++ b/test/test_market.py @@ -12,12 +12,13 @@ BLOCK_TRADES = '/api/v5/market/block-trades'#need to add ''' +from test.config import get_api_credentials + + class MarketAPITest(unittest.TestCase): def setUp(self): - api_key = 'your_apiKey' - api_secret_key = 'your_secretKey' - passphrase = 'your_secretKey' - self.MarketApi = MarketData.MarketAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag='1') + api_key, api_secret_key, passphrase, flag = get_api_credentials() + self.MarketApi = MarketData.MarketAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag=flag) ''' def test_index_component(self): diff --git a/test/PublicDataTest.py b/test/test_public_data.py similarity index 95% rename from test/PublicDataTest.py rename to test/test_public_data.py index 56a028b..79e5d35 100644 --- a/test/PublicDataTest.py +++ b/test/test_public_data.py @@ -1,11 +1,12 @@ import unittest from okx import PublicData +from test.config import get_api_credentials + + class publicDataTest(unittest.TestCase): def setUp(self): - api_key = 'your_apiKey' - api_secret_key = 'your_secretKey' - passphrase = 'your_secretKey' - self.publicDataApi = PublicData.PublicAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag='1') + api_key, api_secret_key, passphrase, flag = get_api_credentials() + self.publicDataApi = PublicData.PublicAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag=flag) ''' TestCase For: INTEREST_LOAN = '/api/v5/public/interest-rate-loan-quota' #need to add diff --git a/test/SavingsTest.py b/test/test_savings.py similarity index 84% rename from test/SavingsTest.py rename to test/test_savings.py index 9dac910..9baf663 100644 --- a/test/SavingsTest.py +++ b/test/test_savings.py @@ -1,12 +1,12 @@ import unittest from okx.Finance import Savings +from test.config import get_api_credentials + class SavingsTest(unittest.TestCase): def setUp(self): - api_key = 'your_apiKey' - api_secret_key = 'your_secretKey' - passphrase = 'your_secretKey' - self.StackingAPI = Savings.SavingsAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag='1') + api_key, api_secret_key, passphrase, flag = get_api_credentials() + self.StackingAPI = Savings.SavingsAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag=flag) def test_get_saving_balance(self): diff --git a/test/SolStakingTest.py b/test/test_sol_staking.py similarity index 82% rename from test/SolStakingTest.py rename to test/test_sol_staking.py index c3899d4..110fb67 100644 --- a/test/SolStakingTest.py +++ b/test/test_sol_staking.py @@ -1,12 +1,12 @@ import unittest from okx.Finance import SolStaking +from test.config import get_api_credentials + class SolStakingTest(unittest.TestCase): def setUp(self): - api_key = 'your_apiKey' - api_secret_key = 'your_secretKey' - passphrase = 'your_secretKey' - self.StackingAPI = SolStaking.SolStakingAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag='1') + api_key, api_secret_key, passphrase, flag = get_api_credentials() + self.StackingAPI = SolStaking.SolStakingAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag=flag) def test_sol_purchase(self): print(self.StackingAPI.sol_purchase(amt="1")) diff --git a/test/SpreadTest.py b/test/test_spread.py similarity index 91% rename from test/SpreadTest.py rename to test/test_spread.py index cbaf6e8..25a596b 100644 --- a/test/SpreadTest.py +++ b/test/test_spread.py @@ -1,11 +1,12 @@ import unittest from okx import SpreadTrading +from test.config import get_api_credentials + + class TradeTest(unittest.TestCase): def setUp(self): - api_key = 'your_apiKey' - api_secret_key = 'your_secretKey' - passphrase = 'your_secretKey' - self.tradeApi = SpreadTrading.SpreadTradingAPI(api_key, api_secret_key, passphrase, False, '1') + api_key, api_secret_key, passphrase, flag = get_api_credentials() + self.tradeApi = SpreadTrading.SpreadTradingAPI(api_key, api_secret_key, passphrase, False, flag) # def test_place_order(self): # print(self.tradeApi.place_order(sprdId='BTC-USDT_BTC-USDT-SWAP',clOrdId='b15',side='buy',ordType='limit', diff --git a/test/StakingDefiTest.py b/test/test_staking_defi.py similarity index 82% rename from test/StakingDefiTest.py rename to test/test_staking_defi.py index 29ac045..bfe908a 100644 --- a/test/StakingDefiTest.py +++ b/test/test_staking_defi.py @@ -1,14 +1,13 @@ import unittest from okx.Finance import StakingDefi +from test.config import get_api_credentials class StakingDefiTest(unittest.TestCase): def setUp(self): - api_key = 'your_apiKey' - api_secret_key = 'your_secretKey' - passphrase = 'your_secretKey' + api_key, api_secret_key, passphrase, flag = get_api_credentials() self.StackingAPI = StakingDefi.StakingDefiAPI(api_key, api_secret_key, passphrase, use_server_time=False, - flag='1') + flag=flag) def test_get_offers(self): print(self.StackingAPI.get_offers(ccy="USDT")) diff --git a/test/SubAccountTest.py b/test/test_sub_account.py similarity index 92% rename from test/SubAccountTest.py rename to test/test_sub_account.py index b4281bd..8682194 100644 --- a/test/SubAccountTest.py +++ b/test/test_sub_account.py @@ -1,12 +1,12 @@ import unittest from okx import SubAccount +from test.config import get_api_credentials + class SubAccountTest(unittest.TestCase): def setUp(self): - api_key = 'your_apiKey' - api_secret_key = 'your_secretKey' - passphrase = 'your_secretKey' - self.SubAccountApi = SubAccount.SubAccountAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag='1') + api_key, api_secret_key, passphrase, flag = get_api_credentials() + self.SubAccountApi = SubAccount.SubAccountAPI(api_key, api_secret_key, passphrase, use_server_time=False, flag=flag) ''' ENTRUST_SUBACCOUNT_LIST = '/api/v5/users/entrust-subaccount-list' #need to add SET_TRSNSFER_OUT = '/api/v5/users/subaccount/set-transfer-out' #need to add diff --git a/test/TradeTest.py b/test/test_trade.py similarity index 82% rename from test/TradeTest.py rename to test/test_trade.py index 3f1b601..6da7a54 100644 --- a/test/TradeTest.py +++ b/test/test_trade.py @@ -1,14 +1,13 @@ import unittest from okx import Trade +from test.config import get_api_credentials 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') + api_key, api_secret_key, passphrase, flag = get_api_credentials() + self.tradeApi = Trade.TradeAPI(api_key, api_secret_key, passphrase, False, flag) # # """ # def test_place_order(self): @@ -234,12 +233,66 @@ def setUp(self): # def test_close_all_positions(self): # print(self.tradeApi.close_positions(instId="BTC-USDT-SWAP", mgnMode="cross",clOrdId='1213124')) - def test_get_oneclick_repay_list_v2(self): - print(self.tradeApi.get_oneclick_repay_list_v2()) - def test_oneclick_repay_v2(self): - print(self.tradeApi.oneclick_repay_v2('BTC',['USDT'])) - def test_oneclick_repay_history_v2(self): - print(self.tradeApi.oneclick_repay_history_v2()) + #def test_get_oneclick_repay_list_v2(self): + # print(self.tradeApi.get_oneclick_repay_list_v2()) + #def test_oneclick_repay_v2(self): + # print(self.tradeApi.oneclick_repay_v2('BTC',['USDT'])) + #def test_oneclick_repay_history_v2(self): + # print(self.tradeApi.oneclick_repay_history_v2()) + + #def test_place_order_with_trade_quote_ccy(self): + # print(self.tradeApi.place_order( + # instId="BTC-USDT", + # tdMode="cash", + # side="buy", + # ordType="limit", + # sz="0.01", + # px="30000", + # tradeQuoteCcy="USDT" + # )) + + #def test_place_order_with_px_amend_type(self): + # print(self.tradeApi.place_order( + # instId="BTC-USDT-SWAP", + # tdMode="cash", + # side="buy", + # ordType="limit", + # sz="1", + # px="30000", + # pxAmendType="1" + # )) + + #def test_amend_order_with_px_amend_type(self): + # print(self.tradeApi.amend_order( + # instId="BTC-USDT-SWAP", + # ordId="123", + # newPx="30500", + # pxAmendType="1" + # )) + + #def test_place_algo_order_with_trade_quote_ccy(self): + # print(self.tradeApi.place_algo_order( + # instId="BTC-USDT-SWAP", + # tdMode="cash", + # side="buy", + # ordType="trigger", + # sz="1", + # triggerPx="30000", + # orderPx="-1", + # tradeQuoteCcy="USDT" + # )) + + #def test_place_algo_order_with_px_amend_type(self): + # print(self.tradeApi.place_algo_order( + # instId="BTC-USDT-SWAP", + # tdMode="cash", + # side="buy", + # ordType="trigger", + # sz="1", + # triggerPx="30000", + # orderPx="-1", + # pxAmendType="1" + # )) if __name__ == '__main__': unittest.main() diff --git a/test/TradingDataTest.py b/test/test_trading_data.py similarity index 86% rename from test/TradingDataTest.py rename to test/test_trading_data.py index ac318b6..0872f37 100644 --- a/test/TradingDataTest.py +++ b/test/test_trading_data.py @@ -1,14 +1,13 @@ import unittest -from ..okx import TradingData +from okx import TradingData +from test.config import get_api_credentials class TradingDataTest(unittest.TestCase): def setUp(self): - api_key = 'your_apiKey' - api_secret_key = 'your_secretKey' - passphrase = 'your_secretKey' + api_key, api_secret_key, passphrase, flag = get_api_credentials() self.TradingDataAPI = TradingData.TradingDataAPI(api_key, api_secret_key, passphrase, use_server_time=False, - flag='1') + flag=flag) """ def test_get_support_coins(self): print(self.TradingDataAPI.get_support_coin()) diff --git a/test/WsPrivateAsyncTest.py b/test/test_ws_private_async.py similarity index 88% rename from test/WsPrivateAsyncTest.py rename to test/test_ws_private_async.py index 6130b83..1244387 100644 --- a/test/WsPrivateAsyncTest.py +++ b/test/test_ws_private_async.py @@ -1,6 +1,7 @@ import asyncio from okx.websocket.WsPrivateAsync import WsPrivateAsync +from test.config import get_api_credentials def privateCallback(message): @@ -8,11 +9,12 @@ def privateCallback(message): async def main(): + api_key, api_secret_key, passphrase, _ = get_api_credentials() url = "wss://wspap.okx.com:8443/ws/v5/private?brokerId=9999" ws = WsPrivateAsync( - apiKey="your apiKey", - passphrase="your passphrase", - secretKey="your secretKey", + apiKey=api_key, + passphrase=passphrase, + secretKey=api_secret_key, url=url, useServerTime=False ) diff --git a/test/WsPublicAsyncTest.py b/test/test_ws_public_async.py similarity index 100% rename from test/WsPublicAsyncTest.py rename to test/test_ws_public_async.py