Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPMC-tech-task-1 #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions 0001-Create-Patch-File.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
From 56109179db851c6fa3ef1c294341a57d508ece77 Mon Sep 17 00:00:00 2001
From: Stefanos <[email protected]>
Date: Fri, 27 Dec 2019 20:19:00 -0500
Subject: [PATCH] Create Patch File

---
client.py | 9 +++++++--
client.pyc | Bin 0 -> 1392 bytes
client_test.py | 1 -
3 files changed, 7 insertions(+), 3 deletions(-)
create mode 100644 client.pyc

diff --git a/client.py b/client.py
index 40badcd..dccf503 100644
--- a/client.py
+++ b/client.py
@@ -35,25 +35,30 @@ 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__":

+
# Query the price once every N seconds.
for _ in xrange(N):
quotes = json.loads(urllib2.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)
diff --git a/client.pyc b/client.pyc
new file mode 100644
index 0000000000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{uTZe7wrUlBT+FKfmf%y%~Dy!Ln%hRWT>7
Ji<(&TegUqPFxLP8

literal 0
HcmV?d00001

diff --git a/client_test.py b/client_test.py
index a608a01..b2a9da8 100644
--- a/client_test.py
+++ b/client_test.py
@@ -16,7 +16,6 @@ class ClientTest(unittest.TestCase):
]
""" ------------ Add the assertion below ------------ """

-
""" ------------ Add more unit tests ------------ """


--
2.19.0

9 changes: 7 additions & 2 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,30 @@ 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__":


# Query the price once every N seconds.
for _ in xrange(N):
quotes = json.loads(urllib2.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)
Binary file added client.pyc
Binary file not shown.
1 change: 0 additions & 1 deletion client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def test_getDataPoint_calculatePriceBidGreaterThanAsk(self):
]
""" ------------ Add the assertion below ------------ """


""" ------------ Add more unit tests ------------ """


Expand Down