Hello,
This is the 9. post of "steem-python for dummies" series. If you didn't read the older ones take your time and have a look.
- steem-python for dummies #1 - Introduction and Basic Operations
- steem-python for dummies #2 - Playing with account data
- steem-python for dummies #3 - Coding an upvote bot
- steem-python for dummies #4 - Private Memos
- steem-python for dummies #5 - Bundling Blockchain Operations
- steem-python for dummies #6 - Delegating
- steem-python for dummies #7 - Creating Accounts
- steem-python for dummies #8 - Calculating Post Rewards
In this post, we will learn creating and removing orders on internal market.
Orders on internal market
Steem blockchain offers a decentralized exchange between SBD and STEEM. In Steemit, this is already possible with a nice user interface.
However, this market doesn't depend to Steemit. All operations on these market including creating orders, removing orders are stored in the chain.
That means it is possible for us to create these operations ourselves.
Creating an order
steem-python has a operation implemented as limit_order_create. However, it doesn't encapsulate like other operations, so we will build the transaction ourselves.
Before doing that, let's see what are the parameters for the operation:
parameter | meaning |
---|---|
owner | related account |
orderid | A unique order id bounded to your account. Will be used to cancel later on. |
amount_to_sell | How much do you want to sell? With the asset. "0.1 SBD" |
min_to_receive | How much do you want to receive? With the asset. "1 STEEM" |
fill_or_kill | Order should be killed if if not filled immediately? (True or False) |
expiration | Expiration time for the order: Ex: 2017-12-31 23:59:59 |
Let's use these information to build, sign, broadcast a LimitOrderCreate transaction.
from steem import Steem
from steem.transactionbuilder import TransactionBuilder
from steembase import operations
s = Steem(nodes=["https://rpc.buildteam.io"],
keys=["active_wif"])
account = 'emrebeyler'
limit_order_create = operations.LimitOrderCreate(
owner=account,
orderid=0,
amount_to_sell="0.1 SBD",
min_to_receive="1 STEEM",
fill_or_kill=False,
expiration="2017-12-31T23:59:59",
)
tb = TransactionBuilder()
tb.appendOps([limit_order_create,])
tb.appendSigner(account, "active")
tb.sign()
resp = tb.broadcast()
Done! I have created an order, asking 1 STEEM for 0.1 SBD. Hoping it will be filled :)
Canceling an order
Remember, we had to post an order_id while creating the order. We will use that id to cancel it.
from steem import Steem
from steem.transactionbuilder import TransactionBuilder
from steembase import operations
s = Steem(nodes=["https://rpc.buildteam.io"],
keys=["active_wif"])
account = 'emrebeyler'
limit_order_cancel = operations.LimitOrderCancel(
owner=account,
orderid=0,
)
tb = TransactionBuilder()
tb.appendOps([limit_order_cancel,])
tb.appendSigner(account, "active")
tb.sign()
resp = tb.broadcast()
Order Book
You can get order book easily.
s = Steem()
print(s.get_order_book(limit=1))
Which is resulting like this, at the moment.
{
'asks': [{
'order_price': {
'base': '750.000 STEEM',
'quote': '146.822 SBD'
},
'real_price': '0.19576266666666667',
'steem': 512512,
'sbd': 100330,
'created': '2017-12-17T10:48:09'
}],
'bids': [{
'order_price': {
'base': '2.207 SBD',
'quote': '11.274 STEEM'
},
'real_price': '0.19576015611140679',
'steem': 11274,
'sbd': 2207,
'created': '2017-12-17T10:57:00'
}]
}
That's all for this post. Feel free to ask questions or request topics about steem-python for the incoming posts.
Posted on Utopian.io - Rewarding Open Source Contributors
Wow, this is going to be so much nicer than using that damned confusing market page! I'll be able to create a script that will do conversions for me.
What's that
isArgsThisClass
method?Out of curiosity, did you intentionally link some of your previous posts on utopian.io and some relatively?
isArgsThisClass is an internal hack in steem-python, where the arguments are actually the instance of the class or not. If it's, It does not re-populate the data and use it.
These series are all published in utopian.io. For the potential readers, I also add the older posts of the series to make sure they already have a look to that posts. :)
Ah, I see.
No, I mean that even though I am reading on streemit.com, you are using some absolute links that take me to utopian to read them rather than being linked relatively so that I can stay here on steemit.com and read them.
Question: Can you put first 4 post of this excellent series here on Steemit? It asks you for password to see first 4 and I would like to avoid to worry yet of another login credential.
Request topic: Say I would like to have a list of certain users and be notified when anyone from that list post on Steemit. Such as VIP following ;-)
Hello,
Regarding the question, these tutorials are backed by utopian so I put links also in utopian. If you don't have a utopian account, you can change the domain to Steemit and see it.
Example:
https://utopian.io/utopian-io/@emrebeyler/steem-python-for-dummies-4-private-memos
to
https://steemit.com/utopian-io/@emrebeyler/steem-python-for-dummies-4-private-memos.
About the request, will do for the next post! :)
Ahh I didn't know this, super and thanks!
About request - can't wait ;-) thanks (edit, already posted, cool and thanks!)
Hey @emrebeyler I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Look at that birthday pos. !BEER
View or trade
BEER
.Hey @emrebeyler, here is a little bit of
BEER
from @isnochys for you. Enjoy it!Teşekkürler
bu yavşağın paylaşımlarını beğenirsen pişman ollursun
adın listeme alındı beğeniyi sil.
Bu işime yarayacak.teşekürler
bu hıyar da paylaşım yapma bilader.
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
@atli bir video koyar unutur gider sen git ağa babalarını gönder onlar gelip benden rica etsinler.. Alayınızı buraya siker gömerim HADDİNİ Bil.. huzuruma oyle gel
@emrebeyler
buradayım bekliyorum
cevap ver
Discordtan yaz bana.
@daghan
https://discord.gg/54f4RgB
ben discord bilmem
nereye bilmiyosun discord'taydın 3 hafta önce