Last updated September 25, 2024

Disclaimer

The following documentation describes a working method that is in production to trade XRP tokens in automated ways. With that said, we are not financial advisors and you should understand the risks involved in trading. The content, thoughts, and opinions expressed here belong solely to ourselves. We take no part and no responsibility/liability over your own actions, including your losses or gains. Any action you take upon the information on this page is strictly at your own risk.

Project background

The price of XRP tokens fluctuates up and down all the time. Below is a screenshot of a daily pricing chart:



The goal is to trade automatically based on market behaviors, such as:

(Phase 1) Normal fluctuations (highlighted in green)
(Phase 2) Pumps and dumps, or known as breakouts (highlighted in red)



Please keep in mind that we are NOT trying to identify the typical chart patterns (e.g. pennant, cup & handle, ascending triangle, triple bottom, descending triangle, top/inverse head & shoulders, bullish/bearish symmetric triangle, rounding bottom, flag continuation, double top, or falling wedge...etc., none of that) to "predict" the direction of where the price will go. We are trying to create a system that knows how to trade in the above mentioned situations (phase 1 & 2) that will yield in growth on the fly.

Below we will describe how we accomplish phase 1 by doing real-time large data analysis and processing.

Our approach

Instead of trying to identify chart patterns & predict the future price and trying to be the first one buy or sell before the price fluctuates to predicted values, we believe that there's still money to be made by following individuals or companies who are experienced and know how to trade better than we are.

We are not trying to be smart. We are trying to follow smart investors and traders. We believe that as long as we are following the smart traders and copy their trading activities as quickly as possible, the smart traders will get the most amount of benefits, but we will also be able to make some profit.

A few things we need to do:

1. We need to identify & track activities of traders in real-time or as fast as possible.
2. We need to track the price and marketcap of XRP tokens in real-time or as fast as possible.
3. Based on recent tracked data, we need to have enough computing power to simulate trading outcomes based on given set of triggers and process these simulations at scale.
4. We need an exchange that has API access to allow us to trade via software.

Identifying and tracking investors & traders to follow

Identifying XRP accounts

We started with identifying XRP account addresses from https://ledger.exposed/rich-stats and https://xrpcharts.ripple.com/#/active_accounts. Keep in mind that many of these top wallet addresses belong to exchanges and are not owned by any individuals or trading companies. These exchange accounts are not a true reflection of trading activities from professional and smart traders. We should not completely ignore them but the trading activities on exchange accounts should be dealt with different "weights" in our script's decision making process when it comes to trading.

We used https://bithomp.com/explorer/ to verify and learn more about the XRP accounts that we want to track.

Tracking XRP accounts

We stored a list of XRP accounts (wallet addresses) that we need to track into a SQL database, and here is the structure we used:



wallet_id - Unique and primary key of records on auto increment
wallet_address - XRP account address
wallet_type - Type of account (1 - individual, 2 - company, 3 - exchange)
wallet_time - Timestamp of when this wallet was lastly checked
wallet_value - Value of the wallet in XRP as of the last check

(Please note, here we are not showing the indexes that you need to create for this database, which depends on how your database queries are written.)

We created another table tracking the changes of wallets:



change_id - Unique and primary key of records on auto increment
wallet_id - The unique wallet_id of the account address
change_time - Timestamp of when the wallet is tracked
change_amount - The difference in XRP value compared with the previous check

We used the API call (https://developers.ripple.com/data-api.html#get-account-balances) provided by Ripple to populate the wallet_time and wallet_value values to the wallets database.

Then we setup an automated script that runs every minute to:

1. Fetch a wallet_id, wallet_address and wallet_value from the wallets database, assign the wallet_value as the "previous balance"
2. Initiate an API call to retrieve the "current balance" of the wallet
3. Find the difference of the balance between the current balance and the previous balance, and set as change_amount
4. Insert a new record into the wallet changes database with the wallet_id, change_time, and change_amount
5. Update the wallet's wallet_value variable with the current balance and the wallet_time as the current time
6. Repeat the above procedures for all of the wallets tracked in the wallets database

With the above implementation, we will be able to track wallet activities for reference. The more wallets we need to track, the more API calls we need to initiate, therefore the more time our script will need to complete a batch job.

For example, if it takes a second for an API call to complete, a single batch job can only handle up to 60 wallets a minute. So if we need to track wallet activities every minute and we have more than 60 wallets to track, we will need to split the wallets and delegate multiple batch jobs to different workers and execute them simultaneously.

The Ripple Get Account Balances API call allowed us to pull the balance of XRP addresses in the past as well so instead of waiting on the scripts to pull in the stats, we populated the database with 30 days worth of data at 1 minute intervals for every address we track. Then, our automated script will pull in new data at 1 minute intervals moving forward.

Tracking the price and marketcap of XRP

We need to track the current price of XRP in order to know how much XRP to buy or sell when our script makes trades. We also need to track the marketcap of XRP because we know the amount of change in XRP volume may or may not have an impact on the price of XRP with respect to the marketcap. For example, a change of 1 million in XRP tokens will most likely not have an impact on the price of XRP when there are over 41 billion tokens in circulation.

To track the price and marketcap of XRP, we used CoinMarketCap's API (https://coinmarketcap.com/api/)

The "/v1/cryptocurrency/quotes/latest" (or "/v1/cryptocurrency/listings/latest") API call allowed us to track the current price and marketcap of any cryptocurrency on CoinMarketCap's platform, including XRP. The data the API returns include:

- id
- name
- symbol
- circulating_supply
- total_supply
- max_supply
- USD->price
- USD->volume_24h
- USD->market_cap
- ...etc.

We created a database table on the currencies that we want to track:



currency_id - Unique and primary key of records on auto increment
id - The "id" variable for the currency returned by CoinMarketCap API
name - The "name" variable for the currency returned by CoinMarketCap API
symbol - The "symbol" variable for the currency returned by CoinMarketCap API
status - Default DISABLED, when ENABLED, system will track the currency's activities

We created another database table to track the activities on currencies:



stat_id - Unique and primary key of records on auto increment
timestamp - Timestamp of the check action
id - The "id" variable for the currency returned by CoinMarketCap API
circulating_suppply - The "circulating_supply" variable for the currency returned by CoinMarketCap API
total_supply - The "total_supply" variable for the currency returned by CoinMarketCap API
max_suipply - The "max_supply" variable for the currency returned by CoinMarketCap API
price - The "USD->price" variable for the currency returned by CoinMarketCap API
volume_24h - The "USD->volume_24h" variable for the currency returned by CoinMarketCap API
market_cap - The "USD->market_cap" variable for the currency returned by CoinMarketCap API
currency - The currency of the price, volume_24h, and market_cap variables, which in our case is set to USD
value_change - Whether or not if the price has changed as compared with the previous record for the same crypto currency. (UP - Up, DN - Down, or NC - No Change)

With the above database tables setup, we created a script that runs every minute to obtain the circulating supply, total supply, max supply, price, 24hour volume, market cap for the top 20 crypto currencies (which includes XRP). We wanted to track other currencies as well because we wanted to analyze to see how other crypto currencies impact XRP and if they play a role in how traders/investors trade XRP

CoinMarketCap APIs allowed us to pull in historic data as well (paid subscription), and so we did. We populated the database with 30 days worth of data at 1 minute intervals for every currency we track. Then, our automated script will pull in new data at 1 minute intervals moving forward.

Running Simulations

Now that we have the data on wallet and currency movements, it is time to run simulations. Our goal in phase 1 is to have the system to make automated trading decisions based on both wallet and market behaviors during normal fluctuations. For example, if the price of XRP remains steady within a normal range yesterday and today, if we train our system to know how to buy and sell that will lead to positive growth at the end of the day, the same trading strategy will most likely work for today.

Here we have defined a few simulation variables that will dictate buying and selling decisions, and a simple interface to test our simulations:



Start Date/Time - Start date and time of the simulation
End Date/Time - End date and time of the simulation
Interval - From the start date and time, the system will analyze data every N minutes
Check Span - On every interval, the system will analyze data in the past N minutes
Trigger: Wallets Count - On every interval, based on the data in the past N minutes specified by the Check Span, the minimum number of wallets resulted in positive or negative balance to trigger a buy or sell action
Trigger: Buy Volume - The minimum amount of XRP balance gains (sum) from the wallets in the past N minutes specified by the Check Span to trigger a buy action
Trigger: Sell Volume - The minimum amount of XRP balance losses (sum) from the wallets in the past N minutes specified by the Check Span to trigger a sell action
Trigger: Sell Threshold - The minimum number of XRP token's market price required to trigger a sell action. (e.g. if XRP price falls below this threshold, no sell actions will occur)
Starting XRP - The amount of XRP the system will start with
Starting USD - The amount of USD the system will start with
Buy Volume - The amount of XRP tokens to buy when a buy action is triggered
Sell Volume - The amount of XRP tokens to sell when a sell action is trigger

Here is a sample simulation setup:



With the above configuration, starting from 2018-10-01 00:00:00, for every minute, the system will analyze the past 20 minutes of wallets data. For example, at 2018-10-01 00:00:00, the system will look at all the wallet activities from 2018-09-30 23:40:01 to 2018-10-01 00:00:00

If the sum of wallet change on all of the wallets tracked is positive, and the total change exceeds 150000 XRP tokens, there are at least 5 wallets with positive change, and based on the current XRP token price in USD, if there's enough USD to purchase 300 XRP tokens, then the system will initiate a buy action.

Else, if the sum of the wallet change on all of the wallets tracked is negative, and the total change exceeds -250000 XRP tokens, and there are at least 5 wallets with negative change, and the current XRP token price is greater or equal to $0.40 USD, and there's at least 100 XRP tokens available to sell, then the system will initiate a sell action.

The system will repeat the above every minute starting from 2018-10-01 00:00:00 until 2018-10-01 23:59:59, and at the end of the simulation, we can compare to see if the buy and sell actions will yield positive or negative growth. At the end of the simulation, we would have 18100 XRP tokens and $255.14 USD left (click here to download a simulation output file), which translates into 18,491 XRP tokens in value based on XRP's market price. We started with 10000 XRP and $5000 USD, which is approx. 18568 XRP tokens in value. Therefore, the simulation would have yielded a loss.

However, that's just one simulation, if we run the simulation with different simulation variables, we can see that one particular variable combination yields a 3.03% growth:



Keep in mind that we picked 10 random combinations and one yielded 3.03% growth. Based on the amount of simulation variables we have, we have identified over 188160 combinations in total. Which means our system will need to run 188160 simulations to identify the one that yields the most growth for the sample timeframe.

When we plugged in the 3.03% growth combination:



We end up with 19118 XRP tokens in value, which is a growth of 550 XRP tokens from the 18568 XRP tokens we started with. (click here to download a simulation output file)

Here's a video demonstration showing the above two simulations:



Every hour, we run 188160 simulations (requires a bit of computing/processing resource) for wallets and market data for the past 6 hours, and pick the one that yields the most growth and run that in production for the coming hour. Then re-run the simulations and repeat every hour moving forward. If there are no simulations that would yield positive growth, then the system does not trade for an hour.

Making trades via APIs

In order to trade automatically, you will need to be part of a cryptocurrency exchange that has API program. For example, both Kraken and BitStamp have APIs available for trades to be made using programs.

Handling breakouts (pump and dumps)

For phase 1, our focus is to be able to make trades during normal fluctuations. When breakouts are happening, our system will not initiate buy or sell orders.

When we have wallets and market data in real time, identifying breakouts is not that difficult. Usually when there's a breakout trending up, almost all of the simulations will yield positive return for a shorter period of time (e.g. 1 hour). When there's a breakout trending down, the majority of the simulations will yield negative return for a shorter period of time.

The change in the wallets tracked also reflect breakout activities. When there's a breakout trending up, the wallets that we track are selling in general, and vice versa when there's a breakout trending down, the wallets that we track are buying in general.

We put a hard stop on trading whenever the system identifies a breakout, and we are currently working on a way to trade during breakouts (Phase 2). Currently we have not found a successful simulation setup yet.

Closing thoughts

Opportunities

We believe that this type of automated trading driven by real-time data capture & analysis and rapid simulations will work with other crypto currencies that can support the workflow. The cryptocurrency needs to:

- Be fast to make trades
- Have a way for us to identify and track wallets in real time
- Have a way for us to track market price and volume data in real time (CoinMarketCap's API already support the majority of the cryptocurrencies)
- Have exchanges that have APIs to allow us make trades using programs

Other methods of black box trading

There are other companies such as Nordic Crypto who offer black box trading tools and services. There are many ways and algorithms to automate trading. What we have described above is a real world demostration of how data can be collected and processed to run simulations and enable automation.