diff --git a/tastytrade/dxfeed/candle.py b/tastytrade/dxfeed/candle.py index 7074600..6e36e36 100644 --- a/tastytrade/dxfeed/candle.py +++ b/tastytrade/dxfeed/candle.py @@ -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 @@ -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 diff --git a/tastytrade/dxfeed/event.py b/tastytrade/dxfeed/event.py index 030def9..37912bf 100644 --- a/tastytrade/dxfeed/event.py +++ b/tastytrade/dxfeed/event.py @@ -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: diff --git a/tastytrade/dxfeed/greeks.py b/tastytrade/dxfeed/greeks.py index df371ba..5036b7d 100644 --- a/tastytrade/dxfeed/greeks.py +++ b/tastytrade/dxfeed/greeks.py @@ -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 diff --git a/tastytrade/dxfeed/profile.py b/tastytrade/dxfeed/profile.py index 5fc1d4d..afee39e 100644 --- a/tastytrade/dxfeed/profile.py +++ b/tastytrade/dxfeed/profile.py @@ -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 diff --git a/tastytrade/dxfeed/quote.py b/tastytrade/dxfeed/quote.py index 392e26e..28c6a66 100644 --- a/tastytrade/dxfeed/quote.py +++ b/tastytrade/dxfeed/quote.py @@ -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 diff --git a/tastytrade/dxfeed/summary.py b/tastytrade/dxfeed/summary.py index eb6f92b..dd47657 100644 --- a/tastytrade/dxfeed/summary.py +++ b/tastytrade/dxfeed/summary.py @@ -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 diff --git a/tastytrade/dxfeed/theoprice.py b/tastytrade/dxfeed/theoprice.py index e7c3d88..ce9ba87 100644 --- a/tastytrade/dxfeed/theoprice.py +++ b/tastytrade/dxfeed/theoprice.py @@ -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 @@ -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 diff --git a/tastytrade/dxfeed/timeandsale.py b/tastytrade/dxfeed/timeandsale.py index 146902f..256366e 100644 --- a/tastytrade/dxfeed/timeandsale.py +++ b/tastytrade/dxfeed/timeandsale.py @@ -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 diff --git a/tastytrade/dxfeed/trade.py b/tastytrade/dxfeed/trade.py index b03c068..f0a1af1 100644 --- a/tastytrade/dxfeed/trade.py +++ b/tastytrade/dxfeed/trade.py @@ -13,25 +13,21 @@ 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 @@ -39,6 +35,6 @@ class Trade(Event): #: 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 diff --git a/tastytrade/dxfeed/underlying.py b/tastytrade/dxfeed/underlying.py index 2daea8d..ab5197c 100644 --- a/tastytrade/dxfeed/underlying.py +++ b/tastytrade/dxfeed/underlying.py @@ -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 @@ -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 diff --git a/tastytrade/utils.py b/tastytrade/utils.py index 965a59f..10b5240 100644 --- a/tastytrade/utils.py +++ b/tastytrade/utils.py @@ -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") @@ -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: diff --git a/tests/test_dxfeed.py b/tests/test_dxfeed.py index 26a2912..af60fb1 100644 --- a/tests/test_dxfeed.py +++ b/tests/test_dxfeed.py @@ -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():