Welcome to NexusFi: the best trading community on the planet, with over 200,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- discounts are available after registering.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Hello,
I have generated fantasy data (1000 stocks) in CSV files. These 1000 stocks are not realy one and their tickers are not real ones.
Importing one file is OK, manually using the custom ascii import (I have made a special .format file).
What would be an easy way (using maybe an external software ?) to create a custom database containing the list of tickers (I have) + the CSV files (I have) ?
The goal is to be able to update a CSV file I have and directly see the new charts in amibroker without having to import manually using the ascii import menu. I hope I don't have to create a data plugin using C++ to achieve that ? I could not post this question to the amibroker yahoo group as I'm not a customer yet.
Thanks!
Can you help answer these questions from other members on NexusFi?
Simplest is probably scripting something in AutoHotKey to duplicate the interactions needed to import them one at a time, and use it to automate the process.
The following is just an example using VBS; obviously could be written in Javascript, or Python
(sorry comments are in italian) :
'
' ManageQUANDL
' @info effettua il download e l'import dei dati QUANDL
' Aggiorna il database QuandlEOD
'
' @param sDISCO una stringa che indica il disco in cui risiedono i dati finanziari
' @param oLOG TextStream Object del di log da usare
'
' NOTA : il campo Address deve contenere :
' STOXX,indexID (ossia nome dell'indice stoxx e del file)
'
PUBLIC SUB ManageQUANDL(sDISCO,oLOG)
'
CONST sQUANDLBaseArchiv = "\FINANZA\OTHERS_DATA\QUANDL\"
CONST sQUANDLBaseURL = "http://www.quandl.com/api/v1/datasets/"
CONST sQUANDLAuthURL = "?&auth_token="
CONST sQUANDLEndPartURL = "&sort_order=desc"
'
DIM oAB,oSTOCKS,oStock,sAddress,sURL,sFileTicker,sAmiBrokerFILE
' invia msg apertura
SET oSHELL = CreateObject("WScript.Shell")
iResp = oSHELL.popup("Start Manage QUANDL",1,G_sTITOLO,0)
SET oSHELL = NOTHING
'
oLOG.WriteLine(""+Cstr(Now()) + " Start QUANDL Import")
'
' ottieni FileSystemScripting per creare directory dati (se non esiste)
SET oFSO = CreateObject("Scripting.FileSystemObject")
sAmiBrokerFILE = sDISCO & sQUANDLBaseArchiv
CALL GeneratePath(oFSO,sAmiBrokerFILE)
SET oFSO = NOTHING
'
' loop sui dati di AmiBroker, se trovi dato quandl cerca di caricare/aggiornare
'
' crea AmiBroker, load database
SET oAB = CreateObject("Broker.Application")
sDB = sDISCO & "\\FINANZA\\AB\\QuandlEOD"
CALL oAB.LoadDatabase(sDB)
' l'elenco dei titoli
SET oSTOCKS = oAB.Stocks
iStockQty = oSTOCKS.Count
'
' loop su tutti i titoli prendi solo quelli di QUANDL
' in address : quandl,unique id (nome file),numero rollover per anno correnti,
'
ndownloaded = 0
FOR i = 0 TO (iStockQty-1)
SET oStock = oSTOCKS( i )
sERROR = ""
IF (oStock.Address <> "" ) THEN
sAddress = Split(oStock.Address,",")
IF (UCASE(sAddress(0)) = "QUANDL") THEN
IF UBound(sAddress) < 2 THEN
sERROR = " Error on Address field of " & oStock.Ticker & " of QUANDL(" & oStock.Address & ")"
ELSE
sFileTicker = sAddress(1) & ".csv"
sURL = sQUANDLBaseURL & sFileTicker & sQUANDLAuthURL & G_sQUANDL_TOKEN & sQUANDLEndPartURL
sAmiBrokerFILE = sDISCO & sQUANDLBaseArchiv & oStock.Ticker & ".csv"
' DEBUG ONLY
'oLOG.WriteLine(""+Cstr(Now()) & " debug url=" & sURL& & " AmiBroker file=" & sAmiBrokerFILE)
END IF
IF sERROR <> "" THEN
oLOG.WriteLine(""+Cstr(Now()) + sERROR)
ELSE
ndownloaded = ndownloaded + 1
ierr = DownloadFile(sURL,sAmiBrokerFILE)
IF ierr <> 0 THEN
oLOG.WriteLine(""+Cstr(Now()) & " Error downloading (" &CSTR(ierr)& ") " & sURL & " to file " & sAmiBrokerFILE )
ELSE
CALL oAB.Import(0,sAmiBrokerFILE,"quandl_futures.format")
END IF
END IF
END IF
END IF
NEXT
SET oSTOCKS = NOTHING
SET oStock = NOTHING
' aggiorna AmiBroker, salva e rilascia
'CALL oAB.RefreshAll()
CALL oAB.SaveDatabase()
SET oAB = NOTHING
'
oLOG.WriteLine(""+Cstr(Now()) + " END QUANDL Import ("+Cstr(ndownloaded)+" files)")
' invia msg chiusra
SET oSHELL = CreateObject("WScript.Shell")
iResp = oSHELL.popup("END Manage QUANDL",1,G_sTITOLO,0)
SET oSHELL = NOTHING
END SUB
This example will download and import in AmiBroker QUANDL data.
The idea is :
loop on all tickers, and see the Address field
if address field will indicate to download/import data I usually put inside the field
the path o part of the path for download/import data..
The DownloadFile() is an utility routine that download data :
'
' DownloadFile
' @info effettua il download della sURL indicata nel
' file sLocation indicato torna 0 per OK, -1 per errore
'
' @param sURL la URL completa di cui deve essere fatto il
' download
' @param sLocation il path base di ove vuoi sia archiviato il
' file downloaded, tipicamente si tratta di
' una locazione che poi NON viene cancellata
'
PUBLIC FUNCTION DownloadFile(sURL,sLocation)
On Error Resume NEXT
'
DIM oXMLHTTP,oADOStream,oFSO,oSHELL
' crea l'XMLHTTP per fare la fetch del file
SET oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
' effettua lo GET del file
CALL oXMLHTTP.open("GET", sURL, false)
CALL oXMLHTTP.send()
' se riesce a creare XMLHTTP, crea uno stream e setta i dati
If oXMLHTTP.Status = 200 Then
' crea lo stream
SET oADOStream = CreateObject("ADODB.Stream")
' Apri lo stream appena creato
CALL oADOStream.Open()
' setta lo Stream in modo binario
oADOStream.Type = 1 'adTypeBinary
' setta nello Stream il response body dell'XMLHTTP
CALL oADOStream.Write(oXMLHTTP.ResponseBody)
' setta la posizione dello Stream all'inizio
oADOStream.Position = 0
' crea oggetto per manipolare file system
SET oFSO = Createobject("Scripting.FileSystemObject")
' se il file esiste, cancellalo
If oFSO.Fileexists(sLocation) Then CALL oFSO.DeleteFile(sLocation)
' rilascia oggetto per manipolare file system
SET oFSO = NOTHING
' chiedi allo Stream di scaricare il file e salvarlo
CALL oADOStream.SaveToFile(sLocation)
' chiudi lo Stream
CALL oADOStream.Close()
' rilascia lo stream
SET oADOStream = NOTHING
DownloadFile = 0
ELSE
'
' errors : signal an wait 300 sec or OK
'
SET oSHELL = CreateObject("WScript.Shell")
iRespOK = oSHELL.popup("Site " & sURL & " is unavailable (press OK to continue)",60,"DownloadFile", 48+0 )
SET oSHELL = NOTHING
DownloadFile = -1
END if
' rilascia lo XMLHTTP
SET oXMLHTTP = NOTHING
END FUNCTION
The GeneratePath() is a simple utility function that verify if specified path exists
otherwise create it.