def test_not_first_create_not_midnight_no_open_rate_first_set(self): self.new_rate.last_trade_at = datetime(2019, 3, 10, 1, 0, 0) self.new_rate = fill_rate_open(new_rate=self.new_rate, current_rate=self.current_rate) self.assertEqual(self.new_rate.rate_open, None)
def test_first_create_midnight_open_rate_exists(self): self.new_rate.rate_open = Decimal("10") self.new_rate.last_trade_at = datetime(2019, 3, 9, 0, 0, 0) self.new_rate = fill_rate_open(new_rate=self.new_rate, current_rate=None) self.assertEqual(self.new_rate.rate_open, Decimal("10"))
def save_rate(the_pair_data: PairData) -> None: new_rate = rate_from_pair_data(the_pair_data, exchange_obj.id) current_rate = (db_session.query(Rate).filter_by( from_currency=new_rate.from_currency, to_currency=new_rate.to_currency, exchange_id=exchange_obj.id, ).first()) new_rate = fill_rate_open(new_rate, current_rate) if current_rate: new_rate.id = current_rate.id db_session.merge(new_rate) else: db_session.add(new_rate)