https://github.com/holgern/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
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
Instead of unlocking the wallet
stm = Steem()
stm.unlock("wallet_pass")
the active key can be set directly:
stm = Steem(keys=["5xx"])
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 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")
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)
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)
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)
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"])
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)
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"])
from steemengine.tokens import Tokens
tokens = Tokens()
print("%d token were registered" % len(tokens))
print(tokens.get_token("ENG"))