“CryptoBot For Binance - Cryptocurrency Trading PHP Script” Documentation by “Övünç Tükenmez” v1.1.4


“CryptoBot For Binance - Cryptocurrency Trading PHP Script”

Last Update: 12.06.2021
By: Ovunc Tukenmez
Email: ovunct@live.com

Thank you for purchasing this PHP software. If you have any question that is beyond the scope of this help file, please feel free to send me an email. Thanks!


Table of Contents

  1. Software
    1. Software Info
    2. Used Technologies
    3. Change Log
  2. Installation
    1. Requirements
    2. Registering a 10% Discounted Commission Rated Binance Account
    3. Installation Process
  3. Trading
    1. Algorithm
    2. User Interface
  4. Online Demo
  5. Sources and Credits

1. Software - top

1.1. Software Info - top

CryptoBot For Binance - Cryptocurrency Trading PHP Script is an advanced PHP software to automate trading of crypto coins in Binance crypto-currency exchange. By following defined rules of the trading strategy of the user, it aims to facilitate repetitive trade process fast using API provided by Binance platform.
The software provides web interface to make possible instant user actions on going process if needed.
SQLite database is used to make installation, setup and migration a smooth/easy process.
The internet browser based interface use the system's own API that is available to use in other custom solutions if needed.


1.2. Used Technologies - top

The following technologies and libraries are used in the CryptoBot For Binance - Cryptocurrency Trading PHP Script:


1.3. Change Log - top

v1.0.0 v1.1.0 v1.1.1 v1.1.2 v1.1.3 v1.1.4

2. Installation - top

2.1. Requirements - top

PHPMLC requires the following software in order to run:


2.2. Registering a 10% Discounted Commission Rated Binance Account - top

Binance takes commission on each trade. By using following link to register an account, you can benefit 10 percent off on commissions!
https://www.binance.com/en/register?ref=WRS9W5SV

Binance discount code
This offer is only available on registration step. This will make huge difference especially if you're going to trade a lot so please make sure you use the correct link:
https://www.binance.com/en/register?ref=WRS9W5SV


2.3. Installation Process - top

Folder Structure:
The folder structure of the "CryptoBot" folder is as follows:
Folder Structure
Move all files from "code" folder to your web server's root or subfolder (like cryptobot). You can use XAMPP for local hosting.
The script should now be accessed by visiting the installed location's url like "http://localhost/cryptobot/".

Setting up the System:
Navigate to "Settings" page using the link on navbar.
settings link
Setting page opens:
settings page
System's api url and Binance api keys should be defined in order the script works properly.
System's api url should point to the address of the file "api.php" in script folder.
To get your Binance account api keys, visit Binance API management page and create a new API key if it doesn't exist.
https://www.binance.com/en/my/settings/api-management binance api management page
Please make sure that "Enable Reading" and "Enable Spot & Margin Trading" permissions are checked in "API restrictions" section. binance api permissions
Once you've created your API key, enter API key and API secret key to the related fields in settings page.
API secret key is shown only once when creating API key. If you didn't copied/noted it, please generate a new API key to get the required keys. binance api key definition on settings page
Price check interval is used by the trading interface to trigger api peridically. It is defined as 150 ms by default.
Binance has several restrictions on its API usage. Please take into the account the "request weight per minute" hard-limit when changing this value. For more information on the API usage restrictions, please visit the following link:
https://www.binance.com/en/support/faq/360004492232
For the current weights for API methods, please refer to the documentation:
https://binance-docs.github.io/apidocs/spot/en/#spot-account-trade
price check interval
Date timezone and date format can be customized using related fields.
For possible values, please refer related pages from the PHP documentation:
https://www.php.net/manual/en/timezones.php
https://www.php.net/manual/en/datetime.format.php
date timezone and date format
Click "Update" button to save changes.


3. Trading - top

3.1. Algorithm - top

algorithm
Even though the user can modify behaviour of the script by implementing his/her own trading strategy using several parameters, the system has the core business logic to follow.
The general idea is to buy low and sell higher in a perfect situation.
Once the script starts at the time T1, the status becomes "waiting_for_opportunity" and then it continuously fetches the current price of selected base asset in a quote asset value.
The current price of the asset at a time can be called as C.
In each price update, system compares the value with the previous high and low of the interval.
So the highest (H) and lowest (L) prices of the interval are saved to database to use in buy or sell decision.
Interval High/Low ratio that should be met to make buy action can be defined by user.
Trend of the price at higher perspective can be useful in order to make buy decision. So user can define first and second ranges that are before of current time to make comparison of their averages.
Maximum interval can be defined too. If maximum interval duration is exceeded, the new interval will start automatically.
The user can also trigger creation of market-buy/market-sell order by clicking "Buy Now"/"Sell Now" buttons.
When the buy condition is met, the system creates limit-buy order at current price. Status changes to "created_buy_order".
In each buy order check interval, the system checks order status. If it's "FILLED", status changes to "waiting_to_sell".
If auto-sell is enabled, system creates limit-sell order at target price and starts watching status of the created order.
In good scenario, the order status becomes "FILLED" and transaction completes at a profit.
If unexpected things happen in the market and price starts to fall rapidly and reaches to the point E ("Max. (Buy Price/Current Price) Ratio" is exceeded), the script can automatically create market-sell order to prevent further losses if user has activated "escape plan".
Several rules can be enabled according to trader's strategy.
The system can also work in "manual mode" by disabling "Auto-Buy" and "Auto-Sell" settings. In that case the user can use manual action buttons.

3.2. User Interface - top


Start/Pause/Stop Buttons:
start/pause/stop buttons
Start button trigger start/continue of trading process.
Pause button trigger pause of trading process.
Stop button trigger stop of trading process that will reset current interval data including trading status. Subsequent Start Button click will reset status to "Waiting for opportunity".

Reset Interval Button:
reset interval button
Reset Interval button clears interval data such as high/low values and starts new interval

Base and Quote Asset Trading Pair:
base and quote asset fields
The script will call "exchangeInfo" method of Binance Api to fill trading rules automatically so if you're changing a base or quote asset, you can leave Asset Price Tick Size and Asset Lot Step Size fields empty. You can manually change them later.
To get most up-to-date information about Trading rules, please visit the following link:
https://www.binance.com/en/trade-rule
Changing base or quote asset will clear all current interval data and trading status.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.

Base Asset Trading Balance:
base asset trading balance
The trading balance of base asset.
Sell order quantity is calculated using this value and the price of symbol.
If you are just starting for trade, you can leave this value as "0".
Once the base asset is bought with quote balance, the base asset balance will be automatically increased.
Changing trading pair will reset this value.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.

Quote Asset Trading Balance:
quote asset trading balance
The trading balance of quote asset.
Buy order quantity is calculated using this value and the price of symbol.
If you are just starting for trade, please make sure that the balance you allocate for trading meets minimum order size.
To get most up-to-date information about Trading rules, please visit the following link:
https://www.binance.com/en/trade-rule
Once the base asset is sold, the quote asset balance will be automatically increased.
Changing trading pair will reset this value.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.

Trading Fee Rate:
trading fee rate
Binance take commission on each trade. System takes into account this value to calculate quantity for order.
To guarantee to not get "insufficient balance" errors, it is suggested to leave this value as "0.01" whether or not using BNB for commissions.
The value is defined as percentage.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.

Auto-Buy & Auto-Sell:
auto-buy and auto-sell checkboxes
It is possible to tell script whether to automatically buy or sell if the defined conditions met.
If "Auto-Buy" checkbox is unchecked, the system will wait for user's (Buy Now) action even if there is buying opportunity.
If "Auto-Sell" checkbox is unchecked, the system will wait for user's (Sell Now) action even if there is selling opportunity.
The form should be submitted by clicking "Save Changes" button in order to save changes.

Trend Calculation First Duration:
trend calculation first duration
To find out current trend automatically, the script uses two time range to compare averages.
First range can be explained as "from the field value before now to current time".
The value is defined in seconds.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.

Trend Calculation Second Duration:
trend calculation second duration
To find out current trend automatically, the script uses two time range to compare averages.
Second range can be explained as "from the field value before start of the first range to start of first range".
The value is defined in seconds.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.

Buy Order Check Interval:
buy order check interval field
Once limit-buy order is created, script will check its status against filled periodically.
The checking period time in seconds can be customized using this field.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.

Sell Order Check Interval:
sell order check interval field
Once limit-sell order is created, script will check its status against filled periodically.
The checking period time in seconds can be customized using this field.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.

(Sell Price/Buy Price) Ratio:
(sell price / buy price) ratio
To make decision to automatically create limit-sell order, script watches out for each price update if the current asset price is higher than the buy price at a user defined profit rate.
In example, if you are willing to sell if the current price is higher than 2 percent of the buy-price, then the "1.02" should be entered as a value.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.

Manual Action Buttons:
manual action buttons cancel buy order button cancel sell order button
If the script waits for some condition occurs in order to create buy/sell order but user want to trigger creation of instant market-buy or market-sell orders, the related button can be clicked.
"Buy Now" button becomes enabled if the current status is "waiting_for_opportunity" or "created_buy_order".
"Sell Now" button becomes enabled if the current status is "waiting_to_sell" or "created_sell_order".
"Cancel" buttons in "Current Buy Order" and "Current Sell Order" areas send cancellation request for the current order.

RULES


Interval Reset Rule: Max. (Interval High/Low) Ratio:
interval reset rule: max. (interval high/low) ratio
If this rule is enabled and current interval's high/low ratio is higher than the defined value, a new interval will be started on "waiting_for_opportunity" status.
The form should be submitted by clicking "Save Changes" button in order to save changes.

Interval Reset Rule: Max. Interval Duration:
interval reset rule: max. interval duration
If this rule is enabled and current interval's duration exceeded the defined value, a new interval will be started on "waiting_for_opportunity" status.
The form should be submitted by clicking "Save Changes" button in order to save changes.

Buying Rule: Min. (Interval High/Low) Ratio:
buying rule: min. (interval high/low) ratio
If this rule is enabled and Auto-Buy is enabled, the system will create buy order on "waiting_for_opportunity" status only if the current interval's high/low ratio value is at minimum of defined value.
The form should be submitted by clicking "Save Changes" button in order to save changes.

Buying Rule: Min. (Current Price/Interval Low) Ratio:
buying rule: min. (current price/interval low) ratio
If this rule is enabled and Auto-Buy is enabled, the system will create buy order on "waiting_for_opportunity" status only if the (current asset price/interval's low) ratio value is at minimum of defined value.
The form should be submitted by clicking "Save Changes" button in order to save changes.

Buying Rule: Max. (Current Price/Interval Low) Ratio:
buying rule: max. (current price/interval low) ratio
If this rule is enabled and Auto-Buy is enabled, the system will create buy order on "waiting_for_opportunity" status only if the (current asset price/interval's low) ratio value is at maximum of defined value.
The form should be submitted by clicking "Save Changes" button in order to save changes.

Buying Rule: Min. Interval Duration:
buying rule: max. (current price/interval low) ratio
If this rule is enabled and Auto-Buy is enabled, the system will create buy order on "waiting_for_opportunity" status only if the the current interval duration exceeded defined value.
The form should be submitted by clicking "Save Changes" button in order to save changes.

Buying Rule: Buy Order Validity:
buying rule: buy order validity
When the limit-buy order is created, the system status becomes "created_buy_order" and system starts to check order status periodically (for each Buy Order Check Interval).
If this rule is enabled and elapsed time from the order creation date is higher than defined value, system will cancel current order and status will revert to "waiting_for_opportunity". The form should be submitted by clicking "Save Changes" button in order to save changes.

Selling Rule: Sell Order Validity:
selling rule: sell order validity
When the limit-sell order is created, the system status becomes "created_sell_order" and system starts to check order status periodically (for each Sell Order Check Interval).
If this rule is enabled and elapsed time from the order creation date is higher than defined value, system will cancel current order, sell all trading base asset at market price and status will revert to "waiting_for_opportunity". The form should be submitted by clicking "Save Changes" button in order to save changes.

Stop Rule: Max. Number of Trades:
stop rule: max. number of trades
If this rule is enabled and total number of trades from the start reach to the defined value, system will stop processing.
When a limit-buy or limit-sell order is filled, the trade count increases by 1.
The form should be submitted by clicking "Save Changes" button in order to save changes.

Escape Plan: Max. (Buy Price/Current Price) Ratio:
escape plan: max. (buy price/current price) ratio
If this plan is enabled and Auto-Buy is enabled and the system status is "waiting_to_sell", the system will automatically create market-sell order if the (buy price/current asset price) ratio is greater than the defined value to prevent any further losses.
The form should be submitted by clicking "Save Changes" button in order to save changes.

Stop Rule: Stop On Escape:
stop on escape rule
If this rule is enabled and the system will stop in case of the escape plan is processed.
The form should be submitted by clicking "Save Changes" button in order to save changes.

Buying Rule: Current Trend is Downward:
buying rule: current trend is downward
If this rule is enabled and Auto-Buy is enabled, the system will create buy order on "waiting_for_opportunity" status only if the current trend is Downward.
Trend is determined by Trend Calculation First Duration and Trend Calculation Second Duration.
The form should be submitted by clicking "Save Changes" button in order to save changes.

Buying Rule: Current Trend is Upward:
buying rule: current trend is upward
If this rule is enabled and Auto-Buy is enabled, the system will create buy order on "waiting_for_opportunity" status only if the current trend is Upward.
Trend is determined by Trend Calculation First Duration and Trend Calculation Second Duration.
The form should be submitted by clicking "Save Changes" button in order to save changes.

Buying Rule: Last Set Boundary is Bottom:
buying rule: last set boundary is bottom
If this rule is enabled and Auto-Buy is enabled, the system will create buy order on "waiting_for_opportunity" status only if the interval's low value is set last.
The form should be submitted by clicking "Save Changes" button in order to save changes.

Interval Reset Rule: After Successful Sale:
interval reset rule: after successful sale
If this rule is enabled a new interval will be started after a successful sale.
The form should be submitted by clicking "Save Changes" button in order to save changes.

4. Online Demo - top

Online demo can be accessed using the following link:
https://jetphp.com/cryptobot/demo/


5. Sources and Credits - top

The following images, icons, libraries or other files are used to build the software:


Once again, thank you so much for purchasing CryptoBot For Binance - Cryptocurrency Trading PHP Script. For any kind of bug reports, feedback, feature requests, or even if you just want to say hello, feel free to email me. I'll be really happy about it.

Ovunc Tukenmez

Go To Table of Contents