def test_does_ah_create_btc_put_option(self): order_params = deepcopy(self.order_params) order_params["market"] = "BTC" new_order = DBCommunication.create_new_option(**order_params) orders = DBCommunication.get_options() self.assertEqual(len(orders), 1, "Only 1 order expected as in testing!") self.assertTrue(self.await_order_status_code(OPEN, new_order))
def test_does_ah_create_eth_put_option(self): # now the ah will retrieve this order from the db an execute it. self.set_price(self.order_params["strike_price"], "priceprovider") new_order = DBCommunication.create_new_option(**self.order_params) orders = DBCommunication.get_options() self.assertEqual(len(orders), 1, "Only 1 order expected as in testing!") self.assertTrue(self.await_order_status_code(OPEN, new_order))
def tearDown(self): DBCommunication.delete_options() ok = self.currentResult.wasSuccessful() errors = self.currentResult.errors failures = self.currentResult.failures print(" All tests passed so far!" if ok else " %d errors and %d failures so far" % (len(errors), len(failures)))
def test_does_ah_create_eth_call_option(self): self.set_price(self.order_params["strike_price"], "priceprovider") option_params = deepcopy(self.order_params) option_params["option_type"] = 2 new_order = DBCommunication.create_new_option(**self.order_params) orders = DBCommunication.get_options() self.assertEqual(len(orders), 1, "Only 1 order expected as in testing!") self.assertTrue(self.await_order_status_code(OPEN, new_order))
def test_does_ah_excercise_eth_atm_put_option(self): # now the ah will retrieve this order from the db an execute it. order_params = deepcopy(self.order_params) self.set_price(order_params["strike_price"], "priceprovider") new_order = DBCommunication.create_new_option(**order_params) orders = DBCommunication.get_options() self.assertEqual(len(orders), 1, "Only 1 order expected as in testing!") self.assertTrue(self.await_order_status_code(OPEN, new_order)) expiration_date = datetime.utcnow() + timedelta(seconds=10) DBCommunication.update_option(new_order["option_id"], {"expiration_date": expiration_date}) self.assertTrue(self.await_order_status_code(4, new_order))
def test_does_ah_expire_otm_btc_call_option(self): # now the ah will retrieve this order from the db an execute it. order_params = deepcopy(self.order_params) order_params["option_type"] = 2 order_params["market"] = "BTC" self.set_price(int(order_params["strike_price"]), "btcpriceprovider") new_order = DBCommunication.create_new_option(**order_params) self.set_price(int(order_params["strike_price"] * 0.95), "btcpriceprovider") orders = DBCommunication.get_options() self.assertEqual(len(orders), 1, "Only 1 order expected as in testing!") self.assertTrue(self.await_order_status_code(OPEN, new_order)) expiration_date = datetime.utcnow() + timedelta(seconds=10) DBCommunication.update_option(new_order["option_id"], {"expiration_date": expiration_date}) self.assertTrue(self.await_order_status_code(EXPIRED, new_order))
def await_order_status_code(self, status_code, order_params): done = False timeout = 15 start = datetime.utcnow() while not done: if datetime.now() - timedelta(seconds=timeout) > start: return False time.sleep(1) order = DBCommunication.get_option(order_params["option_id"]) if order.status_code.id == status_code: done = True return done
def test_does_api_create_eth_put_option_api(self): # now the ah will retrieve this order from the db an execute it. order_params = deepcopy(self.base_order_params) self.set_price(order_params["strike_price"], "priceprovider") res = self._create_option_via_api(order_params) self.assertEqual(res.status_code, 200) orders = DBCommunication.get_options() self.assertEqual(len(orders), 1, "Only 1 order expected as in testing!") self.assertTrue( self.await_order_status_code(OPEN, json.loads(res.content)))
def test_ah_handles_multiple_correct_orders(self): for _ in range(10): order_params = deepcopy(self.base_order_params) self.set_price(order_params["strike_price"], "priceprovider") res = self._create_option_via_api(order_params) self.assertEqual(res.status_code, 200) orders = DBCommunication.get_options() self.assertEqual(len(orders), 10) [ self.assertTrue(self.await_order_status_code(OPEN, o.id)) for o in orders ]
def test_does_api_fail_btc_put_option_api_wrong_params(self): # now the ah will retrieve this order from the db an execute it. order_params = deepcopy(self.base_order_params) order_params["period"] = 10 order_params["market"] = "BTC" self.set_price(order_params["strike_price"], "btcpriceprovider") res = self._create_option_via_api(order_params) self.assertEqual(res.status_code, 200) orders = DBCommunication.get_options() self.assertEqual(len(orders), 1, "Only 1 order expected as in testing!") self.assertTrue( self.await_order_status_code(FAILED, json.loads(res.content)))
def setup_db(): ds = DBCommunication() ds.add_data() return ds