-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from globophobe/feature/0.1.3
Release v0.1.3
- Loading branch information
Showing
31 changed files
with
839 additions
and
410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
from .binance import BinanceExchange | ||
from .bitfinex import BitfinexExchange | ||
from .bitflyer import BitflyerExchange | ||
from .bitmex import BitmexExchange | ||
from .bybit import BybitExchange | ||
from .coinbase import CoinbaseExchange | ||
from .deribit import DeribitExchange | ||
from .ftx import FTXExchange | ||
from .upbit import UpbitExchange | ||
from .binance import Binance | ||
from .bitfinex import Bitfinex | ||
from .bitflyer import Bitflyer | ||
from .bitmex import Bitmex | ||
from .bybit import Bybit | ||
from .coinbase import Coinbase | ||
from .ftx import FTX | ||
from .upbit import Upbit | ||
|
||
__all__ = [ | ||
"BinanceExchange", | ||
"BitmexExchange", | ||
"BitfinexExchange", | ||
"BitflyerExchange", | ||
"BybitExchange", | ||
"CoinbaseExchange", | ||
"DeribitExchange", | ||
"FTXExchange", | ||
"UpbitExchange", | ||
"Binance", | ||
"Bitmex", | ||
"Bitfinex", | ||
"Bitflyer", | ||
"Bybit", | ||
"Coinbase", | ||
"FTX", | ||
"Upbit", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,54 @@ | ||
from datetime import datetime, timezone | ||
from decimal import Decimal | ||
from typing import Tuple | ||
|
||
import pandas as pd | ||
from cryptofeed.defines import TRADES | ||
from cryptofeed.exchanges import Bitfinex | ||
from cryptofeed.exchanges import Bitfinex as BaseBitfinex | ||
from cryptofeed.exchanges.bitfinex import LOG | ||
|
||
from ..exchange import Exchange | ||
from ..feed import Feed | ||
|
||
|
||
class BitfinexExchange(Exchange, Bitfinex): | ||
def std_symbol_to_exchange_symbol(self, symbol: str) -> str: | ||
return "t" + symbol | ||
class Bitfinex(Feed, BaseBitfinex): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.is_initialized = False | ||
|
||
async def _trades(self, pair: str, msg: dict, timestamp: float): | ||
def parse_datetime(self, value: int, unit: str = "ms") -> datetime: | ||
"""Parse datetime with pandas.""" | ||
return pd.Timestamp(value, unit=unit).replace(tzinfo=timezone.utc) | ||
|
||
async def _trades( | ||
self, pair: str, msg: list, timestamp: float | ||
) -> Tuple[str, dict, float]: | ||
async def _trade_update(trade: list, timestamp: float): | ||
uid, ts, notional, price = trade | ||
price = Decimal(price) | ||
notional = abs(Decimal(notional)) | ||
volume = price * notional | ||
ts = self.timestamp_normalize(ts) | ||
trade = { | ||
"exchange": self.id, | ||
volume = price * abs(notional) | ||
t = { | ||
"exchange": self.id.lower(), | ||
"uid": uid, | ||
"symbol": pair, # Do not normalize | ||
"timestamp": ts, | ||
"symbol": pair, | ||
"timestamp": self.parse_datetime(ts), | ||
"price": price, | ||
"volume": volume, | ||
"notional": notional, | ||
"notional": abs(notional), | ||
"tickRule": -1 if notional < 0 else 1, | ||
} | ||
await self.callback(TRADES, trade, ts) | ||
await self.callback(TRADES, t, timestamp) | ||
|
||
# Drop first message. | ||
if self.is_initialized: | ||
if isinstance(msg[1], list): | ||
# Snapshot. | ||
for trade in msg[1]: | ||
await _trade_update(trade, timestamp) | ||
elif msg[1] in ("te", "fte"): | ||
# Update. | ||
await _trade_update(msg[2], timestamp) | ||
elif msg[1] not in ("tu", "ftu", "hb"): | ||
# Ignore trade updates and heartbeats. | ||
LOG.warning("%s %s: Unexpected trade message %s", self.id, pair, msg) | ||
else: | ||
self.is_initialized = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.