Skip to content
This repository was archived by the owner on Jul 21, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added aliases.csv
Empty file.
58 changes: 40 additions & 18 deletions trade_scroller.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from datetime import datetime
import json
import csv
from datetime import datetime, timedelta
from time import sleep

import requests
from gql import Client, gql
from gql import gql, Client
from gql.transport.requests import RequestsHTTPTransport


Expand All @@ -14,7 +16,9 @@ def markets_by_id(data):


def gql_query(timestamp):
transport = RequestsHTTPTransport("https://api.thegraph.com/subgraphs/name/tokenunion/polymarket-matic")
transport = RequestsHTTPTransport(
"https://api.thegraph.com/subgraphs/name/tokenunion/polymarket-matic"
)
client = Client(transport=transport, fetch_schema_from_transport=True)

with open("query.gql") as fp:
Expand All @@ -23,40 +27,58 @@ def gql_query(timestamp):
return client.execute(query, {"ts": timestamp})


def show_transaction(trx, mkt, count):
def show_transaction(trx, mkt, count, aliases):
print(f"# {count} # ****************************************")
print(mkt['question'])
print(mkt["question"])
print(f"Id: {trx['id']}")
print(f"User: {trx['user']['id']}")

amount = float(trx['tradeAmount']) / 1000000
user_address = trx["user"]["id"]
if aliases:
username = next((i[1] for i in aliases if i[0] == user_address), None)
else:
username = None

if username:
print(f"User: {username}")
else:
print(f"User: {user_address}")

amount = float(trx["tradeAmount"]) / 1000000
print(f"Amout: ${amount}")

ts = int(trx['timestamp'])
ts = int(trx["timestamp"])
print(f"Timestamp: {datetime.utcfromtimestamp(ts)}")

outcomeIndex = int(trx['outcomeIndex'])
outcome = mkt['outcomes'][outcomeIndex]
buy_or_sell = trx['type']
outcomeIndex = int(trx["outcomeIndex"])
outcome = mkt["outcomes"][outcomeIndex]

buy_or_sell = trx["type"]

print(f"Action: {buy_or_sell} {outcome}")

num_shares = float(trx['outcomeTokensAmount']) / 1000000
num_shares = float(trx["outcomeTokensAmount"]) / 1000000

print(f"#shares: {num_shares}")


def main():
r = requests.get("https://strapi-matic.poly.market/markets?_limit=-1&active=true")
if r.status_code != requests.codes.ok:
r.raise_for_status()
response.raise_for_status()

markets = markets_by_id(r.json())

try:
with open("watchlist.txt") as f:
watchlist = f.read().splitlines()
except Exception:
except:
watchlist = False

try:
with open("aliases.csv") as f:
aliases = list(csv.reader(f))
except:
aliases = False

count = 0
timestamp = int(datetime.now().timestamp())
while True:
Expand All @@ -66,13 +88,13 @@ def main():
mkt = markets[trx["market"]["id"]]
if watchlist:
if mkt["question"] in watchlist:
show_transaction(trx, mkt, count)
show_transaction(trx, mkt, count, aliases)
else:
show_transaction(trx, mkt, count)
show_transaction(trx, mkt, count, aliases)
count += 1

try:
timestamp = trx['timestamp']
timestamp = trx["timestamp"]
except Exception:
pass
sleep(2.0)
Expand Down