A Blog Of Random Coding Techniques & Experiments Robert Askam

PostBuilding a Crypto Trading Bot in Laravel using PHP and Binance2 months ago

What we are doing

We will be building a crypto currency trading bot using PHP, Laravel and Binance. This trading bot will buy and sell for you using an algorithm of your making. Even if you aren't using Laravel you can get the basics and use a cron job to run your php file.

Automate it

Job

Create a new job called CryptoBot

php artisan make:job CryptoBot

and paste this code

namespace App\Jobs;

use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use App\CryptoTrading;
use App\CryptoTradingBot;

Finished

Thats it!! If you are local run

php artisan queue:work

and you should see the trades going through. This PHP trading bot will check Binance for a crypto and check if its gone up by 1% and put a buy order in. Once this is placed it will check to see if its gone up by another 1% and put a sell order. So every-time you should make 1%. Obviously there is a chance it will go down and if it goes below 5% then it sells.
There are other exchanges and I do not have a preference. This is just the first one I found.

NOTE: Use at your own risk. I take no responsibility for losses of your money. The market fluctuates and you have the real possibility of losing all your money. I recommend starting with a small amount if you are going to do it. This is just example code for learning.

Once you've made your millions ;) I recommend looking at a Trezor as a hardware wallet to keep your coins secure.

Not many guides or a lot of issues with jaggedsoft/php-binance-api but hopefully in the code you will see some fixes. That code base is updated so may be better to download from there but to keep this tutorial correct I used the forked code in the example. Normal one is here.

Thank you for reading my guide on PHP Trading Bot for Crypto Currencies using Binance and Laravel. Any issues feel free to leave a comment.