From 0d37b07c78fd977f5f3bd8403145d45a3ce27959 Mon Sep 17 00:00:00 2001 From: tzquant_zq Date: Mon, 2 Sep 2024 23:34:04 +0800 Subject: [PATCH] add init update --- request_demo.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 request_demo.py diff --git a/request_demo.py b/request_demo.py new file mode 100644 index 0000000..ec1a2cf --- /dev/null +++ b/request_demo.py @@ -0,0 +1,60 @@ +import requests + +def fetch_precision_info(platform): + # 定义请求URL + url = "http://43.133.213.20:8001/api/v1/PrecisionInfo/platform" + + # 定义请求数据 + request_data = {"platform": platform} + price_tick_info = {} + + try: + # 发送GET请求 + response = requests.get(url, params=request_data, timeout=15) + + # 检查响应状态码并输出 + if response.status_code == 200: + precisions = response.json() + print(f"Precision Information: {precisions.get('btcusdt', 'No data available')}") + for symbol, precision in precisions.items(): + symbol = symbol.lower() + price_tick_info[symbol] = precision["price_decimal"] + # 可以选择打印更多信息 + # print(f"Symbol: {symbol}, Price Precision: {precision['price_precision']}, Quantity Precision: {precision['quantity_precision']}") + return price_tick_info + else: + print(f"Error: {response.status_code}, {response.text}") + return None + except requests.RequestException as e: + print(f"Request failed: {e}") + return None + +# 示例调用 +platform = "gate_swap_u" +precision_info = fetch_precision_info(platform) +if precision_info: + print("Price Tick Information:", precision_info) + + +import requests + +def fetch_depth(exchange, symbol): + url = "http://43.133.213.20:8001/api/v1/depth/" + payload = {"exchange": exchange, "symbol": symbol} + + response = requests.post(url, json=payload, timeout=5) + + if response.status_code == 200: + return response.json() + else: + print(f"Error: {response.status_code}, {response.json()}") + return None + + +# 示例参数 +exchange = "gate_swap_u" +symbol = "BTC/USDT" + +# 发送请求 +depth_data = fetch_depth(exchange, symbol) +print(depth_data) \ No newline at end of file