 |
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"
|
|
|
|
|