Could you explain the idea behind "OrderBookFactor"? How does the number have a correlation with the liquidity? If I set it at 3.0, is it 3x the spread, or?
As you've probably understood, to stay market neutral the two orders that you send to the exchanges have to be both executed immediately. Since Blackbird sends limit orders (and not market orders because it would be too risky), you have to make sure that the orders can be fully executed at the price you defined. Indeed, if there is not enough liquidity the orders will only be partially executed, and you won't be market neutral anymore.
To prevent that situation, Blackbird makes sure that there is at least 3 times (parameter
OrderBookFactor) the liquidity in the order book at the limit price that was defined before executing a trade. So before sending a trade of 2.0 BTC at $500 for example, Blackbird will make sure that there is at least 6.0 BTC at $500 available. Actually it's not exactly $500 but the value defined by the parameter
PriceDeltaLimit to give a little bit of margin. But let's ignore that to keep the example simple.
Now, what happens if you don't check the liquidity first? You detect an arbitrage opportunity at $500 (ask price) and you directly send a buy limit order 2.0@$500 to the exchange. But here is the order book of the exchange at that time:
Ask_Price
| Size
|
$500.00
| 0.5
|
$502.00
| 3.2
|
$503.00
| 5.4
|
Your order will be filled for 0.5@$500 and will stay open for the remaining 1.5. If the other order that you send to the other exchange was completely executed, you will have an imbalance: 0.5 BTC vs. 2.0 BTC.
Note: we use 3 times the liquidity because we need some margin in case of
slippage: this occurs when the price changes between the time you send the order and the time the exchange processes it.