Click here to Login





                                                   Date conversion error on Json downloader

  0

0
Christian
2020-09-07 06:44:06


Conversion problem with JSON download.

I'm developing a downloader for JSON files.
Meanwhile all quotes are working but I always get an error message for the dates:

Conversion error: "2020-09-07" -- For every day

In the import module I have already changed the format to YMD and I also use "-" as date separator.
Maybe someone has an idea what I am doing wrong here.


Sample data:

{
"isin": "LU1033693638",
"data": [
{
"date": "2020-09-07",
"open": 24.6,
"close": 24.705,
"high": 24.725,
"low": 24.55,
"turnoverPieces": 6151,
"turnoverEuro": 151878.16
},
{
"date": "2020-09-04",
"open": 24.32,
"close": 24.29,
"high": 24.865,
"low": 24.15,
"turnoverPieces": 11535,
"turnoverEuro": 283828.58
}
],
"totalCount": 46,
"tradedInPercent": false
}



Prescript:

System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
for(int i=0;i<Content.Rows.Length;i++)
{
Content.Rows[i].IsIgnoreLine = true;
}

string content = Content.GetContent();
JsonData j = Content.Net.ReadJsonData(content);

JsonData r = j["data"];

for(int i=0;i<r.Count;i++)
{
{
try{

string date = (r[i]["date"] == null) ? "" : r[i]["date"].ToString();
string open = (r[i]["open"] == null) ? "" : r[i]["open"].ToString();
string high = (r[i]["high"] == null) ? "" : r[i]["high"].ToString();
string low = (r[i]["low"] == null) ? "" : r[i]["low"].ToString();
string close = (r[i]["close"] == null) ? "" : r[i]["close"].ToString();
string volume = (r[i]["turnoverPieces"] == null) ? "" : r[i]["turnoverPieces"].ToString();
Content.AddRow(date, open, high, low, close, volume);
}
catch
{
}
}
}






Christian
2020-09-07 09:04:02

  1

Was able to clarify the problem with a colleague.
Obviously the quotation marks are displayed twice.
I have removed them and now it works.
Here is my new code, maybe somebody also need it.


System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
for(int i=0;i<Content.Rows.Length;i++)
{
Content.Rows[i].IsIgnoreLine = true;
}

string content = Content.GetContent();
JsonData j = Content.Net.ReadJsonData(content);

JsonData r = j["data"];


for(int i=0;i<r.Count;i++)
{

{
try{

string date = (r[i]["date"] == null) ? "" : r[i]["date"].ToString();
date = date.Substring(1,10);
// MessageBox.Show(date);
string open = (r[i]["open"] == null) ? "" : r[i]["open"].ToString();
string high = (r[i]["high"] == null) ? "" : r[i]["high"].ToString();
string low = (r[i]["low"] == null) ? "" : r[i]["low"].ToString();
string close = (r[i]["close"] == null) ? "" : r[i]["close"].ToString();
string volume = (r[i]["turnoverPieces"] == null) ? "" : r[i]["turnoverPieces"].ToString();
Content.AddRow(date, open, high, low, close, volume);
}
catch
{
}
}
}



QuantShare
2020-09-08 10:24:46

  0

Thank you for sharing the solution.


No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
BSE historical data by date
Quandl.com Universal Downloader
iShares ETFs - Class, Total Net Assets, Inception Date and Number...
Dow Jones U.S. Technology Sector Index Fund survivorship bias-fre...
Vary the Start Date of a Trading System Simulation

How-to Lessons
How to automatically start a downloader every few minutes?
How to debug a downloader
How to adjust a stock for splits
How to add custom position-based metrics to your trading system
How to execute a script at regular intervals

Related Forum Threads
Inserting today's date in Downloader field?
JSON downloader
Historical News Downloader Error
Custom date parsing error
Muscat Securities Market downloader shows error

Blog Posts
4 Links to Download Free Historical Stock Prices Data by Date
How to use date components in your trading rules
How to download the history of dividend payments for stocks in th...
How to make sure your Historical Price Data is Split Adjusted
Introduction to sentiment analysis applied to the stock market









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.