Content uploaded by Cristian Mihail Păuna
Author content
All content in this area was uploaded by Cristian Mihail Păuna on Jul 03, 2018
Content may be subject to copyright.
Informatica Economică vol.22, no. 2/2018 35
DOI: 10.12948/issn14531305/22.2.2018.04
Arbitrage Trading Systems for Cryptocurrencies.
Design Principles and Server Architecture
Cristian PĂUNA
The Bucharest University of Economic Studies, Romania
cristian.pauna@ie.ase.ro
When dot.com has become a quaint idea, when electronic shops have lost the mass attention,
while classical and margin trading has become obsolete, something new is coming: cryptocur-
rencies. Hundreds of virtual coins have been invented for a single reason: the profit. The high
price volatility of these new markets and the fact that the virtual coins price is not regulated by
a central bank or a single exchange, gives us opportunities for arbitrage trading. The existence
of important price differences makes possible the profit when an automated system buy cheaper
and sell more expensive in the same time. This paper will present the general principles under-
pinning the implementation of arbitrage trading software for virtual coins market. The very
large number of cryptocurrencies and exchanges fundamentally change the server architecture
of the trading software. The distributed price data in hundreds of sources and the technical
differences of each of these data providers make all the things difficult to be implemented in a
single application. The low-latency order calculation needed for the fast delivery before a sig-
nificant price change, in the presence of thousands of price quotes coming from hundreds of
distributed servers makes everything special.
Keywords: Cryptocurrency (CRYC), Arbitrage trading (ART), Algorithmic trading (AT), High
Frequency Trading (HFT), Automated trading software (ATS)
Introduction
Bitcoin (BTC), Litecoin (LTH), Ethereum
(ETH), Ripple (RIP), thousands of virtual
coins already exists. The Bitcoin “introduced
in 2009”, “caught the interest of the main-
stream media in 2012” [1]. After that, an un-
defined number of virtual coins were in-
vented. All these coins are named virtual just
because they exist only in the electronic rep-
resentation. They are also called cryptocurren-
cies because they are designed to work as a
currency like a medium of value exchange and
the “cryptography is used to secure financial
transactions” [2], to control the creation of
new units, to verify the transfer of funds and
to set the owner for each unit.
The reason involving real money to buy this
kind of virtual assets is of course the profit.
The virtual coins value is fluctuating on the
free markets as any asset, powered by specu-
lative and marketing actions and sustained at
least hypothetical by some economical pro-
cesses involved in the background of each
crypto coin. However, even it is a free market,
the virtual coin market has its own character-
istics, especially when it is about the volatility
and “the flexibility in the supply schedule”
[3].
We are not so far away the days when Bitcoin
almost touched 20.000 USD in a relative short
period of time starting from couple of bucks
and after that plunged back to 7.000 - 8.000
USD in an even shorter interval. This kind of
movements makes the investment in crypto-
currencies an attractive one today. However,
the high price volatility makes this investment
to be a very risky one, drawdowns of more
than 61.8% being very easily assimilated with
a gambling game. For all that, keeping the
money into a virtual currency hoping the
value will increase after a while can be a prof-
itable idea, but it is not the only one. All these
assets are operating independently of a central
bank or a central exchange.
Without a central price regulator the quotes
can be different from an exchange to another.
That means we can find cases when and where
we can buy cheap and sell more expensive the
same thing in the same moment of time. This
will be called an arbitrage trade. The unbal-
anced price of the same asset in two different
places will give us an instant profit.
1
36 Informatica Economică vol.22, no. 2/2018
DOI: 10.12948/issn14531305/22.2.2018.04
The question is how to find these opportuni-
ties and how can we profit from all of these in
the real time. The theory is easy, just find two
exchanges with different quotes for the same
equity, buy where the equity is cheaper and
sell where it is more expensive.
The problems start when we will consider the
facts that there are hundreds of crypto pairs,
hundreds of thousands of combination of
these coins and hundreds of exchanges where
you can buy and sell all of these assets. That
means a human being cannot compare all
these prices in order to find the best trade op-
portunities, to build the orders and to send
them to those exchanges before the price is
changed. Only a computer can to manage all
of these actions.
This paper will present how an arbitrage trad-
ing system for cryptocurrencies can be built,
will reveal the main principles and practices
and will also present some results in order to
open or to grow the interest for this kind of
software systems.
2 Arbitrage trading
As we already presented, the arbitrage trading
means to buy cheap and to sell more expen-
sive the same equity in the same moment of
time in two places where the quote prices are
different. The arbitrage trading is not a new
idea. It was used since years to trade shares.
“Stocks are matched into pairs with minimum
distance between normalized historical
prices” [4] and arbitrage trading strategies can
be used with any stock exchange in order to
make profit.
Usual, the classical arbitrage trade is involv-
ing the same volume of equity in the both
trades. For each trade (i), the profit (Pi) is
equal with the difference between the sell
price (selli) and the buy price (buyi) multiplied
by the volume traded (Vi).
For this simple trade idea, the trading software
must compare continuously the quotes from
different exchanges and find the highest price
differences. But the classical arbitrage trading
is not the only one trading opportunity which
can be found in the cryptocurrency markets.
The virtual coins are traded in pairs. The price
of a pair, for example BTCETH if we will
consider Bitcoin and Ethereum, means how
much ETH we need to sell in order to buy a
specified unit of BTC. When an exchange ask
you a specified price to buy BTCETH and an-
other exchange offers you a higher price for
the same pair, a classical arbitrage trade can
be executed and the profit will result from the
price difference. But sometimes the depend-
ency between two coins is not expressed in the
same way in all exchanges. There are cases
when an exchange will quote the price for
BTCETH and another exchange will quote the
price for ETHBTC. The virtual coins involved
are the same but the price in built in the re-
versed way. For this case, to find an arbitrage
trade the software must compare the price
from the first exchange with the reversed price
into the second. Now we are talking about a
reversed arbitrage trade. In this case the profit
will be:
The execution of the trades is usual simple. A
trading order means to buy or sell the speci-
fied pair at a specified price with an estab-
lished volume. Of course an order can be exe-
cuted by the exchange only if there are enough
coin units to sell in that exchange in order to
buy the ordered volume from the first coin.
This validation must to be done by the trading
software before to send the orders to the ex-
changes, based on the real-time capital data
provided by each exchange. An arbitrage
trade means at least two orders in two differ-
ent exchanges.
Another type of arbitrage trades is involving
more pairs. Sometimes the product of two,
three or more pair quotes is imbalanced be-
tween two exchanges or even in the same ex-
change. For understanding, let's consider the
next inequalities:
BTCETH*ETHLTC<BTCLTC (3)
and
BTCETH*ETHLTC*LTCRIP<BTCRIP (4)
Informatica Economică vol.22, no. 2/2018 37
DOI: 10.12948/issn14531305/22.2.2018.04
In cases like these, multiple arbitrage trades
can be possible in order to make profit. In the
first exchange will be executed more trades
and in the second only one. The software will
buy the lowest price for multiple pairs and sell
the last one on a higher price. The profit for
multiple arbitrage trades will be expressed in
this case by the formula:
For the next level of multi arbitrage trades,
when we buy more pairs and sell more pairs
in order to earn the difference between those
operations, the profit will be expressed by the
next equation:
where (nBUY) is the number of buy trades
and (nSELL) is the number of sell trades made
simultaneous. This kind of trades can be found
using two different exchanges but sometimes
the difference can be found even in the same
exchange. The multiple arbitrage trades are
more complex to be validated and executed
and a serious computational power is needed
in order to deliver all the trading signals and
orders in real time. Only low-latency trading
software can manage this process in order to
deliver the orders in that short time needed to
execute them.
3. Cryptocurrency dictionaries
One of the most important parts of an arbi-
trage trading system for cryptocurrencies is
the dictionary. Due to a very high number of
cryptocurrencies quotes involved and because
there is not a standard for naming the coins
and pairs, a lot of false trading signals can be
built without a strict codification methodol-
ogy. Each exchange has its own coin and pair
codes. We can find cases when the same coin
can be named or coded differently.
For example BTC can be the symbol for
Bitcoin in the most exchanges but some of
them will code the Bitcoin with XBC or BTX.
In order to compare the price of the same cur-
rencies, a codification dictionary must to be
implemented. The trading software must have
its own codification rules and all codes from
all exchanges must to be included into the
trading software database.
In addition there are cases when the code of a
pair into an exchange can be the code of an-
other pair into another exchange. For example
SCAPPC is representing the pair of SC re-
ported to the APPC coin in the most ex-
changes but it others it is the pair between
SCA and PPC. All these codes SC, SCC, PPC
and APPC are valid crypto coin codes. This is
the case when a profitable arbitrage trade can
be found if we will compare the price of the
SCAPPC pair into two exchanges where that
code represent different coin pairs. To avoid
these type of false signals, in the trading soft-
ware dictionary must to be inserted each pair
code from each exchange related with the real
pairs that are quoted. A codification using a
separator is a very good implementation. With
this additional rule, the code will looks like
SC-APPC and SCA-PPC and the confusion is
avoided.
From this reason, the cryptocurrencies dic-
tionary implementation and continuous opti-
mization is a very significant part of the arbi-
trage trading software for virtual coins. More,
the current practice added to this reason an-
other important one. In fact more exchanges
are changing the codification of the crypto
coins and pairs occasionally. This means reli-
able trading software must have the possibility
for an easy change of a coin code or pair code,
in order to save time and to trade the most sig-
nificant profit opportunities without a signifi-
cant change in the code of that software.
In this moment (2018 year) there are more
than 3000 virtual coins on the free market
listed in more than 300 exchanges and we are
still counting. Not on the last place, the fact
that new crypto coins are invented every day
and they are added often into the exchanges
quotes makes the dictionary to be a significant
tool in order to keep the trading software up-
dated with the reality of cryptocurrency mar-
kets.
38 Informatica Economică vol.22, no. 2/2018
DOI: 10.12948/issn14531305/22.2.2018.04
4 Data structure
The price quotes are received from the ex-
changes or from the brokerage companies in
real-time in different data structures. Each ex-
change has its own API application and the
data structure of each exchange is different.
Even all data sources are available by an API
access, the differences between data structures
delivered by each exchange make everything
more complex. The arbitrage software must
be adapted to import all the piece quotes from
each exchange according each technical spec-
ifications.
Another difference is given by the fact that
some exchanges will deliver all the price
quotes on a single interrogation of their API,
others exchanges will deliver the quotes in
different interrogations, one request for each
currency pair price. The third level of diffi-
culty is occurred for those exchanges that ac-
cept a limited number of requests in a speci-
fied time interval. All of these facts make con-
nection with each exchange to be a dedicated
and laborious job.
Whatever are the difficulties to implement the
data connection with the exchanges, once the
price quote is received in real-time, it must to
be recorded into the application database. Be-
cause the update interval is random, each
quote will be inserted as a separate record re-
lated with the exchange code, with the pair
code and with the updated time. For those pro-
cesses that need the historical price quotes, be-
cause of the large number of the records, usual
the history is simplified and represented sepa-
rately as historical records which will include
the next components, that become a standard
for a historical price data series [5]: open price
of a time interval (OPEN), maximal price of a
time interval (MAX), minimal price of a time
interval (MIN), close price of a time interval
(CLOSE), where the time interval has usual
one of the next values: one minute (1M), five
minutes (5M), fifteen minutes (15M), thirty
minutes (30M), one hour = 60 minutes (1H),
four hour = 240 minutes (4H), one day = 1440
minutes (1D), one week = 10080 minutes
(1W), one calendar month (1M), one calendar
year (1Y).
Usual start time interval and data about the
traded volumes are also available together
with the price quotes. Advanced software will
record also the current spread for the equities,
which is the difference between the buy and
the sell price at a moment of time.
All price data quotes from hundreds of ex-
changes and for hundred of thousand of cryp-
tocurrency pairs must to be made in real time.
In addition the data history must to be recorder
for future operations. Using a relational data-
base is a fact. In addition, the huge number of
CRUD operations and the low-latency needed
for the trading signals and orders push the ap-
plication to use multi server architecture pre-
sented in Figure 1. In the current practice,
more servers will do the acquisition processes
of the real time price data from the exchanges,
a different server will makes all CRUD (cre-
ate, record, update, delete) operations and a
different one will compute the trading signals
and will build and deliver the low-latency
trading orders. All of these operations must to
be completed in real-time, before the price is
changing significantly the values in order to
make possible the arbitrage trades.
Fig. 1. Server architecture for a cryptocur-
rency arbitrage system
Informatica Economică vol.22, no. 2/2018 39
DOI: 10.12948/issn14531305/22.2.2018.04
5 SQL needed
Due to the large amount of data, first reasons
to use a relational database are to control data
redundancy, to provide the data integrity and
to avoid data inconsistency. The concurrency
control needed by using several servers to up-
date the same data warehouse with the real-
time price quotes will be also provided by a
relational database. In addition, to restrict the
data access to different levels of authorization
and to provide reliable data backup and recov-
ery, the usage of an SQL relational database
will be the solution, even today when NoSQL
databases are in trend.
In the context of a large volume of CRUD op-
erations and data requests, SQL will provide
the low-latency data responses. The most sig-
nificant example is the signal generator
server. To see how much can be the time re-
sponse difference we have compared a repeti-
tive process to build the arbitrage trading sig-
nals and an SQL procedure to extract the same
signals from the database. In the first case, a
classical procedure to build the trading signals
was wrote to find better prices for each price
quote in the database using only repetitive
code statements.
For a database including more than 1,000,000
real-time quotes, the process to build the arbi-
trage trading signals was longer than two
minutes on a dedicated server with 2x3GHz
processor core and 4 GB RAMM Burst. This
time is too long for reliable trading software.
In more than two minutes the quotes can be
significantly changes, meaning those signals
have a low chance to be executed after the de-
livery on the brokerage account.
In the second case it was implemented an SQL
procedure to build the arbitrage trading sig-
nals with the same amount of data. The results
using SQL are conclusive; the time response
was about 0.25 seconds which is a realistic
time for the trading software. In Figure 2 is
presented a sample code for node.js using
callback functions and SQL to build the arbi-
trage trading signals.
Fig. 2. node.js callback functions for the classical arbitrage trading signals module.
40 Informatica Economică vol.22, no. 2/2018
DOI: 10.12948/issn14531305/22.2.2018.04
6 API data server
A special particularity of the arbitrage trading
systems is the API server that collects real-
time quotes from each data source. Each ex-
change has organized an API application in
order to permit restricted and real-time access
to the data. To interrogate that API, to receive
low-latency data and to insert it in the local
database or warehouse, we need to organize a
special server process for each exchange. In
the Figure 3 it is presented the code for a data
acquisition process using an API. The “Ex-
change” object represents the Rest API proce-
dure module distributed by each exchange.
“bookTickers” is the function from this mod-
ule that exports the price data. Each exchange
has its own exporting functions, the name of
this function and the “data” structure deliv-
ered by this function are different, and conse-
quently the code function must to be adapted
for each particular case.
The data delivered by each exchange is usual
a JSON object [6] including different data re-
lated with the current state of the market. Be-
cause the structure of this JSON object is dif-
ferent from an exchange to another, a general
procedure cannot be built. In the example pre-
sented, the “setInterval” function is a prede-
fined node.js function to repeat the process. In
our case we set to repeat the price quotes im-
port each minute (60 sec * 1000 = 60000).
Setting this time is also a procedure depending
on each exchange. There are exchanges that
allows one per minute requests, other ex-
changes will allow interrogations one time at
two or five minutes and others at ten or larger
interval. Usually when the request interval is
not respected, the API can cancel the connec-
tion with the server and no data will be re-
ceived from that source. In the example
above, the “updateQuote” function is a com-
mon function to update the records with the
piece quotes, this function will be used for any
exchange server, once the data is reduced to
an established data structure.
Fig. 3. node.js call back functions for the real-time price data acquisition server
Important is the fact that the real-time repeti-
tive price process is a server process, orga-
nized for each exchange and depending on the
particularities of each API data source. The
update time is also depending on the data
source. The usage of the node.js server “is
quite lightweight and efficient” [7] and permit
a fast and simple implementation of these en-
tire server processes. When the number of
these modules is a significant one, using
node.js we can distribute the repetitive proce-
dures on more distributed servers, as a meas-
ure to keep the data delivery time under those
limits to ensure the low-latency response.
7 Arbitrage trading signals
In order to consider why we have to do all
these technical efforts, in this chapter it will
be presented a real case of arbitrage trading
signals with cryptocurrencies. Using theCryp-
toTrader [8] the next signals were obtained at
25 May 2018 using 787 cryptocurrencies
listed on 7 different exchanges.
Informatica Economică vol.22, no. 2/2018 41
DOI: 10.12948/issn14531305/22.2.2018.04
Table 1. Arbitrage trading signals made by theCryptoTrader on 25.05.2018
Arbitrage
trading sig-
nal
Buy
exchange
Buy price
Sell
exchange
Sell price
Profit [%]
BTG-BTC
Cryptopia
0.00101454
Binance
0.00604100
495.44
CTM-BTC
Cryptopia
0.00000929
Binance
0.00004469
381.05
BTC-STEEM
Poloniex
0.00029422
Bittrex
0.00036467
23.94
BTC-SBD
Bittrex
0.00023894
Poloniex
0.00026653
11.55
BTC-OMNI
Bittrex
0.00338255
Poloniex
0.00367822
8.74
BTC-SYS
Poloniex
0.00004503
Bittrex
0.00004895
8.71
BTC-GBP
Kraken
5398.10
Gdax
5653.55
4.73
BTC-NAV
Bittrex
0.00012728
Poloniex
0.00013294
4.45
BTC-DOGE
Poloniex
0.00000046
Bittrex
0.00000048
4.35
BTC-PINK
Bittrex
0.00000250
Poloniex
0.00000258
3.20
As we can see in the Table 1, the profit expec-
tation is a considerable one. The signals pre-
sented are the best ten arbitrage trading sig-
nals from a list of about 186 available signals
found at that moment by the trading software.
Any investor who has available money into
those exchanges can trade that signal in order
to make profit. Usual the signal is not availa-
ble for a very long period of time. This is the
reason to use trading software that has to find
the trading opportunities and to trade them
with low-latency orders sent direct to the ex-
changes.
The arbitrage trading software permits a very
fast order delivery for each signal direct to the
exchanges into the investor's accounts. If the
orders arrived before the significant change of
the price quotes, they will be executed and the
profit will be immediately received into the
investor's account. However, time to time,
some signals are false. Some exchanges de-
liver price quotes for some cryptocurrency
pairs but they refuse to execute orders at those
prices. This is usual the fact when the profit
expectation of a signal is too high. Even so,
signals with profit expectation under 999%
can be well executed in the real practice. The
limit is imposed by the exchange by the traded
volume which cannot exceed a specified
value. Some exchanges limit the trading vol-
ume depending on the investor's profile. How-
ever, with all that limits, scheduling the exe-
cution of a signal to be repeated time to time
as a function of the trading software will per-
mit the profit for capitals higher than the trad-
ing limits imposed by each exchange. Usual
signals with the profit expectation around
20% are well traded.
8 Conclusions
Cryptocurrency market price is not regulated
by a central bank. Arbitrage trading opportu-
nities can be found on the free markets in or-
der to make profit. Because of the large num-
ber of virtual coins and exchanges, finding
and computing the arbitrage trading signals
must to be done by the automated trading soft-
ware. A crypto dictionary is a must to have in
the trading software with cryptocurrencies be-
cause of the important codes differences be-
tween exchanges. In addition, this module will
permit all frequent changes in the codification
and new virtual coins to be managed.
The technical differences between data
sources impose an individual server process to
be organized for each data source. A high
number of data sources mean a high number
of server processes. This implies implementa-
tion of more data acquisition process servers
distributed in different technical resources.
Due to the large amount of relational data, re-
lational database and SQL is a reliable solu-
tion in order to ensure the low-latency re-
sponse of the trading software. Arbitrage trad-
ing software with cryptocurrencies delivers a
significant profit.
42 Informatica Economică vol.22, no. 2/2018
DOI: 10.12948/issn14531305/22.2.2018.04
References
[1] N. Gandal, H. Halaburda, “Can We Predict
the Winner in a Market with Network Ef-
fects? Competition in Cryptocurrency
Market Design and Implementation”,
2016, NET Institute Working Paper No.
14-17, Available: https://ssrn.com/ab-
stract= 2506463, May 9, 2018
[2] Wikipedia Encyclopedia - “Financial
Cryptography” - https://en.wikipe-
dia.org/wiki /Financial_cryptography,
May 10, 2018
[3] M. Iwamura, Y. Kitamura, T. Matsumoto,
K.Sailo, “Can We Stabilize the Price of a
Cryptocurrency?: Understanding the De-
sign of Bitcoin and Its Potential to Com-
pete with Central Bank Money”, Institute
of Economic Research Hitotsubashi Uni-
versity Kunitachi, Tokyo, 186-8603 Japan,
2014 Available: https://ssrn.com/abstract
=2519367, May 9 2018
[4] E. Gatev, “Pairs Trading: Performance of
a Relative-Value Arbitrage Rule” - The
Review of Financial Studies, Volume 19,
Issue 3, 2006, Pages 797–827, Available:
https://doi.org/10.1093/rfs/hhj020, May
10, 2018.
[5] MetaTrader 4 (MT4) - Historical price
data structure - Available:
https://docs.mql4.com/ constants/struc-
tures/mqlrates, May 10, 2018.
[6] JavaScript Object Notation (JSON) – “The
javascript object notation (json) data inter-
change format” - Available:
https://buildbot.tools.ietf.org/html/rfc825
9, May 10, 2018.
[7] K. Ley, Y. Ma, Z. Tan, “Performance
Comparison and Evaluation of Web De-
velopment Technologies in PHP, Python,
and Node.js”, 2014 - Computational Sci-
ence and Engineering (CSE), 2014 IEEE
17th International Conference, Available:
https://ieeexplore.ieee.org/ docu-
ment/7023652, May 11, 2018
[8] Cryptocurrency Trading software Platform
- theCryptoTrader - Available:
https://pauna. biz/thecryptotrader, May
12, 2018
Cristian PĂUNA graduated the Faculty of Cybernetics, Statistics and Eco-
nomic Informatics of the Academy of Economic Studies in 1999 and also he
is a graduate of the Faculty of Aircrafts of the Polytechnic University of Bu-
charest in 1995. He got the title of Master of Science in Special Aerospace
Engineering in 1996. In the last decades he had a sustained activity in software
development industry, especially applied in the financial trading domain.
Based on several original mathematical algorithms he is the author of more
automated trading software. At present he is the Principal Software Developer of Algo Trading
Service Ltd. and he is involved as PhD student in Economic Informatics Doctoral School of the
Academy of Economic Studies.