forked from theforage/forage-jpmc-swe-task-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyfirstpatch.patch
More file actions
125 lines (116 loc) · 5.11 KB
/
Copy pathmyfirstpatch.patch
File metadata and controls
125 lines (116 loc) · 5.11 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
diff --git a/__pycache__/client3.cpython-311.pyc b/__pycache__/client3.cpython-311.pyc
new file mode 100644
index 0000000..47a1dda
Binary files /dev/null and b/__pycache__/client3.cpython-311.pyc differ
diff --git a/client3.py b/client3.py
index 14406cb..b0da4ad 100644
--- a/client3.py
+++ b/client3.py
@@ -40,14 +40,14 @@ def getDataPoint(quote):
#done updating the function
price_stock= sum_of_bid_and_ask/2
- print(f"Coorect Stock Price: {price_stock}")
+ print(f"Corect Stock Price: {price_stock}")
return stock, bid_price, ask_price, price_stock
def getRatio(price_a, price_b):
""" Get ratio of price_a and price_b """
""" ------------- Update this function ------------- """
- #Done updationg the function
+ #Done updationg the function
ratio= price_a/price_b
return ratio
diff --git a/client_test.py b/client_test.py
index af2bf26..c74d246 100644
--- a/client_test.py
+++ b/client_test.py
@@ -4,22 +4,48 @@ from client3 import getDataPoint
class ClientTest(unittest.TestCase):
def test_getDataPoint_calculatePrice(self):
quotes = [
- {'top_ask': {'price': 121.2, 'size': 36}, 'timestamp': '2019-02-11 22:06:30.572453', 'top_bid': {'price': 120.48, 'size': 109}, 'id': '0.109974697771', 'stock': 'ABC'},
- {'top_ask': {'price': 121.68, 'size': 4}, 'timestamp': '2019-02-11 22:06:30.572453', 'top_bid': {'price': 117.87, 'size': 81}, 'id': '0.109974697771', 'stock': 'DEF'}
+ {'top_ask': {'price': 121.2, 'size': 36},
+ 'timestamp': '2019-02-11 22:06:30.572453',
+ 'top_bid': {'price': 120.48, 'size': 109},
+ 'id': '0.109974697771', 'stock': 'ABC'},
+ {'top_ask': {'price': 121.68, 'size': 4},
+ 'timestamp': '2019-02-11 22:06:30.572453',
+ 'top_bid': {'price': 117.87, 'size': 81},
+ 'id': '0.109974697771', 'stock': 'DEF'}
]
""" ------------ Add the assertion below ------------ """
+ for quote in quotes:
+
+ stock, bid_price, ask_price, price_stock = getDataPoint(quote)
+ expected_price_stock = (quote["top_bid"]["price"] + quote["top_ask"]["price"]) / 2
+ self.assertEqual(stock, quote["stock"])
+ self.assertEqual(bid_price, quote["top_bid"]["price"])
+ self.assertEqual(ask_price, quote["top_ask"]["price"])
+ self.assertEqual(price_stock, expected_price_stock)
def test_getDataPoint_calculatePriceBidGreaterThanAsk(self):
quotes = [
- {'top_ask': {'price': 119.2, 'size': 36}, 'timestamp': '2019-02-11 22:06:30.572453', 'top_bid': {'price': 120.48, 'size': 109}, 'id': '0.109974697771', 'stock': 'ABC'},
- {'top_ask': {'price': 121.68, 'size': 4}, 'timestamp': '2019-02-11 22:06:30.572453', 'top_bid': {'price': 117.87, 'size': 81}, 'id': '0.109974697771', 'stock': 'DEF'}
+ {'top_ask': {'price': 119.2, 'size': 36},
+ 'timestamp': '2019-02-11 22:06:30.572453',
+ 'top_bid': {'price': 120.48, 'size': 109},
+ 'id': '0.109974697771', 'stock': 'ABC'},
+ {'top_ask': {'price': 121.68, 'size': 4},
+ 'timestamp': '2019-02-11 22:06:30.572453',
+ 'top_bid': {'price': 117.87, 'size': 81},
+ 'id': '0.109974697771', 'stock': 'DEF'}
]
""" ------------ Add the assertion below ------------ """
+ for quote in quotes:
+ stock, bid_price, ask_price, price_stock = getDataPoint(quote)
+ expected_price_stock = (quote["top_bid"]["price"] + quote["top_ask"]["price"]) / 2
+ self.assertEqual(stock, quote["stock"])
+ self.assertEqual(bid_price, quote["top_bid"]["price"])
+ self.assertEqual(ask_price, quote["top_ask"]["price"])
+ self.assertEqual(price_stock, expected_price_stock)
""" ------------ Add more unit tests ------------ """
-
if __name__ == '__main__':
unittest.main()
diff --git a/myfirstpatch.patch b/myfirstpatch.patch
new file mode 100644
index 0000000..2fc49b8
--- /dev/null
+++ b/myfirstpatch.patch
@@ -0,0 +1,36 @@
+diff --git a/client3.py b/client3.py
+index 3fc09b7..14406cb 100644
+--- a/client3.py
++++ b/client3.py
+@@ -35,14 +35,22 @@ def getDataPoint(quote):
+ stock = quote['stock']
+ bid_price = float(quote['top_bid']['price'])
+ ask_price = float(quote['top_ask']['price'])
+- price = bid_price
+- return stock, bid_price, ask_price, price
++
++ sum_of_bid_and_ask= bid_price + ask_price
++ #done updating the function
++
++ price_stock= sum_of_bid_and_ask/2
++ print(f"Coorect Stock Price: {price_stock}")
++ return stock, bid_price, ask_price, price_stock
+
+
+ def getRatio(price_a, price_b):
+ """ Get ratio of price_a and price_b """
+ """ ------------- Update this function ------------- """
+- return 1
++ #Done updationg the function
++ ratio= price_a/price_b
++
++ return ratio
+
+
+ # Main
+@@ -56,4 +64,4 @@ if __name__ == "__main__":
+ stock, bid_price, ask_price, price = getDataPoint(quote)
+ print("Quoted %s at (bid:%s, ask:%s, price:%s)" % (stock, bid_price, ask_price, price))
+
+- print("Ratio %s" % getRatio(price, price))
++ print("Ratio %s" % getRatio(bid_price, ask_price))