Placing Live Orders on Polymarket with our Trading Bot
262 segments
So I have put some of the code into a
new file here which is kind of just a
test to place actual orders because one
thing is you know um simulating placing
orders on the the order book but another
thing is actually doing it in in real
time. So what I've done now is I have uh
created an account on podium market and
added some cash. I added $5. Uh I think
this the portfolio is not correct. I
should have yeah I have uh $5 in in
portfolio just just for testing and
that's actually basically almost the
minimum amount you can trade for uh
especially through the the API.
So I just created a very simple uh bot
that kind of takes inspiration of
something we talked about before placing
like um hedged bets. So we place a bet
on both sides of up and down. So what I
did here, I created this uh this bot. I
just call it Raven, the Raven bot, and
it loads the the client with our um
information. So here we have to pass in
our private key. That's something you
generate over at Poly Market. So the way
it works is you create an account, then
you send over some USDC and uh over to
like a proxy wallet that has a private
key. So it's all in the blockchain
actually. And that private key you
should put into the to the bot.
Then we have a method to get the balance
allowance. That's basically how much
money we have to play for. And in this
case we have $5 or $5.09
uh dollar. And then I added a get best
price. So this is basically where we uh
we use the the client the poly market
client to get the best price of a
certain token.
And then I have done it with both
tokens. So I can pass in the slot of the
market. So in this case we can pass uh
this in here if you can see it up in the
URL. And then it gets the two tokens. So
that's a token for for buy and sorry for
up and down.
And um then we have a set set limit
order which basically just sets two
orders
like actually no in this case this just
set one order and it has some checks and
so it passes in the token ID the price
we want to put an order at the size and
the side so in our case it's the buy
side that we want the size is how many
shares and then the price for example if
you look at the order book here the
price could be uh 21 or 20 cents um for
for one of the sides
and then I have and this again this is
just for testing it's not an actual
trading algorithm or anything but I have
created a method which I call place
balance limit order where we try to
place limit orders um where the total
price is less than a dollar so in this
case it's 0.99
and then again it in one go it tries it
basically sets the limit orders and uh I
will test it with you guys so you can
see how it works how fast it how fast it
is and how yeah basically how it works
because this is kind of new to me and
it's good to just try it out with a
little bit money that we you know can
afford to lose so if I run it locally I
will actually not be able to place the
the bets and um
you cannot see my uh CLI. So if I just
do it like this. So basically what we
can do is we can get our
our command here and then I just pass in
this lock.
Let's say it's this market here. We have
about 8 minutes left and then I pass it
in.
Now you can see here that uh no orders
was uh submitted and in this case uh
actually this is because we have to put
a order on minimum one US dollar. So
there's some limitations through the
API. I don't know if it's specific to
this market but you need to place at
least five shares and at least one US
worth of uh of a of a you know a bet or
a trade. And in this case, we tried to
place five
um at a very low price, right? So the
total price in this case was uh
um $85.
So 85 cents and that's less than $1. So
that's why it rejects it. And uh if I
were to do it and it did not get this
error, it would actually say at at I'm
blocked because I'm on an IP address
that's not allowed on poly market. So
you can go to the
geographic restrictions and if you place
bets either through the platform or
through the API any of these country
codes
or regions then you will actually not be
able to do it and uh in that case you
need to do it through a proxy or you
need to use a VPN but what I've done is
and this is also what we're going to do
in production anyway when but is is
spinning up a digital ocean VPS on a
server that's actually allowed. So I
have created a server on uh Digital
Ocean or in in Amsterdam basically and
that's in Holland, right? And I can uh
log in and I have it here on a uh very
very basic Ubuntu server on Digital
Ocean. So that's uh the smallest droplet
you can get for about $4
uh per month.
And then what we can do is in my
environment here I can do a polyclient
if I can uh spell here poly client.py
and then I can pass in this lock here
for this event. Now this is actually I'm
not sure if we can trade this yet.
Let me just try see what happens. I
don't really know actually. So
all right so I think we actually got
order. Oh, you see here, I don't know if
you can see it.
So, now we actually have You can't see
it here.
I just placed the uh the orders here and
we have two orders here that has not
been filled yet. I guess that's kind of
risky, right? I wonder if I can cancel
them again. Let me just do that. Cancel
all
and then let's wait until the market
open. Okay, it does not update
automatically, I guess. Let me refresh
here one once.
So, are we just waiting now for the
price to beat or what? What what what's
what's going on here? Yeah, we still
don't have a price to beat.
All right. Well, let me uh let me put a
order here now. Um
and actually, I need to change the slot
here. So, I'll just take next market
here.
All right. You can see I put a
Yeah. So, this one actually uh is is
basically instant. This one already
bought at 50 cents, but this one is
still open. So, we have some risk here.
Let's see if it uh Oh, now we coming up
here. Now, we're coming up here. Now,
we're here at the the best price.
Basically, we just need someone to fill
it. Fill our five shares. Come on. No,
it's not filled. What? Come on. It's
five shares.
We still don't have a price to beat.
Why? Why not?
That's kind of weird, isn't it? We don't
have a price to beat in an active
market. Is it just my browser that's
broken or all right? I don't know. But,
uh, yeah. So, um, our order here is
still not filled. So, this is a very
good example of how this strategy
actually don't work, right? Like again
if I can just reiterate basically I just
did a um a place a balance limit order
where the total price of the the limit
order was 0.99
and uh and this is the risk we h we have
to figure out right and and why this
basically doesn't work just like I did
now is because well maybe one of the
orders doesn't get filled which is the
case here now right so um I might
actually lose all of this right so we'll
Okay, it's it's it's a risk I'm willing
to take for this for this, you know,
lesson. I would also just cancel it, I
guess. And this is also something we can
build into the to the bot like
like if it's not it's not filled within
like I don't know 10 seconds or
something, then we cancel it. Maybe or
maybe we put a uh a bit a little bit
higher just to um close the gap to not
have any um
have any risk. Our order is very far
down the order book now. Our 49 cent
order here.
Oh, look at this now. Hey, hey, hey,
hey, hey.
No, it's not filled yet.
Where's my order?
Ah, here. Yeah, yeah, yeah. Okay, it
filled now.
So, look at this. How is what's going on
here?
And the price moved down a little bit
here. Oh, that's interesting. What? I
don't get it now. History. So, my
I did buy it 40 seconds ago. Okay, we
did get it. That's actually pretty
lucky, right? So I
got it at 49 but now actually price is
38.
Let me just update here. See if we have
our Yeah, we have both positions now.
So you can see how now we are actually
in a profit because I was I managed to
get both positions at at those limit
orders. So they should have a 1% return.
But then again if we account for all the
fees that we are we are paying then
maybe not. At least now we tested that
we can place an order through the VPS on
Digital Ocean if our country is
restricted. So we can have our but fail
trades do limit orders and um that's all
cool and that's basically uh it for now.
Next step is kind of polishing it up and
um be able to feed in data. So, I'm
going to take some of the code I have on
the past bot I showed you, put it into
this new one, and kind of just make a
little bit more polished because the
other bot that I showed you,
uh, this but one here is just a cluster
of a lot of um, data, pictures,
trash, bitecoded code. We don't want
this in production. We want something
more clean, more nice. But this is kind
of our testing grounds and the things
that we like we're going to put it over
into our Raven uh bot over here which
I'm working on and hopefully it's
something I can share in the future. So
if there's some features, some ideas you
have, just leave a comment down below
and then I can maybe take a look, maybe
add some features if you have some
ideas. And um yeah, check in next time
and I think this is it for now. Have a
good one. Bye-bye.
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.
Videos recently processed by our community