Python Libraries: Splinterlands SPS Auto-Staker v.1.2

in STEMGeekslast year (edited)

image.png

In my quest to write something that would make me richer, the thought of compounding my SPS Stake automatically came to mind.

Long ago, the Splinterlands team mentioned they may make this a feature of their site, but it never happened. Before I wrote this, I was manually staking my SPS several times a day, and frankly, it was a pain in the arse.


image.png
...'no need to click 'CLAIM' anymore, though you do need to install Python on your local computer to finally be done with all that'...

What better way to get rich than stake my SPS every minute? Think of the compounding, think of yesterday when your SPS was more valuable than today, think of watching the figures decrease over time making you bang your head on the nearest wall and have suicidal thoughts enter your head.

That's a bear market for you. If you can't stand all that shit, then you shouldn't be here. Since writing SPS Stake I have seen the value of my SPS daily income decrease from $9 to around $6.

It may well go lower, that's life and my head is slightly sore.

def get_balance(login_resp: dict, currency_token: str):
    balance: float = 0
    try:
        for entry in login_resp.get("balances"):
            if currency_token == entry.get("token"):
                balance = entry.get("balance")
                break
    except TypeError:
        print(Bcolors.RED + f"Node error getting balance, pausing for {delay} seconds.." + Bcolors.END)
        return 0
    return balance

...'@bauloewe's get_balance routine with a little extra improvisation from yours truly'...

There’s little point in re-inventing the wheel so I looked on GitHub to see if anyone had already written an SPS-Auto Staker. I found some code from @bauloewe from which I extracted some of his routines.

@bauloewe’s and another one I found were written in the days when the Airdrop was active and contained a lot more code than I needed. After wading through the code, I found the parts I needed and merged them into my own.

image.png

I contacted @bauloewe on discord and he kindly allowed me to use his routines after an explanation of what I was doing. I will add @bauloewe as a beneficiary of this post as 'compensation' although he told me the code was Open Source.

SPS Auto-Staker v.1.2 allows the SPS holder to claim their SPS every xx seconds. I have mine set to 60 which is every minute. Every claim will require Resource Credits (RC’s), so bear this in mind if you want to use the script, have lots of SPS but little Hive Power (HP).

from pycoingecko import CoinGeckoAPI
cg = CoinGeckoAPI()

The script is not perfect in any way and gets the SPS price from the hive.engine buybook, while it retrieves the HIVE price using the free CoinGecko API. I wanted to try both methods, and show usage examples of both.

spsprice = cg.get_price(ids='splinterlands', vs_currencies='usd', include_market_cap='true')
usdspsprice = spsprice['splinterlands']['usd']

I did find it odd that CoinGecko list SPS as Splinterlands. That threw me off for a while!

After editing the script and changing some variables to your own parameters, run it and it will show you several things. I like my scripts to be colourful, and show lots of data.

image.png

You will see the total value of your SPS Stake (which could result in severe depression), the approximate value of SPS you can claim per day (in HIVE), and the USD amount based on the HIVE value.

image.png

...'node problems are now caught and will display in the console window. After a minute, the script will resume'...

I was getting node problems which resulted in frequent TypeError errors when running this script and was forced to add a try: in the Get_Balance function. This seems to have fixed it, and I find it works for hours now.

I am still not convinced that the below code works, and auto-switches if there are node issues.

nodes = ['https://api.hive.blog', 'https://api.deathwing.me', 'https://anyx.io']
hive = Hive(node=nodes, keys=[posting_key])
set_shared_blockchain_instance(hive)

However, most problems go away if you simply re-try. It could be down to the first node in the list being hammered. I still get timeouts and errors with the above so added a try: in one of @bauloewe's routines.

The script is ready to download and run after modifying the variables as follows:

delay = 60
posting_key = '5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
username = 'your_username'

Ensure that the delay variable is set to how often you want to claim and stake your SPS. As I have a large SPS stash, I can manage around 0.191 SPS every minute.

While that's peanuts now when SPS was 50c a pop that was a mean 9c per minute. Those were the days, and I feel they may never return.

image.png

SPS Auto-Staker v.1.2 can be found on my personal GitHub Repository here.

Please feel free to comment and criticize my code. I am a beginner Python coder, so don't expect perfection.

FOOTNOTE: - Forgot to add @bauloewe as beneficiary and now it won't let me, how annoying. Will send him some HIVE after this pays out.

RedLine.png

  • Earn currency while you play brewing virtual beer with CryptoBrewMaster
  • Earn currency while you play and become a global Rock Star with Rising Star


CurieCurator.jpg

Sort:  

Code looks good.
I looked at it for a moment and could not improve anything substantial.

Just to be a smartass:

https://github.com/BrynRogersTHG/HIVE-Blockchain---Hive.Engine-SPS-AutoStake/blob/main/StakeSPS_1.2.py#L130

So, the line 131 is only to print a new line?
Add a \n for newline, maybe... saves 1 line of code :P

print(f' - Waiting {delaymins} minutes before staking again...\n')

As for the the values, that a user would need to configure, I use a config.py.
Then in the main you can import config and use for example config.username.

Makes the code longer but easier to use for an outsider.

Also maybe mention the requirements (beem, hiveengine, pycoingecko) in the description.

Anyways: If it works, it works.

Add a \n for newline, maybe... saves 1 line of code :P

Sad to say I have been doing an intensive Udemy course and have come across this, so I do know about. The printing a blank line is old conventions.

As for the the values, that a user would need to configure, I use a config.py.
Then in the main you can import config and use for example config.username.

Yes, am familiar with multi-files and importing. The next open source project I will be adding to GitHub is my RandomVoter project. This currently has all the accounts in a single script, but would be better formatted in what you describe above.

Also maybe mention the requirements (beem, hiveengine, pycoingecko) in the description.

Yes, need to add these to the Readme.MD file.

Have you decided it's not worth selling ATM then?!?

Well yes, I considered it and @azircon's comments kind of dissuaded me in the end. I am too invested to sell out, I think that goes for many of us.

I know what you mean, I'm skimming about 20% out out and then about 20% into Hive and in those pools, but that's waiting to go back into the game.

I'd be insane not to take something out even now, it's a minor hedge, with 80% being ploughed back in, I mean the whole think could just stay flat, after all.

Yes, I take some and am building my HIVE stash back up. I feel it's more stable in the long run.

Every minute!?! That's nuts!

I am going to report you to the Irresponsible JSON police 🤣

LOL, I had it on 2 mins to start, but what the hell. Quicker staking and compounding might offset the massive fall this token has seen in recent months.

It has plummeted a fair whack. I don't think current market sentiment in general for crypto and the splinterlands shenanigans in general have helped!

I'm still claiming manually. The amount I could earn on the daily income in a day means it would not make a significant difference to claim more often. With your bigger stake it may be different. It is fun to code this stuff though.

I use the Coingecko API to generate some graphs. I hadn't tried passing multiple nodes to beem though. I have had some node issues, so I ought to try that.

I put my account name and key in a file that I load at the start. As long as I exclude that from Githib it reduces the chances of accidentally exposing my key.

There's always something to learn.

It is fun to code this stuff though.

That's part of it, to create something semi-useful. RandomVoter is the best thing I have created. I will release it in time.

I hadn't tried passing multiple nodes to beem though. I have had some node issues, so I ought to try that.

I have been having a lot of node issues recently. Voting, and comments not working. Seems you need to do everything twice.

As long as I exclude that from Githib it reduces the chances of accidentally exposing my key.

I almost did that earlier. Lucky the code was 'Private' at the time.

I have slipped up with exposing other passwords in code before, but nothing bad happened. I think people actually look out for cases of that, so you need to be careful. Got to be security-minded, especially with crypto accounts.

I may try running this some time and see if there's anything I would tweak.

It was my posting key, active keys I refuse to add to scripts.., call me paranoid, but there's too much to lose. A script that would move all my DEC from the other accounts would be very handy but as this requires the active keys, I won't do it.

I may try running this some time and see if there's anything I would tweak.

Let me know if it works OK!

active keys I refuse to add to scripts

You could add the key to beempy wallet, so it's not in plain text anymore... also saves you the hive = Hive(keys=['5...']

I haven't used that yet, but thanks for the tip. Moving DEC between my accounts is a pain in the arse, as I have 5 accounts that passively rent cards and so are DEC collectors.

I almost did that earlier. Lucky the code was 'Private' at the time.

i have a bad news to you, it's better if you change the posting key

@slobberchops I'm serious 5JoU1

I can see you have it, or did. I have changed it now. How.. did you retrieve it.. I am curious?

Alright this is pretty dope. Auto claim for SPS and as some mentioned GLX is a good time saver but also since each block is 3 seconds it does actully help to continue to stake often!

If it helps me get slightly richer, then I am for it!

Very cool! something similar would be great for GLX too considering the current APR, thank you so much for sharing!

I could and it probably would't take a lot to convert it. In the first thing I would try would be:

mytoken = 'GLX'

Of course, there are hard-coded references in it for SPS, they would need to be modified.

Several times a day! That's nuts! Who makes that much SPS that they need to claim multiple times per day? I claim like once per week if that. Sometimes it's per month.

Once a minute! Compounding is seriously powerful, if you can do it that frequently (and not be concerned about RC's), then do so.

I don't think my 50 SPS per day is really going to make that big of an impact in the grand scheme of things. Maybe back when the interest rate was closer to 100% versus 20%.

It's better for larger stakeholders, but will give you an idea of how much you get per day. I like stats!

Yep, whales just get whalier!

I'm not interested in coding and really don't know something but still enjoyed reading your blog. @saif-ul-wahab I guess its something for you.

A subtlety that may come in handy for those who, like me, have set a longer delay, or are planning to change it from the basic setting of 60, is the substitution of line 120

dailyincome = round(price * sps_balance * (24*delay), 2)

with the following

dailyincome = round(price * sps_balance * (1440/delaymins), 2)

Very nice! I changed it a little and now I'm using it in glx

Awesome, I may add GLX as well as SPS to a future version.

So far I used the splex.gg tool which has a claim of no less than every hour. Having a claim with shorter times is certainly more convenient. Thank you

A very efficient and acceptable use of python!

Very well!

Is there a reason for switching between the Hive Engine price of SPS and the CoinGecko price?

Nice to make your own programs to do that. I know Splex has it built in there too along with GLX.

I know Splex has it built in there too along with GLX.

Not sure if this is just for subscribers. I am not a fan of SPLEX, too costly for me. Looks good though.

I know what you mean, the fees can only increase from here too.

Congratulations @slobberchops! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You received more than 108000 HP as payout for your posts, comments and curation.
Your next payout target is 110000 HP.
The unit is Hive Power equivalent because post and comment rewards can be split into HP and HBD

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Check out our last posts:

Our Hive Power Delegations to the December PUM Winners
Feedback from the January Hive Power Up Day
Hive Power Up Month Challenge 2022-12 - Winners List
The Hive Gamification Proposal Renewal
Support the HiveBuzz project. Vote for our proposal!

Has anyone encountered this error and managed to solve it?

UnhandledRPCError: missing required posting authority:Missing Posting Authority riccc96Transaction failed to validate using both new (hf26) and legacy serialization

missing required posting authority

Looks like you are using the wrong key, or username.

I have no idea why but I think it was related to the version of beem, just ported to 0.24.26 it works perfectly

Wow... coding and programming.
Definitely the things I would like to have an idea about but it all gets jabbed in my head that I get as confused as ever seeing them..... Maybe it's because my full interest isn't there. Yet😓

$WINE


Congratulations, @theguruasia You Successfully Shared 0.800 WINEX With @slobberchops.
You Earned 0.800 WINEX As Curation Reward.
You Utilized 4/4 Successful Calls.

wine_logo


Contact Us : WINEX Token Discord Channel
WINEX Current Market Price : 0.160


Swap Your Hive <=> Swap.Hive With Industry Lowest Fee (0.1%) : Click This Link
Read Latest Updates Or Contact Us

 last year  

I setup something similar to auto claim/stake for SPS and GLX. It also claims SPS Node rewards. I couldn't imagine clicking those buttons all the time.

I don't suppose you know how to claim accumulated SPS in the Tribeldex pools? I can't find any info about it, or find any API info.

image.png

I wrote something using Selenium (with Python) which is a library that can interact with webpages. The only problematic element is logging in reliably, and closing all the various pop-up windows that change each and every time there's a new feature.

Worth a go if you're learning new Python things.

I looked at this only yesterday, got the session popped open but then you have the issue of Keychain and being logged out. It looked more trouble than it was worth. I had even identified the <DIV section...

Using posting key to log in instead of keychain works well for getting around this. Using XPATH is probably more reliable than the div, too :)

I could dig up my old code for this, but I withdrew from liq pools quite some time ago, so my focus is just like yours, building that sweet, sweet, sps stake

 last year  

I don't have anything in any of the pools, so no I don't. Have you check for any related custom json broadcasts after you do it manually?

I checked the BlockExplorers for HE and Hive and there was just nothing for that particular action. The Tribeldex/Dieselpool Rewards are not showing the SPS rewards, which makes me believe it's a spaghetti airdrop code somewhere on the SPL Backend.

I will have a look thanks, anything to give a clue on this. I asked in the discord dev area and got a lot of silence!

 last year  

There are only a handful of people here on Hive that even do this. It's not unexpected.

I haven't looked in a few days. No API method then.

image.png

Those aren't really tribaldex rewards, so that answer was expected. It's a pure SPL-based reward system. But there has to be a json for it, because the webpage is using only the API itself.