Skip to content

Commit

Permalink
Merge pull request #78 from Polymarket/feat/market-orders
Browse files Browse the repository at this point in the history
Feat/market orders
  • Loading branch information
poly-rodr authored May 21, 2024
2 parents 990ec3a + ebdbf8a commit 916e94a
Show file tree
Hide file tree
Showing 28 changed files with 1,208 additions and 70 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ resp = client.create_and_post_order(OrderArgs(
price=0.50,
size=100.0,
side=BUY,
token_id="16678291189211314787145083999015737376658799626183230671758641503291735614088"
token_id="71321045679252212594626385532706912750332728571942532289631379312455583992563"
))

print(resp)
Expand Down
2 changes: 1 addition & 1 deletion examples/GTD_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def main():
price=0.50,
size=100.0,
side=BUY,
token_id="16678291189211314787145083999015737376658799626183230671758641503291735614088",
token_id="71321045679252212594626385532706912750332728571942532289631379312455583992563",
expiration="1000000000000",
)
signed_order = client.create_order(order_args)
Expand Down
4 changes: 2 additions & 2 deletions examples/get_balance_allowance.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def main():
yes = client.get_balance_allowance(
params=BalanceAllowanceParams(
asset_type=AssetType.CONDITIONAL,
token_id="1343197538147866997676250008839231694243646439454152539053893078719042421992",
token_id="52114319501245915516055106046884209969926127482827954674443846427813813222426",
)
)
print(yes)

no = client.get_balance_allowance(
params=BalanceAllowanceParams(
asset_type=AssetType.CONDITIONAL,
token_id="16678291189211314787145083999015737376658799626183230671758641503291735614088",
token_id="71321045679252212594626385532706912750332728571942532289631379312455583992563",
)
)
print(no)
Expand Down
2 changes: 1 addition & 1 deletion examples/get_last_trade_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def main():
client = ClobClient(host, key=key, chain_id=chain_id)

resp = client.get_last_trade_price(
"16678291189211314787145083999015737376658799626183230671758641503291735614088"
"71321045679252212594626385532706912750332728571942532289631379312455583992563"
)
pprint(resp)
print("Done!")
Expand Down
4 changes: 2 additions & 2 deletions examples/get_last_trades_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def main():
resp = client.get_last_trades_prices(
params=[
BookParams(
token_id="16678291189211314787145083999015737376658799626183230671758641503291735614088"
token_id="71321045679252212594626385532706912750332728571942532289631379312455583992563"
),
BookParams(
token_id="1343197538147866997676250008839231694243646439454152539053893078719042421992"
token_id="52114319501245915516055106046884209969926127482827954674443846427813813222426"
),
]
)
Expand Down
2 changes: 1 addition & 1 deletion examples/get_mid_market_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def main():
client = ClobClient(host, key=key, chain_id=chain_id, creds=creds)

resp = client.get_midpoint(
"16678291189211314787145083999015737376658799626183230671758641503291735614088"
"71321045679252212594626385532706912750332728571942532289631379312455583992563"
)
# {'mid': '0.55'}
print(resp)
Expand Down
4 changes: 2 additions & 2 deletions examples/get_mid_markets_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def main():
resp = client.get_midpoints(
params=[
BookParams(
token_id="16678291189211314787145083999015737376658799626183230671758641503291735614088"
token_id="71321045679252212594626385532706912750332728571942532289631379312455583992563"
),
BookParams(
token_id="1343197538147866997676250008839231694243646439454152539053893078719042421992"
token_id="52114319501245915516055106046884209969926127482827954674443846427813813222426"
),
]
)
Expand Down
2 changes: 1 addition & 1 deletion examples/get_order.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from py_clob_client.client import ClobClient
from py_clob_client.clob_types import ApiCreds, FilterParams
from py_clob_client.clob_types import ApiCreds
from dotenv import load_dotenv
from py_clob_client.constants import AMOY

Expand Down
2 changes: 1 addition & 1 deletion examples/get_orderbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def main():
client = ClobClient(host)

orderbook = client.get_order_book(
"16678291189211314787145083999015737376658799626183230671758641503291735614088"
"71321045679252212594626385532706912750332728571942532289631379312455583992563"
)
print("orderbook", orderbook)

Expand Down
23 changes: 23 additions & 0 deletions examples/get_orderbooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from py_clob_client.client import ClobClient
from py_clob_client.clob_types import BookParams


def main():
host = "http://localhost:8080"
client = ClobClient(host)

resp = client.get_order_books(
params=[
BookParams(
token_id="71321045679252212594626385532706912750332728571942532289631379312455583992563"
),
BookParams(
token_id="52114319501245915516055106046884209969926127482827954674443846427813813222426"
),
]
)
print(resp)
print("Done!")


main()
6 changes: 3 additions & 3 deletions examples/get_orders.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from py_clob_client.client import ClobClient
from py_clob_client.clob_types import ApiCreds, FilterParams
from py_clob_client.clob_types import ApiCreds, OpenOrderParams
from dotenv import load_dotenv
from py_clob_client.constants import AMOY

Expand All @@ -20,8 +20,8 @@ def main():
client = ClobClient(host, key=key, chain_id=chain_id, creds=creds)

resp = client.get_orders(
FilterParams(
market="16678291189211314787145083999015737376658799626183230671758641503291735614088",
OpenOrderParams(
market="71321045679252212594626385532706912750332728571942532289631379312455583992563",
)
)
print(resp)
Expand Down
17 changes: 17 additions & 0 deletions examples/get_price.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from py_clob_client.client import ClobClient
from py_clob_client.clob_types import BookParams


def main():
host = "http://localhost:8080"
client = ClobClient(host)

resp = client.get_price(
"71321045679252212594626385532706912750332728571942532289631379312455583992563",
"BUY",
)
print(resp)
print("Done!")


main()
33 changes: 33 additions & 0 deletions examples/get_prices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from py_clob_client.client import ClobClient
from py_clob_client.clob_types import BookParams


def main():
host = "http://localhost:8080"
client = ClobClient(host)

resp = client.get_prices(
params=[
BookParams(
token_id="71321045679252212594626385532706912750332728571942532289631379312455583992563",
side="BUY",
),
BookParams(
token_id="71321045679252212594626385532706912750332728571942532289631379312455583992563",
side="SELL",
),
BookParams(
token_id="52114319501245915516055106046884209969926127482827954674443846427813813222426",
side="BUY",
),
BookParams(
token_id="52114319501245915516055106046884209969926127482827954674443846427813813222426",
side="SELL",
),
]
)
print(resp)
print("Done!")


main()
30 changes: 30 additions & 0 deletions examples/get_spread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os

from py_clob_client.client import ClobClient
from py_clob_client.clob_types import ApiCreds
from dotenv import load_dotenv
from py_clob_client.constants import AMOY


load_dotenv()


def main():
host = "http://localhost:8080"
key = os.getenv("PK")
creds = ApiCreds(
api_key=os.getenv("CLOB_API_KEY"),
api_secret=os.getenv("CLOB_SECRET"),
api_passphrase=os.getenv("CLOB_PASS_PHRASE"),
)
chain_id = AMOY
client = ClobClient(host, key=key, chain_id=chain_id, creds=creds)

resp = client.get_spread(
"71321045679252212594626385532706912750332728571942532289631379312455583992563"
)
print(resp)
print("Done!")


main()
23 changes: 23 additions & 0 deletions examples/get_spreads.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from py_clob_client.client import ClobClient
from py_clob_client.clob_types import BookParams


def main():
host = "http://localhost:8080"
client = ClobClient(host)

resp = client.get_spreads(
params=[
BookParams(
token_id="71321045679252212594626385532706912750332728571942532289631379312455583992563"
),
BookParams(
token_id="52114319501245915516055106046884209969926127482827954674443846427813813222426"
),
]
)
print(resp)
print("Done!")


main()
9 changes: 4 additions & 5 deletions examples/get_trades.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from py_clob_client.client import ClobClient
from py_clob_client.clob_types import ApiCreds, FilterParams
from py_clob_client.clob_types import ApiCreds, TradeParams
from dotenv import load_dotenv
from pprint import pprint

Expand All @@ -22,10 +22,9 @@ def main():
client = ClobClient(host, key=key, chain_id=chain_id, creds=creds)

resp = client.get_trades(
FilterParams(
limit=1,
taker=client.get_address(),
market="16678291189211314787145083999015737376658799626183230671758641503291735614088",
TradeParams(
maker_address=client.get_address(),
market="0x5f65177b394277fd294cd75650044e32ba009a95022d88a0c1d565897d72f8f1",
)
)
pprint(resp)
Expand Down
34 changes: 34 additions & 0 deletions examples/market_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os

from py_clob_client.client import ClobClient
from py_clob_client.clob_types import ApiCreds, MarketOrderArgs, OrderType
from dotenv import load_dotenv
from py_clob_client.constants import AMOY


load_dotenv()


def main():
host = "http://localhost:8080"
key = os.getenv("PK")
creds = ApiCreds(
api_key=os.getenv("CLOB_API_KEY"),
api_secret=os.getenv("CLOB_SECRET"),
api_passphrase=os.getenv("CLOB_PASS_PHRASE"),
)
chain_id = AMOY
client = ClobClient(host, key=key, chain_id=chain_id, creds=creds)

# create a market buy order for the equivalent of 100 USDC at the market price
order_args = MarketOrderArgs(
token_id="71321045679252212594626385532706912750332728571942532289631379312455583992563",
amount=100,
)
signed_order = client.create_market_order(order_args)
resp = client.post_order(signed_order, orderType=OrderType.FOK)
print(resp)
print("Done!")


main()
2 changes: 1 addition & 1 deletion examples/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def main():
price=0.0005,
size=20,
side=BUY,
token_id="16678291189211314787145083999015737376658799626183230671758641503291735614088",
token_id="71321045679252212594626385532706912750332728571942532289631379312455583992563",
)
signed_order = client.create_order(order_args)
resp = client.post_order(signed_order)
Expand Down
Loading

0 comments on commit 916e94a

Please sign in to comment.