create account

πŸ€– Dice Roller Bot / Python / Primedice 🎲 by aro.steem

View this thread on: hive.blogpeakd.comecency.com
· @aro.steem · (edited)
$9.09
πŸ€– Dice Roller Bot / Python / Primedice 🎲
#### Repository
https://github.com/nnmix/py-primedice-bot

#### What Will I Learn?
- You will learn to automate a PrimeDice Bot given your own rules
- You will learn to use Python: 'requests' and 'json' libraries
- You will learn to use your Prime Dice Account Token
- You will learn to fetch your account details: Coins / Balance
- You will learn to execute automated 'Rule Based' dice rolls

#### Requirements
#####   Personal Prerequisite
- Existing [primedice](https://primedice.com/) account
#####   System prerequisites:
- [Jupyter](https://jupyter.org/) notebook for python 
#####   Knowledge prerequisites:
- Basic understanding of python programming
- Basic understanding of Http Methods, APIs

#### Difficulty
- Intermediate

#### Description
In this tutorial you will get the ability to automate your own flavored Dice Roller Bot on your prime dice account

#### Content

Before getting to the python scripting section you will need the primedice account token to be used in the http method calls.
#####   1. Primedice Account Token:
   a. Sign in to your existing primedice account
   b. Go to MORE > SETTINGS > TOKENS > REVEAL > Copy
       ![e5pgwm318g.gif](https://img.esteem.ws/e5pgwm318g.gif)

#####   2. Jupyter / Python

* You can access jupyter [Online](https://jupyter.org/try) or [Intall](https://jupyter.org/install.html) it locally on your pc. 

* When done open a new python file:
![c0p4o64haw.png](https://img.esteem.ws/c0p4o64haw.png)

* When the file is open, if you are on the online version, you can delete existing sample cell by clicking the cell border (blue highlight) than double pressing 'D'
![vh7xz5m2hw.png](https://img.esteem.ws/vh7xz5m2hw.png)
Until you have an empty cell to write your script within:
![lwrckeg0nt.png](https://img.esteem.ws/lwrckeg0nt.png)

* Now your jupyter editor is up you can start typing your code and run it by pressing **ctrl+enter**

#####   3. Dice Roller/ Python
Let us start talking about the prime dice roller implementation

* Primedice API URL is <code>https://api.primedice.com/graphql</code>
* HTTP Request Header should contain the account token
<code>**'x-access-token' : 'your prime dice account bet token'**</code>
* Post Request Data: 
e.g. to get the list of coins balances (operation name is Balances):
````
[{
	"operationName": "Balances",
	"variables": {
		"available": true
	},
	"query": "query Balances($available: Boolean = false, $vault: Boolean = false) {\\n  user {\\n    id\\n    balances {\\n      available @include(if: $available) {\\n        currency\\n        amount\\n        __typename\\n      }\\n      vault @include(if: $vault) {\\n        currency\\n        amount\\n        __typename\\n      }\\n      __typename\\n    }\\n    __typename\\n  }\\n}\\n"
}]
````

* Executing The API call in python 
e.g.
````
  # requests lib
  import requests
  
  # api url
  api = 'http://me.api.com'
  
  # http headers
  headers =  {
  	'content-type': 'application/json',
  	'x-access-token': '<token-access-keys>'
  }
  
  # http request post raw data
  data = '{ "param" : "value" }'
  
  # invoke api call and get the response
  response = requests.post('api url', headers= httpHeader, data= postData)
````

Now on the prepared python functions to use are:

* <code>def headers()</code>
within this function replace <token-access-keys> with your own keys
  
*  <code>def balance(coin) </code>
  call it to get the balance in Satoshi Units
  -- supported coins in primedice are btc, ltc, bch, doge, eth.
  -- e.g. <code> satoshis = balance('btc') </code>
  
* <code>def roll(amount, condition, target, coin)</code>
  call it to run a dice roll
  -- pass the amount in satoshis unit
  -- your bet target condition 'above' or 'below'
  -- your desired dice target number range ] 0, 100 [
  -- returns success (true or false), result (dice number result), payout (0 on loss, on win it is the total payout including the bet amount) 
  -- e.g. bet amount of 100 satoshis for a roll target above 70:
  <code>success, result, payout = roll(100, 'above', 70, 'btc')</code>

#### The End! 
Finally most of the steps are covered, it is your time to configure your own rules / algorithm that may give you your optimal winning payouts.
  
**Feel free** to share and list your own automation python bot script on the project github project page with your fresh good results for others to try ! πŸ˜ƒ
  
#### Related
- [My steemit announcement: primedice-python](https://steemit.com/primedice/@aro.steem/primedice-python)

#### Proof of Work Done
https://github.com/nnmix/py-primedice-bot/blob/master/main.py

πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 641 others
properties (23)
authoraro.steem
permlinkdice-roller-bot-python-primedice
categoryutopian-io
json_metadata{"community":"busy","app":"busy/2.5.6","format":"markdown","tags":["utopian-io","tutorials","primedice-bot","python","busy"],"users":["include","aro.steem"],"links":["https://github.com/nnmix/py-primedice-bot","https://primedice.com/","https://jupyter.org/","https://jupyter.org/try","https://jupyter.org/install.html","https://steemit.com/primedice/@aro.steem/primedice-python","https://github.com/nnmix/py-primedice-bot/blob/master/main.py"],"image":["https://img.esteem.ws/e5pgwm318g.gif","https://img.esteem.ws/c0p4o64haw.png","https://img.esteem.ws/vh7xz5m2hw.png","https://img.esteem.ws/lwrckeg0nt.png"]}
created2019-02-17 11:38:21
last_update2019-02-17 15:26:18
depth0
children7
last_payout2019-02-24 11:38:21
cashout_time1969-12-31 23:59:59
total_payout_value7.024 HBD
curator_payout_value2.062 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4,670
author_reputation13,589,686,925,958
root_title"πŸ€– Dice Roller Bot / Python / Primedice 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id79,994,973
net_rshares17,488,154,728,609
author_curate_reward""
vote details (705)
@portugalcoin ·
$13.16
Thank you for your contribution @aro.steem.
After reviewing your tutorial we suggest the following points listed below:

- Your tutorial is quite short for a good tutorial. We recommend you aim for capturing at least 2-3 concepts.

- We suggest that in the next tutorial detail plus what you are explaining.

- Using GIFs to show results is definitely better than standard still images.

Thank you for your work in developing this tutorial.
Looking forward to your upcoming tutorials.

Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/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](https://review.utopian.io/result/8/3-3-3-3-3-3-1-3-).

---- 
Need help? Chat with us on [Discord](https://discord.gg/uTyJkNm).

[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  , , , , , , , , , , , , , , , ,
properties (23)
authorportugalcoin
permlinkre-arosteem-dice-roller-bot-python-primedice-20190217t192309635z
categoryutopian-io
json_metadata{"tags":[null],"users":["aro.steem"],"links":["https://join.utopian.io/guidelines","https://review.utopian.io/result/8/3-3-3-3-3-3-1-3-","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2019-02-17 19:23:09
last_update2019-02-17 19:23:09
depth1
children2
last_payout2019-02-24 19:23:09
cashout_time1969-12-31 23:59:59
total_payout_value9.982 HBD
curator_payout_value3.181 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length936
author_reputation599,460,462,895,094
root_title"πŸ€– Dice Roller Bot / Python / Primedice 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,012,401
net_rshares25,057,962,526,964
author_curate_reward""
vote details (17)
@aro.steem ·
Hi @portugalcoin,
Thank you for your advices, push and boost.
Actually yes thats my first tutorial here and it is more like a quicky, i hope next times i will develop and expend it more. Cheers 🍻
properties (22)
authoraro.steem
permlinkre-portugalcoin-re-arosteem-dice-roller-bot-python-primedice-20190217t194643540z
categoryutopian-io
json_metadata{"community":"busy","app":"busy/2.5.6","format":"markdown","tags":["utopian-io"],"users":["portugalcoin"],"links":["/@portugalcoin"],"image":[]}
created2019-02-17 19:46:48
last_update2019-02-17 19:46:48
depth2
children0
last_payout2019-02-24 19:46:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length195
author_reputation13,589,686,925,958
root_title"πŸ€– Dice Roller Bot / Python / Primedice 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,013,310
net_rshares0
@utopian-io ·
Thank you for your review, @portugalcoin! Keep up the good work!
properties (22)
authorutopian-io
permlinkre-re-arosteem-dice-roller-bot-python-primedice-20190217t192309635z-20190220t040655z
categoryutopian-io
json_metadata"{"app": "beem/0.20.17"}"
created2019-02-20 04:06:57
last_update2019-02-20 04:06:57
depth2
children0
last_payout2019-02-27 04:06:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length64
author_reputation152,955,367,999,756
root_title"πŸ€– Dice Roller Bot / Python / Primedice 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,128,400
net_rshares0
@steem-ua ·
$0.04
#### Hi @aro.steem!

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](https://discord.gg/KpBNYGz)**
πŸ‘  
properties (23)
authorsteem-ua
permlinkre-dice-roller-bot-python-primedice-20190217t195513z
categoryutopian-io
json_metadata"{"app": "beem/0.20.18"}"
created2019-02-17 19:55:15
last_update2019-02-17 19:55:15
depth1
children1
last_payout2019-02-24 19:55:15
cashout_time1969-12-31 23:59:59
total_payout_value0.028 HBD
curator_payout_value0.009 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length288
author_reputation23,214,230,978,060
root_title"πŸ€– Dice Roller Bot / Python / Primedice 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,013,639
net_rshares72,529,940,625
author_curate_reward""
vote details (1)
@aro.steem ·
thank you very much @steem-ua, i will join the discord server soon πŸ™‚
properties (22)
authoraro.steem
permlinkre-steem-ua-re-dice-roller-bot-python-primedice-20190217t195513z-20190217t222350494z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["steem-ua"],"app":"steemit/0.1"}
created2019-02-17 22:23:51
last_update2019-02-17 22:23:51
depth2
children0
last_payout2019-02-24 22:23:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length68
author_reputation13,589,686,925,958
root_title"πŸ€– Dice Roller Bot / Python / Primedice 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,018,786
net_rshares0
@utopian-io ·
$0.04
Hey, @aro.steem!

**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](https://chrome.google.com/webstore/detail/steemplus/mjbkjgcplmaneajhcbegoffkedeankaj?hl=en) or [Steeditor](https://steeditor.app)).

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href='https://steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
πŸ‘  
properties (23)
authorutopian-io
permlinkre-dice-roller-bot-python-primedice-20190218t043655z
categoryutopian-io
json_metadata"{"app": "beem/0.20.17"}"
created2019-02-18 04:36:57
last_update2019-02-18 04:36:57
depth1
children1
last_payout2019-02-25 04:36:57
cashout_time1969-12-31 23:59:59
total_payout_value0.028 HBD
curator_payout_value0.009 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length591
author_reputation152,955,367,999,756
root_title"πŸ€– Dice Roller Bot / Python / Primedice 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,030,233
net_rshares71,338,052,999
author_curate_reward""
vote details (1)
@aro.steem ·
thank you @utopian-io for all your works and efforts.
Witness Upvoted 🍺
https://steemd.com/tx/ed6c7f522e1b65fb5b2c0b6c32a474cc12b9c0e1
properties (22)
authoraro.steem
permlinkre-utopian-io-re-dice-roller-bot-python-primedice-20190218t043655z-20190218t072629299z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["utopian-io"],"links":["https://steemd.com/tx/ed6c7f522e1b65fb5b2c0b6c32a474cc12b9c0e1"],"app":"steemit/0.1"}
created2019-02-18 07:26:30
last_update2019-02-18 07:26:30
depth2
children0
last_payout2019-02-25 07:26:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length134
author_reputation13,589,686,925,958
root_title"πŸ€– Dice Roller Bot / Python / Primedice 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,035,149
net_rshares0