Use UV for better package management
This commit is contained in:
@@ -24,22 +24,62 @@ The repository consists of several interconnected modules:
|
|||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- Python 3.9 with latest setuptools
|
- Python 3.9.10 or higher
|
||||||
- Node.js (for poly_merger)
|
- Node.js (for poly_merger)
|
||||||
- Google Sheets API credentials
|
- Google Sheets API credentials
|
||||||
- Polymarket account and API credentials
|
- Polymarket account and API credentials
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
1. **Clone the repository**:
|
This project uses UV for fast, reliable package management.
|
||||||
|
|
||||||
|
### Install UV
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# macOS/Linux
|
||||||
|
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||||
|
|
||||||
|
# Windows
|
||||||
|
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
|
||||||
|
|
||||||
|
# Or with pip
|
||||||
|
pip install uv
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Install Dependencies
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install all dependencies
|
||||||
|
uv sync
|
||||||
|
|
||||||
|
# Install with development dependencies (black, pytest)
|
||||||
|
uv sync --extra dev
|
||||||
|
```
|
||||||
|
|
||||||
|
### Quick Start
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Run the market maker (recommended)
|
||||||
|
uv run python main.py
|
||||||
|
|
||||||
|
# Update market data
|
||||||
|
uv run python update_markets.py
|
||||||
|
|
||||||
|
# Update statistics
|
||||||
|
uv run python update_stats.py
|
||||||
|
```
|
||||||
|
|
||||||
|
### Setup Steps
|
||||||
|
|
||||||
|
1. **Clone the repository**:
|
||||||
|
```bash
|
||||||
git clone https://github.com/yourusername/poly-maker.git
|
git clone https://github.com/yourusername/poly-maker.git
|
||||||
cd poly-maker
|
cd poly-maker
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **Install Python dependencies**:
|
2. **Install Python dependencies**:
|
||||||
```
|
```bash
|
||||||
pip install -r requirements.txt
|
uv sync
|
||||||
```
|
```
|
||||||
|
|
||||||
3. **Install Node.js dependencies for the merger**:
|
3. **Install Node.js dependencies for the merger**:
|
||||||
@@ -67,14 +107,14 @@ Make sure your wallet has done at least one trade thru the UI so that the permis
|
|||||||
- Update `SPREADSHEET_URL` in your `.env` file
|
- Update `SPREADSHEET_URL` in your `.env` file
|
||||||
|
|
||||||
7. **Update market data**:
|
7. **Update market data**:
|
||||||
- Run `python update_markets.py` to fetch all available markets
|
- Run `uv run python update_markets.py` to fetch all available markets
|
||||||
- This should run continuously in the background (preferably on a different IP than your trading bot)
|
- This should run continuously in the background (preferably on a different IP than your trading bot)
|
||||||
- Add markets you want to trade to the "Selected Markets" sheet. You'd wanna select markets from the "Volatility Markets" sheet.
|
- Add markets you want to trade to the "Selected Markets" sheet. You'd wanna select markets from the "Volatility Markets" sheet.
|
||||||
- Configure corresponding parameters in the "Hyperparameters" sheet. Default parameters that worked well in November are there.
|
- Configure corresponding parameters in the "Hyperparameters" sheet. Default parameters that worked well in November are there.
|
||||||
|
|
||||||
8. **Start the market making bot**:
|
8. **Start the market making bot**:
|
||||||
```
|
```bash
|
||||||
python main.py
|
uv run python main.py
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from py_clob_client.clob_types import OrderArgs, BalanceAllowanceParams, AssetTy
|
|||||||
from py_clob_client.order_builder.constants import BUY
|
from py_clob_client.order_builder.constants import BUY
|
||||||
|
|
||||||
from web3 import Web3
|
from web3 import Web3
|
||||||
from web3.middleware import geth_poa_middleware
|
from web3.middleware import ExtraDataToPOAMiddleware
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
@@ -41,8 +41,8 @@ def get_clob_client():
|
|||||||
|
|
||||||
def approveContracts():
|
def approveContracts():
|
||||||
web3 = Web3(Web3.HTTPProvider("https://polygon-rpc.com"))
|
web3 = Web3(Web3.HTTPProvider("https://polygon-rpc.com"))
|
||||||
web3.middleware_onion.inject(geth_poa_middleware, layer=0)
|
web3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)
|
||||||
wallet = web3.eth.account.privateKeyToAccount(os.getenv("PK"))
|
wallet = web3.eth.account.from_key(os.getenv("PK"))
|
||||||
|
|
||||||
|
|
||||||
with open('erc20ABI.json', 'r') as file:
|
with open('erc20ABI.json', 'r') as file:
|
||||||
@@ -56,7 +56,7 @@ def approveContracts():
|
|||||||
|
|
||||||
|
|
||||||
for address in ['0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E', '0xC5d563A36AE78145C45a50134d48A1215220f80a', '0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296']:
|
for address in ['0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E', '0xC5d563A36AE78145C45a50134d48A1215220f80a', '0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296']:
|
||||||
usdc_nonce = web3.eth.getTransactionCount( wallet.address )
|
usdc_nonce = web3.eth.get_transaction_count( wallet.address )
|
||||||
raw_usdc_txn = usdc_contract.functions.approve(address, int(MAX_INT, 0)).build_transaction({
|
raw_usdc_txn = usdc_contract.functions.approve(address, int(MAX_INT, 0)).build_transaction({
|
||||||
"chainId": 137,
|
"chainId": 137,
|
||||||
"from": wallet.address,
|
"from": wallet.address,
|
||||||
@@ -69,41 +69,41 @@ def approveContracts():
|
|||||||
print(f'USDC Transaction for {address} returned {usdc_tx_receipt}')
|
print(f'USDC Transaction for {address} returned {usdc_tx_receipt}')
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
ctf_nonce = web3.eth.getTransactionCount( wallet.address )
|
ctf_nonce = web3.eth.get_transaction_count( wallet.address )
|
||||||
|
|
||||||
raw_ctf_approval_txn = ctf_contract.functions.setApprovalForAll(address, True).buildTransaction({
|
raw_ctf_approval_txn = ctf_contract.functions.setApprovalForAll(address, True).build_transaction({
|
||||||
"chainId": 137,
|
"chainId": 137,
|
||||||
"from": wallet.address,
|
"from": wallet.address,
|
||||||
"nonce": ctf_nonce
|
"nonce": ctf_nonce
|
||||||
})
|
})
|
||||||
|
|
||||||
signed_ctf_approval_tx = web3.eth.account.sign_transaction(raw_ctf_approval_txn, private_key=os.getenv("PK"))
|
signed_ctf_approval_tx = web3.eth.account.sign_transaction(raw_ctf_approval_txn, private_key=os.getenv("PK"))
|
||||||
send_ctf_approval_tx = web3.eth.send_raw_transaction(signed_ctf_approval_tx.rawTransaction)
|
send_ctf_approval_tx = web3.eth.send_raw_transaction(signed_ctf_approval_tx.raw_transaction)
|
||||||
ctf_approval_tx_receipt = web3.eth.wait_for_transaction_receipt(send_ctf_approval_tx, 600)
|
ctf_approval_tx_receipt = web3.eth.wait_for_transaction_receipt(send_ctf_approval_tx, 600)
|
||||||
|
|
||||||
print(f'CTF Transaction for {address} returned {ctf_approval_tx_receipt}')
|
print(f'CTF Transaction for {address} returned {ctf_approval_tx_receipt}')
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
nonce = web3.eth.getTransactionCount( wallet.address )
|
nonce = web3.eth.get_transaction_count( wallet.address )
|
||||||
raw_txn_2 = usdc_contract.functions.approve("0xC5d563A36AE78145C45a50134d48A1215220f80a", int(MAX_INT, 0)).build_transaction({
|
raw_txn_2 = usdc_contract.functions.approve("0xC5d563A36AE78145C45a50134d48A1215220f80a", int(MAX_INT, 0)).build_transaction({
|
||||||
"chainId": 137,
|
"chainId": 137,
|
||||||
"from": wallet.address,
|
"from": wallet.address,
|
||||||
"nonce": nonce
|
"nonce": nonce
|
||||||
})
|
})
|
||||||
signed_txn_2 = web3.eth.account.sign_transaction(raw_txn_2, private_key=os.getenv("PK"))
|
signed_txn_2 = web3.eth.account.sign_transaction(raw_txn_2, private_key=os.getenv("PK"))
|
||||||
send_txn_2 = web3.eth.send_raw_transaction(signed_txn_2.rawTransaction)
|
send_txn_2 = web3.eth.send_raw_transaction(signed_txn_2.raw_transaction)
|
||||||
|
|
||||||
|
|
||||||
nonce = web3.eth.getTransactionCount( wallet.address )
|
nonce = web3.eth.get_transaction_count( wallet.address )
|
||||||
raw_txn_3 = usdc_contract.functions.approve("0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296", int(MAX_INT, 0)).build_transaction({
|
raw_txn_3 = usdc_contract.functions.approve("0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296", int(MAX_INT, 0)).build_transaction({
|
||||||
"chainId": 137,
|
"chainId": 137,
|
||||||
"from": wallet.address,
|
"from": wallet.address,
|
||||||
"nonce": nonce
|
"nonce": nonce
|
||||||
})
|
})
|
||||||
signed_txn_3 = web3.eth.account.sign_transaction(raw_txn_3, private_key=os.getenv("PK"))
|
signed_txn_3 = web3.eth.account.sign_transaction(raw_txn_3, private_key=os.getenv("PK"))
|
||||||
send_txn_3 = web3.eth.send_raw_transaction(signed_txn_3.rawTransaction)
|
send_txn_3 = web3.eth.send_raw_transaction(signed_txn_3.raw_transaction)
|
||||||
|
|
||||||
|
|
||||||
def market_action( marketId, action, price, size ):
|
def market_action( marketId, action, price, size ):
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from py_clob_client.constants import POLYGON
|
|||||||
|
|
||||||
# Web3 libraries for blockchain interaction
|
# Web3 libraries for blockchain interaction
|
||||||
from web3 import Web3
|
from web3 import Web3
|
||||||
from web3.middleware import geth_poa_middleware
|
from web3.middleware import ExtraDataToPOAMiddleware
|
||||||
from eth_account import Account
|
from eth_account import Account
|
||||||
|
|
||||||
import requests # HTTP requests
|
import requests # HTTP requests
|
||||||
@@ -54,7 +54,7 @@ class PolymarketClient:
|
|||||||
# Don't print sensitive wallet information
|
# Don't print sensitive wallet information
|
||||||
print("Initializing Polymarket client...")
|
print("Initializing Polymarket client...")
|
||||||
chain_id=POLYGON
|
chain_id=POLYGON
|
||||||
self.browser_wallet=Web3.toChecksumAddress(browser_address)
|
self.browser_wallet=Web3.to_checksum_address(browser_address)
|
||||||
|
|
||||||
# Initialize the Polymarket API client
|
# Initialize the Polymarket API client
|
||||||
self.client = ClobClient(
|
self.client = ClobClient(
|
||||||
@@ -71,7 +71,7 @@ class PolymarketClient:
|
|||||||
|
|
||||||
# Initialize Web3 connection to Polygon
|
# Initialize Web3 connection to Polygon
|
||||||
web3 = Web3(Web3.HTTPProvider("https://polygon-rpc.com"))
|
web3 = Web3(Web3.HTTPProvider("https://polygon-rpc.com"))
|
||||||
web3.middleware_onion.inject(geth_poa_middleware, layer=0)
|
web3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)
|
||||||
|
|
||||||
# Set up USDC contract for balance checks
|
# Set up USDC contract for balance checks
|
||||||
self.usdc_contract = web3.eth.contract(
|
self.usdc_contract = web3.eth.contract(
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
[project]
|
||||||
|
name = "poly-maker"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "A market making bot for Polymarket prediction markets"
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.9.10"
|
||||||
|
license = { text = "MIT" }
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
"py-clob-client==0.28.0",
|
||||||
|
"python-dotenv==1.2.1",
|
||||||
|
"pandas==2.3.3",
|
||||||
|
"gspread==6.2.1",
|
||||||
|
"gspread-dataframe==4.0.0",
|
||||||
|
"sortedcontainers==2.4.0",
|
||||||
|
"eth-account==0.13.7",
|
||||||
|
"eth-utils==5.3.1",
|
||||||
|
"poly_eip712_structs==0.0.1",
|
||||||
|
"py_order_utils==0.3.2",
|
||||||
|
"requests==2.32.5",
|
||||||
|
"websockets==15.0.1",
|
||||||
|
"cryptography==46.0.3",
|
||||||
|
"google-auth==2.42.1",
|
||||||
|
"web3==7.14.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
dev = [
|
||||||
|
"black==24.4.2",
|
||||||
|
"pytest==8.2.2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["hatchling"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
|
|
||||||
|
[tool.hatch.build.targets.wheel]
|
||||||
|
packages = ["poly_data", "poly_stats", "poly_utils", "data_updater"]
|
||||||
|
|
||||||
|
[tool.black]
|
||||||
|
line-length = 100
|
||||||
|
target-version = ["py39"]
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
py-clob-client==0.20.0
|
|
||||||
python-dotenv
|
|
||||||
pandas
|
|
||||||
gspread
|
|
||||||
gspread-dataframe
|
|
||||||
sortedcontainers
|
|
||||||
black==24.4.2
|
|
||||||
eth-account===0.13.0
|
|
||||||
eth-utils===4.1.1
|
|
||||||
poly_eip712_structs==0.0.1
|
|
||||||
py_order_utils==0.3.2
|
|
||||||
pytest==8.2.2
|
|
||||||
python-dotenv==0.19.2
|
|
||||||
requests==2.32.3
|
|
||||||
websockets==12.0
|
|
||||||
cryptography==42.0.8
|
|
||||||
asyncio
|
|
||||||
requests
|
|
||||||
google-auth
|
|
||||||
web3==5.3.1
|
|
||||||
Reference in New Issue
Block a user