#!/usr/bin/env python3 """G-Exchange minimal Python client. Demo: python3 client.py""" import json, urllib.request BASE = "https://gexchange.website" def get(path): with urllib.request.urlopen(BASE + path, timeout=20) as r: return json.loads(r.read()) def post(path, data): req = urllib.request.Request(BASE + path, data=json.dumps(data).encode(), headers={"Content-Type": "application/json"}) with urllib.request.urlopen(req, timeout=20) as r: return json.loads(r.read()) if __name__ == "__main__": ix = get("/v1/futures/index") print("index:", ix.get("index"), "spread:", ix.get("spread_pct")) import random u = "pyclient_%d" % random.randint(100000, 999999) acct = post("/v1/futures/register", {"username": u, "password": "demo1234"}) print("account:", acct["username"], "balance:", acct["balance_usdc"]) order = post("/v1/futures/trade", {"token": acct["token"], "side": "long", "size_usdc": 50, "leverage": 20}) print("order:", order)