cyberjunky / 3commas-cyber-bots

3Commas bot helpers, AltRank, GalaxyScore, Watchlists, Auto-Compound, TrailingStopLoss, TakeProfitIncrement
MIT License
211 stars 68 forks source link

Galaxyscore.py with paperaccount - error: Fetching 3Commas account failed #49

Closed mthad closed 2 years ago

mthad commented 2 years ago

Describe the bug Hello, First of all thank you for sharing this amazing tools!

I tried to use galaxyscore.py using docker with paper account on 3 commas. When I start the container, I get this error message:

2021-12-20 11:03:28 - galaxyscore.py - 3Commas bot helper galaxyscore!

2021-12-20 11:03:28 - galaxyscore.py - Started at Monday 11:03:28 20-12-2021

2021-12-20 11:03:28 - galaxyscore.py - Loaded configuration from 'config/galaxyscore.ini'

2021-12-20 11:03:28 - galaxyscore.py - Notifications are enabled

2021-12-20 11:03:28 - galaxyscore.py - Reloaded configuration from 'config/galaxyscore.ini'

2021-12-20 11:03:28 - galaxyscore.py - Fetched 3Commas pairs blacklist OK (0 pairs)

2021-12-20 11:03:28 - galaxyscore.py - Fetched 3Commas BTC price OK (45938.02 USDT)

2021-12-20 11:03:29 - galaxyscore.py - Fetched LunarCrush ranking OK (100 coins)

2021-12-20 11:03:29 - galaxyscore.py - Bot base currency: USDT

2021-12-20 11:03:29 - galaxyscore.py - Bot minimal 24h BTC volume: 0.0

Traceback (most recent call last):

  File "galaxyscore.py", line 651, in <module>

    find_pairs(botdata)

  File "galaxyscore.py", line 430, in find_pairs

    marketcode = get_threecommas_account(thebot["account_id"])

  File "galaxyscore.py", line 309, in get_threecommas_account

    logger.error("Fetching 3Commas account failed with error: %s" % error["msg"])

KeyError: 'msg'

Environment:

Additional context I am using paper account on 3 commas

Thanks for your help

mthad commented 2 years ago

tried with release 0.7.9 it worked. but not with main branch. I close this issue

cyberjunky commented 2 years ago

Why close an issue which isn't fixed?

I think you need to read the documentation and add AccountRead rights to your 3Commas API key

mthad commented 2 years ago

Hi, sorry for closing it too early, mistake on my side. Regarding your suggestion, I already set 3Commas API Key with this parameter. my API key - BotsRead, BotsWrite, AccoundsRead: image

cyberjunky commented 2 years ago

Ok will check, thanks

mthad commented 2 years ago

Hi, in the function named def get_threecommas_account(accountid):

this piece of code seems to cause the issue (line 299): additional_headers={"Forced-Mode": "real"}

I commented it and it worked

Did a quick check and it's also present in the code of the following scripts:

Repoduced the issue on galaxyscore.py, altrank.py, compound.py, coinmarketcap.py After commenting the concerned line it worked. Did not test with watchlist.py, watchlist_100eye.py

cyberjunky commented 2 years ago

But without it real mode doesn't work correctly when you put the webinterface in paper mode I think (it was an issue a while ago) Can you test this? If this is the case we need to reinstate the old accountmode setting and use that, but it means we cannot run mixed bots (paper/real)

cyberjunky commented 2 years ago

Maybe they (3Commas) changed this behavior to work with all modes now, since it was strange behavior anyway.

mthad commented 2 years ago

Hi,

Scenario tested with galaxyscore.py (commented the line additional_headers={"Forced-Mode": "real"}):

  1. switched on paper account on web interface, launched galaxyscore.py with botids of real account in galaxyscore.ini --> Result: Bot id in real account successfully updated with the right pairs.
  2. switched on real account on webinterface, launched galaxyscore.py with botids of paper account in galaxyscore.ini --> Result: Bot id in paper account successfully updated with the right pairs.

From the official documentation of 3commas API: " By default, API mode(real or paper) synchronized with mode in web/app. You can set a forced mode for public API through the request header "Forced-Mode" with values "real" or "paper"."

(speculation) It's probably true and matters for other actions through this api, but in our case, because we specify botids, it looks like it doesn't matter to be in real or paper account in webinterface. Ids are unique

cyberjunky commented 2 years ago

@mthad I know about that text. But the issue is to determine the correct mode I have to get the market_code of an account_id linked to a botid. And if this request also needs the correct mode for that account (which it the case, it turns out) We have a chicken and egg problem. I cannot rely on the account_name in the bot for this, this can be "Paper account 12345" or "Test account" or something else.

To recap: I use the get_threecommas_account(accountid) code to get the market_code which tells me which market the bot is connected too, 'binance' for binance and 'paper_trading' if link to paper account.

I would expect I can read both ids (from paper and real botid) with mode is 'real' but this fails sometime as you pointed out, and without it the reading of the 'real' account fails if web interface is in paper mode.

There is other code, but this switched the mode (not only for a webcall) this is also unwanted...

cyberjunky commented 2 years ago

@mthad Working solution it seems: I first read account data in paper mode, if this doesn't give me the market_code for theaccount_id I read it again using real mode ;-)

cyberjunky commented 2 years ago

@mthad can you test with latest version?

mthad commented 2 years ago

Hi, @cyberjunky, tested with new version (main branch), worked successfully in scenario below. Scenario tested with galaxyscore.py:

  1. switched on paper account on web interface, launched galaxyscore.py with botids of real account in galaxyscore.ini --> Result: Bot id in real account successfully updated with the right pairs.

  2. switched on real account on webinterface, launched galaxyscore.py with botids of paper account in galaxyscore.ini --> Result: Bot id in paper account successfully updated with the right pairs.

Thanks for the fix ;-). Happy new year :-)!

cyberjunky commented 2 years ago

@mthad Thank you for reporting and testing, have a happy new year too! :champagne: