Skip to content
uzillion edited this page Jul 7, 2018 · 3 revisions

Like trades, the orders in exchange's files inside the orders folder each go through specific steps before being sent to the alerting system. The streams are in the form JSON, and hence are parsed before being sent through the filters. As order quantities at all price levels are not equally important and can cause unnecessary overhead, only the first 20-25 orders are compared on each side of bids and asks. The steps for orders' functions are as follows:

  1. Depending on which exchange is being dealt with, an initial snapshot of the first 20-25 orders of the order-book is saved as an array of tuples sorted by price.
  2. Then the total quantity of each individual cryptocurrency for sell and buy orders for those 20-25 orders are stored separately.
  3. As the stream keeps sending new updated price level information almost every instant, it is the job of the function to update the order book. These are the general steps taken in maintaining the order book:
    1. Each order contains 2 pieces of important information - the price and the quantity.
    2. The prices of new incoming orders are used to index them in the order book. If a valid index is returned, the new information for that price level is put in place of the old one.
    3. If the incoming price level is not found in the saved order book, and has a price greater than the least bid price and lesser than the greatest ask price, it is pushed into the order book.
    4. In case of exchanges like Binance where the order book's size has to be constantly manually maintained, if at any time any price level falls outside the first 20 orders, that price level is deleted from the order book.
    5. To prevent an extreme change in the difference of two consecutive price levels, the exchange function also filters for outliers by making use of standard deviation to check the normal distribution of price differences between two consecutive price levels.
    6. During each removal, replacement, or addition of a price level, the total quantity for buy or sell orders are accordingly updated.
  4. After the order book has been properly updated, these two conditions are checked before further steps can be taken:
    1. If the worth of total sell quantity and total buy quantity are more than the minimum worth of that currency.
    2. If the difference between the number of price levels for buy and sell orders is no more than 5.
  5. If the above conditions are true, the volume ratio ("sb_ratio") is calculated by dividing the "sell_total" by "buy_total". This essentially tells how much bigger is the sell volume compared to the buy volume.
  6. If the ratio is greater than the defined "sensitivity" value — that is at least how many times one side's volume needs to be greater than the other — the alert is sent to the user. (Note: To check if buy volume is greater than the sell volume, the reciprocal of the "sb_ratio" (1/sb_ratio) is compared to the "sensitivity" value).
  7. To prevent repeated volume alerts for the same currency when the alert has once already been sent, wall flags are made to use. If the volume alert has been sent, the wall flag for that currency is set to true. If at any time the volume ratio ("sb_ratio") falls below the sensitivity value, the wall flag is set to false, and another alert of the reduction of volume is also sent.
Clone this wiki locally