From da362e973abcd00ec016309cf1687b1d942a77ec Mon Sep 17 00:00:00 2001
From: LimpidCrypto <97235361+LimpidCrypto@users.noreply.github.com>
Date: Mon, 2 May 2022 18:34:16 +0200
Subject: [PATCH 1/4] initial commit
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index 15f3162..7eed2e4 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,4 @@
+
# Warning 🚨
**This repository is in active development and is not working yet**. The bot currently requires you to put in your seed value via terminal.
It is planned to use the Tangem wallet in the future so you will never be required to give away your secrets. At the current stage I would never use a bot like this, even if it should work!
From 683390cfe5b77d7e62c849a07dd11eef091ffdcf Mon Sep 17 00:00:00 2001
From: LimpidCrypto <97235361+LimpidCrypto@users.noreply.github.com>
Date: Mon, 2 May 2022 23:16:31 +0200
Subject: [PATCH 2/4] State of 02.05.22
---
README.md | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 147 insertions(+)
diff --git a/README.md b/README.md
index 7eed2e4..978369e 100644
--- a/README.md
+++ b/README.md
@@ -23,11 +23,158 @@ It is planned to use the Tangem wallet in the future so you will never be requir
A trading bot that uses the decentralized exchange of the XRP Ledger. It uses arbitrage trading and market making to make profit.
## 📖 Basics:
+- The XRP Ledger updates apporx. every 4 seconds.
- The XRP Ledger has the world's first [`decentralized exchange`](https://xrpl.org/decentralized-exchange.html#decentralized-exchange) (`DEX`).
- Orders on the `DEX` are called [`Offers`](https://xrpl.org/offers.html#offers).
- This bot only sends [`OfferCreate` transactions](https://xrpl.org/offercreate.html) with the [Immediate or cancel](https://xrpl.org/offercreate.html#offercreate-flags) flag to the ledger.
- `Offers` consume other `Offers` in an [order book](https://en.wikipedia.org/wiki/Order_book). For example if you want to buy a currency you place a `bid Offer` that consumes an `ask Offer` that has the same or a better price than the `bid Offer`.
- Arbitrage trading and market making are not known to make huge profits. There are known to make profits with low risk.
+- The term 'currency' describes both XRP and tokens in this repo.
+
+## How does the bot operate?
+#### Example account:
+Classic address: raiuHwMbTTKbtjWTj8FrfpTtVk8RgYVxWH
+Seed: sn8gyEtTt4ZcKkeiTPA8t36CbqhHu
+Balances:
+- XRP: 1.000
+- USD.Bitstamp = 200
+- USD.Gatehub = 150
+- EUR.Gatehub = 100
+- EUR.Bitstamp = 50
+
+
+
+In the current version the user must provide his secret seed value via input from the terminal.
+Before the first official release the trading bot will be able to interact with the Tangem wallet.
+Advantages of using Tangem:
+ - The user's key pair is stored safely on the Tangem wallet
+ - The user does not have to give away their secret seed value
+
+
+
+Generate the wallet using the [`Wallet`](https://github.com/XRPLF/xrpl-py/blob/master/xrpl/wallet/main.py#L12) object from the [xrpl-py](https://github.com/XRPLF/xrpl-py) library.
+By doing so, we are able to access the account's classic address (r-address) and sign transactions.
+
+
+
+Receive all balances the account holds using the [`account_info`](https://xrpl.org/account_info.html) and the [`account_lines`](https://xrpl.org/account_lines.html#account_lines) methods once. The `account_info` method returns the `Balance` field which contains the accounts XRP values expressed in [drops](https://xrpl.org/xrp.html#xrp-properties). The `account_lines` method returns a list of all [tokens](https://xrpl.org/tokens.html) the account holds. Each object in that list contains the `acccount` field (describes the issuer of the token), the `currency` field (describes the currency code, e.g. 'USD') and the `balance` field (describes the amount the account holds of that token). These balances will be stored in the [`XRPWallet`](https://github.com/LimpidCrypto/XRPL-trading-bot/blob/main/xrpl_trading_bot/wallet/main.py#L10) object which is a child class of the [`Wallet`](https://github.com/XRPLF/xrpl-py/blob/master/xrpl/wallet/main.py#L12) object of the xrpl-py library.
+
+
+
+Receive a message every time a transaction affects the user's account. This message include precise information how the transaction affected the ledger and the account.
+
+
+
+Every time the bot receives a message (described in step 4) that a transaction affected the user's account, the bot makes use of a [transaction parser](https://github.com/XRPLF/xrpl-py/pull/342) (currently added in directly to the bot. The parser will be integrated into the xrpl-py library as soon as possible. When integrated the parser will be deleted from the bot.). The transaction parser parses the accounts final balances after the transaction happend and corrects them in the `XRPWallet` object.
+
+
+
+Because we now always know what currencies the account holds, we can parse all possible [currency pairs](https://www.investopedia.com/terms/c/currencypair.asp) the account could trade from them.
+If we take the above example account the possible currency pairs would be the following:
+- XRP/USD.Bitstamp
+- XRP/USD.Gatehub
+- XRP/EUR.Gatehub
+- XRP/EUR.Bitstamp
+- USD.Bitstamp/USD.Gatehub
+- USD.Bitstamp/EUR.Gatehub
+- USD.Bitstamp/EUR.Bitstamp
+- USD.Gatehub/EUR.Gatehub
+- USD.Gatehub/EUR.Bitstamp
+- EUR.Gatehub/EUR.Bitstamp
+
+
+
+Receive the entire [order book](https://www.investopedia.com/terms/o/order-book.asp) for every currency pair once, using the [`subscribe`](https://xrpl.org/subscribe.html) method. The subscription will immediately be canceled after the order book is received because the bot is retreiving it from a full history node. We do not want to load them unnecessarily. The order books will be stored in the [`OrderBooks`](https://github.com/LimpidCrypto/XRPL-trading-bot/blob/main/xrpl_trading_bot/order_books/main.py#L52) object.
+
+
+
+Receive a message every time a transaction affects the given order book. This message include precise information how the transaction affected the ledger and the order book.
+
+
+Everytime the bot receives a new message (described in step 4) that a transaction affected an order book. The bot takes the transaction and the affected order book to see how the transaction changed the order book. It then parses the final state of the order book. To do this it uses the [`parse_final_order_book`](https://github.com/LimpidCrypto/XRPL-trading-bot/blob/main/xrpl_trading_bot/txn_parser/order_book_changes.py#L52) parser.
+
+
+
+You could say that the decentralized exchange of the XRP Ledger is nothing more than a collection of limit orders. Orders are called [`Offers`](https://xrpl.org/offers.html#offers) on the XRP Ledger. Every time the user wants to trade a currency against another he needs to find another participant, who wants to trade the exact same currencies in the other direction, at the same or better exchange rate. For Examlple:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Everytime the bot receives a new message (described in step 4) that a transaction affected an order book. The bot takes the transaction and the affected order book to see how the transaction changed the order book. It then parses the final state of the order book. To do this it uses the [`parse_final_order_book`](https://github.com/LimpidCrypto/XRPL-trading-bot/blob/main/xrpl_trading_bot/txn_parser/order_book_changes.py#L52) parser.
1. Get users seed value
+2. Generate wallet
+3. Receive the accounts balances once
+4. Subscribe to the accounts transaction stream
+5. Derive new balances on every new transaction
+6. Parse all possible currency pairs
+7. Receive the entire order book for each currency pair once
+8. Subscribe to the transaction stream of each order book
+9. Derive new order books on every new transaction
+10. Build trade paths
+
Person A is willing to pay 10.70 USD in order to receive 10 EUR. To let everybody know he is willing to so he submits an [`OfferCreate`](https://xrpl.org/offercreate.html) transaction to the network. This transaction creates an [`Offer`](https://xrpl.org/offer.html#offer) object on the XRP Ledger which everybody in the network is able to see. Now Person B comes into play. Person B sees that offer of Person A and wants to trade it. So Person B is willing to pay 10 EUR in order to receive 10.70 USD. Person B now submits a `OfferCreate` transaction just as Person A did before. Because both `Offers` have the same exchange rate they are consuming each other. Person A gets 10 EUR from Person B and Person B gets 10.70 USD from Person A.
+
You can imagine that the trading bot is Person B. The bot is constantly searching for `Offers` which combined will result in profit due to price differences. If the bot combine and compare two or more `Offers` with each other this is called a *trade path*.
+
+
+10.5. Adjust values for each trade path
+11. Calulate the profit of each trade path
+12. Filter for the profitable trade paths
+13. Build the OfferCreate transactions
+14. Sign the transactions
+15. Submit the transactions
+16. Wait for all transaction results
+17. Repeat from step 6
+9. Derive new order books on every new transaction
Person A is willing to pay 10.70 USD in order to receive 10 EUR. To let everybody know he is willing to so he submits an [`OfferCreate`](https://xrpl.org/offercreate.html) transaction to the network. This transaction creates an [`Offer`](https://xrpl.org/offer.html#offer) object on the XRP Ledger which everybody in the network is able to see. Now Person B comes into play. Person B sees that offer of Person A and wants to trade it. So Person B is willing to pay 10 EUR in order to receive 10.70 USD. Person B now submits a `OfferCreate` transaction just as Person A did before. Because both `Offers` have the same exchange rate they are consuming each other. Person A gets 10 EUR from Person B and Person B gets 10.70 USD from Person A.
-
You can imagine that the trading bot is Person B. The bot is constantly searching for `Offers` which combined will result in profit due to price differences. If the bot combine and compare two or more `Offers` with each other this is called a *trade path*.
+
You can imagine that the trading bot is Person B. The bot is constantly searching for `Offers` which combined will result in profit due to price differences. If the bot combine to compare two or more `Offers` with each other this is called a *trade path*.
+## Examples
+### Spatial arbitrage trading
+#### Soon
+### Triangular arbitrage trading
+#### Soon
+### Market maker
+#### Soon
+#### Soon +
+last trade TakerPays amount - first trade TakerGets amount = numeric profit/loss +(1 - (last trade TakerPays amount - first trade TakerGets amount) / first trade TakerGets amount) * 100 = percentage profit/loss +
+Filter for positive numeric profit and sort by percentage profit, so the most profitable paths get executed first. +