Shrimpy is a solution that provides a unique solution called "Portfolios". What makes this unique to Shrimpy is that these portfolios do not exist on the exchange. Instead, these portfolios are virtually constructed by Shrimpy and maintained as separate entities through meticulous bookkeeping.
When an unintended balance transfer happens between portfolios, this indicates that something went wrong with the bookkeeping. This article will detail the common situations which can cause this bookkeeping to go wrong.
1. Executing a trade directly on the exchange outside of Shrimpy
The most common reason for unintentional balance transfers is the result of trades that were made directly on the exchange.
When a trade is made directly on the exchange, Shrimpy treats this as a withdrawal of the sold asset and a deposit of the purchased asset. The reason we treat it this way is because one asset vanished and the other appeared, without Shrimpy taking action on the portfolio.
When this happens, the asset that was sold is removed from the portfolio which held that asset, and the asset that was purchased is added to the default portfolio. The reason it is added to the default portfolio is because all deposits are added to the default portfolio.
This is both the expected and the intended behavior. Since Shrimpy does not have any concept for why the asset was bought or sold, Shrimpy cannot make a determination for what to do in this situation. As a result, the only consistent behavior is to move the funds to the default portfolio.
2. The exchange incorrectly reports balance information
Shrimpy relies on the exchanges to report accurate and timely information. If the information is not accurate or timely, it can result in unintended balance transfers from one portfolio to the default portfolio.
Notice: Transfers will always happen to the default portfolio. The transfers are not random among portfolios.
In the following discussion, we will present two possible ways these transfers can happen based on information that is not accurate or not timely.
After Shrimpy has placed an order, we will request information from the exchange to tell us the exact resulting trades from that order.
As an example, let's say we place an order to buy exactly 1 BTC at a price of $59,000. Before we get the results of the order, we are unable to know the amount of the order that was successful. Maybe 0.l25 BTC filled, maybe 0.000 BTC filled, maybe the entire 1 BTC filled. We don't know before we ask the exchange for this information.
When we request that information from the exchange, if the exchange returns the incorrect information, this can throw off Shrimpy. Let's imagine on the order we placed to buy 1 BTC the exchange returned that only 0.125 BTC was filled in the order. That would mean that we still have 0.875 BTC left that we still need to fill. So, Shrimpy will continue to purchase more BTC until we have exactly 1 BTC.
The issue arises when the exchange was incorrect. In the example above, we assumed that the original fill of 0.125 BTC was correct. However, if the exchange was wrong and actually 0.900 BTC was filled. Now Shrimpy will buy more BTC than desired because the exchange returned incorrect information.
After buying more funds, Shrimpy would look at the balances and see extra BTC in the portfolio. Since (from Shrimpy's perspective) we did not purchase this BTC, it will incorrectly make the decision to move the funds to the default portfolio.
Similar to the above section on "Inaccurate information", Shrimpy can experience issues when the information is not returned in a timely manner.
As an example, when Shrimpy places an order, we receive an order ID from the exchange. This order ID is used to access information about the resulting fills and the state of that order. After placing an order, Shrimpy will request updates on the state of the order and use those updates to calculate the resulting portfolios.
However, imagine a situation where we receive an order ID, but when we request data from the exchange, the exchange responds by saying "Order not found". In this case, that would mean the exchange believes the order that we are requesting information about does not exist. Typically, this happens when the exchange is too slow to propagate information between their different services.
As a result, Shrimpy must wait and try again. But, what if Shrimpy keeps trying for 10 minutes and the message received from the exchange is that it still says "Order not found". Certainly, at some point, Shrimpy must give up. We must decide at a certain point that the exchange is providing accurate information and that the order really doesn't exist.
What would happen though if 2 hours later, the order shows up and executes?
At that time, Shrimpy will see this as a trade that executed outside of Shrimpy. As we discussed previously, when Shrimpy sees a trade that happened outside of Shrimpy, we will move those funds to the default portfolio.
In this situation, the Shrimpy team must balance how much time we wait for correct information. Either we can rebalance quickly, which will result in not receiving the information we need (resulting in balance transfers between portfolios), or we can rebalance slowly, get the correct information (even if it takes an hour), but rebalances will take a long time. Our belief is there is a balance. We have decided that we are willing to wait a reasonable amount of time, but not so long that rebalances become unbearably long.
Shrimpy relies on exchanges to provide accurate and timely information. Since each exchange is the source of truth when it comes to the state of a portfolio, it is our responsibility to work within the confines of the information provided by the exchange.
Unfortunately, there have been instances where exchanges have been untimely or inaccurate with the information they provide to Shrimpy. In these cases, Shrimpy may be impacted negatively as a result. We have already implemented countless protections to handle situations that can negatively affect trading, but we will continue to implement as many solutions as necessary to handle the sophisticated edge cases that impact Shrimpy.
Please let us know if you have any questions about how Shrimpy works with exchanges. We are always happy to answer questions at email@example.com