HomeVideos

Placing Live Orders on Polymarket with our Trading Bot

Now Playing

Placing Live Orders on Polymarket with our Trading Bot

Transcript

262 segments

0:00

So I have put some of the code into a

0:03

new file here which is kind of just a

0:07

test to place actual orders because one

0:10

thing is you know um simulating placing

0:13

orders on the the order book but another

0:16

thing is actually doing it in in real

0:18

time. So what I've done now is I have uh

0:22

created an account on podium market and

0:24

added some cash. I added $5. Uh I think

0:27

this the portfolio is not correct. I

0:29

should have yeah I have uh $5 in in

0:32

portfolio just just for testing and

0:34

that's actually basically almost the

0:36

minimum amount you can trade for uh

0:38

especially through the the API.

0:41

So I just created a very simple uh bot

0:44

that kind of takes inspiration of

0:47

something we talked about before placing

0:49

like um hedged bets. So we place a bet

0:53

on both sides of up and down. So what I

0:56

did here, I created this uh this bot. I

0:58

just call it Raven, the Raven bot, and

1:01

it loads the the client with our um

1:05

information. So here we have to pass in

1:07

our private key. That's something you

1:08

generate over at Poly Market. So the way

1:11

it works is you create an account, then

1:14

you send over some USDC and uh over to

1:17

like a proxy wallet that has a private

1:20

key. So it's all in the blockchain

1:21

actually. And that private key you

1:23

should put into the to the bot.

1:26

Then we have a method to get the balance

1:28

allowance. That's basically how much

1:29

money we have to play for. And in this

1:31

case we have $5 or $5.09

1:34

uh dollar. And then I added a get best

1:38

price. So this is basically where we uh

1:40

we use the the client the poly market

1:42

client to get the best price of a

1:46

certain token.

1:48

And then I have done it with both

1:52

tokens. So I can pass in the slot of the

1:55

market. So in this case we can pass uh

1:58

this in here if you can see it up in the

2:00

URL. And then it gets the two tokens. So

2:04

that's a token for for buy and sorry for

2:06

up and down.

2:09

And um then we have a set set limit

2:14

order which basically just sets two

2:16

orders

2:18

like actually no in this case this just

2:20

set one order and it has some checks and

2:23

so it passes in the token ID the price

2:27

we want to put an order at the size and

2:29

the side so in our case it's the buy

2:32

side that we want the size is how many

2:35

shares and then the price for example if

2:36

you look at the order book here the

2:38

price could be uh 21 or 20 cents um for

2:43

for one of the sides

2:46

and then I have and this again this is

2:48

just for testing it's not an actual

2:50

trading algorithm or anything but I have

2:54

created a method which I call place

2:56

balance limit order where we try to

2:59

place limit orders um where the total

3:02

price is less than a dollar so in this

3:04

case it's 0.99

3:08

and then again it in one go it tries it

3:12

basically sets the limit orders and uh I

3:15

will test it with you guys so you can

3:17

see how it works how fast it how fast it

3:19

is and how yeah basically how it works

3:22

because this is kind of new to me and

3:23

it's good to just try it out with a

3:25

little bit money that we you know can

3:26

afford to lose so if I run it locally I

3:31

will actually not be able to place the

3:34

the bets and um

3:38

you cannot see my uh CLI. So if I just

3:41

do it like this. So basically what we

3:44

can do is we can get our

3:47

our command here and then I just pass in

3:50

this lock.

3:52

Let's say it's this market here. We have

3:53

about 8 minutes left and then I pass it

3:57

in.

4:02

Now you can see here that uh no orders

4:04

was uh submitted and in this case uh

4:07

actually this is because we have to put

4:10

a order on minimum one US dollar. So

4:12

there's some limitations through the

4:14

API. I don't know if it's specific to

4:15

this market but you need to place at

4:17

least five shares and at least one US

4:22

worth of uh of a of a you know a bet or

4:25

a trade. And in this case, we tried to

4:28

place five

4:31

um at a very low price, right? So the

4:33

total price in this case was uh

4:36

um $85.

4:38

So 85 cents and that's less than $1. So

4:40

that's why it rejects it. And uh if I

4:43

were to do it and it did not get this

4:45

error, it would actually say at at I'm

4:48

blocked because I'm on an IP address

4:50

that's not allowed on poly market. So

4:52

you can go to the

4:54

geographic restrictions and if you place

4:58

bets either through the platform or

5:01

through the API any of these country

5:03

codes

5:05

or regions then you will actually not be

5:08

able to do it and uh in that case you

5:12

need to do it through a proxy or you

5:16

need to use a VPN but what I've done is

5:19

and this is also what we're going to do

5:20

in production anyway when but is is

5:22

spinning up a digital ocean VPS on a

5:26

server that's actually allowed. So I

5:28

have created a server on uh Digital

5:31

Ocean or in in Amsterdam basically and

5:35

that's in Holland, right? And I can uh

5:39

log in and I have it here on a uh very

5:42

very basic Ubuntu server on Digital

5:44

Ocean. So that's uh the smallest droplet

5:47

you can get for about $4

5:50

uh per month.

5:52

And then what we can do is in my

5:54

environment here I can do a polyclient

5:57

if I can uh spell here poly client.py

6:01

and then I can pass in this lock here

6:04

for this event. Now this is actually I'm

6:06

not sure if we can trade this yet.

6:09

Let me just try see what happens. I

6:12

don't really know actually. So

6:16

all right so I think we actually got

6:18

order. Oh, you see here, I don't know if

6:20

you can see it.

6:22

So, now we actually have You can't see

6:24

it here.

6:27

I just placed the uh the orders here and

6:31

we have two orders here that has not

6:34

been filled yet. I guess that's kind of

6:35

risky, right? I wonder if I can cancel

6:37

them again. Let me just do that. Cancel

6:40

all

6:42

and then let's wait until the market

6:43

open. Okay, it does not update

6:45

automatically, I guess. Let me refresh

6:47

here one once.

6:48

So, are we just waiting now for the

6:50

price to beat or what? What what what's

6:51

what's going on here? Yeah, we still

6:54

don't have a price to beat.

6:57

All right. Well, let me uh let me put a

6:59

order here now. Um

7:02

and actually, I need to change the slot

7:04

here. So, I'll just take next market

7:05

here.

7:14

All right. You can see I put a

7:17

Yeah. So, this one actually uh is is

7:19

basically instant. This one already

7:21

bought at 50 cents, but this one is

7:23

still open. So, we have some risk here.

7:27

Let's see if it uh Oh, now we coming up

7:30

here. Now, we're coming up here. Now,

7:31

we're here at the the best price.

7:33

Basically, we just need someone to fill

7:35

it. Fill our five shares. Come on. No,

7:39

it's not filled. What? Come on. It's

7:41

five shares.

7:43

We still don't have a price to beat.

7:45

Why? Why not?

7:48

That's kind of weird, isn't it? We don't

7:50

have a price to beat in an active

7:52

market. Is it just my browser that's

7:54

broken or all right? I don't know. But,

7:57

uh, yeah. So, um, our order here is

7:59

still not filled. So, this is a very

8:01

good example of how this strategy

8:03

actually don't work, right? Like again

8:05

if I can just reiterate basically I just

8:08

did a um a place a balance limit order

8:11

where the total price of the the limit

8:15

order was 0.99

8:17

and uh and this is the risk we h we have

8:19

to figure out right and and why this

8:22

basically doesn't work just like I did

8:24

now is because well maybe one of the

8:26

orders doesn't get filled which is the

8:28

case here now right so um I might

8:31

actually lose all of this right so we'll

8:33

Okay, it's it's it's a risk I'm willing

8:36

to take for this for this, you know,

8:38

lesson. I would also just cancel it, I

8:40

guess. And this is also something we can

8:43

build into the to the bot like

8:46

like if it's not it's not filled within

8:48

like I don't know 10 seconds or

8:50

something, then we cancel it. Maybe or

8:53

maybe we put a uh a bit a little bit

8:55

higher just to um close the gap to not

8:59

have any um

9:02

have any risk. Our order is very far

9:05

down the order book now. Our 49 cent

9:08

order here.

9:10

Oh, look at this now. Hey, hey, hey,

9:12

hey, hey.

9:14

No, it's not filled yet.

9:18

Where's my order?

9:22

Ah, here. Yeah, yeah, yeah. Okay, it

9:24

filled now.

9:26

So, look at this. How is what's going on

9:28

here?

9:30

And the price moved down a little bit

9:31

here. Oh, that's interesting. What? I

9:35

don't get it now. History. So, my

9:40

I did buy it 40 seconds ago. Okay, we

9:44

did get it. That's actually pretty

9:45

lucky, right? So I

9:49

got it at 49 but now actually price is

9:52

38.

9:55

Let me just update here. See if we have

9:58

our Yeah, we have both positions now.

10:01

So you can see how now we are actually

10:03

in a profit because I was I managed to

10:06

get both positions at at those limit

10:08

orders. So they should have a 1% return.

10:11

But then again if we account for all the

10:13

fees that we are we are paying then

10:17

maybe not. At least now we tested that

10:20

we can place an order through the VPS on

10:24

Digital Ocean if our country is

10:27

restricted. So we can have our but fail

10:30

trades do limit orders and um that's all

10:33

cool and that's basically uh it for now.

10:36

Next step is kind of polishing it up and

10:39

um be able to feed in data. So, I'm

10:41

going to take some of the code I have on

10:43

the past bot I showed you, put it into

10:44

this new one, and kind of just make a

10:46

little bit more polished because the

10:48

other bot that I showed you,

10:51

uh, this but one here is just a cluster

10:53

of a lot of um, data, pictures,

10:57

trash, bitecoded code. We don't want

11:00

this in production. We want something

11:01

more clean, more nice. But this is kind

11:04

of our testing grounds and the things

11:07

that we like we're going to put it over

11:09

into our Raven uh bot over here which

11:14

I'm working on and hopefully it's

11:17

something I can share in the future. So

11:19

if there's some features, some ideas you

11:20

have, just leave a comment down below

11:22

and then I can maybe take a look, maybe

11:24

add some features if you have some

11:25

ideas. And um yeah, check in next time

11:29

and I think this is it for now. Have a

11:30

good one. Bye-bye.

Interactive Summary

Ask follow-up questions or revisit key timestamps.

The video demonstrates the process of setting up and testing a trading bot on a platform called Polymarket. The bot, named Raven, is designed to place hedged bets by betting on both sides of an outcome. The creator explains how to create an account, add funds, and use a private key to connect to the API. They encountered issues with minimum order values and geographic restrictions, leading them to use a DigitalOcean VPS in Amsterdam to bypass these limitations. The video showcases the bot placing limit orders, with some orders not filling immediately, highlighting the risks involved. Ultimately, the creator managed to get both positions filled, resulting in a profit, and plans to refine the bot by incorporating code from a previous project for a cleaner, production-ready version.

Suggested questions

4 ready-made prompts