天择量化公共接口文档
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.8 KiB

9 months ago
  1. import requests
  2. def fetch_precision_info(platform):
  3. # 定义请求URL
  4. url = "http://43.133.213.20:8001/api/v1/PrecisionInfo/platform"
  5. # 定义请求数据
  6. request_data = {"platform": platform}
  7. price_tick_info = {}
  8. try:
  9. # 发送GET请求
  10. response = requests.get(url, params=request_data, timeout=15)
  11. # 检查响应状态码并输出
  12. if response.status_code == 200:
  13. precisions = response.json()
  14. print(f"Precision Information: {precisions.get('btcusdt', 'No data available')}")
  15. for symbol, precision in precisions.items():
  16. symbol = symbol.lower()
  17. price_tick_info[symbol] = precision["price_decimal"]
  18. # 可以选择打印更多信息
  19. # print(f"Symbol: {symbol}, Price Precision: {precision['price_precision']}, Quantity Precision: {precision['quantity_precision']}")
  20. return price_tick_info
  21. else:
  22. print(f"Error: {response.status_code}, {response.text}")
  23. return None
  24. except requests.RequestException as e:
  25. print(f"Request failed: {e}")
  26. return None
  27. # 示例调用
  28. platform = "gate_swap_u"
  29. precision_info = fetch_precision_info(platform)
  30. if precision_info:
  31. print("Price Tick Information:", precision_info)
  32. import requests
  33. def fetch_depth(exchange, symbol):
  34. url = "http://43.133.213.20:8001/api/v1/depth/"
  35. payload = {"exchange": exchange, "symbol": symbol}
  36. response = requests.post(url, json=payload, timeout=5)
  37. if response.status_code == 200:
  38. return response.json()
  39. else:
  40. print(f"Error: {response.status_code}, {response.json()}")
  41. return None
  42. # 示例参数
  43. exchange = "gate_swap_u"
  44. symbol = "BTC/USDT"
  45. # 发送请求
  46. depth_data = fetch_depth(exchange, symbol)
  47. print(depth_data)