Skip to content

Commit

Permalink
Merge branch 'development' into feat/smart_round_for_prices_in_amm_ar…
Browse files Browse the repository at this point in the history
…b_status_dict
  • Loading branch information
dennisocana authored Apr 6, 2021
2 parents e627495 + 91ebd05 commit e35e2eb
Show file tree
Hide file tree
Showing 31 changed files with 3,036 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ We created hummingbot to promote **decentralized market-making**: enabling membe
| <img src="assets/bitfinex_logo.png" alt="Bitfinex" width="90" /> | bitfinex | [Bitfinex](https://www.bitfinex.com/) | 2 | [API](https://docs.bitfinex.com/docs/introduction) |![YELLOW](https://via.placeholder.com/15/ffff00/?text=+) |
| <img src="assets/blocktane_logo.png" alt="Blocktane" width="90" /> | blocktane | [Blocktane](https://blocktane.io/) | 2 | [API](https://blocktane.io/api) |![GREEN](https://via.placeholder.com/15/008000/?text=+) |
| <img src="https://i.ibb.co/h9JdGDW/cbp.jpg" alt="Coinbase Pro" width="90" /> | coinbase_pro | [Coinbase Pro](https://pro.coinbase.com/) | * | [API](https://docs.pro.coinbase.com/) |![GREEN](https://via.placeholder.com/15/008000/?text=+) |
| <img src="assets/coinzoom_logo.svg" alt="CoinZoom" width="90" /> | coinzoom | [CoinZoom](https://trade.coinzoom.com/landing) | * | [API](https://api-docs.coinzoom.com/) |![YELLOW](https://via.placeholder.com/15/ffff00/?text=+) |
| <img src="assets/cryptocom_logo.png" alt="Crypto.com" width="90" /> | crypto_com | [Crypto.com](https://crypto.com/exchange) | 2 | [API](https://exchange-docs.crypto.com/#introduction) |![YELLOW](https://via.placeholder.com/15/ffff00/?text=+) |
| <img src="assets/dydx_logo.png" alt="DyDx" width="90" /> | dydx | [dy/dx](https://dydx.exchange/) | 1 | [API](https://docs.dydx.exchange/) |![GREEN](https://via.placeholder.com/15/008000/?text=+) |
| <img src="assets/eterbase_logo.png" alt="Eterbase" width="90" /> | eterbase | [Eterbase](https://www.eterbase.com/) | * | [API](https://developers.eterbase.exchange/?version=latest) |![RED](https://via.placeholder.com/15/f03c15/?text=+) |
Expand Down
16 changes: 16 additions & 0 deletions assets/coinzoom_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@
hitbtc_api_key = os.getenv("HITBTC_API_KEY")
hitbtc_secret_key = os.getenv("HITBTC_SECRET_KEY")
# CoinZoom Test
coinzoom_api_key = os.getenv("COINZOOM_API_KEY")
coinzoom_secret_key = os.getenv("COINZOOM_SECRET_KEY")
coinzoom_username = os.getenv("COINZOOM_USERNAME")
# Wallet Tests
test_erc20_token_address = os.getenv("TEST_ERC20_TOKEN_ADDRESS")
web3_test_private_key_a = os.getenv("TEST_WALLET_PRIVATE_KEY_A")
Expand Down
1 change: 1 addition & 0 deletions hummingbot/connector/connector_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'blocktane': 'green',
'celo': 'green',
'coinbase_pro': 'green',
'coinzoom': 'yellow',
'crypto_com': 'yellow',
'dydx': 'green',
'eterbase': 'red',
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# distutils: language=c++
cimport numpy as np

cdef class CoinzoomActiveOrderTracker:
cdef dict _active_bids
cdef dict _active_asks
cdef dict _active_asks_ids
cdef dict _active_bids_ids

cdef tuple c_convert_diff_message_to_np_arrays(self, object message)
cdef tuple c_convert_snapshot_message_to_np_arrays(self, object message)
# This method doesn't seem to be used anywhere at all
# cdef np.ndarray[np.float64_t, ndim=1] c_convert_trade_message_to_np_array(self, object message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# distutils: language=c++
# distutils: sources=hummingbot/core/cpp/OrderBookEntry.cpp
import logging
import numpy as np
from decimal import Decimal
from typing import Dict
from hummingbot.logger import HummingbotLogger
from hummingbot.core.data_type.order_book_row import OrderBookRow

_logger = None
s_empty_diff = np.ndarray(shape=(0, 4), dtype="float64")
CoinzoomOrderBookTrackingDictionary = Dict[Decimal, Dict[str, Dict[str, any]]]

cdef class CoinzoomActiveOrderTracker:
def __init__(self,
active_asks: CoinzoomOrderBookTrackingDictionary = None,
active_bids: CoinzoomOrderBookTrackingDictionary = None):
super().__init__()
self._active_asks = active_asks or {}
self._active_bids = active_bids or {}
self._active_asks_ids = {}
self._active_bids_ids = {}

@classmethod
def logger(cls) -> HummingbotLogger:
global _logger
if _logger is None:
_logger = logging.getLogger(__name__)
return _logger

@property
def active_asks(self) -> CoinzoomOrderBookTrackingDictionary:
return self._active_asks

@property
def active_bids(self) -> CoinzoomOrderBookTrackingDictionary:
return self._active_bids

# TODO: research this more
def volume_for_ask_price(self, price) -> float:
return NotImplementedError

# TODO: research this more
def volume_for_bid_price(self, price) -> float:
return NotImplementedError

def get_rates_and_quantities(self, entry) -> tuple:
# price, quantity
return float(entry[0]), float(entry[1])

def get_rates_and_amts_with_ids(self, entry, id_list) -> tuple:
if len(entry) > 1:
price = float(entry[1])
amount = float(entry[2])
id_list[str(entry[0])] = price
else:
price = id_list.get(str(entry[0]))
amount = 0.0
return price, amount

cdef tuple c_convert_diff_message_to_np_arrays(self, object message):
cdef:
dict content = message.content
list content_keys = list(content.keys())
list bid_entries = []
list ask_entries = []
str order_id
str order_side
str price_raw
object price
dict order_dict
double timestamp = message.timestamp
double amount = 0
dict nps = {'bids': s_empty_diff, 'asks': s_empty_diff}

if "b" in content_keys:
bid_entries = content["b"]
if "s" in content_keys:
ask_entries = content["s"]

for entries, diff_key, id_list in [
(bid_entries, 'bids', self._active_bids_ids),
(ask_entries, 'asks', self._active_asks_ids)
]:
if len(entries) > 0:
nps[diff_key] = np.array(
[[timestamp, price, amount, message.update_id]
for price, amount in [self.get_rates_and_amts_with_ids(entry, id_list) for entry in entries]
if price is not None],
dtype="float64", ndmin=2
)
return nps['bids'], nps['asks']

cdef tuple c_convert_snapshot_message_to_np_arrays(self, object message):
cdef:
float price
float amount
str order_id
dict order_dict

# Refresh all order tracking.
self._active_bids.clear()
self._active_asks.clear()
timestamp = message.timestamp
content = message.content
content_keys = list(content.keys())

if "bids" in content_keys:
for snapshot_orders, active_orders in [(content["bids"], self._active_bids), (content["asks"], self._active_asks)]:
for entry in snapshot_orders:
price, amount = self.get_rates_and_quantities(entry)
active_orders[price] = amount
else:
for snapshot_orders, active_orders, active_order_ids in [
(content["b"], self._active_bids, self._active_bids_ids),
(content["s"], self._active_asks, self._active_asks_ids)
]:
for entry in snapshot_orders:
price, amount = self.get_rates_and_amts_with_ids(entry, active_order_ids)
active_orders[price] = amount

# Return the sorted snapshot tables.
cdef:
np.ndarray[np.float64_t, ndim=2] bids = np.array(
[[message.timestamp, float(price), float(self._active_bids[price]), message.update_id]
for price in sorted(self._active_bids.keys())], dtype='float64', ndmin=2)
np.ndarray[np.float64_t, ndim=2] asks = np.array(
[[message.timestamp, float(price), float(self._active_asks[price]), message.update_id]
for price in sorted(self._active_asks.keys(), reverse=True)], dtype='float64', ndmin=2)

if bids.shape[1] != 4:
bids = bids.reshape((0, 4))
if asks.shape[1] != 4:
asks = asks.reshape((0, 4))

return bids, asks

# This method doesn't seem to be used anywhere at all
# cdef np.ndarray[np.float64_t, ndim=1] c_convert_trade_message_to_np_array(self, object message):
# cdef:
# double trade_type_value = 1.0 if message.content[4] == "BUY" else 2.0
# list content = message.content

# return np.array([message.timestamp, trade_type_value, float(content[1]), float(content[2])],
# dtype="float64")

def convert_diff_message_to_order_book_row(self, message):
np_bids, np_asks = self.c_convert_diff_message_to_np_arrays(message)
bids_row = [OrderBookRow(price, qty, update_id) for ts, price, qty, update_id in np_bids]
asks_row = [OrderBookRow(price, qty, update_id) for ts, price, qty, update_id in np_asks]
return bids_row, asks_row

def convert_snapshot_message_to_order_book_row(self, message):
np_bids, np_asks = self.c_convert_snapshot_message_to_np_arrays(message)
bids_row = [OrderBookRow(price, qty, update_id) for ts, price, qty, update_id in np_bids]
asks_row = [OrderBookRow(price, qty, update_id) for ts, price, qty, update_id in np_asks]
return bids_row, asks_row
Loading

0 comments on commit e35e2eb

Please sign in to comment.