TradingBotforCryptocurrencyMarket
TradingBotforCryptocurrencyMarket
net/publication/382760407
Trading Bot for Cryptocurrency Market Based on Smart Price Action Strategies
CITATIONS READS
0 844
6 authors, including:
Anshul Sharma
Chandigarh University
32 PUBLICATIONS 137 CITATIONS
SEE PROFILE
All content following this page was uploaded by Kiran Jot Singh on 10 November 2024.
Kalpana Chawla Centre for Research in Space Science & Technology, Chandigarh University,
1
Abstract
This paper focuses on design of a Python-based crypto currency trading bot to support all major
exchanges and is managed through Telegram messenger application. The system offers a range of
capabilities, including back-testing, mapping, and money management, as well as machine learn-
ing strategy optimization. This enables users to create their own trading strategies and tactics using
Python and pandas. The strategies can be back-tested on historical data, which is widely and freely
available on exchange platforms and in the market that the user wants to trade in. The system also
allows for hyperoptimization of trading strategies based on the results of back-testing, which is
achieved using machine learning algorithms to find the optimal parameters for the strategy. In addi-
tion, the bot enables users to select markets to trade in by creating a static list or using an automated
one based on top traded volumes and/or prices. It also offers the ability to expressly ban marketplaces
in which the user does not want to trade. The system allows users to test their strategies with sim-
ulated money in dry-run mode or to deploy them with real money in live-trade mode. To monitor
trades, the bot can be integrated with the Telegram API. Users can display profit/loss, daily summa-
ries, current open trade outcomes, and many more options. Overall, the bot offers a powerful and
flexible platform for automating and optimizing crypto currency trading strategies.
8.1 Introduction
Cryptocurrency trading has been a boon since 2020 and as good are its profits there are
losses of the same magnitude [1]. To minimize its losses one has to sit and analyse the
trends in market stay up to date in news, make predictions about a particular trade all while
Shubham Mahajan, Kapil Joshi, Amit Kant Pandit and Nitish Pathak (eds.) Integrating Metaheuristics in Computer Vision
for Real-World Optimization Problems, (151–162) © 2024 Scrivener Publishing LLC
151
152 Integrating Metaheuristics in Computer Vision
keeping the emotions aside which is a delicacy not many can accomplish. So to help with
this, this project is based on “automated crypto trading bots,” which will let even beginners
to trade and generate a passive income stream while minimizing losses. This bot will help
test the strategies made by you in historical data.
It is not physical currency like rupees or USD, but rather digital tokens based on block-
chain. Making it possible for people to conduct peer-to-peer transactions without the use of
banks [2]. That is, it is a decentralized kind of currency whose value is determined by what
individuals are willing to pay in the market for them. Bitcoin, Litecoin, Etherium, Tether,
Binance coin, Cardano, Doge, Solana, and WRX are examples of well-known cryptocurren-
cies [3]. In recent years, bitcoin market activity has surged significantly, and cryptocurrency
prices have climbed rapidly. The worldwide cryptocurrency market cap is expected to be
over $844 billion in 2022, with bitcoin having the greatest share of around $324 billion [4].
Figure 8.1 illustrates the crypto market cap acquired from April 28, 2013, to December 21,
2022, globally and as you can check it has been nearly $3,000,000,000,000 at its peak at the
end of 2021 and started capturing market during 2018 [5].
Figure 8.2 illustrates the share of each crypto coin in market of crypto-currency. Bitcoin
(BTC) (60% of the total market in 2022) has always captured the maximum market while
Solana (SOL) (~23% of the total market in 2022) of Anatoly Yakovenko captured the lowest
in the top ten coins [6].
The process of producing new digital “coins” for cryptocurrencies is known as mining.
It is, however, the extent of its simplicity. The procedure involves deciphering challenging
puzzles, validating bitcoin transactions on a blockchain network, and adding the verified
transactions to a distributed ledger in order to find these coins [7].
The process is not as easy as one may think.
$4,000,000,000,000
$3,000,000,000,000
$2,000,000,000,000
$1,000,000,000,000
$0.00
80%
Dominance Percentage
60%
40%
20%
0%
2014 2015 2016 2017 2018 2019 2020 2021 2022 2023
BTC ETH USDT USDC BNB BUSD XRP DOGE ADA SOL Others
To solve these issues, tremendous computational power and advanced equipment are
required. Miners are rewarded with cryptocurrency in return, which is then released into
circulation, thus the name cryptocurrency mining.
Freqtrade is a bitcoin trading robot system that is open source and free to use. It can be
controlled through Telegram and is designed to work with all major exchanges. It includes
features for back-testing, mapping, and money management, as well as machine learning
strategy optimization [8]. With Freqtrade, you can develop your own trading strategy in
Python using pandas, get historical market data for the exchange and markets you want to
trade in, back-test your strategy using past data, optimize your strategy by identifying the
best parameters with hyper-optimization and machine learning algorithms, select the mar-
kets you want to trade in, and run your strategy in either simulated or live trading mode.
You can also use the optional “edge” module to find the best historical trade expectations by
market and control and monitor your trades through Telegram or a REST API. Freqtrade
also includes tools for analyzing your back-testing data or trading history, including auto-
matic standard graphs and the ability to load data into interactive settings.
Data science (data science) is a field of study that combines subject-matter expertise,
programming skills, and a basic understanding of mathematics and statistics to extract
usable insights from data [9]. Crypto-bot uses data science by analyzing the previous can-
dles or the real time data and make the choice to consider ordering a trade or not. The bot
is programmed to analyze the data from previous years in order to determine whether or
not it is a good investment. This involves running the data through various scenarios and
analyzing the results. If the profits are not meeting the desired mark, the bot will rerun the
data with different strategies in order to see if there is a way to improve the outcome.
This method of prediction is considered safe because it is based on real data from the
past, rather than relying on speculation or guesswork. By using this approach, investors can
make informed decisions about whether to invest in a particular trade or not, rather than
taking unnecessary risks. Overall, this system allows for more accurate and reliable predic-
tions, which can help investors to maximize their profits and minimize their losses.
154 Integrating Metaheuristics in Computer Vision
• To help people trade cryptocurrency with less stress and increase their prof-
itability. By automating the process of monitoring market conditions and
executing trades, these bots can help to alleviate some of the mental and
emotional burden of manual trading, and allow traders to focus on other
aspects of their business.
• To reduce the impact of human emotions on trading decisions. As men-
tioned earlier, emotions such as greed and fear can impair rational thinking
and lead to costly mistakes. By automating the trading process, bots can help
to eliminate the influence of emotions on decision-making, leading to more
consistent and objective trades.
8.2 Background
Since the introduction of crypto trading there have been many who know its potential in
the market and are known to its limitations. To address this, many worked on automated
trading using various models that worked shadowing its limitations, potential and how can
it be made better. The research papers were informative and allowed for further under-
standing of the project better.
From the literature cited above, it can be concluded that the automation of cryptocur-
rency trading has some future and can be bought in working conditions via various libraries
like freqtrade from FreqAI to test various methods that may be one’s mind and also test
them in dry run without losing any real money in the run. Thus, minimizing losses in the
actual trade. Furthermore, advances in technologies like Internet of things, Wireless sen-
sor networks and computer vision can be used to develop newer multi domain solutions
[16–22].
Jobs
Indicators Managers the different
Calculation of jobs required to be run
indicators and triggers regularly - market scans,
Calculate re validation of markets
on candle data Bot DB Jobs and
indicators throwing error, etc
scripts
and triggers
Technology - Back
trader Library Technology - CRON on
Linux and python scripts
Bot DB
Market data Central store for all the candle
data, indicators, orders, Algorithms
Fetch public candle positions, etc in tables Trading Different combinations
data via exchange APIs Market
algorithms of indicators to enter
data Technology - PostgreSQL and order and exit trades, set
Technology - CCXT API database management orders and set limit and
python API
Managed by the Django app stop prices
Technology - Python
Classes
Figure 8.3 Architecture overview for the paper trading bot [source: https://mattgosden.medium.com/
tradingbot-series-architecture-for- a-trading-bot-ac2352508c82].
Trading Bot for Cryptocurrency 157
worked or not and provide improvement tips. The architecture of the trading bot is illus-
trated in Figure 8.3. The strategy used three indicators TEMA, RSI, BOLLINGER BANDS
set to desired limits. The results can be seen using telegram bot connected via freqAI using
bot key on the cellular device.
The algorithm for enabling the bot for cryptocurrency profit trading prediction is as
follows:
TEMA. The total average is calculated by using three different exponential moving averages
of three different candle ranges. We are employing this indication since it reacts quickly to
market momentum, which will help the bot reduce losses and increase profits [23].
Bollinger bands. It is used to represent the standard deviation from the exponential mov-
ing average, which effectively shows us the market’s likely movement. This indicator is com-
monly configured with a standard deviation of two and an EMA set to the last 20 candles
[24].
RSI. This indicator is commonly used to determine market momentum in conjunction with
other indicators. The market range for this indicator is thirty to seventy. If the RSI is less
than thirty, the coin has been oversold and could be a good entry point to long the market.
If the RSI is greater than seventy, the coin has been overbought, indicating that a bearish
trend is about to begin [25].
Figure 8.4 shows the Indicators that we used via visual representation on the chart (chart
showing highs and lows in prices of a trade in real time).
22000.00
20000.00
17696.82
17035.76
16808.70
17:05:05
16707.99
16374.71
14000.00
RSI (14, close, SMA, 14, 2) 46, 38 48, 69 ø ø
60.00
48.69
46.38
40.00
20.00
Jun Jul Aug Sep Oct Nov Dec 2023 Feb 20
TradingView
shadow indicate significant selling pressure, and long up candles with little or no lower
shadows indicate strong purchasing pressure [26].
The strategy. We will use strategy to create a snowball effect, which means taking little prof-
its for one week and limiting stop losses to a minimum. For example, for 2% profit we will
risk 4% of our asset. Our strategy will primarily rely on a mix of TEMA, RSI, and Bollinger
Bands to forecast market movement in our favor. As a result, profit is booked. If the Heikin-
Ashi candle is above the TEMA, which signals the uptrend, and the chart has bounced off
the lower BB with an RSI greater than 30, this is a buy signal (green candle) If the Heikin-
Ashi candle is red and the momentum is downward, this indicates that the lower part of the
red candle is hitting TEMA and the candle is in the top part of the Bollinger band, which is
fifty to seventy, this is a sell signal.
8.4 Results
The bot ran well in the DRY RUN (as shown in Figure 8.5) using the mentioned strategy,
without the help of any human interaction checking all the mentioned objectives. It was
easy to trade and test our strategy on the data from binance which allowed us to view the
scope of the improvements. The bot traded on its own and suffered losses of 51% having
balance of 9776.376 USDT in the end and showed us that this strategy may fail in the cur-
rent market based on previous trends, as depicted in Figure 8.6.
It can be seen in Table 8.1, that user suffered losses in our trade except the first one which
means we would have lost money if we used our strategy during that time in these trades so
we need to improve our strategy to make profit.
Table 8.2 summarizes the trades done on the historic data from binance, the bot made
three maximum trades at a time, and did 162 average trades per day and started with 20000
fake money on dry run and having final balance of 9776.376 USDT and suffering losses of
51.12%.
Trading Bot for Cryptocurrency 159
SOL/USDT
250 rsi
Volume
Exit - Loss
200 Exit - Profit
Trade entry
sar
tema
150 Bollinger Band
Price
exit_long
enter_long
100 Price
50
0
Volume
1M
0.5M
0
80
60
RSI
40
20
Jan 2022 Mar 2022 May 2022 Jul 2022 Sep 2022 Nov 2022 Jan 2023
Figure 8.6 The result of this paper’s applied strategy on the historical data from Binance.
160 Integrating Metaheuristics in Computer Vision
Table 8.1 THE BACKTEST REPORT, applied our strategy used on historical data from binance.
Backtesting report
Table 8.2 This table shows the whole summary of our trade.
Metric Value
Backtesting from 2021−12−02 15:00:00
Backtesting to 2022−12−22 04:00:00
Max open trades 3
References
1. Yu, Z., Razzaq, A., Rehman, A., Shah, A., Jameel, K., Mor, R.S., Disruption in global supply chain
and socio-economic shocks: A lesson from COVID-19 for sustainable production and con-
sumption. Oper. Manage. Res., 15, 1–2, 233–248, Jun. 2022, doi: 10.1007/S12063-021-00179-Y/
FIGURES/9.
2. Taskinsoy, J., Say good bye to physical cash and welcome to central bank digital currency. SSRN
Electron. J., Nov. 2021, doi: 10.2139/ssrn.3972858.
3. Tredinnick, L., Cryptocurrencies and the blockchain. Bus. Inf. Rev., 36, 1, 39–44, Mar. 2019, doi:
10.1177/0266382119836314.
4. Robertson, K. and Zhang, J., Suitable price discovery measurement of bitcoin spot and futures
markets. SSRN Electron. J., Jan. 2022, doi: 10.2139/ssrn.4012165.
5. Biju, A.V., Merin Mathew, A., Nithi Krishna, P.P., Akhil, M.P., Akhil akhil, M.P., Is the future
of bitcoin safe? A triangulation approach in the reality of BTC market through a sentiments
analysis. Digit. Finance, 44, 4, 275–290, Jun. 2022, doi: 10.1007/S42521-022-00052-Y.
6. Bhujel, S. and Rahulamathavan, Y., A survey: Security, transparency, and scalability issues of
NFT’s and its marketplaces. Sensors, 22, 22, 8833, Nov. 2022, doi: 10.3390/s22228833.
7. Tosh, D.K., Shetty, S., Liang, X., Kamhoua, C., Njilla, L., Consensus protocols for blockchain-
based data provenance: Challenges and opportunities, in: 2017 IEEE 8th Annual Ubiquitous
162 Integrating Metaheuristics in Computer Vision