Format of quotes problem
rafalsza opened this issue · 9 comments
The problem
A clear and concise description of the bug. If known, explain why you believe the problem is within this library.
Error message(s):
Traceback (most recent call last):
File "/mnt/0696DB8696DB7521/python_projects/trading-python/tests/smc_test/ob6.py", line 408, in <module>
quotes_list = [
File "/mnt/0696DB8696DB7521/python_projects/trading-python/tests/smc_test/ob6.py", line 409, in <listcomp>
Quote(
File "/home/rafal/py-venv/lib/python3.10/site-packages/stock_indicators/indicators/common/quote.py", line 62, in __init__
self.open: Decimal = open if open else 0
File "/home/rafal/py-venv/lib/python3.10/site-packages/stock_indicators/indicators/common/quote.py", line 25, in _set_open
quote.Open = CsDecimal(value)
File "/home/rafal/py-venv/lib/python3.10/site-packages/stock_indicators/_cstypes/decimal.py", line 21, in __new__
return CsDecimal.Parse(str(decimal))
System.FormatException: The input string '0.50000000' was not in a correct format.
at System.Number.ThrowFormatException[TChar](ReadOnlySpan`1 value)
at System.Number.ParseDecimal[TChar](ReadOnlySpan`1 value, NumberStyles styles, NumberFormatInfo info)
at System.Decimal.Parse(String s)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
To Reproduce
from binance.client import Client
from stock_indicators import Quote
from stock_indicators import indicators
from stock_indicators.indicators.common.enums import PeriodSize, PivotPointType
from decimal import Decimal
def import_data(symbol, interval, start_date):
client = Client()
df = pd.DataFrame(
client.get_historical_klines(
symbol, start_str=start_date, interval=interval, limit=5000
)
).astype(float)
df = df.iloc[:, :6]
df.columns = ["timestamp", "open", "high", "low", "close", "volume"]
df["date"] = df.timestamp
df = df.set_index("timestamp")
df.index = pd.to_datetime(df.index, unit="ms")
df.date = pd.to_datetime(df.date, unit="ms")
return df
# Fetch historical data from Binance
symbol = "ARBUSDT"
df = import_data(symbol, "1d", "2022-01-01")
quotes_list = [
Quote(
d,
open=Decimal(o),
high=Decimal(h),
low=Decimal(l),
close=Decimal(c),
volume=Decimal(v),
)
for d, o, h, l, c, v in zip(
df["date"], df["open"], df["high"], df["low"], df["close"], df["volume"]
)
]
results = indicators.get_pivot_points(
quotes_list, PeriodSize.DAY, PivotPointType.STANDARD
)
print(results)
Checkout this recent discussions
If it doesn't help you resolve your problem, please export your DataFrame data using .to_csv, and then upload it here without altering it, so we can inspect it for data compatibility issues.
df.to_csv('quotes.csv', index=False)
Hi, @rafalsza. Thank you for detail report.
I suspect the culprit is CultureInfo
when parsing decimal string to C# Decimal object. We currently don't set CultureInfo
explicitly, which means your local culture info is being used.
So could you share the result from the code below. I need a test about it.
from stock_indicators import indicators
from System.Globalization import CultureInfo
print(CultureInfo.CurrentCulture)
quotes.csv
uploaded csv
Try adding locale.setlocale(locale.LC_ALL, 'C')
before you convert from df
Quotes provided don’t seem to be an issue. Works for me. Try to replicate:
https://replit.com/@daveskender/Stock-Indicators-for-Python-Quotes-Issue-348
@LeeDongGeon1996 do we know if this is actually the issue, using decimal points instead of commas when locale
settings don't like the way quotes are formatted? @rafalsza have you tried either 1) reformatting quotes to be compatible or 2) changing your locale
environment settings (in your wrapper code)?
@rafalsza give v1.2.1 a try and see if it helps you resolve this issue. Feedback appreciated.
@rafalsza give v1.2.1 a try and see if it helps you resolve this issue. Feedback appreciated.
yes, it works now, thank you
The patch finally has been released in v1.3.1.