I have made myself a small script which is supposed to take a text file with all stocks’ data and to update the AB database (if the ticker exists already) or create a new ticker if not found in AB:
ab = win32com.client.Dispatch("Broker.Application") ab.LoadDatabase(dbname) for line in mktlist: l = line.split(';') # l - ticker # l - Alias # l - FullName # l - Currency try: stock = ab.Stocks(l) if stock is not None: # stock found # update stock data - this part works OK stock.Alias = l stock.FullName = l stock.Currency = l # etc... stock.IsDirty = 1 else: # stock not found # create new - this part doesn't work new_stock = ab.Stocks.Add(l) new_stock.Alias = l new_stock.FullName = l new_stock.Currency = l # etc... new_stock.IsDirty = 1 except Exception as e: print("%s:\n" % (e)) print("%s\n" % (traceback.format_exc())) ab.RefreshAll() ab.SaveDatabase() ab.Quit()
The problem I have is that while the update of existing ticker and determining that a ticker does not exist work perfectly, the new ticker is not created.
Have you any idea what I am doing wrong?
Thanks for your help.