From e85c04d37b2366cdbd5d90bd51fe8c675a670ac8 Mon Sep 17 00:00:00 2001 From: Hrishikesh Date: Wed, 26 Jun 2024 22:37:20 +0530 Subject: [PATCH] first commit --- .idea/.gitignore | 3 +++ .idea/Software dev.iml | 14 ++++++++++++++ .idea/inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/misc.xml | 7 +++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ client3.py | 10 +++++++--- 7 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/Software dev.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000000..26d33521af1 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Software dev.iml b/.idea/Software dev.iml new file mode 100644 index 00000000000..7a6134d11f1 --- /dev/null +++ b/.idea/Software dev.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 00000000000..105ce2da2d6 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000000..e8cd8866966 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000000..57a3d7a01ac --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000000..35eb1ddfbbc --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/client3.py b/client3.py index 3fc09b75f16..557e5789d59 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 ------------- """ - return 1 + if (price_b == 0): + return + return price_a / price_b # Main @@ -52,8 +54,10 @@ 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) + prices[stock] = price 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"], prices["DEF"]))