marketmakermonitor 23.7
A tool that monitors quote messages from market maker
License: MIT

# Market Maker Monitor
This program takes as input a file containing orders from different symbols and Exchanges, and outputs an order book and calculates market making percentage for each symbol.

It mainly has the following two classes:

#### `class Book`
Keeps tracking of quotes, and stores sorted bid orders and ask orders.

#### `class Monitor`
(1) Monitors quotes and determines whether they meet the Market Making requirements.

(2) Provides an End of Day Report detailing the Market Maker statistics. That is, the percentage of the trading day the Market Making requirements were met.

Please refer to `src/marketmakermonitor/orderbook/book.py` and `src/marketmakermonitor/monitor/monitor.py` for details.

## Usage
### Sample code
```
    # Create a monitor object
    monitor = Monitor()
    
    # Create a dictionary that maps each symbol to an order book
    obs = {}
    
    # Specify the file address of the quote data
    quote_file = '../resource/sample_quote_data.csv'
    
    # Create a loader object with quote data
    loader = Loader(quote_file)
    
    # Specify the file address of the requirement data (min requirement size, star time, stop time for each symbol)
    r_file = '../resource/sample_requirement_data.csv'
    
    # Feed the monitor with the requirement data
    monitor.set_tickers(r_file)
    
    # Let the order book and monitor track each quote
    # Note that the function parse_csv() can take one (obs or monitor) or two arguments (obs and monitor)
    loader.parse_csv(obs, monitor)
    
    # Create the End of Day report with the output path prefix
    monitor.export_eod_report_csv('../output/')
    
    # Get the highest bid and the lowest ask
    # -1 means there is no bid order or ask order
    for symbol, ob in obs.items():
        print('Best bid: ' + str(ob.get_highest_bid()))
        print('Best ask: ' + str(ob.get_lowest_ask()))
        
    # Display the bid orders and ask orders with regard to a single symbol
    # Bid orders are sorted by price in decreasing order
    # Ask orders are sorted by price in increasing order
    # Only prices and quantities are shown
    obs['JEX_B'].display()
```
### Output Screenshots
Here are the screenshots of the output from the sample code above.
#### End of Day Report:

![Example Image](src/output/end_of_day_report_screenshot.jpg)

#### Terminal output:

![Example Image](src/output/terminal_output_screenshot.jpg)

### Try it yourself
(1) Create a virtual environment
```commandline
python3 -m venv <DIR>
source <DIR>/bin/activate
```
(2) Install the package with PyPi
```commandline
pip install -r requirements.txt
python -m pip install marketmakermonitor
```
(3) Run sample code

The sample code is stored in the Python file `src/marketmakermonitor/main.py`. 

You can reproduce the output above by running that file.

## Input Data Format
### Quote data
A csv file that has the following columns:

`<Timestamp><Exchange><OrderId><Symbol><Price><Quantity><Side><MsgType>`

### Requirement data
A csv file that has the following columns:

`<TradeDate><Symbol><TimeMarketMaking (nanoseconds)><TimeTradingDuration (hours)><MarketMaking%>`