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'
     }]
     # ------------ Add the assertion below ------------
     self.assertEqual(getDataPoint(quotes[0])[-1], 120.48)
     self.assertEqual(getDataPoint(quotes[1])[-1], 117.87)
 def test_div_zero_values(self):
     quotes = [{
         'top_ask': {
             'price': 10.5,
             'size': 36
         },
         'timestamp': '2019-02-11 22:06:30.572453',
         'top_bid': {
             'price': 10.4,
             'size': 109
         },
         'id': '0.109974697771',
         'stock': 'ABC'
     }, {
         'top_ask': {
             'price': 0,
             'size': 4
         },
         'timestamp': '2019-02-11 22:06:30.572453',
         'top_bid': {
             'price': 0,
             'size': 81
         },
         'id': '0.109974697771',
         'stock': 'DEF'
     }]
     # ------------ Add the assertion below ------------
     self.assertEqual(
         getRatio(getDataPoint(quotes[0])[-1],
                  getDataPoint(quotes[1])[-1]), 0)
Beispiel #3
0
 def test_getRatio_calculateRatio(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'
     }]
     stock1, bid_price1, ask_price1, price1 = getDataPoint(quotes[0])
     stock2, bid_price2, ask_price2, price2 = getDataPoint(quotes[1])
     self.assertEqual(getRatio(price1, price2), 1.008891671884784)
Beispiel #4
0
    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'
        }]
        """ ------------ Add the assertion below ------------ """

        self.assertEqual(getDataPoint(quotes[0]),
                         ('ABC', 120.48, 119.2, 119.84))
        self.assertEqual(getDataPoint(quotes[1]),
                         ('DEF', 117.87, 121.68, 119.775))
 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'
     }]
     """ ------------ 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))
     """ ------------ When the second price is zero the function should return nothing ------------ """
Beispiel #6
0
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'}
    ]
  for i in quotes:
    self.assertEqual(getDataPoint(i),(i['stock'],i['bid_price'],i['ask_price'],(i['bid_price']+i['ask_price'])/2))


  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'}
    ]
    for i in quotes:
    self.assertEqual(getDataPoint(i),(i['stock'],i['bid_price'],i['ask_price'],(i['bid_price']+i['ask_price'])/2))


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



if __name__ == '__main__':
    unittest.main()
 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'
     }]
     prices = {}
     for quote in quotes:
         stock, bid_price, ask_price, price = getDataPoint(quote)
         prices[stock] = price
     self.assertEqual(getRatio(prices['ABC'], prices['DEF']),
                      prices['ABC'] / prices['DEF'])
     #self.assertEqual(getRatio((quote['top_ask']['price']['ABC']+quote['top_bid']['price'])/2,quote['price']), (quote['stock'],quote['top_bid']['price'],quote['top_ask']['price'],(quote['top_bid']['price']+quote['top_ask']['price'])/2))
     """ ------------ Add the assertion below ------------ """
Beispiel #8
0
 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'
     }]
     """ ------------ 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))
Beispiel #9
0
 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'
     }]
     """ ------------ Add the assertion below ------------ """
     for quote in quotes:
         stock = quote['stock']
         bid_price = quote['top_bid']['price']
         ask_price = quote['top_ask']['price']
         price = (bid_price + ask_price) / 2
         dataPoint = (stock, bid_price, ask_price, price)
         self.assertEqual(getDataPoint(quote), dataPoint)
 def test_ForNull_valueForTop_ask(self):
     n = [
         {
             'top_ask': {
                 'price': 0,
                 'size': 36
             },
             'timestamp': '2019-02-11 22:06:30.572453',
             'top_bid': {
                 'price': 115.48,
                 'size': 67
             },
             'id': '0.109974697771',
             'stock': 'ABC'
         },
         {
             'top_ask': {
                 'price': 110.89,
                 'size': 0
             },
             'timestamp': '2019-02-11 22:06:30.572453',
             'top_bid': {
                 'price': 100.09,
                 'size': 99
             },
             'id': '0.109974697771',
             'stock': 'ABC'
         },
     ]
     for n in n:
         self.assertEqual(
             getDataPoint(n),
             (n['stock'], n['top_bid']['price'], n['top_ask']['price'],
              (n['top_bid']['price'] + n['top_ask']['price']) / 2))
 def test_ForNull_valueForStock(self):
     quotes = [
         {
             'top_ask': {
                 'price': 96.2,
                 'size': 36
             },
             'timestamp': '2019-02-11 22:06:30.572453',
             'top_bid': {
                 'price': 0,
                 'size': 10
             },
             'id': '0.109974697771',
             'stock': ''
         },
         {
             'top_ask': {
                 'price': 96.2,
                 'size': 36
             },
             'timestamp': '2019-02-11 22:06:30.572453',
             'top_bid': {
                 'price': 44,
                 'size': 0
             },
             'id': '0.109974697771',
             'stock': ''
         },
     ]
     for n in quotes:
         self.assertEqual(
             getDataPoint(n),
             (n['stock'], n['top_bid']['price'], n['top_ask']['price'],
              (n['top_bid']['price'] + n['top_ask']['price']) / 2))
 def test_ForDuplicate_value(self):
     quotes = [
         {
             'top_ask': {
                 'price': 96.2,
                 'size': 36
             },
             'timestamp': '2019-02-11 22:06:30.572453',
             'top_bid': {
                 'price': 89.05,
                 'size': 66
             },
             'id': '0.109974697771',
             'stock': 'DEF'
         },
         {
             'top_ask': {
                 'price': 96.2,
                 'size': 36
             },
             'timestamp': '2019-02-11 22:06:30.572453',
             'top_bid': {
                 'price': 89.05,
                 'size': 66
             },
             'id': '0.109974697771',
             'stock': 'DEF'
         },
     ]
     for n in quotes:
         self.assertEqual(
             getDataPoint(n),
             (n['stock'], n['top_bid']['price'], n['top_ask']['price'],
              (n['top_bid']['price'] + n['top_ask']['price']) / 2))
	def test_getDataPoint_calculatePrice(self):
		#""" ------------ Build ------------ """
		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'}
		]	
		#""" ------------ Act && Assert ------------ """
		for quote in quotes:
			stock = quote['stock']
			bid_price = float(quote['top_bid']['price'])
			ask_price = float(quote['top_ask']['price'])
			price = ( bid_price + ask_price ) / 2
			self.assertEqual(getDataPoint(quote), (stock, bid_price, ask_price, price ))
Beispiel #14
0
    def test_getRatio_calcuateRatio(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'
        }]
        ratio = (
            (quotes[0]['top_bid']['price'] + quotes[0]['top_ask']['price']) / 2
        ) / ((quotes[1]['top_bid']['price'] + quotes[1]['top_ask']['price']) /
             2)

        prices = {}
        for quote in quotes:
            stock, _, _, price = getDataPoint(quote)
            prices[stock] = price

        self.assertEqual(getRatio(prices['ABC'], prices['DEF']), ratio)
                '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 = [{
            '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',
import unittest
from client 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'}
    ]
    """ ------------ 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 = [
      {'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 :
    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 ------------ """



if __name__ == '__main__':
    unittest.main()

  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'}
    ]
    
    """ ------------ Add the assertion below ------------ """
    for quote in quotes:
      self.assertEqual(getDataPoint(quote), (quote['stock'], quote['top_bid']['price'], quote['top_ask']['price'], (quote['top_ask']['price']+quote['top_bid']['price'])/2))

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

def test_getRatio_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'}
]
""" ------------ Add more assertion below ------------ """

prices = {}
    for q in quotes:
      stock, bid_price, ask_price, price = getDataPoint(q)
      prices[stock] = price
    self.assertEqual(getRatio(prices['ABC'], prices['DEF']), (prices['ABC']/prices['DEF']))


if __name__ == '__main__':
    unittest.main()