Witam
Jestem kompletnie zielony jesli chodzi o Jscript, a na prawde nie mam czasu uczyc sie tego jezyka. Prosze Was o pomoc, mysle ze wezme tylko chwile Waszego czasu, bo sam problem nie jest zbyt skomplikowany.
Potrzebuje programu, ktory aktualizowal by moja baze danych w Amibrokerze (program do tradingu) automatycznie z pliku .csv i robil to nieprzerwanie co np. minute az do jego wylaczenie. Googlowalem jakis czas i znalazlem kodzik od tworcy programu .
Chcialbym was prosic o pomoc w przerobieniu go tak, by sie wykonywal co np. 1 minute , az go wylacze. I z racji ze nie mam za duzo doswiadczenia z tego typu plikami, chcialbym zeby mnie ktos nakierowal co ja w ogóle mam zrobic zeby ten skrypt "chodzil".
BTW: Wiem ze to wszystko jest banalne, ale mam mnostwo pracy i nie mam sil na kolejny problem :/
function ImportCSV( filename )
{
var fso, f, r;
var ForReading = 1;
var AmiBroker;
var ticker;
var date;
var quote;
var fields;
var stock;
/* Create AmiBroker app object */
AmiBroker = new ActiveXObject( "Broker.Application" );
/* ... and file system object */
fso = new ActiveXObject( "Scripting.FileSystemObject" );
/* we use file name ( without extension ) as a ticker name */
ticker = fso.GetBaseName( filename ).toUpperCase();
/* add a ticker - this is safe operation, in case that */
/* ticker already exists, AmiBroker returns existing one */
/* we are doing this outside loop since the file contains */
/* quotes of single stock only */
stock = AmiBroker.Stocks.Add( ticker );
/* open ASCII file */
f = fso.OpenTextFile( filename, ForReading);
/* notify the user */
WScript.Echo( "Importing " + ticker );
/* skip first line which contains format definition */
f.SkipLine();
/* read the file line by line */
while ( !f.AtEndOfStream )
{
r = f.ReadLine();
/* split the lines using comma as a separator */
fields = r.split(",");
/* split date at - separator */
var datefld = fields[ 0 ].split("-");
/* ensure Y2K compliance by converting year to 4 digit number */
var year = parseInt( datefld[ 2 ] );
year += ( year < 50 ) ? 2000 : 1900;
datefld[ 2 ] = year.toString();
/* put date back all together */
datefld.join(" ");
date = new Date( datefld );
/* add a new quotation */
quote = stock.Quotations.Add( date.getVarDate() );
/* put data into it */
quote.Open = parseFloat( fields[ 1 ] );
quote.High = parseFloat( fields[ 2 ] );
quote.Low = parseFloat( fields[ 3 ] );
quote.Close = parseFloat( fields[ 4 ] );
quote.Volume = parseInt( fields[ 5 ] );
}
/* refresh ticker list and windows */
AmiBroker.RefreshAll();
/* notify the user */
WScript.Echo( "Finished" );
}
I tu jeszcze propozycja wywolania tej funkcji:
ImportCSV( "aapl.csv" );