Bitcoin Forum
June 21, 2024, 09:40:58 AM *
News: Voting for pizza day contest
 
   Home   Help Search Login Register More  
Pages: [1] 2 3 »  All
  Print  
Author Topic: scripting primedice --- getting started  (Read 4778 times)
tspacepilot (OP)
Legendary
*
Offline Offline

Activity: 1456
Merit: 1078


I may write code in exchange for bitcoins.


View Profile
April 23, 2015, 05:45:11 PM
 #1

This thread is just to give folks interested in scripting primedice's api a little help to get off the ground and going.  I'm just showing a few shell scripts I've used to log in and send bets etc.  These are expected to be run on a UNIX like machine with grep, sed, curl.

So, first thing you have to do is login and get your access token.  Here's a little script that logs you in and saves your token in a file called "token".  Use this script with your actual password and username as arg1 and arg2:

Code:
#!/bin/bash
#
# log into PD, return access_token
curl -X POST --data "username=$1&password=$2" https://api.primedice.com/api/login 2>/dev/null | sed -e 's/.*access_token":"\(.*\)"}/\1/' > token

cat token

All this does is use curl to POST your login and then filters the output with sed.  The last line just prints the token to STDOUT in case that's useful for another program that calls this.

I'll show you guys one more, you can use this to send a bet using three args, the amount, the target number, and up or down ("<",">").  Note that because < and > are shell redirects for filedescriptors, you'll have to enclose the up/down in quotes.  This is the script:

Code:
#!/bin/bash

amount=$1
target=$2
condition=$3

token=`cat token`

curl -X POST --data "amount=$amount&target=$target&condition=$condition" https://api.primedice.com/api/bet?access_token=$token 2>/dev/null  | sed -e 's/.*"win":\(true\|false\).*/\1/'

Again, the assumption here is that you ran 'login' already and have your access token stored in a file called 'token'.  The script prints out "true" if you won and "false" if you lost.

These basic scripts aren't really even scripts.  They're just one liners to do the work of forumlating the curl command for you and keeping track of your access token.  I've used them to write some betting algorithms in perl.  I don't want to get too far into this, but some folks have asked me via pm for help in this so I thought this might get them started.  If you wanted to write a true bot then you'd want to do something more than use sed to filter all the output from a particular request, you'd want to use a json parser and keep track of all the data that comes back each time and update your local record accordingly.  The idea here is just to get you started if you want to play around with the api but need a few examples to get going.

Hope this helps you guys!  Have fun and safe betting!

EDIT: Realized that I should say that to use this code you'd probably want to cut-n-paste the lines into a file and then save it and make it executable.  For example, if you called my login script "login" then you'd say:

Code:
$ chmod 755 login

And after that you could run it with:

Code:
$ ./login MYUSERNAME MYPASSWORD

And similarly with the "bet" script, save it, make it executable, and call it with three args:

Code:
$ ./bet 10 50 "<"

^^ that's a bet of 10 satoshis on under 50.

Bitcoinerist
Member
**
Offline Offline

Activity: 70
Merit: 10

Loan me, 1-5% interest :P Moooooo


View Profile
June 18, 2015, 01:17:24 AM
 #2

Thank you for writing this and teaching this to everyone! It cleared some things up!

Cows are nice Tongue Gotta love them #MooMooDude COWS!
xiionqz
Member
**
Offline Offline

Activity: 70
Merit: 10


View Profile
June 18, 2015, 01:27:24 AM
 #3

thanks man  Grin
tspacepilot (OP)
Legendary
*
Offline Offline

Activity: 1456
Merit: 1078


I may write code in exchange for bitcoins.


View Profile
June 18, 2015, 02:43:42 AM
 #4

Glad you guys liked it.  Feel free to PM me if you want more help or just reply in this thread.  I'm glad someone found this useful Smiley
bitllionaire
Legendary
*
Offline Offline

Activity: 1120
Merit: 1000


View Profile
June 18, 2015, 02:46:48 AM
 #5

It's really cool
What uses do you think it is interesting to use the primedice api?
tspacepilot (OP)
Legendary
*
Offline Offline

Activity: 1456
Merit: 1078


I may write code in exchange for bitcoins.


View Profile
June 18, 2015, 05:28:52 AM
 #6

bitllionaire:  at least for me, it's useful because I don't have to hit "click, click, click" until my wrist wears out.  And I don't have to load the chat if I'm not interested in it (sometime's I'm intersted in it and you can use the API to chat as well, if you're interested, I can show you guys how).  Basically using a script lets you take advantage of your computer to use primedice as you want to.  I think the most obvious thing is to do autobetting with a more complicated pattern than the simple autobet functionality on the website, when you're using the api and a script, you can do whatever you would do using clicks but faster and with less effort.

Anyway, you guys tell me how you've used it.  You said it was cool, what did you use it for?
raitpngman
Newbie
*
Offline Offline

Activity: 50
Merit: 0


View Profile
June 11, 2016, 05:34:53 AM
 #7

I've beat my head on this one and can' figure it out. How do I get the last 30 bets and send it to a file?
tspacepilot (OP)
Legendary
*
Offline Offline

Activity: 1456
Merit: 1078


I may write code in exchange for bitcoins.


View Profile
June 13, 2016, 09:24:25 PM
 #8

I've beat my head on this one and can' figure it out. How do I get the last 30 bets and send it to a file?

I haven't used primedice in over a year so I don't know if there have been any API changes which may be getting in your way.

What did you try?  How far did you get? What errors did you see?
greyhawk
Hero Member
*****
Offline Offline

Activity: 952
Merit: 1009


View Profile
June 13, 2016, 09:33:58 PM
 #9

Code:
#!/bin/bash
#
# log into PD, return access_token
curl -X POST --data "username=$1&password=$2" https://api.primedice.com/api/login 2>/dev/null | sed -e 's/.*access_token":"\(.*\)"}/\1/' > token

cat token

It is best practices not to accept passwords as a cli arg as the password will appear in your .bash_history file in plaintext.

It is better to prompt the user to enter the password like this:

Code:
#!/bin/bash
#
# log into PD, return access_token

read -p "Password:" password

curl -X POST --data "username=$1&password=$password" https://api.primedice.com/api/login 2>/dev/null | sed -e 's/.*access_token":"\(.*\)"}/\1/' > token

cat token

That way it won't appear in the .bash_history file, when you run "history" or if you keep pressing "up" in the terminal window to scroll through command history.
DarkThrones
Full Member
***
Offline Offline

Activity: 252
Merit: 100


View Profile
June 13, 2016, 09:44:35 PM
 #10

Is there a way to make a script only bet if it sees certain conditions met? That's the only thing about a script I would be interested in. If you could help me understand that would be awesome.
raitpngman
Newbie
*
Offline Offline

Activity: 50
Merit: 0


View Profile
June 13, 2016, 11:11:13 PM
 #11

Is there a way to make a script only bet if it sees certain conditions met? That's the only thing about a script I would be interested in. If you could help me understand that would be awesome.

No problem. You can use counters, loops (while,for), and conditional statements (if, elseif, else). It gets a little like spaghetti if things get complicated, but you can make it work.
raitpngman
Newbie
*
Offline Offline

Activity: 50
Merit: 0


View Profile
June 13, 2016, 11:16:06 PM
 #12

I haven't used primedice in over a year so I don't know if there have been any API changes which may be getting in your way.

What did you try?  How far did you get? What errors did you see?

result=$(curl -X GET https://api.primedice.com/api/mybets?access_token=$token)

I called the api and it returned something. When I look in the variable or send the output to a file, it shows something like "mybets[]" I don't know if this is an empty array or I need to pass another variable to the api in the call or if the information is contained in the variable. I've tried to iterate through the array (but I'm new at scripting, google is a friend) but am unable to get anywhere.
raitpngman
Newbie
*
Offline Offline

Activity: 50
Merit: 0


View Profile
June 13, 2016, 11:17:51 PM
 #13

Is there a way to make a script only bet if it sees certain conditions met? That's the only thing about a script I would be interested in. If you could help me understand that would be awesome.

An example

while [ $better -le 60000 ]
do
result=$(curl -X POST --data "amount=$better&target=$target&condition=$condition" https://api.primedice.com/api/bet?access_token=$token 2>/dev/null | sed -e 's/.*"win":\(true\|false\).*/\1/')

echo
echo "$counter bet = $better"
echo "result = $result"

if [ "$result" = "true" ]; then
   let better=$amount
elif [ "$result" = "false" ]; then
   let better=$(($better * 10))
else
   break
fi


let counter=$counter+1
done
DarkThrones
Full Member
***
Offline Offline

Activity: 252
Merit: 100


View Profile
June 14, 2016, 01:57:33 AM
 #14

Is there a way to make a script only bet if it sees certain conditions met? That's the only thing about a script I would be interested in. If you could help me understand that would be awesome.

An example

while [ $better -le 60000 ]
do
result=$(curl -X POST --data "amount=$better&target=$target&condition=$condition" https://api.primedice.com/api/bet?access_token=$token 2>/dev/null | sed -e 's/.*"win":\(true\|false\).*/\1/')

echo
echo "$counter bet = $better"
echo "result = $result"

if [ "$result" = "true" ]; then
   let better=$amount
elif [ "$result" = "false" ]; then
   let better=$(($better * 10))
else
   break
fi


let counter=$counter+1
done
Unfortunately you lost me. Or else I would be able to make the world's only profitable dicing script. It's fairly obvious what has to be done.
raitpngman
Newbie
*
Offline Offline

Activity: 50
Merit: 0


View Profile
June 14, 2016, 03:15:44 AM
 #15


Unfortunately you lost me. Or else I would be able to make the world's only profitable dicing script. It's fairly obvious what has to be done.

Basically, you bet 0 and record the results until you get the results you want. Then you bet what you want. When you are done betting rest the variables and bet 0 again.

The example was to help you with assigning variables, loops, and if/then statements.

"Or else I would be able to make the world's only profitable dicing script."
LOL, it is fairly elusive. I think I've actually made a profitable dicing script, but the return is abysmal. I'm better off throwing my money in the betting pool and taking other people's money.
tspacepilot (OP)
Legendary
*
Offline Offline

Activity: 1456
Merit: 1078


I may write code in exchange for bitcoins.


View Profile
June 28, 2016, 03:10:01 PM
 #16

"Or else I would be able to make the world's only profitable dicing script."
LOL, it is fairly elusive. I think I've actually made a profitable dicing script, but the return is abysmal. I'm better off throwing my money in the betting pool and taking other people's money.

A couple of things. 

1) I haven't used primedice in years.  It's possible that the API has changed and that the scripts in the OP no longer work.
2) As far as I know, if you've actually made a "profitable" dicing script, then what's happened is that you've been lucky.  Assuming you're playing against a fair house with a house edge, it should be mathematically impossible to guarantee a profit.  If you've got one, then you're just in a situation where you haven't yet converged to your estimated long-run return.
Daffadile
Hero Member
*****
Offline Offline

Activity: 1162
Merit: 500

CryptoTalk.Org - Get Paid for every Post!


View Profile WWW
June 28, 2016, 06:29:27 PM
 #17

Why make this bot script ? You know it won't help or is it just for fun like a challenge. It also needs your password and username isn't that a security risk ?

 
                                . ██████████.
                              .████████████████.
                           .██████████████████████.
                        -█████████████████████████████
                     .██████████████████████████████████.
                  -█████████████████████████████████████████
               -███████████████████████████████████████████████
           .-█████████████████████████████████████████████████████.
        .████████████████████████████████████████████████████████████
       .██████████████████████████████████████████████████████████████.
       .██████████████████████████████████████████████████████████████.
       ..████████████████████████████████████████████████████████████..
       .   .██████████████████████████████████████████████████████.
       .      .████████████████████████████████████████████████.

       .       .██████████████████████████████████████████████
       .    ██████████████████████████████████████████████████████
       .█████████████████████████████████████████████████████████████.
        .███████████████████████████████████████████████████████████
           .█████████████████████████████████████████████████████
              .████████████████████████████████████████████████
                   ████████████████████████████████████████
                      ██████████████████████████████████
                          ██████████████████████████
                             ████████████████████
                               ████████████████
                                   █████████
.YoBit AirDrop $.|.Get 700 YoDollars for Free!.🏆
seuntjie
Legendary
*
Offline Offline

Activity: 1717
Merit: 1125



View Profile WWW
June 29, 2016, 11:10:19 AM
 #18

Alternatively, you can use DiceBots programmer mode and concentrate solely on your betting system/strategy.

DiceBot handles all of the interactions with the websites (as it supports other sites as well). Check out these links to get started with DiceBots programmer mode and skip all of these manual API calls and things:

DiceBot: https://bot.seuntjie.com
Programmer Mode: https://bot.seuntjie.com/programmermode.aspx
Youtube tutorials: https://www.youtube.com/playlist?list=PLZH88mwZAXLxVtHpc3PIFamkiT1o2V3LX
Programmer Mode Thread: https://bitcointalk.org/index.php?topic=1114503

rianwarcil
Full Member
***
Offline Offline

Activity: 204
Merit: 100


View Profile
June 29, 2016, 11:24:45 AM
 #19

thanks before man Wink :*
tspacepilot (OP)
Legendary
*
Offline Offline

Activity: 1456
Merit: 1078


I may write code in exchange for bitcoins.


View Profile
June 29, 2016, 04:42:13 PM
 #20

Alternatively, you can use DiceBots programmer mode and concentrate solely on your betting system/strategy.

DiceBot handles all of the interactions with the websites (as it supports other sites as well). Check out these links to get started with DiceBots programmer mode and skip all of these manual API calls and things:

DiceBot: https://bot.seuntjie.com
Programmer Mode: https://bot.seuntjie.com/programmermode.aspx
Youtube tutorials: https://www.youtube.com/playlist?list=PLZH88mwZAXLxVtHpc3PIFamkiT1o2V3LX
Programmer Mode Thread: https://bitcointalk.org/index.php?topic=1114503

Thanks seuntjie,

I'm not really trying to compete with your dicebot here.  The point of this thread was just to offer up some scripting I was playing around with a few years ago in case anyone found it useful.  Clearly there are those that have done a complete job of this work and if your point is just to bet automatically, then that's probably the best way to go.  For me, playing around with scripts and coding is fun just for the education of it, so I'm often interested in a DIY approach even if it means that I wont end up getting as far as someone who's working full time on the job.

BTW, when I last tried to look into your dicebot stuff (again, I think this was years ago), I want to say that I ran into some roadblock.  I don't remember if it was that your stuff wasn't open source, or if it was just that your stuff is all in C#/.NET and there wasn't a reliable compiler on my system (GNU/Linux).
Pages: [1] 2 3 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!