-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbids.py
53 lines (46 loc) · 1.47 KB
/
bids.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import pandas as pd
class Bids:
def __init__(self):
"""
Initializes class to store bids
"""
self.__bids = list()
def add_bid(self, user_name: str, qty: int, price: int) -> None:
"""
Adds bids to the auction
"""
self.__bids.append((user_name, qty, price))
def get_bids(self) -> pd.DataFrame:
"""
Returns current bids at auction
"""
bids_df = pd.DataFrame(
self.__bids,
columns=["User", "Quantity", "Price"],
)
return bids_df
def get_bids_sorted_by_price(self) -> pd.DataFrame:
"""
Returns current bids at auction sorted on price
"""
bids_df = self.get_bids()
bids_df = bids_df.sort_values(
by="Price",
ascending=False,
inplace=False,
).reset_index(drop=True)
return bids_df
def get_price_levels(self) -> pd.DataFrame:
"""
Returns the quantity at each price level sorted on highest price first
"""
price_levels = self.get_bids()
price_levels = price_levels.groupby("Price")["Quantity"].sum()
price_levels = price_levels.reset_index(drop=False, inplace=False)
price_levels = price_levels.sort_values(
by="Price",
ascending=False,
inplace=False,
)
price_levels = price_levels.reset_index(drop=True, inplace=False)
return price_levels