Skip to content

Commit

Permalink
Merge branch 'development' into feat/optimize_protocol_endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
vic-en authored Mar 31, 2021
2 parents 7524959 + cf1c10f commit 21b7186
Show file tree
Hide file tree
Showing 30 changed files with 251 additions and 239 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ We created hummingbot to promote **decentralized market-making**: enabling membe

| logo | id | name | ver | doc | status |
|:---:|:---:|:---:|:---:|:---:|:---:|
| <img src="assets/ascend_ex_logo.png" alt="AscendEx" width="90" /> | ascend_ex | [AscendEx](https://ascendex.com/en/global-digital-asset-platform) | 1 | [API](https://ascendex.github.io/ascendex-pro-api/#ascendex-pro-api-documentation) |![GREEN](https://via.placeholder.com/15/008000/?text=+) |
| <img src="assets/beaxy_logo.png" alt="Beaxy" width="90" /> | beaxy | [Beaxy](https://beaxy.com/) | 2 | [API](https://beaxyapiv2trading.docs.apiary.io/) |![YELLOW](https://via.placeholder.com/15/ffff00/?text=+) |
| <img src="https://i.ibb.co/m0YDQLd/Screen-Shot-2019-03-14-at-10-53-42-AM.png" alt="Binance" width="90" /> | binance | [Binance](https://www.binance.com/) | 3 | [API](https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md) |![GREEN](https://via.placeholder.com/15/008000/?text=+) |
| <img src="assets/binanceus_logo.png" alt="Binance US" width="90" /> | binance_us | [Binance US](https://www.binance.com/) | 3 | [API](https://github.com/binance-us/binance-official-api-docs/blob/master/rest-api.md) |![YELLOW](https://via.placeholder.com/15/ffff00/?text=+) |
| <img src="assets/binance_perpetual_logo.png" alt="Binance Perpetual" width="90" /> | binance_perpetual | [Binance Futures](https://www.binance.com/) | 1 | [API](https://binance-docs.github.io/apidocs/futures/en/) |![GREEN](https://via.placeholder.com/15/008000/?text=+) |
|<img src="assets/bittrex_logo.png" alt="Bittrex Global" width="90" height="30" />| bittrex | [Bittrex Global](https://global.bittrex.com/) | 3 | [API](https://bittrex.github.io/api/v3) |![YELLOW](https://via.placeholder.com/15/ffff00/?text=+) |
| <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/bitmax_logo.png" alt="BitMax" width="90" /> | bitmax | [BitMax](https://bitmax.io/en/global-digital-asset-platform) | 1 | [API](https://bitmax-exchange.github.io/bitmax-pro-api/#bitmax-pro-api-documentation) |![GREEN](https://via.placeholder.com/15/008000/?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/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=+) |
Expand Down
Binary file added assets/ascend_ex_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/bitmax_logo.png
Binary file not shown.
2 changes: 1 addition & 1 deletion hummingbot/connector/connector_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'binance_perpetual_testnet': 'green',
'binance_us': 'yellow',
'bitfinex': 'yellow',
'bitmax': 'green',
'ascend_ex': 'green',
'bittrex': 'yellow',
'blocktane': 'green',
'celo': 'green',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# distutils: language=c++
cimport numpy as np

cdef class BitmaxActiveOrderTracker:
cdef class AscendExActiveOrderTracker:
cdef dict _active_bids
cdef dict _active_asks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ from hummingbot.core.data_type.order_book_row import OrderBookRow

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

cdef class BitmaxActiveOrderTracker:
cdef class AscendExActiveOrderTracker:
def __init__(self,
active_asks: BitmaxOrderBookTrackingDictionary = None,
active_bids: BitmaxOrderBookTrackingDictionary = None):
active_asks: AscendExOrderBookTrackingDictionary = None,
active_bids: AscendExOrderBookTrackingDictionary = None):
super().__init__()
self._active_asks = active_asks or {}
self._active_bids = active_bids or {}
Expand All @@ -30,11 +30,11 @@ cdef class BitmaxActiveOrderTracker:
return _logger

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

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

# TODO: research this more
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
from hummingbot.core.data_type.order_book_tracker_data_source import OrderBookTrackerDataSource
from hummingbot.core.utils.async_utils import safe_gather
from hummingbot.logger import HummingbotLogger
from hummingbot.connector.exchange.bitmax.bitmax_active_order_tracker import BitmaxActiveOrderTracker
from hummingbot.connector.exchange.bitmax.bitmax_order_book import BitmaxOrderBook
from hummingbot.connector.exchange.bitmax.bitmax_utils import convert_from_exchange_trading_pair, convert_to_exchange_trading_pair
from hummingbot.connector.exchange.bitmax.bitmax_constants import EXCHANGE_NAME, REST_URL, WS_URL, PONG_PAYLOAD
from hummingbot.connector.exchange.ascend_ex.ascend_ex_active_order_tracker import AscendExActiveOrderTracker
from hummingbot.connector.exchange.ascend_ex.ascend_ex_order_book import AscendExOrderBook
from hummingbot.connector.exchange.ascend_ex.ascend_ex_utils import convert_from_exchange_trading_pair, convert_to_exchange_trading_pair
from hummingbot.connector.exchange.ascend_ex.ascend_ex_constants import EXCHANGE_NAME, REST_URL, WS_URL, PONG_PAYLOAD


class BitmaxAPIOrderBookDataSource(OrderBookTrackerDataSource):
class AscendExAPIOrderBookDataSource(OrderBookTrackerDataSource):
MAX_RETRIES = 20
MESSAGE_TIMEOUT = 30.0
SNAPSHOT_TIMEOUT = 10.0
Expand Down Expand Up @@ -105,13 +105,13 @@ async def get_order_book_data(trading_pair: str) -> Dict[str, any]:
async def get_new_order_book(self, trading_pair: str) -> OrderBook:
snapshot: Dict[str, Any] = await self.get_order_book_data(trading_pair)
snapshot_timestamp: float = snapshot.get("data").get("ts")
snapshot_msg: OrderBookMessage = BitmaxOrderBook.snapshot_message_from_exchange(
snapshot_msg: OrderBookMessage = AscendExOrderBook.snapshot_message_from_exchange(
snapshot.get("data"),
snapshot_timestamp,
metadata={"trading_pair": trading_pair}
)
order_book = self.order_book_create_function()
active_order_tracker: BitmaxActiveOrderTracker = BitmaxActiveOrderTracker()
active_order_tracker: AscendExActiveOrderTracker = AscendExActiveOrderTracker()
bids, asks = active_order_tracker.convert_snapshot_message_to_order_book_row(snapshot_msg)
order_book.apply_snapshot(bids, asks, snapshot_msg.update_id)
return order_book
Expand Down Expand Up @@ -141,7 +141,7 @@ async def listen_for_trades(self, ev_loop: asyncio.BaseEventLoop, output: asynci

for trade in msg.get("data"):
trade_timestamp: int = trade.get("ts")
trade_msg: OrderBookMessage = BitmaxOrderBook.trade_message_from_exchange(
trade_msg: OrderBookMessage = AscendExOrderBook.trade_message_from_exchange(
trade,
trade_timestamp,
metadata={"trading_pair": trading_pair}
Expand Down Expand Up @@ -181,7 +181,7 @@ async def listen_for_order_book_diffs(self, ev_loop: asyncio.BaseEventLoop, outp

msg_timestamp: int = msg.get("data").get("ts")
trading_pair: str = convert_from_exchange_trading_pair(msg.get("symbol"))
order_book_message: OrderBookMessage = BitmaxOrderBook.diff_message_from_exchange(
order_book_message: OrderBookMessage = AscendExOrderBook.diff_message_from_exchange(
msg.get("data"),
msg_timestamp,
metadata={"trading_pair": trading_pair}
Expand All @@ -207,7 +207,7 @@ async def listen_for_order_book_snapshots(self, ev_loop: asyncio.BaseEventLoop,
try:
snapshot: Dict[str, any] = await self.get_order_book_data(trading_pair)
snapshot_timestamp: float = snapshot.get("data").get("ts")
snapshot_msg: OrderBookMessage = BitmaxOrderBook.snapshot_message_from_exchange(
snapshot_msg: OrderBookMessage = AscendExOrderBook.snapshot_message_from_exchange(
snapshot.get("data"),
snapshot_timestamp,
metadata={"trading_pair": trading_pair}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
from typing import Optional, List, AsyncIterable, Any
from hummingbot.core.data_type.user_stream_tracker_data_source import UserStreamTrackerDataSource
from hummingbot.logger import HummingbotLogger
from hummingbot.connector.exchange.bitmax.bitmax_auth import BitmaxAuth
from hummingbot.connector.exchange.bitmax.bitmax_constants import REST_URL, getWsUrlPriv, PONG_PAYLOAD
from hummingbot.connector.exchange.ascend_ex.ascend_ex_auth import AscendExAuth
from hummingbot.connector.exchange.ascend_ex.ascend_ex_constants import REST_URL, PONG_PAYLOAD
from hummingbot.connector.exchange.ascend_ex.ascend_ex_utils import get_ws_url_private


class BitmaxAPIUserStreamDataSource(UserStreamTrackerDataSource):
class AscendExAPIUserStreamDataSource(UserStreamTrackerDataSource):
MAX_RETRIES = 20
MESSAGE_TIMEOUT = 10.0
PING_TIMEOUT = 5.0
Expand All @@ -26,8 +27,8 @@ def logger(cls) -> HummingbotLogger:
cls._logger = logging.getLogger(__name__)
return cls._logger

def __init__(self, bitmax_auth: BitmaxAuth, trading_pairs: Optional[List[str]] = []):
self._bitmax_auth: BitmaxAuth = bitmax_auth
def __init__(self, ascend_ex_auth: AscendExAuth, trading_pairs: Optional[List[str]] = []):
self._ascend_ex_auth: AscendExAuth = ascend_ex_auth
self._trading_pairs = trading_pairs
self._current_listen_key = None
self._listen_for_user_stream_task = None
Expand All @@ -50,18 +51,18 @@ async def listen_for_user_stream(self, ev_loop: asyncio.BaseEventLoop, output: a
while True:
try:
response = await aiohttp.ClientSession().get(f"{REST_URL}/info", headers={
**self._bitmax_auth.get_headers(),
**self._bitmax_auth.get_auth_headers("info"),
**self._ascend_ex_auth.get_headers(),
**self._ascend_ex_auth.get_auth_headers("info"),
})
info = await response.json()
accountGroup = info.get("data").get("accountGroup")
headers = self._bitmax_auth.get_auth_headers("stream")
headers = self._ascend_ex_auth.get_auth_headers("stream")
payload = {
"op": "sub",
"ch": "order:cash"
}

async with websockets.connect(f"{getWsUrlPriv(accountGroup)}/stream", extra_headers=headers) as ws:
async with websockets.connect(f"{get_ws_url_private(accountGroup)}/stream", extra_headers=headers) as ws:
try:
ws: websockets.WebSocketClientProtocol = ws
await ws.send(ujson.dumps(payload))
Expand All @@ -75,12 +76,12 @@ async def listen_for_user_stream(self, ev_loop: asyncio.BaseEventLoop, output: a
output.put_nowait(msg)
except Exception:
self.logger().error(
"Unexpected error when parsing Bitmax message. ", exc_info=True
"Unexpected error when parsing AscendEx message. ", exc_info=True
)
raise
except Exception:
self.logger().error(
"Unexpected error while listening to Bitmax messages. ", exc_info=True
"Unexpected error while listening to AscendEx messages. ", exc_info=True
)
raise
finally:
Expand All @@ -89,7 +90,7 @@ async def listen_for_user_stream(self, ev_loop: asyncio.BaseEventLoop, output: a
raise
except Exception:
self.logger().error(
"Unexpected error with Bitmax WebSocket connection. " "Retrying after 30 seconds...", exc_info=True
"Unexpected error with AscendEx WebSocket connection. " "Retrying after 30 seconds...", exc_info=True
)
await asyncio.sleep(30.0)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import hmac
import hashlib
from typing import Dict, Any
from hummingbot.connector.exchange.bitmax.bitmax_utils import get_ms_timestamp
from hummingbot.connector.exchange.ascend_ex.ascend_ex_utils import get_ms_timestamp


class BitmaxAuth():
class AscendExAuth():
"""
Auth class required by bitmax API
Learn more at https://bitmax-exchange.github.io/bitmax-pro-api/#authenticate-a-restful-request
Auth class required by AscendEx API
Learn more at https://ascendex.github.io/ascendex-pro-api/#authenticate-a-restful-request
"""
def __init__(self, api_key: str, secret_key: str):
self.api_key = api_key
Expand Down Expand Up @@ -39,7 +39,7 @@ def get_auth_headers(

def get_headers(self) -> Dict[str, Any]:
"""
Generates generic headers required by bitmax
Generates generic headers required by AscendEx
:return: a dictionary of headers
"""

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# A single source of truth for constant variables related to the exchange


EXCHANGE_NAME = "ascend_ex"
REST_URL = "https://ascendex.com/api/pro/v1"
WS_URL = "wss://ascendex.com/0/api/pro/v1/stream"
PONG_PAYLOAD = {"op": "pong"}
Loading

0 comments on commit 21b7186

Please sign in to comment.