-
Notifications
You must be signed in to change notification settings - Fork 0
Hummingbot spot connector bot-api integration changes #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: genius_yield-spot-connector
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,7 +110,14 @@ def supported_order_types(self): | |
| return [OrderType.LIMIT, OrderType.LIMIT_MAKER, OrderType.MARKET] | ||
|
|
||
| async def get_all_pairs_prices(self) -> List[Dict[str, str]]: | ||
| pairs_prices = await self._api_get(path_url=CONSTANTS.TICKER_BOOK_PATH_URL) | ||
| response = await self._api_get(path_url=CONSTANTS.ALL_MARKETS_PATH_URL) | ||
| pairs_prices = [ | ||
| { | ||
| "symbol": market["market_id"], | ||
| "price": market["base_close"] | ||
| } | ||
| for market in response | ||
| ] | ||
| return pairs_prices | ||
|
|
||
| def _is_request_exception_related_to_time_synchronizer(self, request_exception: Exception): | ||
|
|
@@ -167,24 +174,20 @@ async def _place_order(self, | |
| type_str = GeniusYieldExchange.genius_yield_order_type(order_type) | ||
| side_str = CONSTANTS.SIDE_BUY if trade_type is TradeType.BUY else CONSTANTS.SIDE_SELL | ||
| symbol = await self.exchange_symbol_associated_to_pair(trading_pair=trading_pair) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs to be double checked wheter trading_pair is appropriate here. Might be correct to use asset_ticker instead |
||
| api_params = {"symbol": symbol, | ||
| "side": side_str, | ||
| "quantity": amount_str, | ||
| "type": type_str, | ||
| "newClientOrderId": order_id} | ||
| if order_type is OrderType.LIMIT or order_type is OrderType.LIMIT_MAKER: | ||
| price_str = f"{price:f}" | ||
| api_params["price"] = price_str | ||
| if order_type == OrderType.LIMIT: | ||
| api_params["timeInForce"] = CONSTANTS.TIME_IN_FORCE_GTC | ||
| api_params = { | ||
| "offer_token": symbol.split('_')[0], | ||
| "offer_amount": str(amount), | ||
| "price_token": symbol.split('_')[1], | ||
| "price_amount": str(price) | ||
| } | ||
|
|
||
| try: | ||
| order_result = await self._api_post( | ||
| path_url=CONSTANTS.ORDER_PATH_URL, | ||
| data=api_params, | ||
| is_auth_required=True) | ||
| o_id = str(order_result["orderId"]) | ||
| transact_time = order_result["transactTime"] * 1e-3 | ||
| o_id = str(order_result["transaction_id"]) | ||
| transact_time = self._time_synchronizer.time() | ||
|
Comment on lines
-186
to
+190
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to check wheter we can use tx id as means of an orders id. Contact api does not have a seperate order id field it seems. |
||
| except IOError as e: | ||
| error_description = str(e) | ||
| is_server_overloaded = ("status is 503" in error_description | ||
|
|
@@ -197,97 +200,52 @@ async def _place_order(self, | |
| return o_id, transact_time | ||
|
|
||
| async def _place_cancel(self, order_id: str, tracked_order: InFlightOrder): | ||
| symbol = await self.exchange_symbol_associated_to_pair(trading_pair=tracked_order.trading_pair) | ||
| api_params = { | ||
| "symbol": symbol, | ||
| "origClientOrderId": order_id, | ||
| "order_references": [order_id] | ||
| } | ||
| cancel_result = await self._api_delete( | ||
| path_url=CONSTANTS.ORDER_PATH_URL, | ||
| params=api_params, | ||
| path_url=CONSTANTS.CANCEL_ORDER_PATH_URL, | ||
| data=api_params, | ||
| is_auth_required=True) | ||
| if cancel_result.get("status") == "CANCELED": | ||
| if cancel_result.get("transaction_id"): | ||
| return True | ||
| return False | ||
|
|
||
| async def _format_trading_rules(self, exchange_info_dict: Dict[str, Any]) -> List[TradingRule]: | ||
| """ | ||
| Example: | ||
| { | ||
| "symbol": "ETHBTC", | ||
| "baseAssetPrecision": 8, | ||
| "quotePrecision": 8, | ||
| "orderTypes": ["LIMIT", "MARKET"], | ||
| "filters": [ | ||
| { | ||
| "filterType": "PRICE_FILTER", | ||
| "minPrice": "0.00000100", | ||
| "maxPrice": "100000.00000000", | ||
| "tickSize": "0.00000100" | ||
| }, { | ||
| "filterType": "LOT_SIZE", | ||
| "minQty": "0.00100000", | ||
| "maxQty": "100000.00000000", | ||
| "stepSize": "0.00100000" | ||
| }, { | ||
| "filterType": "MIN_NOTIONAL", | ||
| "minNotional": "0.00100000" | ||
| } | ||
| ] | ||
| } | ||
| """ | ||
| trading_pair_rules = exchange_info_dict.get("symbols", []) | ||
| trading_pair_rules = exchange_info_dict | ||
| retval = [] | ||
| for rule in filter(genius_yield_utils.is_exchange_information_valid, trading_pair_rules): | ||
| for rule in trading_pair_rules: | ||
| try: | ||
| trading_pair = await self.trading_pair_associated_to_exchange_symbol(symbol=rule.get("symbol")) | ||
| filters = rule.get("filters") | ||
| price_filter = [f for f in filters if f.get("filterType") == "PRICE_FILTER"][0] | ||
| lot_size_filter = [f for f in filters if f.get("filterType") == "LOT_SIZE"][0] | ||
| min_notional_filter = [f for f in filters if f.get("filterType") in ["MIN_NOTIONAL", "NOTIONAL"]][0] | ||
|
|
||
| min_order_size = Decimal(lot_size_filter.get("minQty")) | ||
| tick_size = price_filter.get("tickSize") | ||
| step_size = Decimal(lot_size_filter.get("stepSize")) | ||
| min_notional = Decimal(min_notional_filter.get("minNotional")) | ||
| trading_pair = combine_to_hb_trading_pair(base=rule["base_asset"], quote=rule["target_asset"]) | ||
| min_order_size = Decimal(rule["filters"]["minQty"]) | ||
| tick_size = Decimal(rule["filters"]["tickSize"]) | ||
| step_size = Decimal(rule["filters"]["stepSize"]) | ||
| min_notional = Decimal(rule["filters"]["minNotional"]) | ||
|
|
||
| retval.append( | ||
| TradingRule(trading_pair, | ||
| min_order_size=min_order_size, | ||
| min_price_increment=Decimal(tick_size), | ||
| min_base_amount_increment=Decimal(step_size), | ||
| min_notional_size=Decimal(min_notional))) | ||
| min_price_increment=tick_size, | ||
| min_base_amount_increment=step_size, | ||
| min_notional_size=min_notional)) | ||
|
|
||
| except Exception: | ||
| self.logger().exception(f"Error parsing the trading pair rule {rule}. Skipping.") | ||
| return retval | ||
|
|
||
| async def _status_polling_loop_fetch_updates(self): | ||
| await self._update_order_fills_from_trades() | ||
| await super()._status_polling_loop_fetch_updates() | ||
|
|
||
| async def _update_trading_fees(self): | ||
| """ | ||
| Update fees information from the exchange | ||
| """ | ||
| pass | ||
|
|
||
| async def _request_order_status(self, tracked_order: InFlightOrder) -> OrderUpdate: | ||
| trading_pair = await self.exchange_symbol_associated_to_pair(trading_pair=tracked_order.trading_pair) | ||
| symbol = await self.exchange_symbol_associated_to_pair(trading_pair=tracked_order.trading_pair) | ||
|
Comment on lines
-276
to
+237
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again might be more appropriate to use ticker here |
||
| updated_order_data = await self._api_get( | ||
| path_url=CONSTANTS.ORDER_PATH_URL, | ||
| params={ | ||
| "symbol": trading_pair, | ||
| "origClientOrderId": tracked_order.client_order_id}, | ||
| path_url=f"{CONSTANTS.ORDER_PATH_URL}/{tracked_order.exchange_order_id}", | ||
| is_auth_required=True) | ||
|
|
||
| new_state = CONSTANTS.ORDER_STATE[updated_order_data["status"]] | ||
|
|
||
| order_update = OrderUpdate( | ||
| client_order_id=tracked_order.client_order_id, | ||
| exchange_order_id=str(updated_order_data["orderId"]), | ||
| exchange_order_id=str(updated_order_data["transaction_id"]), | ||
| trading_pair=tracked_order.trading_pair, | ||
| update_timestamp=updated_order_data["updateTime"] * 1e-3, | ||
| update_timestamp=self._time_synchronizer.time(), | ||
| new_state=new_state, | ||
| ) | ||
|
|
||
|
|
@@ -301,11 +259,10 @@ async def _update_balances(self): | |
| path_url=CONSTANTS.ACCOUNTS_PATH_URL, | ||
| is_auth_required=True) | ||
|
|
||
| balances = account_info["balances"] | ||
| for balance_entry in balances: | ||
| asset_name = balance_entry["asset"] | ||
| free_balance = Decimal(balance_entry["free"]) | ||
| total_balance = Decimal(balance_entry["free"]) + Decimal(balance_entry["locked"]) | ||
| balances = account_info | ||
| for asset_name, balance in balances.items(): | ||
| free_balance = Decimal(balance) | ||
| total_balance = free_balance | ||
| self._account_available_balances[asset_name] = free_balance | ||
| self._account_balances[asset_name] = total_balance | ||
| remote_asset_names.add(asset_name) | ||
|
|
@@ -317,14 +274,14 @@ async def _update_balances(self): | |
|
|
||
| def _initialize_trading_pair_symbols_from_exchange_info(self, exchange_info: Dict[str, Any]): | ||
| mapping = bidict() | ||
| for symbol_data in filter(genius_yield_utils.is_exchange_information_valid, exchange_info["symbols"]): | ||
| mapping[symbol_data["symbol"]] = combine_to_hb_trading_pair(base=symbol_data["baseAsset"], | ||
| quote=symbol_data["quoteAsset"]) | ||
| for symbol_data in exchange_info: | ||
| mapping[symbol_data["market_id"]] = combine_to_hb_trading_pair(base=symbol_data["base_asset"], | ||
| quote=symbol_data["target_asset"]) | ||
| self._set_trading_pair_symbol_map(mapping) | ||
|
|
||
| async def _get_last_traded_price(self, trading_pair: str) -> float: | ||
| params = { | ||
| "symbol": await self.exchange_symbol_associated_to_pair(trading_pair=trading_pair) | ||
| "market-id": await self.exchange_symbol_associated_to_pair(trading_pair=trading_pair) | ||
| } | ||
|
|
||
| resp_json = await self._api_request( | ||
|
|
@@ -333,4 +290,5 @@ async def _get_last_traded_price(self, trading_pair: str) -> float: | |
| params=params | ||
| ) | ||
|
|
||
| return float(resp_json["lastPrice"]) | ||
| return float(resp_json["price"]) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to verify wheter we can map symbol to market_id