From 1dd5db9f6a52f3ba93e4ecff6126a2ad362ed323 Mon Sep 17 00:00:00 2001 From: Mansi Gupta Date: Thu, 27 Jan 2022 19:04:19 +0530 Subject: [PATCH] Create Patch File --- __pycache__/client3.cpython-35.pyc | Bin 0 -> 1198 bytes client3.py | 9 ++++++--- client_test.py | 7 +++++-- 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 __pycache__/client3.cpython-35.pyc diff --git a/__pycache__/client3.cpython-35.pyc b/__pycache__/client3.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..31764d341095f8c7faa788f8de6360811077baf0 GIT binary patch literal 1198 zcmYjROK%%D5FYMJk}WxD;+GmAU;_m00`;TF#Soe{t(_JqP{Xki1X-w9te0bZ<<+iC zQbnxDC-*n>*n1DX^w1x}YfrfrJ@wQfCAA@!!Cb4WE&~wsF(?5Nw$MFDyoK&V;xF_7k^ls)h9Jlvfgm%4pJ;Cb1epz|HvwB9nsDiX zTw`y32V4SN28`gA+3(wp`8n{XDuI>oW8Kj4*JB}4@C zK8R)L(z0kn_tu+-D0oGToWz}Xmb1gjM;BU;dOJI1ooD4mt#og1cW-y+YK-#w%R)ST zdsF;PMCLSH3rPkv_Gzdi5>rQU_lAL<86I?rz%Bv0@fN<|f1eLi52ikB5V;R-0+_P7 zV;b0poW#+j$B$$!#yRq=EO~v#^#$?@QJ~;IX5|J{Tqq?XxH=)vX zerX!I9;K&+FyTlRInL}%UB2@Oa?DJ4R@Rx0Lla(&YmL&nO^Y_9v-lRp&Qxh%`zy$0 zn*Q0&d;OORrRoo}N)`R@j=taD(wJXtY1**$+1BX#Nk11W@kGbx0|F8HpfPVa(cg;-8H1elcqb3;*9^**Zamlc>YcNVX`uoWm%kVOQaf8 zI*Des33M^UBp9f=N+L<`sE0}T;^p(>*M=QBp8f+;WkXC;6BLv<6H@Fs8kU-nQYuu^ zSe)FTlj{*yCOWI-Fw-WGmr(K`!U6bSnKGO|}H&jH}Ow iRG=k(u|_WSkVKog?ni#)wOiEvF5C4Z)?u6Mq4zIlf)>{R literal 0 HcmV?d00001 diff --git a/client3.py b/client3.py index f1771c3..c48cf62 100644 --- a/client3.py +++ b/client3.py @@ -35,14 +35,16 @@ def getDataPoint(quote): stock = quote['stock'] bid_price = float(quote['top_bid']['price']) ask_price = float(quote['top_ask']['price']) - price = bid_price + price = (bid_price + ask_price) / 2 return stock, bid_price, ask_price, price def getRatio(price_a, price_b): """ Get ratio of price_a and price_b """ """ ------------- Update this function ------------- """ """ Also create some unit tests for this function in client_test.py """ - return 1 + if (price_b == 0): + return + return price_a/price_b # Main if __name__ == "__main__": @@ -52,8 +54,9 @@ def getRatio(price_a, price_b): quotes = json.loads(urllib.request.urlopen(QUERY.format(random.random())).read()) """ ----------- Update to get the ratio --------------- """ + prices = {} for quote in quotes: 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(prices['ABC'], price['DEF']))) diff --git a/client_test.py b/client_test.py index af2bf26..c2d0d29 100644 --- a/client_test.py +++ b/client_test.py @@ -1,5 +1,5 @@ import unittest -from client3 import getDataPoint +from client3 import* class ClientTest(unittest.TestCase): def test_getDataPoint_calculatePrice(self): @@ -8,6 +8,8 @@ def test_getDataPoint_calculatePrice(self): {'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: + self.assertEqual(getDataPoint(quote),(quote['stock'], quote['top_bid']['price'],quote['top_ask']['price'],(quote['top_bid']['price'] + quote['top_ask']['price']) / 2)) def test_getDataPoint_calculatePriceBidGreaterThanAsk(self): quotes = [ @@ -15,7 +17,8 @@ def test_getDataPoint_calculatePriceBidGreaterThanAsk(self): {'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: + self.assertEqual(getDataPoint(quote),(quote['stock'], quote['top_bid']['price'],quote['top_ask']['price'],(quote['top_bid']['price'] + quote['top_ask']['price']) / 2)) """ ------------ Add more unit tests ------------ """