Skip to content

Commit

Permalink
dxfeed events to snake case
Browse files Browse the repository at this point in the history
  • Loading branch information
Graeme22 committed Dec 3, 2024
1 parent b510862 commit 2382352
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 111 deletions.
14 changes: 5 additions & 9 deletions tastytrade/dxfeed/candle.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ class Candle(Event):
specified price type with data taken from a specified exchange.
"""

#: symbol of this event
eventSymbol: str
#: time of this event
eventTime: int
#: transactional event flags
eventFlags: int
event_flags: int
#: unique per-symbol index of this candle event
index: int
#: timestamp of the candle in milliseconds
Expand All @@ -38,10 +34,10 @@ class Candle(Event):
#: volume-weighted average price
vwap: Optional[Decimal] = None
#: bid volume in the candle
bidVolume: Optional[Decimal] = None
bid_volume: Optional[Decimal] = None
#: ask volume in the candle
askVolume: Optional[Decimal] = None
ask_volume: Optional[Decimal] = None
#: implied volatility in the candle
impVolatility: Optional[Decimal] = None
imp_volatility: Optional[Decimal] = None
#: open interest in the candle
openInterest: Optional[int] = None
open_interest: Optional[int] = None
10 changes: 9 additions & 1 deletion tastytrade/dxfeed/event.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
from typing import Any, List

from pydantic import BaseModel, ValidationError, field_validator
from pydantic import BaseModel, ConfigDict, ValidationError, field_validator
from pydantic.alias_generators import to_camel

from tastytrade import logger
from tastytrade.utils import TastytradeError


class Event(BaseModel):
#: symbol of this event
event_symbol: str
#: time of this event
event_time: int

model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)

@field_validator("*", mode="before")
@classmethod
def change_nan_to_none(cls, v: Any) -> Any:
Expand Down
6 changes: 1 addition & 5 deletions tastytrade/dxfeed/greeks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ class Greeks(Event):
portfolio has a risky sensitivity in this parameter.
"""

#: symbol of this event
eventSymbol: str
#: time of this event
eventTime: int
#: transactional event flags
eventFlags: int
event_flags: int
#: unique per-symbol index of this event
index: int
#: timestamp of this event in milliseconds
Expand Down
32 changes: 14 additions & 18 deletions tastytrade/dxfeed/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,39 @@ class Profile(Event):
traded security on the market at any given moment of time.
"""

#: symbol of this event
eventSymbol: str
#: time of this event
eventTime: int
#: description of the security instrument
description: str
#: short sale restriction of the security instrument
#: possible values are ACTIVE | INACTIVE | UNDEFINED
shortSaleRestriction: str
short_sale_restriction: str
#: trading status of the security instrument
#: possible values are ACTIVE | HALTED | UNDEFINED
tradingStatus: str
trading_status: str
#: starting time of the trading halt interval
haltStartTime: int
halt_start_time: int
#: ending time of the trading halt interval
haltEndTime: int
halt_end_time: int
#: identifier of the ex-dividend date
exDividendDayId: int
ex_dividend_day_id: int
#: description of the reason that trading was halted
statusReason: Optional[str] = None
status_reason: Optional[str] = None
#: maximal (high) price in last 52 weeks
high52WeekPrice: Optional[Decimal] = None
high_52_week_price: Optional[Decimal] = None
#: minimal (low) price in last 52 weeks
low52WeekPrice: Optional[Decimal] = None
low_52_week_price: Optional[Decimal] = None
#: the correlation coefficient of the instrument to the S&P500 index
beta: Optional[Decimal] = None
#: shares outstanding
shares: Optional[Decimal] = None
#: maximal (high) allowed price
highLimitPrice: Optional[Decimal] = None
high_limit_price: Optional[Decimal] = None
#: minimal (low) allowed price
lowLimitPrice: Optional[Decimal] = None
low_limit_price: Optional[Decimal] = None
#: earnings per share
earningsPerShare: Optional[Decimal] = None
earnings_per_share: Optional[Decimal] = None
#: the amount of the last paid dividend
exDividendAmount: Optional[Decimal] = None
ex_dividend_amount: Optional[Decimal] = None
#: frequency of cash dividends payments per year (calculated)
dividendFrequency: Optional[Decimal] = None
dividend_frequency: Optional[Decimal] = None
#: the number of shares that are available to the public for trade
freeFloat: Optional[Decimal] = None
free_float: Optional[Decimal] = None
22 changes: 9 additions & 13 deletions tastytrade/dxfeed/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,25 @@ class Quote(Event):
fields that change with each quote.
"""

#: symbol of this event
eventSymbol: str
#: time of this event
eventTime: int
#: sequence of this quote
sequence: int
#: microseconds and nanoseconds part of time of the last bid or ask change
timeNanoPart: int
time_nano_part: int
#: time of the last bid change
bidTime: int
bid_time: int
#: bid exchange code
bidExchangeCode: str
bid_exchange_code: str
#: time of the last ask change
askTime: int
ask_time: int
#: ask exchange code
askExchangeCode: str
ask_exchange_code: str
#: bid price
bidPrice: Decimal
bid_price: Decimal
#: ask price
askPrice: Decimal
ask_price: Decimal
#: bid size as integer number (rounded toward zero)
#: or decimal for cryptocurrencies
bidSize: Optional[Decimal] = None
bid_size: Optional[Decimal] = None
#: ask size as integer number (rounded toward zero)
#: or decimal for cryptocurrencies
askSize: Optional[Decimal] = None
ask_size: Optional[Decimal] = None
26 changes: 11 additions & 15 deletions tastytrade/dxfeed/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,27 @@ class Summary(Event):
Before opening the bidding, the values are reset to N/A or NaN.
"""

#: symbol of this event
eventSymbol: str
#: time of this event
eventTime: int
#: identifier of the day that this summary represents
dayId: int
day_id: int
#: the price type of the last (close) price for the day
#: possible values are FINAL | INDICATIVE | PRELIMINARY | REGULAR
dayClosePriceType: str
day_close_price_type: str
#: identifier of the previous day that this summary represents
prevDayId: int
prev_day_id: int
#: the price type of the last (close) price for the previous day
#: possible values are FINAL | INDICATIVE | PRELIMINARY | REGULAR
prevDayClosePriceType: str
prev_day_close_price_type: str
#: open interest of the symbol as the number of open contracts
openInterest: int
open_interest: int
#: the first (open) price for the day
dayOpenPrice: Optional[Decimal] = None
day_open_price: Optional[Decimal] = None
#: the maximal (high) price for the day
dayHighPrice: Optional[Decimal] = None
day_high_price: Optional[Decimal] = None
#: the minimal (low) price for the day
dayLowPrice: Optional[Decimal] = None
day_low_price: Optional[Decimal] = None
#: the last (close) price for the day
dayClosePrice: Optional[Decimal] = None
day_close_price: Optional[Decimal] = None
#: the last (close) price for the previous day
prevDayClosePrice: Optional[Decimal] = None
prev_day_close_price: Optional[Decimal] = None
#: total volume traded for the previous day
prevDayVolume: Optional[Decimal] = None
prev_day_volume: Optional[Decimal] = None
8 changes: 2 additions & 6 deletions tastytrade/dxfeed/theoprice.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ class TheoPrice(Event):
this event.
"""

#: symbol of this event
eventSymbol: str
#: time of this event
eventTime: int
#: transactional event flags
eventFlags: int
event_flags: int
#: unique per-symbol index of this event
index: int
#: timestamp of this event in milliseconds
Expand All @@ -27,7 +23,7 @@ class TheoPrice(Event):
#: theoretical price
price: Decimal
#: underlying price at the time of theo price computation
underlyingPrice: Decimal
underlying_price: Decimal
#: delta of the theoretical price
delta: Decimal
#: gamma of the theoretical price
Expand Down
26 changes: 11 additions & 15 deletions tastytrade/dxfeed/timeandsale.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,38 @@ class TimeAndSale(Event):
correction/cancellation processing.
"""

#: symbol of this event
eventSymbol: str
#: time of this event
eventTime: int
#: transactional event flags
eventFlags: int
event_flags: int
#: unique per-symbol index of this time and sale event
index: int
#: timestamp of the original event
time: int
#: microseconds and nanoseconds part of time of the last bid or ask change
timeNanoPart: int
time_nano_part: int
#: sequence of this quote
sequence: int
#: exchange code of this time and sale event
exchangeCode: str
exchange_code: str
#: price of this time and sale event
price: Decimal
#: size of this time and sale event as integer number (rounded toward zero)
size: int
#: the bid price on the market when this time and sale event occured
bidPrice: Decimal
bid_price: Decimal
#: the ask price on the market when this time and sale event occured
askPrice: Decimal
ask_price: Decimal
#: sale conditions provided for this event by data feed
exchangeSaleConditions: str
exchange_sale_conditions: str
#: transaction is concluded by exempting from compliance with some rule
tradeThroughExempt: str
trade_through_exempt: str
#: initiator of the trade
aggressorSide: str
aggressor_side: str
#: whether this transaction is a part of a multi-leg order
spreadLeg: bool
spread_leg: bool
#: whether this transaction is completed during extended trading hours
extendedTradingHours: bool
extended_trading_hours: bool
#: normalized SaleCondition flag
validTick: bool
valid_tick: bool
#: type of event - 0: new, 1: correction, 2: cancellation
type: str
#: Undocumented; always None
Expand Down
18 changes: 7 additions & 11 deletions tastytrade/dxfeed/trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,28 @@ class Trade(Event):
instrument.
"""

#: symbol of this event
eventSymbol: str
#: time of this event
eventTime: int
#: time of the last trade
time: int
#: microseconds and nanoseconds time part of the last trade
timeNanoPart: int
time_nano_part: int
#: sequence of the last trade
sequence: int
#: exchange code of the last trade
exchangeCode: str
exchange_code: str
#: identifier of the current trading day
dayId: int
day_id: int
#: tick direction of the last trade
#: possible values are DOWN | UNDEFINED | UP | ZERO | ZERO_DOWN | ZERO_UP
tickDirection: str
tick_direction: str
#: whether the last trade was in extended trading hours
extendedTradingHours: bool
extended_trading_hours: bool
#: price of the last trade
price: Decimal
#: change of the last trade
change: Optional[Decimal] = None
#: size of the last trade as integer number (rounded toward zero)
size: Optional[int] = None
#: total vlume traded for a day as integer number (rounded toward zero)
dayVolume: Optional[int] = None
day_volume: Optional[int] = None
#: total turnover traded for a day
dayTurnover: Optional[Decimal] = None
day_turnover: Optional[Decimal] = None
18 changes: 7 additions & 11 deletions tastytrade/dxfeed/underlying.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ class Underlying(Event):
corresponding values on the market at any given moment of time.
"""

#: symbol of this event
eventSymbol: str
#: time of this event
eventTime: int
#: transactional event flags
eventFlags: int
event_flags: int
#: unique per-symbol index of this event
index: int
#: timestamp of this event in milliseconds
Expand All @@ -26,14 +22,14 @@ class Underlying(Event):
#: 30-day implied volatility for this underlying based on VIX methodology
volatility: Decimal
#: front month implied volatility for the underlying using VIX methodology
frontVolatility: Decimal
front_volatility: Decimal
#: back month implied volatility for the underlying using VIX methodology
backVolatility: Decimal
back_volatility: Decimal
#: call options traded volume for a day
callVolume: int
call_volume: int
#: put options traded volume for a day
putVolume: int
put_volume: int
#: options traded volume for a day
optionVolume: int
option_volume: int
#: ratio of put options volume to call options volume for a day
putCallRatio: Decimal
put_call_ratio: Decimal
6 changes: 2 additions & 4 deletions tastytrade/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pandas_market_calendars as mcal # type: ignore
from httpx._models import Response
from pydantic import BaseModel
from pydantic import BaseModel, ConfigDict

NYSE = mcal.get_calendar("NYSE")
TZ = ZoneInfo("US/Eastern")
Expand Down Expand Up @@ -230,9 +230,7 @@ class TastytradeJsonDataclass(BaseModel):
and performs type validation and coercion.
"""

class Config:
alias_generator = _dasherize
populate_by_name = True
model_config = ConfigDict(alias_generator=_dasherize, populate_by_name=True)


def validate_response(response: Response) -> None:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_dxfeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def test_parse_infinities_and_nan():
]
summary = Summary.from_stream(summary_data)[0]
summary = cast(Summary, summary)
assert summary.dayOpenPrice is None
assert summary.dayClosePrice is None
assert summary.dayHighPrice is None
assert summary.day_open_price is None
assert summary.day_close_price is None
assert summary.day_high_price is None


def test_malformatted_data():
Expand Down

0 comments on commit 2382352

Please sign in to comment.