-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Test build | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'test/**' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
Test: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Build and push to Docker Hub | ||
uses: ./.github/actions/Docker | ||
with: | ||
REGISTRY_ADDRESS: ${{ secrets.DOCKER_HUB_ADDRESS }} | ||
REGISTRY_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
REGISTRY_PASSWORD: ${{ secrets.DOCKER_HUB_TOKEN }} | ||
REGISTRY_NAME_SPACE: ${{ secrets.DOCKER_HUB_NAME_SPACE }} | ||
DOCKER_BUILD_NAME: 'test' | ||
DOCKER_BUILD_PATH: './test' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM python:3.12-alpine | ||
|
||
ENV TZ=Europe/London | ||
|
||
COPY . /app | ||
RUN pip install --no-cache-dir -r /app/requirements.txt | ||
|
||
CMD ["python", "-u", "/app/main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import ast | ||
import json | ||
import asyncio | ||
import datetime | ||
import requests | ||
import websockets | ||
|
||
|
||
response = requests.get( | ||
"https://gamma-api.polymarket.com/events?limit=100&closed=false" | ||
).json() | ||
tokens_pair = dict() | ||
|
||
for event in response: | ||
if event["volume"] > 10_000_000 and event["volume24hr"] > 1_000_000: | ||
|
||
for market in event["markets"]: | ||
if market["volumeNum"] < 1_000_000: | ||
continue | ||
|
||
if "outcomePrices" in market and "clobTokenIds" in market: | ||
token1, token2 = ast.literal_eval(market["clobTokenIds"]) | ||
tokens_pair[token1] = token2 | ||
tokens_pair[token2] = token1 | ||
|
||
|
||
url = "wss://ws-subscriptions-clob.polymarket.com/ws/market" | ||
last_pong = datetime.datetime.now() | ||
|
||
|
||
async def main(): | ||
async with websockets.connect(url) as websocket: | ||
await websocket.send( | ||
json.dumps( | ||
{ | ||
"assets_ids": list(tokens_pair.values()), | ||
"type": "market", | ||
} | ||
) | ||
) | ||
|
||
while True: | ||
message = await websocket.recv() | ||
|
||
if message != "PONG": | ||
last_pong = datetime.datetime.now() | ||
|
||
info = json.loads(message) | ||
|
||
info = { | ||
event["asset_id"]: event | ||
for event in info | ||
if event["event_type"] == "book" | ||
} | ||
checked = [] | ||
|
||
for asset_id in info.keys(): | ||
if asset_id in checked: | ||
continue | ||
|
||
pair_id = tokens_pair[asset_id] | ||
|
||
if pair_id not in info.keys(): | ||
# print("Matching bet not found in the same epoch") | ||
continue | ||
|
||
event1 = info[asset_id] | ||
event2 = info[pair_id] | ||
|
||
# if ( | ||
# event1["asks"] | ||
# and event2["bids"] | ||
# and event1["asks"][-1]["size"] != event2["bids"][-1]["size"] | ||
# ): | ||
# print("Bets mismatch") | ||
# print(event1["asks"][-1]) | ||
# print(event2["bids"][-1]) | ||
|
||
# if ( | ||
# event1["bids"] | ||
# and event2["asks"] | ||
# and event1["bids"][-1]["size"] != event2["asks"][-1]["size"] | ||
# ): | ||
# print("Bets mismatch") | ||
# print(event1["bids"][-1]) | ||
# print(event2["asks"][-1]) | ||
|
||
if ( | ||
event1["asks"] | ||
and event2["asks"] | ||
and float(event1["asks"][-1]["price"]) | ||
+ float(event2["asks"][-1]["price"]) | ||
< 1 | ||
): | ||
print("Arbitrage opportunities found") | ||
print(event1["asks"][-1]) | ||
print(event2["asks"][-1]) | ||
|
||
checked.append(asset_id) | ||
checked.append(pair_id) | ||
|
||
if last_pong + datetime.timedelta(seconds=10) < datetime.datetime.now(): | ||
await websocket.send("PING") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
requests | ||
websockets |