chief-gant / SplinterlandsTraderBot

A trading bot written in Python that makes a profit by buying underpriced cards and quickly reselling them.
18 stars 0 forks source link

KeyError: 'dec_price' - Bot 3.9 #3

Closed jaclkeen closed 2 years ago

jaclkeen commented 2 years ago

Found offer: Magi of Chaos (Regular) There was a problem while buying the card, there might be a problem with the offer. The offer will be excluded from the next iterations.


Starting iteration Parameters:{'check_interval': 0, 'fixed_price_interval': 300, 'minimum_balance': 10, 'min_abs_gain': 0.1, 'min_rel_gain': 0.1, 'min_post_number': 50} Balance: $54.75

No good offers found


Starting iteration Parameters:{'check_interval': 0, 'fixed_price_interval': 300, 'minimum_balance': 10, 'min_abs_gain': 0.1, 'min_rel_gain': 0.1, 'min_post_number': 50} Traceback (most recent call last): File "splinterlands_trader_bot.py", line 635, in File "splinterlands_trader_bot.py", line 615, in run File "splinterlands_trader_bot.py", line 293, in update_dec_price KeyError: 'dec_price'

jaclkeen commented 2 years ago

Also received the following error which seems to be related. They both only occur once an offer has been found. No offer has succeeded thus far.

Parameters:{'check_interval': 0, 'fixed_price_interval': 300, 'minimum_balance': 10, 'min_abs_gain': 0.1, 'min_rel_gain': 0.1, 'min_post_number': 50} Balance: $53.57

Found offer: Soul Strangler (Regular) There was a problem while buying the card, there might be a problem with the offer. The offer will be excluded from the next iterations.


Starting iteration Parameters:{'check_interval': 0, 'fixed_price_interval': 300, 'minimum_balance': 10, 'min_abs_gain': 0.1, 'min_rel_gain': 0.1, 'min_post_number': 50} Balance: $53.57

No good offers found


Starting iteration Parameters:{'check_interval': 0, 'fixed_price_interval': 300, 'minimum_balance': 10, 'min_abs_gain': 0.1, 'min_rel_gain': 0.1, 'min_post_number': 50} Balance: $53.57

No good offers found

Traceback (most recent call last): File "splinterlands_trader_bot.py", line 635, in File "splinterlands_trader_bot.py", line 626, in run File "splinterlands_trader_bot.py", line 518, in update_posts File "splinterlands_trader_bot.py", line 78, in get_publicaciones File "splinterlands_trader_bot.py", line 78, in TypeError: string indices must be integers

knightblaster commented 2 years ago

I am also having this issue... havent been able to run the bot for more than a few minutes before it basically crashes with the above error.

chief-gant commented 2 years ago

I will check it out and have a fix during the day!

chief-gant commented 2 years ago

Relating only to the first error reported. As far as I could see, the KeyError: 'dec_price' is related to the Splinterlands API, in particular to this url: http://api2.splinterlands.com/settings. It should be stable, but just in case I'll try to catch the Exception. But this seems like something that can happen at random, and not very often. If I catch the error and avoid the program from terminating, it should be enough (to avoid it from actually crashing).

chief-gant commented 2 years ago

Regarding the second error reported, I also added a few exceptions to keep the program from crashing. I didn't get errors since. Please update the bot (with git pull) and try to run it again, and let me know how it goes for you. I will keep this issue open for now while waiting for your feedback.

jaclkeen commented 2 years ago

Thanks @chief-gant! Your updates did prevent the app from crashing. However, it is still unable to buy cards. The service has found 4 offers and 3 failed with 'There was a problem while buying the card, there might be a problem with the offer', and the other failed with the 'Error while fetching DEC price.'

chief-gant commented 2 years ago

Ok, I'll go over your errors and what I did.

First, the message 'Error while fetching DEC price' is not related to buying cards. The program updates the DEC to USD rate at the beginning of every new iteration, and if it fails it just tries again. So if you got that error message, and at some point you got a different one, it means eventually it was able to fetch the DEC price.

About the three purchase failures, where you got the message 'There was a problem while buying the card, there might be a problem with the offer'. Every time the bot attempts to purchase a card, it waits a fixed amount of time while it checks if the card ownership changed. If after that fixed amount of time (as of now, 60 seconds) the card is still not yours, the bot then concludes that there was a problem while purchasing the card, and it will not try again. That might have one of three possible causes:

  1. The offer was already bought by another person/bot. It can happen that another user has a faster Internet connection or a faster bot and they had the upper hand.
  2. Some offers appear in the API and even in pages such as PeakMonsters, CardAuctionz, etc. and are just impossible to buy. They are just there, and no matter how much you try and buy them, it always ends in an error. For that very reason we added something to keep the bot from retrying endlessly to buy the same card.
  3. Something changed in the way the blockchain manages the operations.

I proceeded to buy a couple of cards with an alt account using the program (some random cheap offers, not "good" ones) and I had no issue. Therefore, I discarded the possibility cause #3. That basically leaves the two causes that can't be fixed by the code.

I'll add some more thoughts in my next comment.

knightblaster commented 2 years ago

Definitely still crashing on my end as well... getting stufff like this:

Starting iteration Parameters:{'check_interval': 0, 'fixed_price_interval': 300, 'minimum_balance': 0, 'min_abs_gain': 0.1, 'min_rel_gain': 0.1, 'min_post_number': 50} Balance: $1.13

No good offers found

Traceback (most recent call last): File "splinterlands_trader_bot.py", line 665, in File "splinterlands_trader_bot.py", line 656, in run File "splinterlands_trader_bot.py", line 563, in update_posts File "splinterlands_trader_bot.py", line 80, in get_card_owner KeyError: 0

chief-gant commented 2 years ago

I just read this "new" api fail, I'll make a fix for it. Then I'll finish what I was going to say.

chief-gant commented 2 years ago

The problem @knightblaster posted might be related to the problem. It is having problems while getting the card owner, so it might be related.

I made a few corrections, and in the new update every API call is handled in case it doesn't work as intended. All of this seems to be indicating that the API is somewhat unstable, so catching all these exceptions should be enough.

If the only good offers available are "faulty offers" (as I mentioned in my point #2), it basically means there are no good offers, and that might be what's basically happening. I've been monitoring the bot usage and some days it has a lot of operations, and some other days there are less movement. I'll keep an eye out for now to see how the bot works, but if it appears to be working for some people and not for others it might be for reasons others than the bot itself.

I believe though that these updates will make it more stable, so it should work at least better than now.

chief-gant commented 2 years ago

The update is now live. Please update your version. Meanwhile I'll keep checking the bot usage by users in general.

knightblaster commented 2 years ago

FYI, so far (about 12 hours), the changes have fixed the issues on my end, so thank you! :)

jaclkeen commented 2 years ago

I’ve had mine running for about 2 hours now, and your changes appear to have fixed the issues on my end as well. Thank you for the help and the quick fix!

chief-gant commented 2 years ago

Great! I was waiting to hear from both of you. I will wait until tomorrow and then I will close the issue.