I'm trying to update OpenInt for existing EOD quotes in my AmiBroker database using a Python script. Testing on ticker SMFL, I expect all OpenInt values to update from 0 to 1. However, after running the script, the values remain 0 in the quote editor.
Interestingly, if I move ab.SaveDatabase() inside the update loop and set a breakpoint there, I see the values update correctly in the editor when I step through the breakpoints. But when running the script without debugging, all values stay at 0 despite the same save call.
Here’s the output:
Started AmiBroker...
Loaded AmiBroker DB...
Updated total Quotes: 649
Saving final database...
Closing AmiBroker...
Process finished with exit code 0
Why is this happening? Any insights would be appreciated. Thank you!
Thanks!
import win32com.client
AMIBROKER_DB_PATH = "C:\\Program Files\\AmiBroker\\Databases\\foo"
if __name__ == "__main__":
ab = win32com.client.Dispatch("Broker.Application")
print("Started AmiBroker...")
ab.LoadDatabase(AMIBROKER_DB_PATH)
print("loaded AmiBroker DB...")
quotes_count = 0
stock = ab.Stocks("SMFL")
for q in stock.Quotations:
q.OpenInt = 1.0
quotes_count += 1
print("Updated total Quotes:", quotes_count)
print("Saving final database...")
ab.SaveDatabase()
print("Closing AmiBroker...")
ab.Quit()
Can you open task manager and ensure there is no other instance running?
close all instances and then test.
OLE works with the first instance, and that is what you should be looking at.
and you can share your import format file
I used ole for ages, even without using ab.SaveDatabase() quotes should update
if your script didn't exit properly, it leaves behind AB in a background state.
so clear everything, then test by OPENING AB first instance manually "then" running py script.
don't use ab.Quit()
## at the end
del ab ## explicitly dispose this variable
Went to Task manager and closed Amibroker instance( there was just 1)
Removed ab.Quit() and used del ab at the end.
Manually opened ab instance.
Ran the script.
Able to see the update in manually opened AB instance quote editor.
As you said ab.SaveDatabase() does not make any difference. Thanks again!
Updated script for ref
if __name__ == "__main__":
ab = win32com.client.Dispatch("Broker.Application")
print("Started AmiBroker...")
ab.LoadDatabase(AMIBROKER_DB_PATH)
print("loaded AmiBroker DB...")
quotes_count = 0
stock = ab.Stocks("SMFL")
for q in stock.Quotations:
q.OpenInt = 3
quotes_count += 1
print("Updated total Quotes:", quotes_count)
print("Saving final database...")
# ab.SaveDatabase()
print("Closing AmiBroker...")
## at the end
del ab ## explicitly dispose this variable