steem-python for dummies #9 - Creating orders in the market

in utopian-io •  7 years ago 


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.

  1. steem-python for dummies #1 - Introduction and Basic Operations
  2. steem-python for dummies #2 - Playing with account data
  3. steem-python for dummies #3 - Coding an upvote bot
  4. steem-python for dummies #4 - Private Memos
  5. steem-python for dummies #5 - Bundling Blockchain Operations
  6. steem-python for dummies #6 - Delegating
  7. steem-python for dummies #7 - Creating Accounts
  8. 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:


LimitOrderCreate Implementation

parametermeaning
ownerrelated account
orderidA unique order id bounded to your account. Will be used to cancel later on.
amount_to_sellHow much do you want to sell? With the asset. "0.1 SBD"
min_to_receiveHow much do you want to receive? With the asset. "1 STEEM"
fill_or_killOrder should be killed if if not filled immediately? (True or False)
expirationExpiration 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 :)


Steemd representation of this transaction

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()


Steemd representation of this transaction

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

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

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.

Out of curiosity, did you intentionally link some of your previous posts on utopian.io and some relatively?

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. :)

isArgsThisClass is an

Ah, I see.

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. :)

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! :)

  ·  7 years ago (edited)

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

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

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



Hey @emrebeyler, here is a little bit of BEER from @isnochys for you. Enjoy it!

@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

buradayım bekliyorum
cevap ver

Discordtan yaz bana.

ben discord bilmem

nereye bilmiyosun discord'taydın 3 hafta önce

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]

Teşekkürler

bu yavşağın paylaşımlarını beğenirsen pişman ollursun
adın listeme alındı beğeniyi sil.