diff --git a/README.md b/README.md
index cf33539..09f5e46 100644
--- a/README.md
+++ b/README.md
@@ -25,179 +25,26 @@ exception if no response is received in the specified seconds.
## Bincentive Client Methods
Bincentive Trader Client
-**Kind**: global class
+
-* [BincentiveClient](#BincentiveClient)
-
- * [.get_strategy_list(timeout=None)](#BincentiveClient+get_strategy_list)
- * [.get_exchange_list(timeout=None)](#BincentiveClient+get_exchange_list)
- * [.add_market_order(strategy_id, exchange_id, base_currency, quote_currency, side, amount, leverage=None, timeout=None)](#BincentiveClient+add_market_order)
- * [.get_history_list(strategy_id, begin_time, end_time, account_type='real', timeout=None)](#BincentiveClient+get_history_list)
- * [.add_api_key(api_key, api_secret_key, exchange_id, timeout=None)](#BincentiveClient+add_api_key)
- * [.get_api_key_list(timeout=None)](#BincentiveClient+get_api_key_list)
- * [.delete_api_key(exchange_id, timeout=None)](#BincentiveClient+delete_api_key)
- * [.get_account_asset(self, strategy_id, account_type='virtual', timeout=None)](#BincentiveClient+get_account_asset)
- * [.get_exchange_symbol_list(self, exchange_id, timeout=None)](#BincentiveClient+get_exchange_symbol_list)
- * [.get_currency_list(self, timeout=None)](#BincentiveClient+get_currency_list)
-
-
-
-
-
-
-### bincentiveClient.get_strategy_list(timeout=None)
-Gets the list of strategies
-
-**Kind**: instance method of [BincentiveClient](#BincentiveClient)
-
-
-
-
-### bincentiveClient.get_exchange_list(timeout=None)
-Gets the list of exchanges
-
-**Kind**: instance method of [BincentiveClient](#BincentiveClient)
-
-
-
-### bincentiveClient.add_market_order(strategy_id, exchange_id, base_currency, quote_currency, side, amount, leverage=None, timeout=None)
-Adds an order for a specific strategy
-
-**Kind**: instance method of [BincentiveClient](#BincentiveClient)
-
-| Param | Type |
-| --- | --- |
-| strategy_id | number |
-| exchange_id | number |
-| base_currency | string |
-| quote_currency | string |
-| side | string |
-| amount | number |
-| leverage | number |
-
-
-
-
-### bincentiveClient.get_history_list(strategy_id, begin_time, end_time, account_type='real')
-Gets the historical data of all transactions
-
-**Kind**: instance method of [BincentiveClient](#BincentiveClient)
-
-| Param | Type |
-| --- | --- |
-| strategy_id | number |
-| begin_time | datetime |
-| end_time | datetime |
-| account_type | string |
-
-account_type description:
- - 'virtual' means signal send to bincentive
- - 'real' means order send to exchange
-
-sample code
-
-```python
-import pytz
-from datetime import datetime
-us = pytz.timezone('US/Pacific')
-begin = datetime(2019, 1, 1, 6, 0, 0).replace(tzinfo=us)
-end = datetime.now().replace(tzinfo=us)
-strategy_id = 100342
-history = client.get_history_list(strategy_id, begin, end)
-
-```
-
-
-
-### bincentiveClient.add_api_key(api_key, api_secret_key, exchange_id, timeout=None)
-Adds all the keys of each transaction
-
-**Kind**: instance method of [BincentiveClient](#BincentiveClient)
-
-| Param | Type |
-| --- | --- |
-| api_key | string |
-| api_secret_key | string |
-| exchange_id | number |
-
-
-
-
-### bincentiveClient.get_api_key_list(timeout=None)
-Gets API key list
-
-**Kind**: instance method of [BincentiveClient](#BincentiveClient)
-
-
-
-### bincentiveClient.delete_api_key(exchange_id, timeout=None)
-Deletes all the keys of a transaction
-
-**Kind**: instance method of [BincentiveClient](#BincentiveClient)
-
-| Param | Type |
-| --- | --- |
-| exchangeId | number |
-
-
-
-
-### bincentiveClient.get_account_asset(self, strategy_id, account_type='virtual', timeout=None)
-Gets the historical data of account asset
+### bincentiveClient.set_position(self, strategy_id, Ratio, LimitPrice, timeout=None)
+Set a position ratio for a specific strategy to send the order
**Kind**: instance method of [BincentiveClient](#BincentiveClient)
| Param | Type |
| --- | --- |
| strategy_id | number |
-| account_type | string |
-
-account_type description:
- - 'virtual' means signal send to bincentive
- - 'real' means order send to exchange
+| Ratio | number |
+| LimitPrice | number |
sample code
```python
-strategy_id = 100342
-account_asset = client.get_account_asset(strategy_id)
-
-```
+stgy_id = your_strategy_id
+r = 0.3
-
-
-### bincentiveClient.get_exchange_symbol_list(self, exchange_id, timeout=None)
-Gets all symbol of the exchange
-
-**Kind**: instance method of [BincentiveClient](#BincentiveClient)
-
-| Param | Type |
-| --- | --- |
-| exchange_id | number |
-
-
-sample code
-
-```python
-exchange_id = 3
-exchange_symbol = client.get_exchange_symbol_list(exchange_id)
-
-```
-
-
-
-### bincentiveClient.get_currency_list(self, timeout=None)
-Gets the currency_id corresponding currency_name
-
-**Kind**: instance method of [BincentiveClient](#BincentiveClient)
-
-
-sample code
-
-```python
-
-currency_list = client.get_currency_list()
-
-```
+order_id = client.set_position(strategy_id=stgy_id, Ratio=r, LimitPrice=1)
+```
\ No newline at end of file
diff --git a/bincentive_trader/client.py b/bincentive_trader/client.py
index aa38c0e..c748dd2 100644
--- a/bincentive_trader/client.py
+++ b/bincentive_trader/client.py
@@ -17,10 +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.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 = {
@@ -69,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
@@ -156,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
@@ -180,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,
@@ -188,29 +146,43 @@ 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: int
+ :param Ratio: float
+ :param LimitPrice: float
+ :return: Signal id or None if no order was created.
+ """
+ endpoint = self.TRADER_ENDPOINT + '/api/v1/strategy/SetPosition'
+ 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