Updating Industy of Symbol using Python

Hello, I'm currently working on a Python script to automatically update the industry of a script. I'm interested in finding a method in Python that retrieves all the industries and their corresponding IDs. This way, I can avoid manually updating the industry ID for each individual industry

The following is the code to update a script with Industry ID = 5

import win32com.client as win32
import time

# Connect to Amibroker
try:
    amibroker = win32.Dispatch('Broker.Application')
    print("Connected to AmiBroker")
except Exception as e:
    print(f"Error connecting to AmiBroker: {e}")
    exit()  # Exit the script if there is an error connecting

# Get the stock object
symbol = "MOL"
stock = amibroker.Stocks(symbol)

# Update symbol information
if stock:
    stock.Ticker = "MOL"
    stock.FullName = "Meghmani Organics Ltd"
    stock.IndustryID = 5  # Set IndustryID to 5 (ID for "Coal")
    print(f"Updated information for {symbol}")
else:
    print(f"Stock not found: {symbol}")

# Refresh the database
amibroker.RefreshAll()
time.sleep(3)  

print("Database updated")

Currently, I have to write the industry ID manually. I would like to change this so that I can simply pass the industry name to the script, and the script will fetch the ID itself.

Any help with this would be greatly appreciated.

1 Like

Instead of using python script, you can used ASCII import instead. But, first you need to create the import format using the Import Wizard.

1 Like

@Peter2047 Is there a way we can import symbol industry details via ASCII import by using industry name rather than industry ID?

If so, can you please guide how to do this, as I am not familiar with this feature.

Just read the Amibroker knowledge base

You should read all of knowledge base first.

fxshrat has provided you the link for importing by Industry Name. Industry ID has one advantage - less chance of misspelling. One way easy to convert industry name to ID is using Excel Vlookup function.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.