AmiQuote Symbol Translation table not loaded through OLE automation

Is there an extra step when using AMiQuote OLE automation in order to read Symbol Translation table for Stooq.pl?

  1. AmiQuote Poland does not work with OLE automation. My AmiBroker db has symbols such as BHW.PL which needs to be translated to BHW at Stooq.pl:
    AmiQuote Poland does not work with OLE automation
  2. AmiQuote Poland works manually, without automation, using same AmiQuote 3.27 32 bit. Symbol translation table DOES NOT seem to be loaded:
    AmiQuote Poland works manually2
  3. AmiQuote Hungary works with OLE automation, as no symbol translation is needed, both my db and Stooq.pl have symbols in KONSUM.HU format:
    AmiQuote Hungary works with OLE automation3
  4. My ruby automation does:
ab = WIN32OLE.new("Broker.Application") # C:\Program Files (x86)\AmiBroker\Broker.exe
  ab.LoadDatabase( dirAB + db )
  stks = ab.Stocks()
  qty = stks.Count
  puts "Opening #{db} database with #{qty} pre-existing symbols"
  
  puts "Starting AmiQuote 32-bit"
  aq = WIN32OLE.new("AmiQuote.Document") # C:\Program Files (x86)\AmiBroker\AmiQuote\Quote.exe

  if @country == "PL"
    tickerList = plTickers # 90 symbols
  elsif @country == "HU"
    tickerList = huTickers # 38 symbols
  elsif
  ..
  end

if @source == "StooqHistorical"
    aq.Source = 7 
	puts "Using Stooq Historical as the source of data"
..
end

toDate = (d + 0).strftime("%m/%d/%Y") #date in 02/16/2016 format
  puts "From: " + fromDate 
  puts "To:   " + toDate 
  aq.From = fromDate
  aq.To = toDate

aq.AutoImport = true #import automatically
	
  dst = Time.now
  dstTimeZone = dst.strftime("%Z")
  dstFormatted = dst.strftime("%m-%d-%Y %H:%M:%S")
  puts "#{comp} Time Zone is #{dstTimeZone}"
  puts "Download started at #{dstFormatted}"
  aq.Download() #starts download
  #wait until download is finished
  while aq.DownloadInProgress || aq.ImportInProgress
	sleep 1 #check InProgress every x seconds 
  end
  det = Time.now
  detFromatted = det.strftime("%m-%d-%Y %H:%M:%S")
  download_took = (det - dst)/60
  puts "Download completed at #{detFromatted}"
  puts "Download took #{download_took.round} minutes"

Is there an extra step when using AMiQuote OLE automation in order to read Symbol Translation table for Stooq.pl? I consulted https://www.amibroker.com/guide/aqobjects.html

  1. AmiQuote Poland does not work with OLE automation. My AmiBroker db has symbols such as BHW.PL which needs to be translated to BHW at Stooq.pl Symbol translation table DOES NOT seem to be loaded, although it exists at C:\Program Files (x86)\AmiBroker\AmiQuote\yahooi.translations :
    AmiQuote Poland does not work with OLE automation
  2. AmiQuote Poland works manually, without automation, using same AmiQuote 3.27 32 bit:
    AmiQuote Poland works manually2
  3. AmiQuote Hungary works with OLE automation, as no symbol translation is needed, both my db and Stooq.pl have symbols in Symbol.HU format:
    AmiQuote Hungary works with OLE automation3
  4. My ruby automation does:
ab = WIN32OLE.new("Broker.Application") # C:\Program Files (x86)\AmiBroker\Broker.exe
  ab.LoadDatabase( dirAB + db )
  stks = ab.Stocks()
  qty = stks.Count
  puts "Opening #{db} database with #{qty} pre-existing symbols"
  
  puts "Starting AmiQuote 32-bit"
  aq = WIN32OLE.new("AmiQuote.Document") # C:\Program Files (x86)\AmiBroker\AmiQuote\Quote.exe

  if @country == "PL"
    tickerList = plTickers # 90 symbols
  elsif @country == "HU"
    tickerList = huTickers # 38 symbols
  elsif
  ..
  end

if @source == "StooqHistorical"
    aq.Source = 7 
	puts "Using Stooq Historical as the source of data"
..
end

toDate = (d + 0).strftime("%m/%d/%Y") #date in 02/16/2016 format
  puts "From: " + fromDate 
  puts "To:   " + toDate 
  aq.From = fromDate
  aq.To = toDate

aq.AutoImport = true #import automatically
	
  dst = Time.now
  dstTimeZone = dst.strftime("%Z")
  dstFormatted = dst.strftime("%m-%d-%Y %H:%M:%S")
  puts "#{comp} Time Zone is #{dstTimeZone}"
  puts "Download started at #{dstFormatted}"
  aq.Download() #starts download
  #wait until download is finished
  while aq.DownloadInProgress || aq.ImportInProgress
	sleep 1 #check InProgress every x seconds 
  end
  det = Time.now
  detFromatted = det.strftime("%m-%d-%Y %H:%M:%S")
  download_took = (det - dst)/60
  puts "Download completed at #{detFromatted}"
  puts "Download took #{download_took.round} minutes"

I suspect that there is something wrong with my Symbol Translation file, but do not know why it would work properly when done manually, but not read the symbol translation table via OLE automation.
5) Symbol Translation table seems to display correctly through AmiQuote / Tools / Symbol Translation table menu for Stooq.pl.
6) C:\Program Files (x86)\AmiBroker\AmiQuote\yahooi.translations is not read-only or hidden.
7) It is a bit odd that the symbol paris for Stooq.pl are saved as yahooi.translations as opposed to say stooqpl.translations but it matches entries in AmiQuote / Tools / Symbol Translation table menu for Stooq.pl
AmiQuote symbol translation

You are starting AmiQuote in WRONG directory. You should start AmiQuote so CURRENT WORKING DIRECTORY is set properly to where it is located. Otherwise it won’t find translation files because it refers to them using CURRENT WORKING DIRECTORY instead of absolute path. You should start it explicit in correct folder. Otherwise if you run it from your “ruby” it would very likely have wrong working directory (such as where your ruby file is or in C:\Windows or some other random place).

OK, thank you.

  1. Originally I started my ruby file AmiQuote6.rb which opens AmiQuote from C:\Dropbox\Trading where
    C:\Dropbox\Trading\AmiQuote6.rb
    C:\Program Files (x86)\AmiBroker\AmiQuote\Quote.exe
    C:\Program Files (x86)\AmiBroker\AmiQuote\yahooi.translations
  2. Next I copied my rb code file to C:\Program Files (x86)\AmiBroker\AmiQuote\ and kicked off rb from that directory, all imports still failed
    C:\Program Files (x86)\AmiBroker\AmiQuote\AmiQuote6.rb
    C:\Program Files (x86)\AmiBroker\AmiQuote\Quote.exe
    C:\Program Files (x86)\AmiBroker\AmiQuote\yahooi.translations
  3. Next I copied my translations file to C:\Dropbox\Trading\ and kicked off rb from that directory, all imports still failed
    C:\Dropbox\Trading\AmiQuote6.rb
    C:\Program Files (x86)\AmiBroker\AmiQuote\Quote.exe
    C:\Dropbox\Trading\yahooi.translations
  4. Next I copied my translations and rb files to c:\ruby\bin\ and kicked off rb from that directory, all imports still failed
    c:\ruby\bin\AmiQuote6.rb
    C:\Program Files (x86)\AmiBroker\AmiQuote\Quote.exe
    c:\ruby\bin\yahooi.translations
  5. I'm also attaching a screenshot of how yahooi.translations file looks like with all characters showing, in case there is something wrong with it, note that it has my db file symbol such as BHW.PL comma space and symbol at Stooq.pl such as BHW, then it is followed by CR CR LF and then the next pair of translation symbols.
    AmiQuote symbols translation file with all characters showing

Copying files is useless excercise. OLE does not work that way. OLE server is registered with path in the Windows REGISTRY, and no amount of copying would ever fix that.

Again I can only repeat what I wrote already: you need to START (launch) AmiQuote with proper current working directory.

Current working directory is set when you create PROGRAM SHORTCUT and set “Start In” field properly and run program from that shortcut. If you run program in any other way than properly created shortcut, it will get working directory of parent or in case of script the location of CSCRIPT/WSCRIPT which is typically C:\Windows\System32 folder.

Tomasz,

Would you please point out the discepency between what you said:

TomaszOwner3d
You are starting AmiQuote in WRONG directory. You should start AmiQuote so CURRENT WORKING DIRECTORY is set properly to where it is located. Otherwise it won’t find translation files because it refers to them using CURRENT WORKING DIRECTORY instead of absolute path. You should start it explicit in correct folder. Otherwise if you run it from your “ruby” it would very likely have wrong working directory (such as where your ruby file is or in C:\Windows or some other random place).

and what I said? :

9. Next I copied my rb code file to *C:\Program Files (x86)\AmiBroker\AmiQuote* and kicked off rb from that directory, all imports still failed
C:\Program Files (x86)\AmiBroker\AmiQuote\AmiQuote6.rb
C:\Program Files (x86)\AmiBroker\AmiQuote\Quote.exe
C:\Program Files (x86)\AmiBroker\AmiQuote\yahooi.translations

AmiQuote OLE fails even from AQ directory

You forget the fact that ruby is INTERPRETED language and it does not matter where you have your .rb file, as it is not your .rb file that does the job but ruby interpreter which is elsewhere. Remember google is your best friend https://stackoverflow.com/questions/1937743/how-to-get-the-current-working-directorys-absolute-path-from-irb

@mdwin01, in general, one tool that can help in case like this is the Sysinternals ProcessExplorer

If you launch it before invoking the script, you can see where the different processes are running (in this case you are interested in Quote.exe).

I modified your .rb script to use a database of mine and found that to use the translation tables - on my machine/configuration - I had to copy them in the C:\Windows\System32 folder since the Quote (64bit) instance launched by the Ruby script "Current directory" was there:

image

2 Likes

Thank you for pitching in, beppe. Just like in your env, ruby invoked Quote.exe current directory is C:\Windows\System32\ but copying translation files ( C:\Windows\System32\yahooi.translations ) there does not help, all imports still fail.

I don’t know how to “start AmiQuote so CURRENT WORKING DIRECTORY is set properly to where it is located” in ruby…

FWIW: To make things easier AQ 3.29 would change the current working directory for you if it is set incorrectly.