6.5.1 Data Collecting and Parsing
The primary purpose of the ExchangeApiService
class is to connect to external APIs and scrape web-
sites. Multiple external services, such as the Coin-
MarketCap API, the CCXT library (onl, ), and the
CoinMarketFees website (Atzberger et al., 2022), are
present in the class and are actively utilized. The
CCXT library is responsible for collecting data such
as coin prices and order book details, users of this li-
brary will have direct access to the source (the API
endpoints of various exchanges), resulting in the most
accurate data available. The CoinMarketCap API is
mostly used for retrieving the topmost 1000 popular
currencies because these coins often have the highest
trading activity and are more likely to provide arbi-
trage opportunities.
As the ccxt library is not very reliable on fees, we
have used beautiful soup (a python library for web
scraping (Richardson, 2007)) to collect as much data
as possible from the CoinMarketFees website, where
fees are typically accurate.
6.5.2 Data Manipulation and Arbitrage Spotting
ArbitrageBot is an implementation of the generic Bot
class; its primary function is to manipulate received
data and identify arbitrage opportunities. The gather-
data method relies on the superclass’s methods in or-
der to retrieve data from the ExchangeApiService.
After that, a comparison is made between all ex-
changes, and then all pairs of the used exchanges,
under a predetermined threshold of percentage differ-
ence, and a JSON-style dictionary is constructed con-
taining all opportunities. Information about market
liquidity and fees is obtain through other methods.
6.6 Controller Layer
This layer’s purpose is to expose the Rest endpoints.
Encapsulating the routers module, which contains the
API’s controllers for its many functionalities (user
router, authentication router, mail router and arbitrage
router). This module primarily defines the URLs, pa-
rameters, dependencies, and response schemas of our
endpoints. In addition, by utilizing dependency in-
jection, unauthorized access to the resources is pre-
vented. The database connection is also provided us-
ing injections by referencing a function from our con-
nection file which yields a Session object that can be
later used for queries (Copeland, 2008). In order to
maintain a clean separation between our layers, end-
point functionality is delegated to the repository mod-
ule of the persistent layer.
Endpoints. One of the top objectives in creating
our endpoints was to ensure full synchronicity be-
tween them so that time-intensive endpoints, such
as the endpoint for identifying opportunities, would
not cause the application to underperform. Thus,
endpoints will function optimally when several si-
multaneous calls are made without any time delays.
The arbitrage router contains endpoints primarily as-
sociated with our business layer, such as endpoints
for identifying opportunities, storing scrapped fees
in our database, retrieving past arbitrage opportuni-
ties from our database, obtaining trading fees for spe-
cific coins and exchanges, a WebSocket for contin-
uous streaming our opportunities, and endpoints for
internal connection and disconnection from the Web-
Socket (Pterneas, 2013). The authentication router is
mostly associated with the security layer, where all
functionality is outsourced, and its primary job is to
expose a login endpoint. Similarly, to the authentica-
tion router, the Mail router has the primary purpose
of exposing an endpoint related to the email notifica-
tions for our users. Lastly, the User router is related to
CRUD operations on our users, namely creating (reg-
istering), reading, updating, and deleting user infor-
mation.
WebSocket. Due to challenges in gathering data in
the client-side portion of this application, as time-
intensive endpoints would be terminated on refresh-
ing, losing crucial information, our solution is a Web-
Socket that continuously broadcasts the most recently
computed list of opportunities. Thus, when required,
the client-side can obtain all data almost instantly.
Note that this WebSocket, as well as a few arbitrage
endpoints, are publicly accessible via our API solu-
tion. Several setbacks have occurred throughout the
development of this websocket. Typically, websock-
ets should be a separate service that operates indepen-
dently from the rest of the application. However, this
is not possible in our case, thus our websocket is es-
sentially incorporated as an endpoint, which has led
to numerous difficulties in maintaining synchronic-
ity. For the rest of the endpoints, synchronicity is
assured by design, as the FastApi framework inserts
the endpoint functions in a self-managing thread or
event pool, but this is not the case with websockets.
We had to manually obtain the running event loop and
inject the websocket’s functionality, which proved to
be quite challenging, but we were ultimately success-
ful. However, additional optimizations are required as
the number of external clients connecting to our web-
socket affects its performance.
CSEDU 2023 - 15th International Conference on Computer Supported Education
244