Skip to content

Commit

Permalink
Merge branch 'development' into feat/avellaneda_stoikov
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasbaum authored Apr 1, 2021
2 parents f68d76b + 6ccb628 commit 87eabd5
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 34 deletions.
9 changes: 6 additions & 3 deletions hummingbot/client/command/config_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,12 @@ async def inventory_price_prompt(
exchange = config_map["exchange"].value
market = config_map["market"].value
base_asset, quote_asset = market.split("-")
balances = await UserBalances.instance().balances(
exchange, base_asset, quote_asset
)
if global_config_map["paper_trade_enabled"].value:
balances = global_config_map["paper_trade_account_balance"].value
else:
balances = await UserBalances.instance().balances(
exchange, base_asset, quote_asset
)
if balances.get(base_asset) is None:
return

Expand Down
3 changes: 3 additions & 0 deletions hummingbot/client/command/create_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ async def prompt_a_config(self, # type: HummingbotApplication
config: ConfigVar,
input_value=None,
assign_default=True):
if config.key == "inventory_price":
await self.inventory_price_prompt(self.strategy_config_map, input_value)
return
if input_value is None:
if assign_default:
self.app.set_text(parse_config_default_to_text(config))
Expand Down
2 changes: 1 addition & 1 deletion hummingbot/client/config/config_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def get_erc20_token_addresses() -> Dict[str, List]:
address_file_path = TOKEN_ADDRESSES_FILE_PATH
token_list = {}

resp = requests.get(token_list_url, timeout=3)
resp = requests.get(token_list_url, timeout=1)
decoded_resp = resp.json()

for token in decoded_resp["tokens"]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ async def _user_stream_event_listener(self):
update_data = event_message.get("a", {})
event_reason = update_data.get("m", {})
if event_reason == "FUNDING_FEE":
await self.get_funding_payment(event_message.get("E", int(time.time())))
await self.get_funding_payment()
else:
# update balances
for asset in update_data.get("B", []):
Expand Down Expand Up @@ -933,7 +933,7 @@ async def get_funding_payment(self):
funding_payment_tasks = []
for pair in self._trading_pairs:
funding_payment_tasks.append(self.request(path="/fapi/v1/income",
params={"symbol": convert_to_exchange_trading_pair(pair), "incomeType": "FUNDING_FEE", "limit": 1},
params={"symbol": convert_to_exchange_trading_pair(pair), "incomeType": "FUNDING_FEE", "limit": len(self._account_positions)},
method=MethodType.POST,
add_timestamp=True,
is_signed=True))
Expand Down
28 changes: 14 additions & 14 deletions hummingbot/connector/exchange/beaxy/beaxy_exchange.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ cdef class BeaxyExchange(ExchangeBase):
tracked_order.last_state = order_update['order_status']

if order_update['filled_size']:
execute_price = Decimal(order_update['limit_price'] if order_update['limit_price'] else order_update['average_price'])
execute_amount_diff = Decimal(order_update['filled_size']) - tracked_order.executed_amount_base
execute_price = Decimal(str(order_update['limit_price'] if order_update['limit_price'] else order_update['average_price']))
execute_amount_diff = Decimal(str(order_update['filled_size'])) - tracked_order.executed_amount_base

# Emit event if executed amount is greater than 0.
if execute_amount_diff > s_decimal_0:
Expand Down Expand Up @@ -398,9 +398,9 @@ cdef class BeaxyExchange(ExchangeBase):
if tracked_order.is_done:
if not tracked_order.is_failure and not tracked_order.is_cancelled:

new_confirmed_amount = Decimal(order_update['size'])
new_confirmed_amount = Decimal(str(order_update['size']))
execute_amount_diff = new_confirmed_amount - tracked_order.executed_amount_base
execute_price = Decimal(order_update['limit_price'] if order_update['limit_price'] else order_update['average_price'])
execute_price = Decimal(str(order_update['limit_price'] if order_update['limit_price'] else order_update['average_price']))

# Emit event if executed amount is greater than 0.
if execute_amount_diff > s_decimal_0:
Expand Down Expand Up @@ -748,8 +748,8 @@ cdef class BeaxyExchange(ExchangeBase):
res = await self._api_request('get', BeaxyConstants.TradingApi.TRADE_SETTINGS_ENDPOINT)
for symbol_data in res['symbols']:
symbol = self.convert_from_exchange_trading_pair(symbol_data['name'])
self._maker_fee_percentage[symbol] = Decimal(symbol_data['maker_fee'])
self._taker_fee_percentage[symbol] = Decimal(symbol_data['taker_fee'])
self._maker_fee_percentage[symbol] = Decimal(str(symbol_data['maker_fee']))
self._taker_fee_percentage[symbol] = Decimal(str(symbol_data['taker_fee']))

self._last_fee_percentage_update_timestamp = current_timestamp
except asyncio.CancelledError:
Expand All @@ -774,8 +774,8 @@ cdef class BeaxyExchange(ExchangeBase):

for balance_entry in account_balances:
asset_name = balance_entry['currency']
available_balance = Decimal(balance_entry['available_balance'])
total_balance = Decimal(balance_entry['total_balance'])
available_balance = Decimal(str(balance_entry['available_balance']))
total_balance = Decimal(str(balance_entry['total_balance']))
self._account_available_balances[asset_name] = available_balance
self._account_balances[asset_name] = total_balance
remote_asset_names.add(asset_name)
Expand Down Expand Up @@ -855,8 +855,8 @@ cdef class BeaxyExchange(ExchangeBase):

for msg in msgs:
asset_name = msg['currency']
available_balance = Decimal(msg['available_balance'])
total_balance = Decimal(msg['total_balance'])
available_balance = Decimal(str(msg['available_balance']))
total_balance = Decimal(str(msg['total_balance']))
self._account_available_balances[asset_name] = available_balance
self._account_balances[asset_name] = total_balance

Expand All @@ -882,8 +882,8 @@ cdef class BeaxyExchange(ExchangeBase):
execute_amount_diff = s_decimal_0

if order_status == 'partially_filled':
order_filled_size = Decimal(order['trade_size'])
execute_price = Decimal(order['trade_price'])
order_filled_size = Decimal(str(order['trade_size']))
execute_price = Decimal(str(order['trade_price']))

execute_amount_diff = order_filled_size - tracked_order.executed_amount_base

Expand Down Expand Up @@ -917,9 +917,9 @@ cdef class BeaxyExchange(ExchangeBase):

elif order_status == 'completely_filled':

new_confirmed_amount = Decimal(order['size'])
new_confirmed_amount = Decimal(str(order['size']))
execute_amount_diff = new_confirmed_amount - tracked_order.executed_amount_base
execute_price = Decimal(order['limit_price'] if order['limit_price'] else order['average_price'])
execute_price = Decimal(str(order['limit_price'] if order['limit_price'] else order['average_price']))

# Emit event if executed amount is greater than 0.
if execute_amount_diff > s_decimal_0:
Expand Down
22 changes: 11 additions & 11 deletions hummingbot/core/utils/trading_pair_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
Any,
Optional,
)
from hummingbot.core.utils.async_utils import safe_gather
from hummingbot.logger import HummingbotLogger
from hummingbot.client.settings import CONNECTOR_SETTINGS, ConnectorType
import logging
import asyncio
import requests

from .async_utils import safe_ensure_future

Expand All @@ -35,6 +35,8 @@ def __init__(self):
safe_ensure_future(self.fetch_all())

async def fetch_all(self):
tasks = []
fetched_connectors = []
for conn_setting in CONNECTOR_SETTINGS.values():
module_name = f"{conn_setting.base_name()}_connector" if conn_setting.type is ConnectorType.Connector \
else f"{conn_setting.base_name()}_api_order_book_data_source"
Expand All @@ -46,15 +48,13 @@ async def fetch_all(self):
module = getattr(importlib.import_module(module_path), class_name)
args = {}
args = conn_setting.add_domain_parameter(args)
safe_ensure_future(self.call_fetch_pairs(module.fetch_trading_pairs(**args), conn_setting.name))
tasks.append(asyncio.wait_for(asyncio.shield(module.fetch_trading_pairs(**args)), timeout=3))
fetched_connectors.append(conn_setting.name)

self.ready = True

async def call_fetch_pairs(self, fetch_fn, exchange_name):
results = await safe_gather(*tasks, return_exceptions=True)
self.trading_pairs = dict(zip(fetched_connectors, results))
# In case trading pair fetching returned timeout, using empty list
try:
self.trading_pairs[exchange_name] = await fetch_fn
except (asyncio.TimeoutError, asyncio.CancelledError, requests.exceptions.RequestException):
self.logger().error(f"Connector {exchange_name} failed to retrieve its trading pairs. "
f"Trading pairs autocompletion won't work.")
self.trading_pairs[exchange_name] = []
for connector, result in self.trading_pairs.items():
if isinstance(result, asyncio.TimeoutError):
self.trading_pairs[connector] = []
self.ready = True
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def validate_price_floor_ceiling(value: str) -> Optional[str]:
return "Value must be more than 0 or -1 to disable this feature."


def on_validated_price_type(value: str):
if value == 'inventory_cost':
pure_market_making_config_map["inventory_price"].value = None


def exchange_on_validated(value: str):
required_exchanges.append(value)

Expand Down Expand Up @@ -241,6 +246,7 @@ def exchange_on_validated(value: str):
prompt="What is the price of your base asset inventory? ",
type_str="decimal",
validator=lambda v: validate_decimal(v, min_value=Decimal("0"), inclusive=True),
required_if=lambda: pure_market_making_config_map.get("price_type").value == "inventory_cost",
default=Decimal("1"),
),
"filled_order_delay":
Expand Down Expand Up @@ -308,6 +314,7 @@ def exchange_on_validated(value: str):
type_str="str",
required_if=lambda: pure_market_making_config_map.get("price_source").value != "custom_api",
default="mid_price",
on_validated=on_validated_price_type,
validator=lambda s: None if s in {"mid_price",
"last_price",
"last_own_trade_price",
Expand Down
3 changes: 0 additions & 3 deletions hummingbot/templates/conf_fee_overrides_TEMPLATE.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ balancer_taker_fee_amount:
uniswap_maker_fee_amount:
uniswap_taker_fee_amount:

bitmax_maker_fee:
bitmax_taker_fee:

ascend_ex_maker_fee:
ascend_ex_taker_fee:

Expand Down
12 changes: 12 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

from setuptools import setup
from setuptools.command.build_ext import build_ext
from Cython.Build import cythonize
import numpy as np
import os
Expand All @@ -17,6 +18,16 @@
os.environ["CFLAGS"] = "-std=c++11"


# Avoid a gcc warning below:
# cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid
# for C/ObjC but not for C++
class BuildExt(build_ext):
def build_extensions(self):
if '-Wstrict-prototypes' in self.compiler.compiler_so:
self.compiler.compiler_so.remove('-Wstrict-prototypes')
super().build_extensions()


def main():
cpu_count = os.cpu_count() or 8
version = "20210309"
Expand Down Expand Up @@ -165,6 +176,7 @@ def main():
"bin/hummingbot.py",
"bin/hummingbot_quickstart.py"
],
cmdclass={'build_ext': BuildExt},
)


Expand Down

0 comments on commit 87eabd5

Please sign in to comment.