How to Build a Simple PHP Crypto Trading Bot Using the HitBTC API

php crypto trading bot with hitbtc.com api

Building a crypto trading bot doesn’t have to be complicated. With this PHP trading bot, you can automate buying and selling cryptocurrencies like Shiba Inu (SHIB) using the HitBTC API. The best part is that this bot is entirely web-based, meaning all you need is a web hosting account and a domain name. If you already have a website, there’s no need to buy a new domain or hosting plan. You can simply upload the bot files to a separate directory, such as https://yourwebsite.com/bot/index.php, and run it in the background.

The bot is designed to work 24/7 through a cron job, which is available in most web hosting panels like DirectAdmin or cPanel. The cron job executes the bot script at regular intervals, allowing it to continuously monitor the market, make trades, and update relevant information. While the bot runs automatically, it’s still recommended to check it occasionally to ensure everything is running smoothly.

Click Here to Get the Files from Github


How the Bot Works

This PHP trading bot interacts directly with the HitBTC API using your account’s API key and secret. Once configured, the bot monitors the market price of a chosen cryptocurrency and automatically decides when to buy or sell based on percentages you set. It also tracks its actions in text files to avoid repeating trades, record prices, and keep a count of successful trades.

Here’s a quick overview of the key features:

  • Automated Trading: Buys and sells a specific token like Shiba Inu (SHIB) using USDT.
  • Text File Tracking: Uses files like flipping.txt, user_bot_paid.txt, and counter.txt to track trades and prices.
  • Stop-Loss Function: Stops trading if the price drops below a set threshold.
  • Cron Job Integration: Runs continuously without manual intervention.
  • Manual Balance Check: A separate balance.php file allows you to view your HitBTC account balance without logging in.

Step 1: Download and Upload Bot Files

You’ll need to download the following files from my GitHub repository:

  • index.php – main bot file
  • counter.txt – trade counter
  • flipping.txt – trade status tracker
  • user_bot_paid.txt – starting trade price
  • balance.php – optional account balance checker

GitHub repository: crypto-trading-bot-php-hitbtc-api

After downloading, upload all files to a folder on your hosting account. You can name the folder anything you like; for example, I used bot and accessed it at:
https://yourwebsite.com/bot/index.php


Step 2: Configure the Main Bot File (index.php)

The index.php file contains most of the settings needed to run the bot:

  • API Keys: $apiKey and $apiSecret must be generated from your HitBTC account.
  • Trading Symbol: $symbol defines which token to trade. For example: $symbol = "SHIBUSDT"; // Shiba Inu traded with USDT âš  Note: This bot is designed for tokens priced below 1 USD, like SHIB. If you want to trade tokens above 1 USD, the script will require customization.
  • Quantity: $quantity defines how many tokens to buy or sell in each trade. Example: $quantity = 3827000;
  • Trade Percentages: $buy_percent = 0.02; // Buy when price drops 2% $sell_percent = 0.02; // Sell when price rises 2% $dont_waste_money_percent = 0.9; // Stop trading if price falls 10% below buy price

These percentages can be adjusted to fit your trading strategy.


Step 3: Setting Up Cron Jobs

To run the bot continuously, configure a cron job in your hosting panel. Set the schedule to run every minute, hour, day, month, and day of the week using *. The command should look like this:

curl -L -s https://yourwebsite.com/bot/index.php

This ensures the bot runs 24/7 automatically. Make sure to configure all bot files correctly before starting the cron job.


Step 4: Understanding the Supporting Files

1. counter.txt

This file counts each successful trade. Start with 0 for a new bot. Each buy or sell increments the counter by 1, so after one buy and one sell, the file will show 2. You can reset it anytime by manually writing 0.

2. flipping.txt

This is a crucial file that controls the bot’s trading behavior. It uses three keywords:

  • buy – bot will sell next
  • sell – bot will buy next
  • stop – bot will pause trading

If it’s your first time running the bot, you must set this manually based on your current account status. For example, if you already bought tokens, write buy so the bot knows it should wait to sell.

3. user_bot_paid.txt

This file stores the starting price for the bot to begin trading. You must set this manually the first time. After each trade, the bot automatically updates the price. For example, in the GitHub example, the price is set at 0.0000088410 USDT for Shiba Inu.

4. balance.php

A standalone file to check your HitBTC account balance using your API keys. This is optional and is not part of the cron job.


Step 5: Tips for Smooth Operation

  • Always check the bot occasionally to ensure it’s running as expected.
  • Adjust percentages and quantity based on market conditions and your risk tolerance.
  • Use stop in flipping.txt to pause trading if the market becomes unstable.
  • Start with small quantities until you are comfortable with the bot’s behavior.

Conclusion

This PHP crypto trading bot offers a simple, web-based solution for automated trading on HitBTC. By using cron jobs, it runs continuously while tracking trades, prices, and account status through text files. With basic configuration, even beginners can automate trading strategies for tokens like Shiba Inu. By carefully setting up API credentials, trade percentages, and initial prices, you can start trading safely and efficiently without constantly monitoring the market.

Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top