Import data through ole

Can someone explain or point me where can I find details about importing data through OLE apart from AmiBroker’s OLE Automation Object Model?

Specifically what Type stands for and how many Types there are, at the Import method of the Application Object :

Function Import(ByVal Type As Integer, ByVal FileName As String, [ByVal DefFileName As Variant]) As Long

Also if it is possible to pass multiple files that use the same format file in one command, for example:

Amibroker.Import(0, file1 file2 file3, formatFile);

Type should always be set to 0. And you need to import one file in single call to Import.
Old newsletter article includes examples
http://www.amibroker.com/newsletter/02-2001.html

3 Likes

I would like to use Import() function of OLE object. The documentation is found here;
https://www.amibroker.com/guide/objects.html

The function prototype is like this;
Function Import(ByVal Type As Integer, ByVal FileName As String, [ByVal DefFileName As Variant]) As Long

I cannot find further documentation other than the prototype. Please point me to the link for more documentation if I have missed out.

I do not know what value to use for ByVal Type As Integer and what kind of of Long value is returned. I am also not able to find description for [ByVal DefFileName As Variant].

It was already explained on the forum: How to manually import OHLC data via AFL script? and here Import data through ole

I find it hard to believe that you missed it because Discourse automatically displays existing relevant posts when you try to create new topic.

image

1 Like

Sorry about it. I will keep a lookout for this feature of Discourse in future when posting new topics. Do be patient with some of your slower customers.

I think it is a good practice to update all documentation into a single location. I suggest that the updated documentation on this thread be updated onto the Amibroker documentation.

https://www.amibroker.com/guide/objects.html

As a general rule, it is confusing to customers when documentation are in multiple places.

Are you aware that to do what you are asking for in practice would mean that I could not answer e-mails or posts on forum because this is “different place” than User’s guide. If your suggestion about “single place” was implemented you would ask here and the answer would be placed in Users’ Guide and nowhere else.

There is a good old saying “be careful what you wish for”

Hi Tomasz,

Thanks for your patience in answering our posts timely, as always. What I had in mind was that if your customers can find the answers from the documentation themselves, they can bother you less on this forum and not divert your time from development.

For instance, things like description of a function should be in the documentation. Providing merely the function prototype is not enough, as was the case for Import() (see link below).

https://www.amibroker.com/guide/objects.html

3 Likes

And how is that OLE script launched?

This is the best explanation in KB to run OLE scripts. You can put code in batch file or in CMD etc

AmiBroker Knowledge Base » Running OLE automation scripts with 32- and 64-bit versions of AmiBroker
explicit Engine specified.
<path to 32 or 64bit>cscript.exe //E:jscript hello.js

but you can run OLE from any language that supports like MS excel, python etc
they all should be able to CreateObject() to call AB ole server

ZoomToRange not working in Python OLE - AFL Programming - AmiBroker Community Forum

1 Like

Note that running .JS or .VBS is Windows is NOT rocket science.

All it involves is simply double click on such file.

That is precisely how do you run ANY program in Windows. By default .JS and .VBS scripts are associated with Windows Scripting Host (wscript.exe).

Also scripts can be directly run from Window Task Scheduler like any other program.

Hi,

I have couple of basic questions on Importing data through OLE.

  1. Do I need to keep Amibroker closed for data import to work?
    a. I kept Amibroker open with default database and data import didnt happen successfully into default database.
    b. When I closed Amibroker and ran the script again, data import happened successfully.
import win32com.client
AmiBroker = win32com.client.Dispatch("Broker.Application")

try:
    AmiBroker.Import( 0, "c:\\Users\\polygonv2\\eod_daily\\2024\\eod_2024-03-11.csv", "c:\\Program Files\\AmiBroker\\Formats\\polygon.format" )
except: 
    print('An exception occured')
AmiBroker.RefreshAll()

I have used above script written in python to load it into Amibroker database through OLE.

  1. Does data import through ole happens only into default database. I have tried changing database using the following code while Amibroker is closed and data is not loaded into expected database.
import win32com.client
AmiBroker = win32com.client.Dispatch("Broker.Application")

if str.split(AmiBroker.DatabasePath, '\\')[-2] == "eoddata_new":
    print(f"Current Database Path and Name is {AmiBroker.DatabasePath}")
else:
    AmiBroker.LoadDatabase("c:\\Program Files\\AmiBroker\\Databases\\eoddata_new\\")
    print(f"Loaded Database Path and Name is {AmiBroker.DatabasePath}")

try:
    AmiBroker.Import( 0, "c:\\Users\\tedla\\Downloads\\EODDATA\\Amex\\AMEX_2024\\AMEX_20240227.csv", "c:\\Program Files\\AmiBroker\\Formats\\eoddata.format" )
except: 
    print('An exception occured')
AmiBroker.RefreshAll()

Can anyone please point me in the right direction on how I can pick the database before loading, do I need to keep the Amibroker closed during the load or not.

I tried searching for these answers but I couldnt find any.