Skip to content

Commit

Permalink
First task
Browse files Browse the repository at this point in the history
  • Loading branch information
jeetc7 committed Feb 23, 2024
1 parent 24707a7 commit 6292570
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions client3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]))

0 comments on commit 6292570

Please sign in to comment.