From e325345ec6b3a69457a4f0b9a9ad102b01c94ccc Mon Sep 17 00:00:00 2001 From: neal8891214 <39132539+neal8891214@users.noreply.github.com> Date: Fri, 17 May 2019 00:54:21 +0800 Subject: [PATCH 1/5] Update client.py add setposition and change domain --- bincentive_trader/client.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bincentive_trader/client.py b/bincentive_trader/client.py index aa38c0e..1f1e8d1 100644 --- a/bincentive_trader/client.py +++ b/bincentive_trader/client.py @@ -18,6 +18,7 @@ def __init__(self, email, password, testing=True): if testing: self.LOGIN_ENDPOINT = 'https://fs-sitapi.bincentive.com/member/api/member/login' self.TRADER_ENDPOINT = 'https://qdapps-sitapi.bincentive.com/' + self.SETPOSITION_ENDPOINT = 'https://bi-gateway-go-rd.bincentive.com/api/v1/strategy/SetPosition' else: self.LOGIN_ENDPOINT = 'https://fs-api.bincentive.com/member/api/member/login' self.TRADER_ENDPOINT = 'https://qdapps-proapi.bincentive.com/' @@ -214,3 +215,22 @@ def get_currency_list(self, timeout=None): r = self._post(endpoint, timeout=timeout) return r.json()['data'] + def set_position(self, strategy_id, Ratio, LimitPrice, timeout=None): + """Adds a market order for a specific strategy. + :param strategy_id: + :param Ratio: + :param LimitPrice: + :return: Signal id or None if no order was created. + """ + endpoint = self.SETPOSITION_ENDPOINT + payload = { + 'strategyId': strategy_id, + 'Ratio': Ratio, + 'LimitPrice': LimitPrice + } + r = self._post(endpoint, json=payload, timeout=timeout) + if r.status_code == 200: + return r.json()['data']['id'] + else: + return None + \ No newline at end of file From 3aa2778fcee42f0b9a85ce825ec3dcabf42d3e85 Mon Sep 17 00:00:00 2001 From: neal8891214 <39132539+neal8891214@users.noreply.github.com> Date: Tue, 21 May 2019 13:45:24 +0800 Subject: [PATCH 2/5] pyhton_SDK with new gateway MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit change the gateway to new gateway. get_strategy_list、get_exchange_list、get_history_list、def add_api_key、get_api_key_list、delete_api_key、get_exchange_symbol_list and set_position are available now. --- bincentive_trader/client.py | 128 +++++++++++------------------------- 1 file changed, 40 insertions(+), 88 deletions(-) diff --git a/bincentive_trader/client.py b/bincentive_trader/client.py index 1f1e8d1..c748dd2 100644 --- a/bincentive_trader/client.py +++ b/bincentive_trader/client.py @@ -17,11 +17,11 @@ class TraderClient(object): def __init__(self, email, password, testing=True): if testing: self.LOGIN_ENDPOINT = 'https://fs-sitapi.bincentive.com/member/api/member/login' - self.TRADER_ENDPOINT = 'https://qdapps-sitapi.bincentive.com/' - self.SETPOSITION_ENDPOINT = 'https://bi-gateway-go-rd.bincentive.com/api/v1/strategy/SetPosition' + self.TRADER_ENDPOINT = 'https://bi-gateway-go-rd.bincentive.com' + else: self.LOGIN_ENDPOINT = 'https://fs-api.bincentive.com/member/api/member/login' - self.TRADER_ENDPOINT = 'https://qdapps-proapi.bincentive.com/' + self.TRADER_ENDPOINT = 'https://bi-gateway-go-rd.bincentive.com' self.session = requests.Session() self.session.headers = { @@ -70,86 +70,47 @@ def _request(self, method, endpoint, timeout, *args, **kwargs): def _post(self, endpoint, json=None, timeout=None): return self._request('POST', endpoint, timeout, json=json) + + def _get(self, endpoint, timeout=None): + return self._request('GET', endpoint, timeout) + + def _delete(self, endpoint, timeout=None): + return self._request('DELETE', endpoint, timeout) + + def _put(self, endpoint, json=None, timeout=None): + return self._request('PUT', endpoint, timeout, json=json) def get_strategy_list(self, timeout=None): """Gets the list of approved strategies.""" - endpoint = self.TRADER_ENDPOINT + 'api/trader/getApprovedStrategyList' - r = self._post(endpoint, timeout=timeout) + endpoint = self.TRADER_ENDPOINT + '/api/v1/user/StrategyNameList' + r = self._get(endpoint, timeout=timeout) return r.json()['data'] def get_exchange_list(self, timeout=None): """Gets the list of exchanges currently active.""" - endpoint = self.TRADER_ENDPOINT + 'api/common/getActiveExchangeList' - r = self._post(endpoint, timeout=timeout) + endpoint = self.TRADER_ENDPOINT + '/api/v1/common/ExchangeList' + r = self._get(endpoint, timeout=timeout) return r.json()['data'] - def add_market_order(self, strategy_id, exchange_id, base_currency, quote_currency, side, amount, - leverage=1, timeout=None): - """Adds a market order for a specific strategy. - :param strategy_id: int - :param exchange_id: int - :param base_currency: e.g., 'BTC' - :param quote_currency: e.g., 'USDT' - :param side: 'BUY' or 'SELL' - :param amount: the amount to sell or buy - :param leverage: Bitmex exchange leverage. This parameter is used only on Bitmex exchange and can be set - to `None` if using other exchanges. - :param timeout: request timeout - :return: Signal id or None if no order was created. - """ - endpoint = self.TRADER_ENDPOINT + 'api/order/addOrder' - payload = { - 'strategyId': strategy_id, - 'exchangeId': exchange_id, - 'baseCurrency': base_currency, - 'quoteCurrency': quote_currency, - 'orderSide': side, - 'unit': amount, - 'leverage': leverage, - 'orderType': 'MARKET', - } - r = self._post(endpoint, json=payload, timeout=timeout) - if r.status_code == 200: - return r.json()['data']['signalId'] - else: - return None - - def get_history_list(self, strategy_id, begin_time, end_time, account_type='real', timeout=None): + def get_history_list(self, strategy_id, startDate, endDate, timeout=None): """Gets the historical data of all transactions. :param strategy_id: int - :param begin_time: datetime object. If no tzinfo is provided, defaults to local timezone. - :param end_time: datetime object. If no tzinfo is provided, defaults to local timezone. - :param account_type: 'real' or 'virtual' + :param startDate: str, YYYY-MM-DD + :param endDate: str, YYYY-MM-DD :param timeout: request timeout :return: history list """ - local_tz = tzlocal.get_localzone() - if begin_time.tzinfo is None: - begin_time = begin_time.astimezone(local_tz) - if end_time.tzinfo is None: - end_time = end_time.astimezone(local_tz) - - convert_start_time = begin_time.isoformat() - convert_end_time = end_time.isoformat() - endpoint = self.TRADER_ENDPOINT + 'api/order/getHistoryList' - payload = { - 'strategyId': strategy_id, - 'beginTime': convert_start_time, - 'endTime': convert_end_time, - 'accountType': account_type, - } - r = self._post(endpoint, json=payload, timeout=timeout) + endpoint = self.TRADER_ENDPOINT + '/api/v1/user/OrderList?strategyId={}&startDate={}&endDate={}'.format(strategy_id, startDate, endDate) + r = self._get(endpoint, timeout=timeout) return r.json()['data'] - def add_api_key(self, api_key, api_secret_key, exchange_id, timeout=None): + def add_api_key(self, api_key, api_secret_key, strategyId, timeout=None): """Adds all the keys of each transaction.""" - endpoint = self.TRADER_ENDPOINT + 'api/member/addApiKey' + endpoint = self.TRADER_ENDPOINT + '/api/v1/user/ApiKey' payload = { 'apiKey': api_key, 'secretKey': str(self.subkey.encrypt(pgpy.PGPMessage.new(api_secret_key))), - 'exchangeId': exchange_id, - 'apiNickname': '', - 'fixApiAssign': True, + 'strategyId': strategyId, } self._post(endpoint, json=payload, timeout=timeout) return True @@ -157,23 +118,20 @@ def add_api_key(self, api_key, api_secret_key, exchange_id, timeout=None): def get_api_key_list(self, timeout=None): """Gets API key list. """ - endpoint = self.TRADER_ENDPOINT + 'api/member/getApiKeyList' - r = self._post(endpoint, timeout=timeout) + endpoint = self.TRADER_ENDPOINT + '/api/v1/user/ApiKey' + r = self._get(endpoint, timeout=timeout) return r.json()['data'] - def delete_api_key(self, exchange_id, timeout=None): + def delete_api_key(self, strategyId, timeout=None): """Deletes all the keys of a transaction. - :param exchange_id: int + :param strategyId: int :param timeout: request timeout :return: True if api key is deleted. """ - endpoint = self.TRADER_ENDPOINT + 'api/member/deleteApiKey' - payload = { - 'exchangeId': exchange_id - } - self._post(endpoint, json=payload, timeout=timeout) + endpoint = self.TRADER_ENDPOINT + '/api/v1/user/ApiKey?strategyId={}'.format(strategyId) + self._delete(endpoint, timeout=timeout) return True - + ''' def get_account_asset(self, strategy_id, account_type='virtual', timeout=None): """Get account asset. :param strategy_id: int @@ -181,7 +139,6 @@ def get_account_asset(self, strategy_id, account_type='virtual', timeout=None): :param timeout: request timeout :return: account asset """ - endpoint = self.TRADER_ENDPOINT + 'api/trader/getAccountAsset' payload = { 'strategyId': strategy_id, @@ -189,40 +146,35 @@ def get_account_asset(self, strategy_id, account_type='virtual', timeout=None): } r = self._post(endpoint, json=payload, timeout=timeout) return r.json()['data'] - + ''' def get_exchange_symbol_list(self, exchange_id, timeout=None): """Get exchange symbol list. :param exchange_id: int :param timeout: request timeout :return: exchange symbol list """ - - endpoint = self.TRADER_ENDPOINT + 'api/common/getExchangeSymbolList' - payload = { - "exchangeId": exchange_id, - } - r = self._post(endpoint, json=payload, timeout=timeout) + endpoint = self.TRADER_ENDPOINT + '/api/v1/common/SymbolList?exchangeId={}'.format(exchange_id) + r = self._get(endpoint, timeout=timeout) return r.json()['data'] - + ''' def get_currency_list(self, timeout=None): """Get exchange symbol list. :param exchange_id: int :param timeout: request timeout :return: exchange symbol list """ - endpoint = self.TRADER_ENDPOINT + 'api/common/getCurrencyList' r = self._post(endpoint, timeout=timeout) return r.json()['data'] - + ''' def set_position(self, strategy_id, Ratio, LimitPrice, timeout=None): """Adds a market order for a specific strategy. - :param strategy_id: - :param Ratio: - :param LimitPrice: + :param strategy_id: int + :param Ratio: float + :param LimitPrice: float :return: Signal id or None if no order was created. """ - endpoint = self.SETPOSITION_ENDPOINT + endpoint = self.TRADER_ENDPOINT + '/api/v1/strategy/SetPosition' payload = { 'strategyId': strategy_id, 'Ratio': Ratio, From e7e2a77dd0dc09d9e18e8072c5b583954501d954 Mon Sep 17 00:00:00 2001 From: neal8891214 <39132539+neal8891214@users.noreply.github.com> Date: Tue, 21 May 2019 18:24:37 +0800 Subject: [PATCH 3/5] new gateway python SDK correct the output about delete api and add api --- bincentive_trader/client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bincentive_trader/client.py b/bincentive_trader/client.py index c748dd2..8a764db 100644 --- a/bincentive_trader/client.py +++ b/bincentive_trader/client.py @@ -112,8 +112,8 @@ def add_api_key(self, api_key, api_secret_key, strategyId, timeout=None): 'secretKey': str(self.subkey.encrypt(pgpy.PGPMessage.new(api_secret_key))), 'strategyId': strategyId, } - self._post(endpoint, json=payload, timeout=timeout) - return True + r = self._post(endpoint, json=payload, timeout=timeout) + return r.json()['data'] def get_api_key_list(self, timeout=None): """Gets API key list. @@ -129,8 +129,8 @@ def delete_api_key(self, strategyId, timeout=None): :return: True if api key is deleted. """ endpoint = self.TRADER_ENDPOINT + '/api/v1/user/ApiKey?strategyId={}'.format(strategyId) - self._delete(endpoint, timeout=timeout) - return True + r = self._delete(endpoint, timeout=timeout) + return r.json()['data'] ''' def get_account_asset(self, strategy_id, account_type='virtual', timeout=None): """Get account asset. From 93a85099874ceed3e468af6bedf8d2b416579b65 Mon Sep 17 00:00:00 2001 From: neal8891214 <39132539+neal8891214@users.noreply.github.com> Date: Thu, 30 May 2019 19:15:01 +0800 Subject: [PATCH 4/5] change the TRADER_ENDPOINT change the TRADER_ENDPOINT in testing = false --- bincentive_trader/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bincentive_trader/client.py b/bincentive_trader/client.py index 8a764db..fa69844 100644 --- a/bincentive_trader/client.py +++ b/bincentive_trader/client.py @@ -21,7 +21,7 @@ def __init__(self, email, password, testing=True): else: self.LOGIN_ENDPOINT = 'https://fs-api.bincentive.com/member/api/member/login' - self.TRADER_ENDPOINT = 'https://bi-gateway-go-rd.bincentive.com' + self.TRADER_ENDPOINT = 'https://bi-gateway-go-prod.bincentive.com/' self.session = requests.Session() self.session.headers = { From f76d5bc212e1958a128120ae22e404c48a824a4b Mon Sep 17 00:00:00 2001 From: neal8891214 <39132539+neal8891214@users.noreply.github.com> Date: Thu, 30 May 2019 19:29:19 +0800 Subject: [PATCH 5/5] correct the new TRADER_ENDPOINT remove '/' in the TRADER_ENDPOINT --- bincentive_trader/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bincentive_trader/client.py b/bincentive_trader/client.py index fa69844..79044a2 100644 --- a/bincentive_trader/client.py +++ b/bincentive_trader/client.py @@ -21,7 +21,7 @@ def __init__(self, email, password, testing=True): else: self.LOGIN_ENDPOINT = 'https://fs-api.bincentive.com/member/api/member/login' - self.TRADER_ENDPOINT = 'https://bi-gateway-go-prod.bincentive.com/' + self.TRADER_ENDPOINT = 'https://bi-gateway-go-prod.bincentive.com' self.session = requests.Session() self.session.headers = {