Programming Project Part #1

in #python9 days ago

I made a post on Hive about a programming project I’ve been working on — a Python trading bot.

The way I like to think about this project isn’t just as a single script, but more like a small company where each script is an employee with a specific job. It helps me stay organized, especially since things can get a bit complex and messy if you try to cram everything into one giant file.

dfg.PNG

First Things First: What Does the Bot Need to Know?
Before the bot can actually do anything, it needs some key information:

The Binance API key and secret
These are keys you can easily get from your Binance account. They allow the bot to get account info and trade (buy, sell, or place orders). These keys don’t let you withdraw funds, but they do give you internal control of your account.

Whether or not we’re using testnet mode
Binance lets you use either the mainnet (real money) or the testnet, where you can get fake funds and simulate trades. Testnet is super helpful when building something like this bot — you can let it buy and sell without worrying about losing real money if something goes wrong.

The Telegram bot token and chat ID
You can also get these from Telegram to have your Python bot send messages and status updates. In the future, I might even let the bot respond to commands via Telegram (I haven’t looked into that part yet though).

And finally, the coin we want to trade, and the rules for how to trade it
(like target amount, budget, profit %, trailing %, etc.)
I’ll cover more of this in another post — this part is actually what makes my bot unique compared to most others. As far as I know, there aren’t many bots that handle this the same way.

But Where Does This Info Go?
Instead of hardcoding all this into the bot itself, we store it in a config.json file. That way, the bot — and any future scripts we add — can just read from that file and get the info they need. It keeps everything clean and modular.

How Do We Get That config.json File?
We have two options:

Manually write the JSON file ourselves (kinda annoying and easy to mess up).

Use a script to automate the process.
So I wrote a script called generate_config.py, which does exactly that:

If config.json doesn’t exist, it creates one using a predefined template.

If it does exist, it reads the file and checks that everything inside is valid.

If it exists but is invalid or corrupted, it replaces it with a fresh template — ready to be filled out again. This is what it would look like in the end, kinda
Capture.PNG