# Market Making
## High overview of design

## Vault
Receives funds of market makers and allocates them to Market Making Vault and Hedging Vault depending on the set allocation.
### Structure:
`name` - The Vault's name
`type_name` - String representation of the Vault's underlying Coin's fully-qualified type name.
`lp_type` - The Vault's type of LP coins.
`allocation` - Allocation of assets which is used for market making and for hedging.
`lock_period` - Duration for which an asset is locked in a Vault.
#### Dynamic fields:
1) LP coin balance
2) Values and balances of underlying coin (base coin) and quote coin
3) Market Making Vault
4) Hedging Vault
### Functions:
* `new_vault`
* `initialize_liquidity`
* `initialize_market_making_vault`
* `initialize_hedging_vault`
* `deposit`
* `withdraw`
* `rebalance`
## Market Making Vault
### Structure:
`name` - The Vault's name
`type_names` - String representation of the Vault's underlying Coin's fully-qualified type names.
#### Dynamic fields:
1) Risk Limits struct
#### Risk Limits:
Repsresents risk limits which help manage the exposure and risk associated with the market making activities.
`max_order_size` - Defines the maximum size of an order that the strategy or vault can place in the market. It helps control the size of the orders and ensures they do not exceed a predefined limit, which helps manage the risk associated with large orders.
`max_position_side` - Defines the maximum size of the inventory or position that the strategy or vault can hold for a particular asset. It helps manage the risk associated with excessive exposure to a particular asset.
`max_daily_trading_volume` - Defines the maximum trading volume that the strategy or vault can generate in a single day. It helps manage the risk associated with excessive trading activity that may result in large losses or increased market impact.
`max_open_orders` - Defines the maximum number of open orders that the strategy or vault can have in the market at any given time. It helps manage the risk associated with excessive order placement and ensures that the vault doesn't flood the market with too many orders.
`price_deviation_limits` - Defines the maximum allowable deviation in price from the current market price for placing buy and sell orders. It helps manage the risk associated with extreme price movements or market volatility.
`time_limits` - Defines the maximum time duration for which orders can remain open or pending in the market. It helps manage the risk associated with orders that may be stuck in the market for an extended period of time and may become stale or result in losses.
### Functions:
* `new_market_making_vault`
* `initialize_risk_limits`
* `place_limit_order`
* `cancel_limit_order`
* `cancel_all_limits_orders`
* `deposit`
* `withdraw`
* `emergencyStop`
* `update_risk_limits`
* `adjustInventory`
* `updateOrders`
* `getMarketData`
* `computeBidAsk`
## Hedging Vault
### Loading...
## Market Making Strategy
### Functions:
1. `initialize(priceSpread, orderBookDepth, tickSize)` - This function would initialize the market making strategy by setting the initial parameters such as the price spread, order book depth, tick size, etc. This function would be called only once, during the deployment of the market making strategy smart contract.
2. `get_market_data()` - This function would retrieve the current market data such as the last traded price, order book depth, etc.
3. `compute_bid_ask(orderBook, priceSpread, orderBookDepth, tickSize)` - his function would calculate the bid-ask spread based on the current market data. The function would take the order book depth, price spread, tick size, and other relevant parameters into account to calculate the bid-ask spread.
4. `update_orders(buyOrder, sellOrder)` - This function would update the existing orders in the market based on the current market data and the order book depth and spread.
5. `adjust_inventory(buyOrder, sellOrder)` - This function would adjust the inventory of the market making vault based on the orders placed in the market. It would calculate the current inventory based on the orders in the order book and update the inventory accordingly.
6. `compute_pnl(inventory, lastTradedPrice)` - This function would calculate the profit and loss of the market making vault based on the current market data and the inventory. It would take into account the inventory and the current market prices to calculate the profit and loss.
7. `update_parameters(priceSpread, orderBookDepth, tickSize)` - This function would update the parameters of the market making strategy such as the price spread, order book depth, tick size, etc. This function would be called externally by the market maker to update the parameters.
8. `emergency_stop(remainingAssets)` - This function would stop the market making strategy in case of an emergency such as a sudden price movement, exchange outage, etc. It would stop the execution of the market making strategy and return any remaining assets to the market maker.
### Loading...