Repository
https://github.com/holgern/steemengine
steemengine
steemengine is a python library for working with steem-engine.com tokens.
I released version 0.2.0 which can be installed by
pip install steemengine
New features
It is now possible to view the wallet of a user and receive information about all registered token. Sending of token is possible and creating Buy/Sell order on the market can be done. It is also possible to deposit STEEM and withdraw STEEMP.
As a token transfer is a custom_json operation, there is the possibility that broadcasting a transfer will not change the token amount. There are some rules in place that may prevent that a transfer run trough( e.g. quantity must be a string and not a float). I tried to prevent such cases by:
{"symbol":symbol.upper(),"to":to,"quantity":str(amount),"memo":memo}
assuring that the symbol contains only upper chars and that the quantity is a string.
I updated my beem library, in order to allow token transfer (spaces in the custom json field were removed and broadcasting a custom json with an active key is now possible). Thus, all described functions work only with a beem version >=0.20.19
. The beem version can be checked with
beempy --version
Wallet password
Instead of unlocking the wallet
stm = Steem()
stm.unlock("wallet_pass")
the active key can be set directly:
stm = Steem(keys=["5xx"])
View Token balance
It is possible to get the token balance for an account using the Wallet
class.
from steemengine.wallet import Wallet
wallet = Wallet("holger80")
print(wallet)
print(wallet.get_token("JAR"))
Token transfer
Token transfer is possible using the new Wallet
class. The account name and the token balance is checked before sending.
The exception TokenNotInWallet
is raised, when the token is available in the wallet. When the transfer amount is higher than the balance, a InsufficientTokenAmount
exception is raised.
from beem import Steem
from steemengine.wallet import Wallet
stm = Steem()
stm.unlock("wallet_pass")
wallet = Wallet("holger80", steem_instance=stm)
wallet.transfer("jarunik",1, "JAR", memo="https://steemit.com/utopian-io/@holger80/update-for-steemengine-token-transfer-and-market-operation-added")
Market deposit
The STEEM balance is checked before sending the deposit. When not sufficient STEEM are in the account, a InsufficientTokenAmount
is raised.
from beem import Steem
from steemengine.market import Market
stm = Steem()
stm.unlock("wallet_pass")
m=Market(steem_instance=stm)
m.deposit("holger80", 0.01)
Market withdraw
The STEEMP
token balance is checked before. When the amount is not sufficient, a InsufficientTokenAmount
is raised.
from beem import Steem
from steemengine.market import Market
stm = Steem()
stm.unlock("wallet_pass")
m=Market(steem_instance=stm)
m.withdraw("holger80", 0.009)
Buy order
The STEEMP
token balance is checked, when it is below amount_token_to_buy * price
, a InsufficientTokenAmount
is raised.
from beem import Steem
from steemengine.market import Market
stm = Steem()
stm.unlock("wallet_pass")
m=Market(steem_instance=stm)
m.buy("holger80", 1, "JAR", 0.09)
Cancel a buy order
A buy order can be cancelled, when the buy order ID is known. It can be found out by using the get_buy_book
function.
from beem import Steem
from steemengine.market import Market
stm = Steem()
stm.unlock("wallet_pass")
m=Market(steem_instance=stm)
open_buy_orders = m.get_buy_book("JAR", "holger80")
m.cancel("holger80", "buy", open_buy_orders[0]["$loki"])
Sell order
The token balance is checked, when it is to low, a InsufficientTokenAmount
is raised.
from beem import Steem
from steemengine.market import Market
stm = Steem()
stm.unlock("wallet_pass")
m=Market(steem_instance=stm)
m.sell("holger80", 1, "JAR", 10)
Cancel a sell order
A sell order can be cancelled, when the sell order ID is known. It can be found out by using the get_sell_book
function.
from beem import Steem
from steemengine.market import Market
stm = Steem()
stm.unlock("wallet_pass")
m=Market(steem_instance=stm)
open_sell_orders = m.get_sell_book("JAR", "holger80")
m.cancel("holger80", "sell", open_sell_orders [0]["$loki"])
View all tokens
from steemengine.tokens import Tokens
tokens = Tokens()
print("%d token were registered" % len(tokens))
print(tokens.get_token("ENG"))
Commits
Changelog and more examples added to readme
- commit 5e39644
- Doku to some functions added
Add Market, Tokens and Wallet classes
- commit dc38ce9
- Market() can be used for deposit,withdrawel, buy and sell.
- Wallet() can be used for checking the wallet balance and sending tokens
- Tokens() can be used for checking all available tokens
Rename function names to meet PEP8 conventions
- commit 4c067b0
- Add two exapmles (token sending and token upvote bot)
- Increase version number
- find returns an array
- find_one returns an object
It's always great to see you supporting all kinds of projects with Python packages. I've personally not really checked out STEEM ENGINE, but I saw that a lot of people were very excited about it, so I'm curious to see where it goes. I'm also always very interested in checking out the code itself, as you are a great developer and I think other Python developers can learn a lot from you.
Saying this, there's still some feedback I'd like to give:
rpc.py
you never usetime
,threading
etc.{}
or[]
as a default value isn't best practice: "this 'default' array gets created as a persistent object, and every invocation ofmy_method
that doesn't specify an extras param will be using that same list object—any changes to it will persist and be carried to every other invocation!".wallet.py
in the functionchange_account()
you don't actually use thecheck_account
variable - not sure if you just missed this or something is wrong there.h
andc
could be improved (and some variables are camelCase, while others snake_case), but other than that everything is very readable.pytest
overunittest
as it's imo better.Good update with a lot of work. It's always a pleasure seeing your posts, so I can't wait to see future updates!
Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.
To view those questions and the relevant answers related to your post, click here.
Need help? Chat with us on Discord.
[utopian-moderator]
$rewarding 30% 13min
Thanks for the review.
I check if the given account is an existing steem user name in
change_account()
. I do not need the account object, so it is not further used. I think I can just remove the left side (check_account
).I will use your suggestions for my next update.
Thank you for your review, @amosbastian! Keep up the good work!
Fantastic. Can this be used to create automated sell orders that track a fixed $US price as Steem moves?
Posted using Partiko iOS
Yes, that would be possible with version 0.2.0.
Now someone just needs to make a JS version of it.
Congratulations @holger80! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :
Click here to view your Board
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!
Vote for @Steemitboard as a witness and get one more award and increased upvotes!
Hi @holger80!
Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server
Hey, @holger80!
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!
Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!
Seems like the Steem-Engine team itself should be doing this kind of work and more... but glad you stepped in to cover them on this. I just hope they're committed to their project and it's not just a get rich quick product. I have hope though.
Hi, @holger80!
You just got a 3.5% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.
This post has been included in the latest edition of SoS Daily News - a digest of all the latest news on the Steem blockchain.
Hallo Holger, hab mir gerade Steem Engine angeschaut und auch die DEX. Ich muss sagen, was ihr da geleistet habt, ist unglaublich und ihr könnt arg auf euch stolz sein. Ich wünschte richtig ich könnt auch Python coden, aber das würd sicher Jahre dauern. Egal, zum Glück gibts Leute wie euch, die das drauf haben. SUPER ARBEIT - bin immer noch sprachlos. Jedenfalls ein Gewinn für Steemit! DANKE