Update for steemengine - token transfer and market operation added

Words
486
Reading
3 min
Listen
Play
8y

image.png

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)

image.png

image.png

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)

image.png

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)

image.png

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)

image.png

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

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

GitHub Account

https://github.com/holgern

Update for steemengine - token transfer and market operation added | Ecency