42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
import requests
|
|
from py_clob_client.client import ClobClient
|
|
import os
|
|
from dotenv import load_dotenv
|
|
|
|
### Functions ###
|
|
def check_geoblock() -> None:
|
|
response = requests.get("https://polymarket.com/api/geoblock")
|
|
geo = response.json()
|
|
if geo["blocked"]:
|
|
print(f"Trading not available in {geo['country']}")
|
|
raise ValueError('GEOBLOCKED - KILLING SCRIPT')
|
|
else:
|
|
print("Trading available")
|
|
|
|
def create_client():
|
|
print('creating client...')
|
|
load_dotenv()
|
|
private_key = os.getenv("PRIVATE_KEY")
|
|
host = "https://clob.polymarket.com"
|
|
chain_id = 137 # Polygon mainnet
|
|
|
|
temp_client = ClobClient(host, key=private_key, chain_id=chain_id)
|
|
api_creds = temp_client.create_or_derive_api_creds()
|
|
|
|
client = ClobClient(
|
|
host,
|
|
key=private_key,
|
|
chain_id=chain_id,
|
|
creds=api_creds,
|
|
signature_type=2, # Rabby
|
|
funder=os.getenv("FUNDER")
|
|
# funder="0xb2967A7e578E700E27611238B7F762BdADC72CcB"
|
|
# 0x2bb5be619b8f348954dd2290abcd267735a9f4a0
|
|
|
|
)
|
|
# View your trade history
|
|
trades = client.get_trades()
|
|
print(f"You've made {len(trades)} trades")
|
|
print('client created successfully!')
|
|
|
|
return client |