-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit-bot.py
More file actions
114 lines (88 loc) · 4.02 KB
/
split-bot.py
File metadata and controls
114 lines (88 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import requests
from datetime import datetime, timedelta
import pytz
import time
import os
import json
import asyncio
from utils.split_manager import market_split, publish_sell_limit_offer
async def perform_market_actions(condition_id, asset_ids):
# Perform market split
await market_split(condition_id, 10)
# Wait for a short period to allow the split to be processed
await asyncio.sleep(5)
# Process and publish sell limit offers for each asset
for asset_id in asset_ids:
# Remove quotes and whitespace, then convert to integer
cleaned_asset_id = int(asset_id.strip().strip('"'))
print(f"Attempting to publish sell offer for asset ID: {cleaned_asset_id}")
try:
await publish_sell_limit_offer(cleaned_asset_id, 5, 0.99)
print(f"Sell limit offer published for asset ID: {cleaned_asset_id}")
except Exception as e:
print(f"Error publishing sell limit offer for asset ID {cleaned_asset_id}: {str(e)}")
def get_events():
url = "https://gamma-api.polymarket.com/events?limit=75&order=updatedAt&ascending=false"
response = requests.get(url)
if response.status_code == 200:
return response.json()
else:
print(f"Failed to retrieve data: Status code {response.status_code}")
return None
def get_market_details(slug):
url = f"https://gamma-api.polymarket.com/events?slug={slug}"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
if data and len(data) > 0 and "markets" in data[0]:
market = data[0]["markets"][0]
return {
"conditionId": market.get("conditionId"),
"assetIds": market.get("clobTokenIds", "[]").strip("[]").split(",")
}
return None
def actions_on_new_market_found(slug, utc_timestamp, no_volume=False):
madrid_tz = pytz.timezone('Europe/Madrid')
madrid_time = utc_timestamp.astimezone(madrid_tz)
human_readable_timestamp = madrid_time.strftime("%Y-%m-%d %H:%M:%S %Z")
market_details = get_market_details(slug)
log_entry = f"{slug} - Found at: {human_readable_timestamp}"
if no_volume:
log_entry += " (no volume)"
if market_details:
log_entry += f" - Condition ID: {market_details['conditionId']}"
log_entry += f" - Asset IDs: {', '.join(market_details['assetIds'])}"
with open('./market-log.txt', 'a') as log_file:
log_file.write(log_entry + "\n")
print(log_entry)
# Perform market actions
if market_details:
asyncio.run(perform_market_actions(market_details['conditionId'], market_details['assetIds']))
def main():
seen_markets = set()
while True:
now = datetime.now(pytz.UTC)
events = get_events()
if events:
for event in events:
updated_at = datetime.fromisoformat(event['updatedAt'].replace('Z', '+00:00'))
if now - updated_at <= timedelta(hours=1):
slug = event['slug']
if slug not in seen_markets:
# Check if the event has tags and if any of them are "sports"
if 'tags' in event and any(tag['label'].lower() == 'sports' for tag in event['tags']):
continue # Skip this event if it has a "sports" tag
no_volume = False
if 'volume' in event:
volume = float(event['volume'])
if volume > 200.0:
continue
else:
no_volume = True
seen_markets.add(slug)
actions_on_new_market_found(slug, now, no_volume)
time.sleep(15) # Wait for 15 seconds before the next check
if __name__ == "__main__":
if not os.path.exists('./market-log.txt'):
open('./market-log.txt', 'w').close() # Create the file if it doesn't exist
main()