Exemple #1
0
    def setUp(self):
        self.maxDiff = None
        self.clock: Clock = Clock(ClockMode.BACKTEST, 1.0,
                                  self.start_timestamp, self.end_timestamp)
        self.market: BacktestMarket = BacktestMarket()

        self.market_data = MockOrderBookLoader(self.trading_pair,
                                               self.base_asset,
                                               self.quote_asset)
        self.market_data.set_balanced_order_book(10, 5, 15, 0.1, 1)

        self.market.add_data(self.market_data)

        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.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)
 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)
    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)
 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))
Exemple #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
 async def show_balances(self):
     self._notify("Updating balances, please wait...")
     df = await self.balances_df()
     lines = [
         "    " + line for line in df.to_string(index=False).split("\n")
     ]
     self._notify("\n".join(lines))
     eth_address = global_config_map["ethereum_wallet"].value
     if eth_address is not None:
         bal = UserBalances.ethereum_balance()
         bal = round(bal, 4)
         self._notify(
             f"Ethereum balance in ...{eth_address[-4:]} wallet: {bal} ETH")
         self._notify(
             f"Note: You may have other ERC 20 tokens in this same address (not shown here)."
         )
     celo_address = global_config_map["celo_address"].value
     if celo_address is not None:
         try:
             if not CeloCLI.unlocked:
                 await self.validate_n_connect_celo()
             bals = CeloCLI.balances()
             self._notify("Celo balances:")
             for token, bal in bals.items():
                 self._notify(
                     f"  {token} - total: {bal.total} locked: {bal.locked}")
         except Exception as e:
             self._notify(f"Celo CLI Error: {str(e)}")
 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))
 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
 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))
 def test_validate_node_synced(self):
     err_msg = CeloCLI.validate_node_synced()
     self.assertEqual(None, err_msg)