diff --git a/stock_indicators/_cstypes/datetime.py b/stock_indicators/_cstypes/datetime.py index 8ffb0f3f..b4eb4de8 100644 --- a/stock_indicators/_cstypes/datetime.py +++ b/stock_indicators/_cstypes/datetime.py @@ -19,11 +19,11 @@ class DateTime: >>> cs_now 3/26/2021 10:02:22 PM """ - def __new__(cls, datetime) -> CsDateTime: + def __new__(cls, datetime: PyDateTime) -> CsDateTime: return CsDateTime.Parse(datetime.isoformat()) -def to_pydatetime(cs_datetime): +def to_pydatetime(cs_datetime: CsDateTime) -> PyDateTime: """ Converts C#'s `System.DateTime` struct to a native Python datetime object. diff --git a/stock_indicators/_cstypes/decimal.py b/stock_indicators/_cstypes/decimal.py index 4d7f81fe..a179de76 100644 --- a/stock_indicators/_cstypes/decimal.py +++ b/stock_indicators/_cstypes/decimal.py @@ -9,7 +9,7 @@ class Decimal: Class for converting a number into C#'s `System.Decimal` class. Parameters: - decimal : `int`, `float` or any `object` that can be represented as a number. + decimal : `int`, `float` or any `object` that can be represented as a number string. Example: Constructing `System.Decimal` from `float` of Python. @@ -22,7 +22,7 @@ def __new__(cls, decimal) -> CsDecimal: return CsDecimal.Parse(str(decimal), CsCultureInfo.InvariantCulture) -def to_pydecimal(cs_decimal): +def to_pydecimal(cs_decimal: CsDecimal) -> PyDecimal: """ Converts an object to a native Python decimal object. diff --git a/stock_indicators/indicators/common/quote.py b/stock_indicators/indicators/common/quote.py index 1254c43f..c75beafe 100644 --- a/stock_indicators/indicators/common/quote.py +++ b/stock_indicators/indicators/common/quote.py @@ -1,13 +1,12 @@ +from datetime import datetime from decimal import Decimal -from typing import Iterable +from typing import Any, Iterable, Optional -from stock_indicators._cslib import CsQuote -from stock_indicators._cslib import CsQuoteUtility +from stock_indicators._cslib import CsQuote, CsQuoteUtility from stock_indicators._cstypes import List as CsList from stock_indicators._cstypes import DateTime as CsDateTime from stock_indicators._cstypes import Decimal as CsDecimal -from stock_indicators._cstypes.datetime import to_pydatetime -from stock_indicators._cstypes.decimal import to_pydecimal +from stock_indicators._cstypes import to_pydatetime, to_pydecimal from stock_indicators.indicators.common.enums import CandlePart from stock_indicators.indicators.common._contrib.type_resolver import generate_cs_inherited_class @@ -56,7 +55,9 @@ class _Quote: close = property(_get_close, _set_close) volume = property(_get_volume, _set_volume) - def __init__(self, date, open = None, high = None, low = None, close = None, volume = None): + def __init__(self, date: datetime, open: Optional[Any] = None, + high: Optional[Any] = None, low: Optional[Any] = None, + close: Optional[Any] = None, volume: Optional[Any] = None): self.date = date self.open: Decimal = open if open else 0 self.high: Decimal = high if high else 0 @@ -86,4 +87,7 @@ def use(cls, quotes: Iterable["Quote"], candle_part: CandlePart): class Quote(generate_cs_inherited_class(_Quote, CsQuote)): - """A single dated quote containing OHLCV elements.""" + """ + A single dated quote containing OHLCV elements. + OHLCV values can be given as any object that can be represented as a number string. + """