Skip to content

Commit

Permalink
Cleanup + bypass combos on deribit while support is added
Browse files Browse the repository at this point in the history
  • Loading branch information
bmoscon committed Sep 4, 2022
1 parent 43b6fba commit db43ea3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
2 changes: 2 additions & 0 deletions cryptofeed/defines.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@
FUTURES = 'futures'
PERPETUAL = 'perpetual'
OPTION = 'option'
OPTION_COMBO = 'option_combo'
FUTURE_COMBO = 'future_combo'
SPOT = 'spot'
CALL = 'call'
PUT = 'put'
Expand Down
29 changes: 14 additions & 15 deletions cryptofeed/exchanges/bittrex.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ async def candle(self, msg: dict, timestamp: float):
raw=msg
)
await self.callback(CANDLES, c, timestamp)

async def order(self, msg: dict, timestamp: float):
"""
example message:
Expand Down Expand Up @@ -270,7 +270,7 @@ async def order(self, msg: dict, timestamp: float):
status = order['status']
if status == 'new':
status = SUBMITTING
# There was no obsevation made, that there are more than "OPEN" and "CLOSED". Needs Support clarification with BITTREX.
# There was no observation made, that there are more than "OPEN" and "CLOSED". Needs Support clarification with BITTREX.
elif status == 'OPEN':
status = OPEN
elif status == 'CLOSED':
Expand All @@ -286,11 +286,11 @@ async def order(self, msg: dict, timestamp: float):
status,
LIMIT if order['type'].lower() == 'limit' else MARKET,
Decimal(order['limit']) if 'limit' in order else None,
Decimal(order['fillQuantity']), # the filled Size
remainingSize, # the remaining Size
Decimal(order['fillQuantity']), # the filled Size
remainingSize, # the remaining Size
timestamp=str(order['createdAt']),
client_order_id= order['clientOrderId'] if 'clientOrderId' in order else None,
#account=self.subaccount,
client_order_id=order['clientOrderId'] if 'clientOrderId' in order else None,
# account=self.subaccount,
raw=msg
)
await self.callback(ORDER_INFO, oi, timestamp)
Expand Down Expand Up @@ -351,9 +351,9 @@ async def message_handler(self, msg: str, conn, timestamp: float):
data = json.loads(zlib.decompress(base64.b64decode(message), -zlib.MAX_WBITS).decode(), parse_float=Decimal)
await self.balance(data, timestamp)
elif update['M'] == 'authenticationExpiring':
#WARNING : BITTREX: Invalid message type {'C': 'd-942EDED9-B,0|Bjh,1|Bji,3|Bjj,0|Bjk,0', 'M': [{'H': 'C3', 'M': 'authenticationExpiring', 'A': []}]}
# WARNING : BITTREX: Invalid message type {'C': 'd-942EDED9-B,0|Bjh,1|Bji,3|Bjj,0|Bjk,0', 'M': [{'H': 'C3', 'M': 'authenticationExpiring', 'A': []}]}
LOG.debug("%s: private subscription authentication expired. %s", self.id, msg)
else:
else:
LOG.warning("%s: Invalid message type %s", self.id, msg)
elif 'E' in msg:
LOG.error("%s: Error from exchange %s", self.id, msg)
Expand All @@ -364,7 +364,7 @@ async def generate_token(self, conn: AsyncConnection):
content = timestamp + random_content
signed_content = hmac.new(self.key_secret.encode(), content.encode(), hashlib.sha512).hexdigest()

msg = {'A': [self.key_id, timestamp, random_content, signed_content], 'H': 'c3', 'I': 0, 'M': 'Authenticate'}
msg = {'A': [self.key_id, timestamp, random_content, signed_content], 'H': 'c3', 'I': 0, 'M': 'Authenticate'}
# There is only subacounts on BITTREX for institutional customers.
# if self.subaccount:
# msg['args']['subaccount'] = self.subaccount
Expand All @@ -373,7 +373,7 @@ async def generate_token(self, conn: AsyncConnection):
async def authenticate(self, conn: AsyncConnection):
if self.requires_authentication:
await self.generate_token(conn)

async def subscribe(self, conn: AsyncConnection):
self.__reset()
# H: Hub, M: Message, A: Args, I: Internal ID
Expand All @@ -384,12 +384,12 @@ async def subscribe(self, conn: AsyncConnection):
channel = self.exchange_channel_to_std(chan)
i = 1
# If we subscribe to ORDER_INFO, then that is registered for all symbols in our account.
##if channel in (ORDER_INFO, BALANCES):
# if channel in (ORDER_INFO, BALANCES):
if self.is_authenticated_channel(self.exchange_channel_to_std(chan)):
msg = {'A': ([chan],) , 'H': 'c3', 'I': i, 'M': 'Subscribe'}
msg = {'A': ([chan],), 'H': 'c3', 'I': i, 'M': 'Subscribe'}
await conn.write(json.dumps(msg))
i += 1
else:
else:
for symbol in self.subscription[chan]:
if channel == L2_BOOK:
msg = {'A': ([chan.format(symbol, self.__depth())],), 'H': 'c3', 'I': i, 'M': 'Subscribe'}
Expand All @@ -406,9 +406,8 @@ async def subscribe(self, conn: AsyncConnection):
interval = 'HOUR_1'
elif self.candle_interval == '1d':
interval = 'DAY_1'
msg = {'A': ([chan.format(symbol, interval)],), 'H': 'c3', 'I': i, 'M': 'Subscribe'}
msg = {'A': ([chan.format(symbol, interval)],), 'H': 'c3', 'I': i, 'M': 'Subscribe'}
else:
LOG.error("%s: invalid subscription for channel %s", channel)
await conn.write(json.dumps(msg))
i += 1

2 changes: 2 additions & 0 deletions cryptofeed/exchanges/deribit.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def _parse_symbol_data(cls, data: list) -> Tuple[Dict, Dict]:
quote = e['quote_currency']
stype = e['kind'] if e['settlement_period'] != 'perpetual' else PERPETUAL
otype = e.get('option_type')
if stype in ('option_combo', 'future_combo'):
continue
strike_price = e.get('strike')
strike_price = int(strike_price) if strike_price else None
expiry = e['expiration_timestamp'] / 1000
Expand Down

0 comments on commit db43ea3

Please sign in to comment.