Saturday, November 9, 2019

Crypto Market Making Bot

Basic Market Making Strategy¶


At the market making approach, Hummingbot always posts restrict bid and ask offers on a market and waits for other market participants ("takers") to fill their orders.

See institutional grade market making bot.

Users can define how far off ("spreads") in the mid price the bidding and inquires are, the order amount, and how frequently prices should be updated (order cancels + new orders posted).
Warning

Please exercise caution when conducting this strategy and set a proper kill switch rate.  The present version of the strategy is meant to be a template that users customize and can test.  Running the plan with funds may result in losses.

Prerequisites: Inventory¶


You will have to hold adequate stock of quote and/or base currencies on the exchange to place orders of the market's minimum order size.
You will also need some Ethereum to cover gas for transactions on a DEX (if applicable).
Placing Orders: Minimum Order Size¶

When placing orders, when the dimensions of the order determined by the order price and amount is below the exchange's minimum order size, then the orders will not be created.
For example, if the bid order amount * bidding price < exchange's minimum order size while ask order amount * ask price > market's minimum order size, a sell order would be created but no bidding order would be generated.
When employing the multiple order style, this may result in a few (or none) of the orders being placed on a single side.
By way of example, if the bidding order sum 1 * bid price 1 < exchange's minimum order size while bid order amount 2 * bid price 2 > exchange's minimum order size, then only the 2nd bidding order could be made.

The following walks through all the steps when running config for the very first time.
Hint: Autocomplete inputs during configuration

When moving through the command line config process, pressing  a prompt will show valid available inputs.

What is your market making approach >>> Input pure_market_making.
Enter import, which will ask you to specify the file title, if you have initialized.
Enter your manufacturer market name >>> The exchange where the bot will put bid and ask orders.

Input the token symbol you would like to trade on [manufacturer exchange name] >>> Enter the token emblem for the maker exchange.

Note: Options available are based on each exchange's methodology for labeling currency pairs.  Make sure that the pair is a pair for your exchange.

Specify if you would like a single order per side (i.e. one bidding and one inquire ), or multiple orders every side.
Multiple permits for different prices and sizes for each side.  See further configuration for many orders.
Just how far away from your mid price do you need to place the initial bid (Enter 0.01 to indicate 1%)?
How far away from the mid price do you need to place the initial ask (Input 0.01 to indicate 1%)?
How often do you want to cancel and substitute bids and asks (in seconds)?
What's your favorite quantity per order (denominated in the bottom asset, default is 1)?
Do you want to allow inventory skew?
What is your goal base asset stock percentage (Input 0.01 to indicate 1%)?  >>> More information in Inventory-Based Dynamic Order Sizing section.
How long do you want to wait before putting the next order in case your order gets stuffed (in seconds).  (Default is 10 minutes )?  >>> More info in Order Replenish Time section.
Do you need to allow order_filled_stop_cancellation.  If enabled, if orders are totally satisfied, the other side remains uncanceled (Default is False)?  >>> More information in"Hanging Orders" section.
Do you need to allow jump_orders?  If enabled, when the bid price is lower than your order price, buy order will leap to a tick over top bid price & vice versa for sale.  (Default is False) >>>

How deep would you like to enter the order book for calculating the very best bid and ask, ignoring dust orders on the top (expressed in base currency)?  (Default is 0) >>> More information in Penny Jumping Mode section.

Adding Transaction Costs to Prices¶

Transaction costs are by default added to the prices.  This setting can be disabled by visiting hummingbot/strategy/pure_market_making/start.py and setting add_transaction_costs_to_orders into False.

Fee_pct denotes the percentage manufacturer fees per order (generally common in Centralized exchanges) while fixed_fees refers to the horizontal fees (generally common in Decentralized exchanges).
The bidding order price is now calculated as:
Bid price with trade cost
The ask order price is currently calculated as:
Ask price with transaction cost
Adding the trade cost will lessen the bidding order price and increase the ask order price.
We currently display warnings if the adjusted price post adding the trade costs is 10% away from the initial price.  This setting may be modified by altering warning_report_threshold in the c_add_transaction_costs_to_pricing_proposal function inside hummingbot/strategy/pure_market_making/pure_market_making_v2. pyx.
If the buy price with the trade cost is zero or negative, it isn't rewarding to put orders and orders won't be placed.
Multiple Order configurations ¶
Multiple orders allow you to create numerous orders for each bid and ask side, e.g. multiple bid orders with different prices and different sizes.

How many orders do you want to put on both sides, (default is 1)?  >>> This sets number_of_orders (definition).
What's the size of the first bidding and ask order, (default is 1) >>> This sets order_start_size (definition).
How much do you wish to improve the order size for every additional order (default is 0)?  >>> That sets order_step_size (definition).
Input the price increments (as percent ) for subsequent orders (Enter 0.01 to indicate 1%)?  >>> That sets order_interval_percent (definition).
Caution: If you set this to some very low number, multiple orders may be placed on the same price level.  For example for an asset such as SNM/BTC, should you place an order interval percent of 0.004 (~0.4%) because of low asset value the price of the next order will be rounded to the closest price supported from the trade, which in this case might result in multiple orders being put in precisely the same price level.
Inventory-Based Dynamic Order Sizing¶

This function allows you to specify a goal base to quote asset stock ratio and adapt order dimensions whenever the current portfolio ratio deviates from this target.
For instance, if you are targeting a 50/50 foundation to quote asset ratio but also the current value of your foundation advantage accounts for at least 50% of the value of your stock, then bid order sum (buy base advantage ) is diminished, while ask order amount (sell base advantage ) is raised.
Prompt Description

Would you like to enable inventory skew?  (y/n) >>> That sets inventory_skew_enabled (definition).

What's your target base asset inventory percentage (Enter 0.01 to indicate 1 percent ) >>> This sets inventory_target_base_percent (definition).
Here is a list skew calculator which shows how it adjusts order sizes.
Determining order size¶
The enter order_amount is corrected by the ratio of present base (or quote) percentage versus target percentage:

Order Adjustment Based on Filled Events¶
By default, Hummingbot places orders as soon as there are no active orders; i.e., Hummingbot instantly places a new order to replace a filled order.  When there's a sustained movement in the market in any 1 direction for a while, there's a risk of continued trading in that direction: for instance, continuing to purchase and collect base tokens in the case of a protracted downward move or continuing to market in the case of a protracted upward movement.

The filled_order_replenish_wait_time parameter allows to get a delay when placing a new order in the case of an order being filled, which can help mitigate the above scenarios.
Example: Should you have a buy order that is filled at 1:00:00 and the delay is set as 10 minutes.  The next orders put wil be at 1:00:10.  The sell order is also cancelled within this delay period and positioned at 1:00:10 to make sure that both sell and buy orders remain in sync.
Prompt Description

Just how long do you want to wait before putting another order in case your order gets stuffed (in seconds).  (Default is 10 seconds)?  >>> This sets filled_order_replenish_wait_time (definition).

Typically, orders are placed as pairs, e.g. 1 buy order + one sell order (or multiple of buy/sell, in several mode).  There's currently an option utilizing enable_order_filled_stop_cancellation to leave the orders on the opposite side hanging (not cancelled) if a one side (buy or sell) is stuffed.
Example: Assume you're running pure market earning only order mode, the order size is 1 and the mid price is 100.  Then,
Based on bidding and request thresholds of 0.01, your bid/ask orders will be placed at 99 and 101, respectively.
Your existing bid at 99 is fully filled, i.e. somebody takes your order and you purchase 1.
By default, following the cancel_order_wait_time, the ask order at 101 would be canceled
With the enable_order_filled_stop_cancellation parameter:
The first 101 ask order remains outstanding
After the cancel_order_wait_time, a new set of bid and ask orders are created, causing a total of 1 bid order and two ask orders (original and new).  The initial ask order remains outstanding until that is stuffed or cancelled.
The enable_order_filled_stop_cancellation can be utilized if there's enough volatility such that the hanging order might eventually get filled.  It should also be used with caution, as the user should track the bot to manually cancel orders that don't get filled.  While running this attribute it is advised to disable inventory skew.
Hanging order attribute: now on single trading style only

Considering that the"hanging orders" attribute is experimental, it's currently only available in only order mode for analyzing and receiving further feedback from the neighborhood.

How long would you like to wait before placing another order in the event your order gets filled (in seconds).  (Default is 10 minutes )?  >>> That sets filled_order_replenish_wait_time (definition).
Would you need to enable order_filled_stop_cancellation.  If enabled, when orders are totally satisfied, the other hand stays uncanceled (Default is False)?  >>> That sets enable_order_filled_stop_cancellation (definition).
Penny Jumping mode¶
Users now have the option to automatically adjust the prices to just over top bid and only below top request using jump_orders_enabled.  The user can specify how deep to enter the orderbook for calculating the very best bid and best ask price using jump_orders_depth.  This is available in order manner.
Example: Assume you're running pure market making in only order manner, the order size is 1 and the mid price is 100.  Then if you set jump_order_depth to 0,

Based on bid and request thresholds of 0.01, your bid/ask orders might originally have been put at 99 and 101, respectively.
If the current top bid in the market is 98, now the buy order is mechanically adjusted to only above 98, state 98.001 and put at this price.
If the current top inquire in the market is 102, now the market order is automatically adjusted to just below 102, state 101.999 and put at this price.

Would you want to allow jump_orders?  If enabled, when the top bid price is lesser than your order price, purchase order will jump to a tick over bid price & vice.  (Default is False) >>> That sets jump_orders_enabled (definition).

How deep do you want to go into the order book for calculating the top bid and ask, ignoring dust orders on the top (expressed in base money )?
Setup Parameters¶
The next parameters are fields in Hummingbot configuration files located in the /conf folder (e.g. conf/conf_pure_market_making_strategy_[#].yml).
Term Definition

order_amount
(single order strategy) The order sum for the limitation bid and ask orders.
Make certain you have enough quotation and foundation tokens to place the bid and ask orders.  The plan won't put orders if you don't have enough balance for both sides of this order.
Cancel_order_wait_time An amount in moments, which is the length for the put limit orders.  Default value: 60 seconds.
The limitation bid and ask orders are cancelled and new bids and requests are placed in line with the current mid price and preferences at this interval.
Bid_place_threshold A sum expressed in decimals (i.e. input of 0.01 corresponds to 1%).  The plan will put the purchase (bid) order 1 percent from the mid price if set to 0.01.
 If you place bid_place_threshold to 0.1 that is 10 percent, then it is going to set your purchase order (bidding ) at 10% below mid price of 100 that is 90.
Ask_place_threshold A sum expressed in decimals (i.e. input of 0.01 corresponds to 1 percent ).  The strategy will place the market (ask) order 1 percent away from the mid price if set to 0.01.
 If you place ask_place_threshold to 0.1 which is 10 percent, then it will place your sell order (inquire ) at 10% above mid price of 100 that is 110.
number_of_orders
(multiple order plan ) The range of orders to place for each side.
Illustration: Entering 3 places three bid and three ask orders.
order_start_size
(multiple order plan ) The size of the initial order, that is the order closest to the mid price (i.e. best bid and best ask).

order_step_size
(multiple order strategy) The size of incremental size increases for orders following orders in the first order.
Example: Entering 1 when the first order size is 10 contributes to bid sizes of 11 and 12 for the second and third orders, respectively, for a 3 order plan.
order_interval_percent
(multiple order strategy only) The percentage amount increase in price for subsequent orders in the very first order.
Example: To get a mid price of 100, ask_place_threshold of 0.01, and order_interval_percent of 0.005,

The first, second, and third party ask prices will be 101 (= 100 + 0.01 x 100), 101.5 (= 101 + 0.005 x 100), and 102.

Inventory_skew_enabled If this is correct, the bid and ask order sizes are corrected depending on the inventory_target_base_percent.
Inventory_target_base_percent A sum expressed in decimals (i.e. input of 0.01 corresponds to 1%).  The strategy will place bid and ask orders together with corrected sizes (according to order_amount, order_start_size) and try to keep this foundation asset vs. total (base + quotation ) strength value.
Instance: You're market making ETH / USD using order_amount: 1 and balances of 10 ETH and 1000 USD.  Your present asset value and quote asset value is ~ 67% and 33%, respectively.  In case inventory_target_base_percent: 0.5, the order amount will be adjusted out of 1 ETH bid, 1 ETH ask to 0.67 ETH bid, 1.33 ETH ask.
Filled_order_replenish_wait_time An amount in seconds, which defines the delay before setting the next order for unmarried order mode.  Default value: 10 seconds.
Enable_order_filled_stop_cancellation If this is correct, the orders on the side opposite to the filled orders stays uncanceled.  Default value: False.

Jump_orders_enabled If this is correct, the bidding and ask order prices are corrected based on the current top bid and ask prices in the market.  Default value: False.

Jump_orders_depth If jump_orders_enabled is true, this specifies how deep to the orderbook to go for calculating the very best bid and ask prices including the user's busy orders.  Value: 0.
Risks and Trading Signs ¶
Caution
Maybe not financial or investment information.  Below are descriptions of several dangers linked to the market manufacturing strategy.  There may be additional risks not described below.
Ideal case¶
Pure market making strategies works best when you've got a market that's relatively calm, but with sufficient trading action.  What that means to get a pure market makers is, he'd have the ability to get both of his bid and ask offers traded frequently; the price of his stock doesn't change by a lot so there's no risk of him ending up on the wrong side of a fashion.  He would be able to repeatedly capture small profits via the bid/ask spread over time.

From the figure above, the period between 25 Feb and 12 Mar are an illustration of the ideal case.  The price of the asset stayed within a relatively compact range, and also there was sufficient trading activity for a market maker's offers to be taken regularly.
The only thing a market maker should be concerned about in this situation is he should make certain the trading spread that he sets is bigger than the trading fees given to the market.
Low trading action ¶
Markets with reduced trading activity greater risk for pure market earning strategies.  Here's an illustration:

In any market with reduced trading action, there is a risk where the market maker might have to hold onto inventory for a long time without a chance to trade it back.  Throughout that time, the prices of the assets may rise or drop dramatically despite seeing trading activity.  This exposes the market manufacturer to inventory risk following mitigating some of this risk by using bid spreads.
Other strategies might be more suitable from a risk perspective in this kind of market, e.g. cross-exchange market earning.
Volatile or trending markets¶

Another frequent risk that market makers need to be aware of is trending markets.  Here's 1 example:

In case a pure market maker set his spreads naively in this market, e.g. equidistant bid/ask spread, there is a risk of the market maker's bid consistently being stuffed as prices trend down, while at precisely the same time the market continues to move away from the market maker's request, decreasing the chances of sells.  This would result in an accumulation of inventory in precisely the time where this could reduce inventory stock value, which can be"wrong-way" risk.
But, it is still possible to improve the probability of generating gains in this type of market by skewing bid inquires, i.e. setting a wider bid spread (e.g. -4%) than ask spread (e.g. +0.5%).  In this way, the market maker is trying to catch price spikes at the direction of this trend and purchase extra stock only in case of a larger movements, but sell more rapidly when there's an opportunity so as to minimize the duration that the stock is held.  This approach also has a mean reversion prejudice, i.e. buy just when there is a larger move downwards, in the hopes of stabilization or recovery following such a massive movement.
Market making in volatile or trending markets is more advanced and insecure for new dealers.  It's suggested that a dealer looking to market create in this kind of environment to get mentally familiar with it (e.g. via paper trading) before committing significant capital to the plan.
Technology / infrastructure threat ¶
There are many moving parts when operating a market making bot that all have to work together in order to properly operate:

A mistake in any component may result in bot mistakes, which may vary from insignificant and minor to major.
It's crucial for any market making bot to be able to regularly refresh its bid and ask offers on the market in order to adapt to changing market conditions.  In the event the market earning bot is disconnected from the exchange for an extended period of time the bid/ask provides it made could be abandoned on the market and subject to price changes of the market.  Those orders may be filled at a loss as market prices move, while the market maker is offline.  It's essential for any market maker to be sure infrastructure is both secure and dependable.

No comments:

Post a Comment