2. INTRODUCTION
CRYPTOBOT is designed to perform automatic lending of
Cryptocurrencies through Poloniex, Bitfinex and Bittrex Exchanges.
Additionally 50+ Cryptocurrency Exchanges can be integrated and traded
from the Platform.
2
3. APPLICATION
CRYPTOBOT User Interface will be a SPA (SINGLE PAGE
APPLICATION) powered by Angular JS v 4.3.0 and Spring Boot and
host of other components, frameworks and APIs.
3
4. TECHNOLOGY STACK
AMAZON CLOUD HOSTED PLATFORM
ANGULAR JS
JAVA 1.8
SPRING BOOT
SPRING MVC REST
SPRING DATA JPA
HAZELCAST IMDG
TOMCAT EMBEDDED or NETTY
4
5. TECHNOLOGY STACK (CONTD…)
MYSQL
GOOGLE
AUTHENTICATOR
AWS ELB
AWS JAVA SDK
DOCKER SWARM
POLONIEX API
BITFINEX API
BITTREX API
5
9. THE PLATFORM
The platform will comprise of user account management, referral
system, cryptocurrency lending, lending history, third-party
exchanges, administration, charts and Bot components.
The platform will be able to lend out multiple Cryptocurrencies
through multiple Exchanges.
The platform will be built with extensibility, scalability and high
availability.
The platform will be able to serve hundreds of thousands of users.
The platform will be designed for 99.9% uptime.
Entire operations of the platform will be automated.
10
11. HOME PAGE
The Page will have a header to choose multiple languages. The
default language can be configured.
The Page will provide a button to Setup Bot
On click of Setup Bot button, options for User Registration and User
Authentication will be displayed.
The Page will also display current lending rates of Cryptocurrencies
from supported exchanges.
12
12. USER REGISTRATION
Registration page with form inputs for Name, Email address,
Password will be displayed.
On form submission page will send HTTP POST request to the platform
REST API
REST API will process the registration request and if successful send a
confirmation email to the user’s supplied Email address.
REST API will send a response back to the Registration page as Success or
Failed.
If success, Authentication page will be loaded.
13
13. USER AUTHENTICATION
Authentication page with form inputs for Email address and Password will be
displayed.
On form submission page will send HTTP POST request to the Platform
OAuth2 REST API
REST API will verify the form input and issues an access token if successful
authentication.
Page will receive the access token and Google Authenticator token form is
displayed.
On submission of Google Authenticator token, page will send a request for
validation from the platform.
If Google Authenticator token is valid, User Home page will be loaded.
If Google Authenticator token is invalid, OAuth2 token will be invalidated
and Login form will be loaded again.
14
14. USER HOME
User Home page will be loaded with Header elements containing Logo,
Account, and Logout with respective icons are displayed.
A language chooser drop-down box will also displayed.
The page will also contain eight Tabs – Settings, My Loans, My Interest, My
Deposits, My Withdrawals, Transfer Balance, My Referrals, Bot fee with
respective icons.
There will be a Notification Tab also displayed to configure Notification
settings.
For first time user, Settings tab will be displayed.
15
15. USER HOME – SETTINGS TAB
Settings Tab will have four display boxes. Three boxes for Exchange Bot
activation. One box for Settings.
Three exchanges will be supported at the moment; Poloniex, Bitfinex and
Bittrex.
16
16. SETTINGS TAB - BOT
The Bot display box will have Exchange name, ON/OFF slider button to
enable or disable Bot, Settings for enabling Coins for the exchange.
17
17. SETTINGS TAB – ENABLE BOT
Once ON slider button is enabled, User has to provide Exchange API
Key and Secret.
Page will send the request to the Platform REST API with access token
retrieved from the cookie.
Bot creation and the launcher will be explained in the Platform
Design Section.
18
18. SETTINGS TAB – DISABLE BOT
The OFF slider will be enabled in the Bot display box, a disable
request will be sent to the Platform with access token retrieved from
the cookie.
Disabling of Bot will be explained in the Platform Design Section.
19
19. USER HOME – MY LOANS TAB
A tabular data will be displayed for the loans of the user.
Exchange, Token, State, Duration, End time, Amount lent out, the
Interest rate will be the information displayed in the tabular structure.
User’s total Coin balances and the current interest rate will be
displayed.
A hyperlink will be provided to view forecast value gain at the current
interest rate and constant price for 50 years.
On clicking hyperlink a Line Graph will be displayed with $ value of X-
Axis and Date on Y-Axis.
A pie chart will also be provided to show the current balance in $ for the
subscribed exchanges.
20
20. USER HOME – MY INTEREST TAB
The page will display the total lending balance and total interest (30d)
A tabular structure with Exchange, Coin, Balance, Balance($), Interest
(30d), Interest (30d $) information will be displayed.
Pie chart with Balances of each Exchange subscribed will be displayed.
Pie chart with Interest from each Exchange subscribed will be displayed.
21
21. USER HOME – MY DEPOSITS
A form with an input box, currency chooser, and exchange chooser will
be displayed.
The User will be able to deposit currencies to various Exchanges
from the page.
On submission of the form, REST API will connect to Exchange and
deposit the amount into the Exchange account.
22
22. USER HOME -MY
WITHDRAWALS
A tabular data of Currency, Exchange, Balance and Withdraw
button will be displayed.
On click of Withdraw button, a request will be sent to REST API.
REST API will connect to Exchange and the requested amount will
be withdrawn from the account.
The updated balance will be displayed in the tabular data for the
withdrawn currency.
23
23. USER HOME – TRANSFER BALANCE
A tabular data will be displayed with Currency, Exchange, and Balance
Amount.
A form will also be displayed with two Currency choosers and Exchange
chooser for transferring the balance from one currency to another in the
Exchange.
A button will be available to perform the Balance Transfer.
On click of the button, REST API will be invoked and balance transfer
operation will be performed in the Exchange.
The balance will be updated in the Exchange account and displayed in the
tabular data.
24
24. USER HOME – MY REFERRALS
The User of the CRYPTOBOT system will be able to refer another user
through Email, SMS.
Both the parties involved in the Referral process will get Bonus coins in
their account balance.
25
25. BOT FEE
This tab will display the Bot fees accrued through lending operations by
User from the subscribed exchanges through CRYPTOBOT.
For the lender, a 15% fee will be applied to earned Interest.
The Bot fee can be configured in the system.
26
26. NOTIFICATION TAB – NOTIFICATION
SETTINGS
ON/OFF Slider buttons will be provided for Notifications by Email and
SMS.
The Notification system will be explained in the Platform Design
Section.
27
27. ADMIN USER INTERFACE
The Admin User Interface will be used to perform administrative
functions from the CRYPTOBOT System.
The Admin UI will be used to activate or de-active User accounts on
suspicious activity.
The Bot settings and parameters can be configured from Admin
User Interface.
The Lending settings and configuration can also be applied.
Addition or Removal of Exchanges from the system.
Addition or Removal of trading currencies.
28
28. HIGHCHARTS
Highcharts JS is a JavaScript charting library based on SVG, with
fallbacks to VML and canvas for old browsers.
CRYPTOBOT charts will be displayed by availing Highcharts Graph APIs
and chart components.
29
30. ALGORITHMS & FUNCTIONS
Lending Algorithm
Finely divided lending
Referral program
Lending fee
Short sale
Long sale
Loan Orders
Forced Liquidation
Order book
31
31. POLONIEX LENDING ALGORITHM
Automatically lend your coins on Poloniex at the highest possible
rates, 24 hours a day.
Configure your own lending strategy! Be aggressive and hold out for a
great rate or be conservative and lend often but at a lower rate, your
choice!
The ability to spread your offers out to take advantage of spikes in the
lending rate.
Withhold lending a percentage of your coins until the going rate
reaches a certain threshold to maximize your profits.
Lock in a high daily rate for a longer period of time period of up to sixty
days, all configurable!
32
32. POLONIEX LENDING ALOGORITHM
CONTD…
Automatically transfer any funds you deposit (configurable on a
coin-by-coin basis) to your lending account instantly after deposit.
View a summary of your bot's activities, status, and reports via an easy-
to-set-up webpage that you can access from anywhere!
Choose any currency to see your profits in, even show how much you
are making in USD!
Select different lending strategies on a coin-by-coin basis.
Run multiple instances of the bot for multiple accounts easily using
multiple config files.
Configure a date you would like your coins back, and watch the bot
make sure all your coins are available to be traded or withdrawn at the
beginning of that day.
33
33. BITFINEX LENDING ALGORITHM –
MARGIN BOT
Margin Bot is designed to manage 1 or more bitfinex accounts, doing its best
to keep any money in the "deposit" wallet lent out at the highest rate possible
while avoiding long periods of pending loans (as often happens when using the
Flash Return Rate, or some other arbitrary rate). There are numerous options
and setting to tailor the bot to your requirements.
MinDailyLendRate. The lowest daily lend rate to use for any offer except the
HighHold, as it is a special case (a warning message is shown in case
HighHoldDailyRate < MinDailyLendRate).
SpreadLend. The number of offers to split the available balance uniformly
across the [GapTop, GapBottom] range. If set to 1 all balance will be offered at
the rate of GapBottom position.
GapBottom. The depth of lendbook (in volume) to move trough before placing
the first offer. If set to 0 first offer will be placed at the rate of lowest ask.
34
34. BITFINEX LENDING
ALGORITHM –
MARGIN BOTCONTD… GapTop. The depth of lendbook (in volume) to move trough before placing
the last offer. if SpreadLend is set to >1 all offers will be distributed
uniformly in the [GapTop, GapBottom] range.
ThirtyDayDailyThreshold. Daily lend rate threshold after which we offer lends
for 30 days as opposed to 2. If set to 0 all offers will be placed for a 2 day
period.
HighHoldDailyRate. Special High Hold offer for keeping a portion of wallet
balance at a much higher daily rate. Does not count towards SpreadLend
parameter. Always offered for 30 day period.
HighHoldAmount. The amount of currency to offer at the HighHoldDailyRate
rate. Does not count towards SpreadLend parameter. Always offered for 30 day
period. If set to 0 High Hold offer is not made.
35
35. BITFINEX LENDING ALGORITHM –
CASCADE BOT
Cascade Bot lending strategy is modified so that starting daily lend rate is
not defined as an absolute value, but rather than an increment (which can
also be negative) to FRR.
Cascade lending bot for Bitfinex. Places lending offers at a high rate,
then gradually lower them until they're filled.
This is intended as a proof of concept alternative to fractional reserve rate
(FRR) loans. FRR lending heavily distorts the swap market on Bitfinex. My
hope is that Bitfinex will remove the FRR, and implement an on-site version
of this bot for lazy lenders (myself included) to use instead.
StartDailyLendRateFRRInc Float. The starting rate of FRR +
StartDailyLendRateFRRInc that offers will be placed at.
36
36. BITFINEX LENDING
ALGORITHM –
CASCADE BOT CONTD… ReduceDailyLendRate Float. The rate at which to reduce already
existing offers every ReductionIntervalMinutes minutes.
MinDailyLendRate Float. The minimum daily lend rate that you're
willing to lend at.
LendPeriod Integer. The period for lend offers.
ReductionIntervalMinutes Float. How often should the unlent offers` rate be
decremented. Note that this parameter should be more than or equal to the
interval at which bot is scheduled to run (usually 10 minutes).
ExponentialDecayMult Float. Exponential decay constant which sets the
decay rate. Set to 1 for a linear decay. Decay formula: NewDailyRate =
(CurrentDailyRate - MinDailyLendRate) * ExponentialDecayMult +
MinDailyLendRate.
37
39. PLATFORM DESIGN – REST API
The Platform will be built using Spring Boot technology with Tomcat
Embedded server.
Spring MVC REST APIs exposed from the platform communicates with
the web app built using Angular JS v 2.0 or above.
Data access and storage in the platform will be performed using
Spring Data middleware components.
In order to speed up the operations in the Platform Hazelcast In
Memory Data Grid (IMDG) will be used.
Docker Swarm will be used as container in which Platform
components run during development, testing and production
deployments.
The Platform will be deployed on Amazon Elastic Compute Cloud.
40
40. PLATFORM DESIGN – REST API
CONTD…
The platform serves requests from web app through Spring MVC REST
APIs. The following REST APIs are identified:
/register
/authenticate
/googleauthenticator
/logout
/account
/deposit
/withdraw
/transfer
/createbot
41
44. PLATFORM DESIGN – BOT CREATION
Bot can be created for the User Home Settings box. User needs to
provide API Key and Secret of the Exchange to create the Bot.
Bot creation request will be sent to Platform REST API with the access
token.
Bot creation REST API will send the request to Exchange through REST
APIs exposed by Exchange with API Key and Secret provided by
Exchange.
On successful response from Exchange by verifying the credentials,
the Platform moves to Bot creation process.
On unsuccessful response from Exchange, Platform REST API sends the
response to user as Bot creation Failed.
45
45. PLATFORM DESIGN - BOT
ACTIVATION
Once Bot activation request is received from the Platform, Bot
configuration settings for respective Exchange will be loaded from
Database or Hazelcast IMDG.
AWS Java SDK will be used to clone an already created t2.nano or t2.micro
Ubuntu AMI (Amazon Instance) running Embedded Tomcat or Netty
instance will be created in an automated fashion from the Platform.
The Embedded Tomcat or Netty will expose a Web Socket Endpoint for
real-time communication with the Platform and User such as Loan offers
and Loan demands, Interest rates, Exchange rates.
The Bot Host Name, IP Address will be stored in the Hazelcast as a value
along with Encrypted API Key and Email address of the user.
46
46. PLATFORM DESIGN – BOT WEB
SOCKET
On successful launch of Bot, the User will be able to create a dedicated
connection to the Web Socket Endpoint of the Bot by retrieving the IP
address of the Web Socket Endpoint of the Bot from Hazelcast.
The Web Socket Session object will be stored in the HashSet for use by
Multi-threaded Bot component for lending operations.
In case of disconnection of Web Socket connection from User, existing
Web Socket Session object will be removed from the HashSet.
Once Web Socket is disconnected User will try to connect to the Bot again
and when a new Web Socket connection is established, Web Socket
Session object will be added to HashSet again.
47
47. PLATFORM DESIGN – MULTI-
THREADED BOT COMPONENT
The Multi-threaded Bot component will be launched when the Bot is
launched and it will use the Bot settings from Database or Hazelcast.
The Multi-threaded Bot component will be connected to the Exchange
to perform periodic operations.
The components will be configured for active, inactive, sleep and
request timeout scenarios.
The responses from connected Exchanges will be sent back to Platform and
User by looking up the Web Socket Session object from HashSet.
48
48. PLATFORM DESIGN – BOT AMI
INSTANCE LAUNCHER
An Ubuntu based t2.nano or t2.micro instance with Embedded Tomcat will
be cloned from an existing AMI in Amazon Elastic Computing Cloud.
In the init script of existing Ubuntu AMI, Embedded Tomcat will
be configured to launch at start up.
Once a request for the launch of Bot is received AWS Java SDK will be
used to clone the t2.nano or t2.micro Ubuntu AMI and manage the
lifecycle of AMI instance.
49
49. PLATFORM DESIGN – EXCHANGE
API INTEGRATION
Platform and Bot will connect to Exchange APIs to perform Lending
operations.
Spring REST client APIs will be used to connect to Exchange REST
APIs.
50
50. PLATFORM DESIGN – DOCKER
Docker is an open platform for developers and sysadmins to build, ship,
and run distributed applications, whether on laptops, data center VMs,
or the cloud.
Autorestart is a service-level setting in Docker that can
automatically start the containers if they stop or crash.
A Docker Swarm is a cluster of Docker engines, or nodes, to
deploy services.
The swarm manager uses ingress load balancing to expose the
services to make available externally to the swarm.
Docker Cloud makes it easy to spawn new containers of services to
handle the additional load.
51
51. PLATFORM DESIGN –DOCKER
CONTD…
The CRYPTOBOT platform will be shipped to Test, Integration and
Production environment using Docker Swarm deployed on Amazon EC2.
52
52. PLATFORM DESIGN - NOTIFICATIONS
The lending activities and alerts can be configured in the system.
The notification settings such as SMTP Server, SMS Gateway can be
retrieved from Database and Hazelcast cache.
The platform will send notifications or alerts to the subscribed users
as and when notifications or alerts are received in the system.
The notifications window can be configured in the system
database.
53
53. DATABASE DESIGN
MySQL database will be used to store data.
User Account, Referral System, Lending, Loans, Admin, History,
Exchanges, Sale, Buy, Balance, Currencies, Charts, Notifications, Bots
are the identified tables for the Database.
Spring Data JPA will be used for Data Access operations from the
Database.
54