Click here to Login

Trading Software Trading objects Features How-to Blog Search


                                                   Export to CSV the whole database including symbols

  0

0
Raja Gupta
2010-07-31 11:18:14



I am new user for this software. Is there a way to export to whole database file to ascii file to be further imported into an Oracle database. I know there is a way
to export to CSV file for every symbol. I want to dump the whole file includung symbols to a CSV file.

I am sorry if this should be very common knowledge to anyone using this software but I could not find the answer in the forum.
Thanks,



QuantShare
2010-08-02 06:24:29

  0

Best Answer
A whole copy of the database to a CSV file can be performed using the scripting language. Tools -> Script Editor.

Here is the script to perform this:

Symbol[] symbols = Symbols.GetSymbols();
System.Text.StringBuilder text = new System.Text.StringBuilder("");
for(int i=0;i < symbols.Length;i++)
{
Symbol sym = symbols[i];
HistoricalQuotes quotes = Quotes.GetHistoricalQuotes(sym.Name);
for(int j=0;j < quotes.Close.Length;j++)
{
text.AppendLine(sym.Name + ";" + quotes.Date[j].ToString("dd/MM/yyyy") + ";" + quotes.Close[j]+ ";" + quotes.Open[j] + ";" + quotes.High[j] + ";" + quotes.Low[j] + ";" + quotes.Volume[j]);
}
}

System.IO.File.WriteAllText(@"c:\quotes.csv", text.ToString());


- The last line reference the file.
- The format is: Symbol;Date;Close;Open;High;Low;Volume



Raja Gupta
2010-08-02 13:33:17

  0

Thanks much. What if the database , i am trying to convert to ascii, is a custom database instead of quotes database.


QuantShare
2010-08-02 14:14:44

  0

You must change
HistoricalQuotes quotes = Quotes.GetHistoricalQuotes(sym.Name);
by
DatabasesData data = Databases.GetDatabasesData(sym.Name, "database name", "field name");
for(int j=0;j < data.Value.Length;j++)
{
text.AppendLine(sym.Name + ";" + data.Date[j].ToString("dd/MM/yyyy") + ";" + data.Value[j].ToString());
}



Raja Gupta
2010-08-02 14:49:17

  0

Thanks! it worked and I must say that the program is really fast. It dumped 42000 rows in less than 2 seconds.


ariel
2012-04-11 10:47:13

  0

I tried the script you suggested and got a few error msgs. Do you know if the script/functions have to be updated in any way? Thanks.


QuantShare
2012-04-12 06:41:00

  0

Ariel,

What error message are you getting?
Can you post the script here?

Also, do not forget to update ("database name" and "field name") with the appropriate database name and field name.



ariel
2012-04-12 07:44:20

  0

Thanks for your reply!

I am trying to export the entire custom database "earnings_cal" (all tickers and all fields). So I just copy-pasted the script you posted above and made the changes that you suggested. (btw, I wasn't sure what is the "field name" in the case of the earning_cal database, since I am interested in all fields. Also, am I supposed to leave the inverted commas for the filed and database names?). In any event, I get a few error msgs after running it. Here is the script and the error msgs I get:

SCRIPT:

Symbol[] symbols = Symbols.GetSymbols();
System.Text.StringBuilder text = new System.Text.StringBuilder("");
for(int i=0;i < symbols.Length;i++)
{
Symbol sym = symbols[i];
DatabasesData data = Databases.GetDatabasesData(sym.Name, "Custom", "earnings_cal");
for(int j=0;j < data.Value.Length;j++)
{
text.AppendLine(sym.Name + ";" + data.Date[j].ToString("dd/MM/yyyy") + ";" + data.Value[j].ToString());
}
}

System.IO.File.WriteAllText(@"c:\quotes.csv", text.ToString());



ERROR MSGS:

Error(s)
L0 C1378 : Expected ';'
L1 C1 : The list of attributes does not apply to the current context
L2 C9 : Expected ';'
L2 C31 : Expected ')'
L2 C35 : Expected ';'
L4 C1 : The list of attributes does not apply to the current context
L5 C1 : The list of attributes does not apply to the current context
L6 C9 : Expected ';'
L6 C34 : Expected ')'
L6 C38 : Expected ';'
L12 C30 : Invalid character
L0 C1369 : Expression has no effect
L0 C1378 : Variable 'symbols' has not been declared
L2 C9 : Variable 'i' has not been declared
L6 C9 : Variable 'j' has not been declared
L6 C17 : Variable 'data' has not been declared
L8 C1 : Variable 'text' has not been declared
L8 C17 : Variable 'sym' has not been declared




QuantShare
2012-04-12 08:22:10

  0

At the bottom the script editor, set "C#" instead of "JScript".

Also, set the database and field names here:
"Custom", "earnings_cal"




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
Ticker Symbols List of the National Stock Exchange, NSE, India
Tweet Sentiment Index for the Forex and Stock Market
Update the Stock Exchange Associated With U.S. Stocks - Market Fi...
Fails to deliver - Reported by the SEC
Frankfurt Stock Exchange Symbols

How-to Lessons
How to quickly select stocks based on the last value of a databas...
How to export trading data to a CSV file
How to import trading data from CSV files
How to quickly download the most recent EOD data for your stocks
How to display the number of notes per stock

Related Forum Threads
Delete symbols from Database
Can I update the sector and industry information in the stock dat...
Deleting Data From The Database
Multiple symbols on the same chart
Deleting no-data symbols

Blog Posts
How to Create a List of Ticker Symbols
Ranking stocks based on their correlation with the S&P 500 Index
How to download the history of dividend payments for stocks in th...
Trading Forex with the commitments of traders report
Download Trading Data using the URL-Script









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 © 2012 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items