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 ------------ """
     # The following are the test cases for this
     self.assertEqual(getDataPoint(quotes[0]),
                      ('ABC', 120.48, 121.2, 120.84))
     # #quotes[0] is actually the quote that we need
     self.assertEqual(getDataPoint(quotes[1]),
                      ('DEF', 117.87, 121.68, 119.775))
     self.assertEqual(getRatio(1, 1), 1)
    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 ------------ """
        quote0 = "ABC", 120.48, 121.2, (120.48 + 121.2) / 2

        self.assertEqual(getDataPoint(quotes[0]), quote0)
        for qt in quotes:
            self.assertEqual(
                getDataPoint(qt),
                (qt['stock'], qt['top_bid']['price'], qt['top_ask']['price'],
                 (qt['top_bid']['price'] + qt['top_ask']['price']) / 2))
Ejemplo n.º 3
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'}
    ]
    """ ------------ 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 ------------ """
        # The following are the test cases
        data_point_1 = getDataPoint(quotes[0])
        self.assertGreater(data_point_1[1], data_point_1[2])

        data_point_2 = getDataPoint(quotes[1])
        self.assertGreater(data_point_1[1], data_point_1[2])
Ejemplo n.º 5
0
 def test_getRatio_calculateStockBZero(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': 0,
             'size': 4
         },
         'timestamp': '2019-02-11 22:06:30.572453',
         'top_bid': {
             'price': 0,
             'size': 81
         },
         'id': '0.109974697771',
         'stock': 'DEF'
     }]
     # getRatio when price B is zero
     prices = {}
     for quote in quotes:
         price = getDataPoint(quote)[3]
         stock = getDataPoint(quote)[0]
         # Assign key value pair for ABC/DEF
         prices[stock] = price
     self.assertEqual(getRatio(prices["ABC"], prices["DEF"]), None)
Ejemplo n.º 6
0
 def test_getRatio(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 ------------ """
     price_a = getDataPoint(quotes[0])[2]
     price_b = getDataPoint(quotes[1])[2]
     ratio = price_a / price_b
     self.assertEqual(getRatio(price_a, price_b), ratio)
Ejemplo n.º 7
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:
       print(getDataPoint(quote))
       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 i in quotes:
         stock = i['stock']
         bid_price = float(i['top_bid']['price'])
         ask_price = float(i['top_ask']['price'])
         price = (bid_price + ask_price) / 2
         self.assertEqual(getDataPoint(i),
                          (stock, bid_price, ask_price, price))
Ejemplo n.º 9
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 ------------ """
     # Check if getDataPoint function returns the correct tuple where top_ask > top_bid
     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))
Ejemplo n.º 10
0
 def test_getDataPoint_calculatePriceBidEqualtoNegativeAsk(self):
     quotes = [{
         'top_ask': {
             'price': -120.00,
             'size': 36
         },
         'timestamp': '2019-02-11 22:06:30.572453',
         'top_bid': {
             'price': 120.00,
             'size': 109
         },
         'id': '0.109974697771',
         'stock': 'ABC'
     }, {
         'top_ask': {
             'price': -117.87,
             '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.assertAlmostEqual(
             getDataPoint(quote),
             (quote['stock'], float(quote['top_bid']['price']),
              float(quote['top_ask']['price']),
              (float(quote['top_bid']['price']) +
               float(quote['top_ask']['price'])) / 2))
Ejemplo n.º 11
0
 def test_getDataPoint_calculatePriceBidLessThanAsk(self):
     quotes = [{
         'top_ask': {
             'price': 119.2,
             'size': 36
         },
         'timestamp': '2019-02-11 22:06:30.572453',
         'top_bid': {
             'price': 12.48,
             'size': 1
         },
         'id': '0.109974697771',
         'stock': 'ABC'
     }, {
         'top_ask': {
             'price': 121.68,
             'size': 4
         },
         'timestamp': '2019-02-11 22:06:30.572453',
         'top_bid': {
             'price': 12.87,
             'size': 2
         },
         'id': '0.109974697771',
         'stock': 'DEF'
     }]
     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_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 ------------ """
     dataPoint = ('ABC', 120.48, 121.2, (120.48 + 121.2) / 2)
     self.assertEqual(getDataPoint(quotes[0]), dataPoint)
Ejemplo n.º 13
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 x in quotes:
         stock, bid_price, ask_price, price = getDataPoint(x)
         self.assertEqual(stock, x['stock'])
         self.assertEqual(bid_price, x['top_bid']['price'])
         self.assertEqual(ask_price, x['top_ask']['price'])
         self.assertEqual(
             price, (x['top_bid']['price'] + x['top_ask']['price']) / 2)
Ejemplo n.º 14
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:
         # check if we have accurate positioning and correct data point
         # and the price is correctly calculated.
         bid_price = quote["top_bid"]["price"]
         ask_price = quote["top_ask"]["price"]
         price = (bid_price + ask_price) / 2.0
         accurate_dataPoint = (quote["stock"], bid_price, ask_price, price)
         self.assertEqual(getDataPoint(quote), accurate_dataPoint)
 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_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:
         bid_price = quote['top_ask']['price']
         ask_price = quote['top_bid']['price']
         self.assertEqual(
             getDataPoint(quote)[3], (bid_price + ask_price) / 2)
 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 quote in quotes:
         stock, bid_price, ask_price, price = getDataPoint(quote)
         self.assertEqual(price, (quote.get('top_ask').get('price') +
                                  quote.get('top_bid').get('price')) / 2)
Ejemplo n.º 18
0
 def test_getDataPoint_isTuple(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 quote in quotes:
         self.assertIsInstance(getDataPoint(quote), tuple)
Ejemplo n.º 19
0
 def test_getRatio_priceAEqualsZero(self):
     quotes = [{
         'top_ask': {
             'price': 0,
             'size': 36
         },
         'timestamp': '2019-02-11 22:06:30.572453',
         'top_bid': {
             'price': 0,
             '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': 122.87,
             'size': 81
         },
         'id': '0.109974697771',
         'stock': 'DEF'
     }]
     """ ------------ Add the assertion below ------------ """
     prices = {}
     for quote in quotes:
         stock, bid_price, ask_price, price = getDataPoint(quote)
         prices[stock] = price
     self.assertEqual(getRatio(prices['ABC'], prices['DEF']), 0)
Ejemplo n.º 20
0
 def test_getDataPoint_isOf_validLength(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'
     }]
     # check if we have complete data point (4 values in this case).
     for quote in quotes:
         self.assertEqual(len(getDataPoint(quote)), 4)
 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 the 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']))
Ejemplo n.º 22
0
    def test_getDataPoint_calculateRatio(self):
        quotes = [{
            'top_ask': {
                'price': 120.2,
                'size': 36
            },
            'timestamp': '2019-02-11 22:06:30.572453',
            'top_bid': {
                'price': 156.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': 98.87,
                'size': 81
            },
            'id': '0.109974697771',
            'stock': 'DEF'
        }]

        prices = {}

        for x in quotes:
            stock, bid_price, ask_price, price = getDataPoint(x)
            prices[stock] = price

        self.assertEqual(getRatio(prices['ABC'], prices['DEF']),
                         (prices['ABC'] / prices['DEF']))
    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 ------------ """
        quote0 = "ABC", 120.48, 121.2, (120.48 + 121.2) / 2

        self.assertEqual(getDataPoint(quotes[0]), quote0)
Ejemplo n.º 24
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'
     }]
     for quote in quotes:
         expected = (
             quote['stock'], quote['top_bid']['price'],
             quote['top_ask']['price'],
             (quote['top_bid']['price'] + quote['top_ask']['price']) / 2)
         self.assertEquals(getDataPoint(quote), expected)
Ejemplo n.º 25
0
 def test_getDataPoint_calculatePrice(self):
     quotes = [{
         'top_ask': {
             'price': 121.2,
             'size': 36
         },
         'timestamp': '2020-05-15 19:42:00.572453',
         'top_bid': {
             'price': 120.48,
             'size': 109
         },
         'id': '0.109974697771',
         'stock': 'ABC'
     }, {
         'top_ask': {
             'price': 121.68,
             'size': 4
         },
         'timestamp': '2020-05-15 19:42:00.572453',
         'top_bid': {
             'price': 117.87,
             'size': 81
         },
         'id': '0.109974697771',
         'stock': 'DEF'
     }]
     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))
Ejemplo n.º 26
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))
Ejemplo n.º 27
0
    def test_getRatio_zero_priceB(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': 0,
                'size': 4
            },
            'timestamp': '2019-02-11 22:06:30.572453',
            'top_bid': {
                'price': 0,
                'size': 81
            },
            'id': '0.109974697771',
            'stock': 'DEF'
        }]

        pricedict = {}
        for quote in quotes:
            stock, bid_price, ask_price, price = getDataPoint(quote)
            pricedict[stock] = price
        self.assertEqual(getRatio(pricedict['ABC'], pricedict['DEF']), (None))
Ejemplo n.º 28
0
    def test_getRatio_calculateRatioPriceBIsZero(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'
        }]

        stock, bid_price, ask_price, price = getDataPoint(quotes[0])
        price_a = price

        price_b = 0

        self.assertEqual(getRatio(price_a, price_b), None)
    def test_getDataPoint_calculatePriceAlmostZero(self):
        quotes = [{
            'top_ask': {
                'price': 0.2,
                'size': 56
            },
            'timestamp': '2019-02-11 22:06:30.572453',
            'top_bid': {
                'price': 0.48,
                'size': 109
            },
            'id': '0.109974697771',
            'stock': 'ABC'
        }, {
            'top_ask': {
                'price': 0.120,
                'size': 56
            },
            'timestamp': '2019-02-11 22:06:30.572453',
            'top_bid': {
                'price': 0.20,
                'size': 109
            },
            'id': '0.109974697771',
            'stock': 'DEF'
        }, {
            'top_ask': {
                'price': 1.120,
                'size': 76
            },
            'timestamp': '2019-02-11 22:06:30.572453',
            'top_bid': {
                'price': 0.20,
                'size': 59
            },
            'id': '0.109974697771',
            'stock': 'ABC'
        }, {
            'top_ask': {
                'price': 0.190,
                'size': 74
            },
            'timestamp': '2019-02-11 22:06:30.572453',
            'top_bid': {
                'price': 1.170,
                'size': 81
            },
            'id': '0.109974697771',
            'stock': 'DEF'
        }]

        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_calculatePriceSmallDifference(self):
        quotes = [{
            'top_ask': {
                'price': 120.2,
                'size': 36
            },
            'timestamp': '2019-02-11 22:06:30.572453',
            'top_bid': {
                'price': 120.25,
                'size': 109
            },
            'id': '0.109974697771',
            'stock': 'ABC'
        }, {
            'top_ask': {
                'price': 1.25,
                'size': 56
            },
            'timestamp': '2019-02-11 22:06:30.572453',
            'top_bid': {
                'price': 1.4,
                'size': 49
            },
            'id': '0.109974697771',
            'stock': 'ABC'
        }, {
            'top_ask': {
                'price': 12.25,
                'size': 15
            },
            'timestamp': '2019-02-11 22:06:30.572453',
            'top_bid': {
                'price': 12.20,
                'size': 10
            },
            'id': '0.109974697771',
            'stock': 'DEF'
        }, {
            'top_ask': {
                'price': 140.68,
                'size': 74
            },
            'timestamp': '2019-02-11 22:06:30.572453',
            'top_bid': {
                'price': 140.75,
                'size': 81
            },
            'id': '0.109974697771',
            'stock': 'DEF'
        }]

        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))