Esempio n. 1
0
    def setUp(self):
        self.maxDiff = None
        self.clock: Clock = Clock(ClockMode.BACKTEST, 1.0,
                                  self.start_timestamp, self.end_timestamp)
        self.market: MockPaperExchange = MockPaperExchange()

        self.market.set_balanced_order_book(self.trading_pair, 10, 5, 15, 0.1,
                                            1)

        self.market.set_balance(self.base_asset, 500)
        self.market.set_balance(self.quote_asset, 500)
        self.market.set_quantization_param(
            QuantizationParams(self.trading_pair, 5, 5, 5, 5))
        self.market_info = MarketTradingPairTuple(self.market,
                                                  self.trading_pair,
                                                  self.base_asset,
                                                  self.quote_asset)
        self.logging_options: int = CeloArbStrategy.OPTION_LOG_ALL
        self.strategy = CeloArbStrategy()
        self.strategy.init_params(self.market_info,
                                  min_profitability=Decimal("0.01"),
                                  order_amount=Decimal("1"),
                                  celo_slippage_buffer=Decimal("0.001"),
                                  logging_options=self.logging_options,
                                  hb_app_notification=False,
                                  mock_celo_cli_mode=True)
        self.clock.add_iterator(self.market)
        self.clock.add_iterator(self.strategy)
        self.market_order_fill_logger: EventLogger = EventLogger()
        self.market.add_listener(MarketEvent.OrderFilled,
                                 self.market_order_fill_logger)
        CeloCLI.unlock_account(TEST_ADDRESS, TEST_PASSWORD)
Esempio n. 2
0
 def test_balances(self):
     result = CeloCLI.unlock_account(celo_address, celo_password)
     self.assertEqual(result, None)
     results = CeloCLI.balances()
     self.assertTrue(results[CELO_BASE].total > 0)
     self.assertTrue(results[CELO_BASE].available() > 0)
     self.assertTrue(results[CELO_QUOTE].total > 0)
     self.assertTrue(results[CELO_QUOTE].available() > 0)
Esempio n. 3
0
    def test_unlock_account(self):
        # test invalid password
        result = CeloCLI.unlock_account(celo_address, "XXX")
        print(result)
        self.assertNotEqual(result, None)
        # test invalid address
        result = CeloCLI.unlock_account("XXX", celo_password)
        print(result)
        self.assertNotEqual(result, None)

        result = CeloCLI.unlock_account(celo_address, celo_password)
        self.assertEqual(result, None)
Esempio n. 4
0
 def test_sell_cgld(self):
     sell_amount = Decimal("1")
     result = CeloCLI.unlock_account(celo_address, celo_password)
     self.assertEqual(result, None)
     rates = CeloCLI.exchange_rate(sell_amount)
     sell_rate = [r for r in rates if r.from_token == CELO_BASE][0]
     tx_hash = CeloCLI.sell_cgld(sell_amount)
     self.assertTrue(len(tx_hash) > 0)
     tx_hash = CeloCLI.sell_cgld(sell_amount,
                                 sell_rate.to_amount * Decimal("0.999"))
     self.assertTrue(len(tx_hash) > 0)
     # set forAtLeast amount to 20% more than what was quoted should raise excecption
     with self.assertRaises(Exception) as context:
         tx_hash = CeloCLI.sell_cgld(sell_amount,
                                     sell_rate.to_amount * Decimal("1.2"))
     print(str(context.exception))
Esempio n. 5
0
 async def validate_n_connect_celo(self, to_reconnect: bool = False, celo_address: str = None,
                                   celo_password: str = None) -> Optional[str]:
     if celo_address is None:
         celo_address = global_config_map["celo_address"].value
     if celo_password is None:
         await Security.wait_til_decryption_done()
         celo_password = Security.decrypted_value("celo_password")
     if celo_address is None or celo_password is None:
         return "Celo address and/or password have not been added."
     if CeloCLI.unlocked and not to_reconnect:
         return None
     err_msg = CeloCLI.validate_node_synced()
     if err_msg is not None:
         return err_msg
     err_msg = CeloCLI.unlock_account(celo_address, celo_password)
     return err_msg
Esempio n. 6
0
 def test_buy_cgld(self):
     # exchange atm is about 1.64, so let's buy about 2 USD
     buy_amount = Decimal("2")
     result = CeloCLI.unlock_account(celo_address, celo_password)
     self.assertEqual(result, None)
     rates = CeloCLI.exchange_rate(buy_amount)
     buy_rate = [r for r in rates if r.from_token == CELO_QUOTE][0]
     tx_hash = CeloCLI.buy_cgld(buy_amount)
     self.assertTrue(len(tx_hash) > 0)
     tx_hash = CeloCLI.buy_cgld(buy_amount,
                                buy_rate.to_amount * Decimal("0.999"))
     self.assertTrue(len(tx_hash) > 0)
     # set forAtLeast amount to 20% more than what was quoted should raise excecption
     with self.assertRaises(Exception) as context:
         tx_hash = CeloCLI.buy_cgld(buy_amount,
                                    buy_rate.to_amount * Decimal("1.2"))
     print(str(context.exception))
Esempio n. 7
0
 def test_exchange_rate(self):
     rates = CeloCLI.exchange_rate(Decimal("1"))
     for rate in rates:
         print(rate)
     self.assertTrue(
         all(r.from_token in (CELO_BASE, CELO_QUOTE) and r.to_token in (
             CELO_BASE, CELO_QUOTE) and r.from_token != r.to_amount
             for r in rates))
     self.assertTrue(
         all(r.from_amount > 0 and r.to_amount > 0 for r in rates))
Esempio n. 8
0
 async def celo_balances_df(
         self,  # type: HummingbotApplication
 ):
     rows = []
     bals = CeloCLI.balances()
     for token, bal in bals.items():
         rows.append({
             "Asset": token.upper(),
             "Amount": round(bal.total, 4)
         })
     df = pd.DataFrame(data=rows, columns=["Asset", "Amount"])
     df.sort_values(by=["Asset"], inplace=True)
     return df
Esempio n. 9
0
 def test_validate_node_synced(self):
     err_msg = CeloCLI.validate_node_synced()
     self.assertEqual(None, err_msg)