Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling for MM2.json config not found error #8

Open
damascene opened this issue Apr 2, 2024 · 2 comments
Open

Better handling for MM2.json config not found error #8

damascene opened this issue Apr 2, 2024 · 2 comments

Comments

@damascene
Copy link

When I launch the bot without having a config file MM2.json in pytomicDEX_makerbot/config/ I get the following error:

FileNotFoundError: Komodefi SDK config not found at /home/user/pytomicDEX_makerbot/config/MM2.json!

Traceback

coins file not found, downloading...
Traceback (most recent call last):
  File "/home/user/pytomicDEX_makerbot/makerbot.py", line 10, in <module>
    from models import Tui
  File "/home/user/pytomicDEX_makerbot/models.py", line 1069, in <module>
    table = Table()
            ^^^^^^^
  File "/home/user/pytomicDEX_makerbot/models.py", line 447, in __init__
    self.dex = Dex()
               ^^^^^
  File "/home/user/pytomicDEX_makerbot/models.py", line 45, in __init__
    self.api = pykomodefi.KomoDeFi_API(config=self.mm2_config)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/top/.cache/pypoetry/virtualenvs/trading-5fBmn1aJ-py3.11/lib/python3.11/site-packages/pykomodefi/models.py", line 10, in __init__
    self.set_config(config)
  File "/home/top/.cache/pypoetry/virtualenvs/trading-5fBmn1aJ-py3.11/lib/python3.11/site-packages/pykomodefi/models.py", line 39, in set_config
    raise FileNotFoundError(f"Komodefi SDK config not found at {config}!")
FileNotFoundError: Komodefi SDK config not found at /home/user/pytomicDEX_makerbot/config/MM2.json!

I think printing an error and suggestion to get the file would be better.

@jd-2205
Copy link

jd-2205 commented Nov 19, 2024

This looks like an unfinished refactoring or outdated code, because makerbot should generate the MM2.json. For me the following patch fixes all the errors appearing on startup:

diff --git a/balances.py b/balances.py
index 0b4a180..34823be 100755
--- a/balances.py
+++ b/balances.py
@@ -1,9 +1,9 @@
 #!/usr/bin/env python3
 from helpers import status_print
-from models import Dex, Tables
+from models import Dex, Table
 
 dex = Dex()
-tables = Tables()
+table = Table()
 
 coins_list = dex.enabled_coins_list
 
@@ -11,4 +11,4 @@ if len(coins_list) == 0:
     status_print("No coins are activated!")
 else:
     # Documentation: https://developers.komodoplatform.com/basic-docs/atomicdex/atomicdex-api-legacy/my_balance.html
-    tables.balances(coins_list)
+    table.balances(coins_list)
diff --git a/const.py b/const.py
index 7ca82e2..532a256 100644
--- a/const.py
+++ b/const.py
@@ -58,7 +58,7 @@ SEEDS_FILE = f"{SCRIPT_PATH}/scan/seed_phrases.json"
 ACTIVATION_FILE = f"{SCRIPT_PATH}/activate_commands.json"
 ACTIVATION_URL = "http://stats.kmd.io/api/atomicdex/activation_commands/"
 try:
-    ACTIVATE_COMMANDS = requests.get(ACTIVATION_URL).json()["commands"]
+    ACTIVATE_COMMANDS = requests.get(ACTIVATION_URL).json()
     with open(f"{SCRIPT_PATH}/activate_commands.json", "w+") as f:
         json.dump(ACTIVATE_COMMANDS, f, indent=4)
 except:
diff --git a/models.py b/models.py
index 3705349..4ec0f36 100644
--- a/models.py
+++ b/models.py
@@ -1066,10 +1066,6 @@ class Config:
                 return value
 
 
-table = Table()
-dex = Dex()
-
-
 class Tui:
     def __init__(self):
         self.config = Config()
@@ -1099,7 +1095,7 @@ class Tui:
                     " "
                 )
                 if isinstance(coins, list):
-                    dex.activate_coins(coins)
+                    self.dex.activate_coins(coins)
                     break
             except KeyboardInterrupt:
                 break
@@ -1128,7 +1124,7 @@ class Tui:
         self.table.orders(self.dex.api.orders)
 
     def view_swaps(self):
-        self.table.swaps_summary(dex.api.rpc("my_recent_swaps").json())
+        self.table.swaps_summary(self.dex.api.rpc("my_recent_swaps").json())
 
     def loop_views(self):
         self.table.loop_views()
@@ -1149,7 +1145,7 @@ class Tui:
             amount = color_input(
                 f"Enter the amount of {coin} you want to withdraw, or 'MAX' to withdraw full balance: "
             )
-            amount = dex.validate_withdraw_amount(amount)
+            amount = self.dex.validate_withdraw_amount(amount)
             while not amount:
                 error_print(
                     f"{amount} is not 'MAX' or a valid numeric value, try again."
@@ -1157,19 +1153,19 @@ class Tui:
                 amount = color_input(
                     f"Enter the amount of {coin} you want to withdraw, or 'MAX' to withdraw full balance: "
                 )
-                amount = dex.validate_withdraw_amount(amount)
+                amount = self.dex.validate_withdraw_amount(amount)
 
             address = color_input(f"Enter the destination address: ")
-            while not dex.is_address_valid(coin, address):
+            while not self.dex.is_address_valid(coin, address):
                 error_print(f"{address} is not a valid {coin} address, try again.")
                 address = color_input(f"Enter the destination address: ")
 
-            resp = dex.withdraw(coin, amount, address)
+            resp = self.dex.withdraw(coin, amount, address)
             if "error" in resp:
                 error_print(resp)
             elif "result" in resp:
                 if "tx_hex" in resp["result"]:
-                    send_resp = dex.send_raw_tx(coin, resp["result"]["tx_hex"])
+                    send_resp = self.dex.send_raw_tx(coin, resp["result"]["tx_hex"])
                     if "tx_hash" in send_resp:
                         success_print(
                             f"{amount} {coin} sent to {address}. TXID: {send_resp['tx_hash']}"
@@ -1188,7 +1184,7 @@ class Tui:
             q = color_input("Stop Komodo DeFi Framework on exit? [Y/N]: ")
 
         if q.lower() == "y":
-            resp = dex.quit()
+            resp = self.dex.quit()
             if "error" in resp:
                 error_print(resp)
             elif "success" in resp:

@damascene
Copy link
Author

@jd-2205 Would you consider making it as a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants