okxv5 1.8.11__py3-none-any.whl → 1.8.12__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
okxv5/TradingBot_api.py CHANGED
@@ -1,127 +1,67 @@
1
- # 从.client模块导入Client类
2
1
  from .client import Client
3
- # 从.consts模块导入所有常量
4
2
  from .consts import *
5
3
 
6
4
 
7
- # 定义TradingBotAPI类,它继承自Client类
8
5
  class TradingBotAPI(Client):
9
- # 构造函数
10
6
  def __init__(self, api_key, api_secret_key, passphrase, use_server_time=False, flag='1'):
11
- # 调用父类Client的构造函数进行初始化
12
7
  Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag)
13
8
 
14
- # 创建网格策略订单
15
- def grid_order_algo(self, instId='', algoOrdType='', maxPx='', minPx='', gridNum='', runType='', tpTriggerPx='',
16
- slTriggerPx='', tag='', quoteSz='', algoClOrdId='',
17
- baseSz='', sz='', direction='', lever='', basePos='', tpRatio='', slRatio='',
18
- profitSharingRatio='', triggerParams=[]):
19
- # 构建请求参数字典
20
- params = {'instId': instId, 'algoOrdType': algoOrdType, 'maxPx': maxPx, 'minPx': minPx, 'gridNum': gridNum,
21
- 'runType': runType, 'tpTriggerPx': tpTriggerPx, 'slTriggerPx': slTriggerPx, 'tag': tag,
22
- 'quoteSz': quoteSz, 'baseSz': baseSz, 'sz': sz, 'direction': direction, 'lever': lever,
23
- 'basePos': basePos,
24
- 'tpRatio': tpRatio, 'slRatio': slRatio, 'algoClOrdId': algoClOrdId,
25
- 'profitSharingRatio': profitSharingRatio, 'triggerParams': triggerParams}
26
- # 发送POST请求,创建网格策略订单
9
+ def grid_order_algo(self, instId = '', algoOrdType = '', maxPx= '', minPx = '', gridNum ='', runType = '', tpTriggerPx = '', slTriggerPx = '', tag = '', quoteSz = '',algoClOrdId='',
10
+ baseSz = '', sz = '', direction = '', lever = '', basePos = '',tpRatio = '',slRatio='',profitSharingRatio='',triggerParams =[]):
11
+ params = {'instId': instId, 'algoOrdType': algoOrdType, 'maxPx': maxPx, 'minPx': minPx, 'gridNum': gridNum, 'runType': runType, 'tpTriggerPx': tpTriggerPx, 'slTriggerPx': slTriggerPx, 'tag': tag, 'quoteSz': quoteSz, 'baseSz': baseSz, 'sz': sz, 'direction': direction, 'lever': lever, 'basePos':basePos,
12
+ 'tpRatio': tpRatio,'slRatio': slRatio,'algoClOrdId':algoClOrdId,'profitSharingRatio':profitSharingRatio,'triggerParams':triggerParams}
27
13
  return self._request_with_params(POST, GRID_ORDER_ALGO, params)
28
14
 
29
- # 修改网格策略订单
30
- def grid_amend_order_algo(self, algoId='', instId='', slTriggerPx='', tpTriggerPx='', tpRatio='', slRatio=''):
31
- # 构建请求参数字典
32
- params = {'algoId': algoId, 'instId': instId, 'slTriggerPx': slTriggerPx, 'tpTriggerPx': tpTriggerPx,
33
- 'tpRatio': tpRatio, 'slRatio': slRatio, }
34
- # 发送POST请求,修改网格策略订单
15
+ def grid_amend_order_algo(self, algoId = '', instId = '', slTriggerPx= '', tpTriggerPx ='',tpRatio = '',slRatio=''):
16
+ params = {'algoId': algoId, 'instId': instId, 'slTriggerPx': slTriggerPx, 'tpTriggerPx': tpTriggerPx,'tpRatio': tpRatio,'slRatio': slRatio,}
35
17
  return self._request_with_params(POST, GRID_AMEND_ORDER_ALGO, params)
36
18
 
37
- # 停止网格策略订单
38
- def grid_stop_order_algo(self, algoId='', instId='', algoOrdType='', stopType=''):
39
- # 构建请求参数列表(注意这里是一个包含字典的列表)
19
+ def grid_stop_order_algo(self, algoId = '', instId = '', algoOrdType= '', stopType =''):
40
20
  params = [{'algoId': algoId, 'instId': instId, 'algoOrdType': algoOrdType, 'stopType': stopType}]
41
- # 发送POST请求,停止网格策略订单
42
21
  return self._request_with_params(POST, GRID_STOP_ORDER_ALGO, params)
43
-
44
- # 获取网格策略待处理订单列表
45
- def grid_orders_algo_pending(self, algoOrdType='', algoId='', instId='', instType='', after='', before='',
46
- limit=''):
47
- # 构建请求参数字典
48
- params = {'algoOrdType': algoOrdType, 'algoId': algoId, 'instId': instId, 'instType': instType,
49
- 'after': after, 'before': before, 'limit': limit}
50
- # 发送GET请求,获取网格策略待处理订单
22
+
23
+ def grid_orders_algo_pending(self, algoOrdType = '', algoId = '', instId = '', instType = '', after = '', before = '', limit = ''):
24
+ params = {'algoOrdType': algoOrdType, 'algoId': algoId, 'instId': instId, 'instType': instType, 'after': after, 'before': before, 'limit': limit}
51
25
  return self._request_with_params(GET, GRID_ORDERS_ALGO_PENDING, params)
52
26
 
53
- # 获取网格策略历史订单列表
54
- def grid_orders_algo_history(self, algoOrdType='', algoId='', instId='', instType='', after='', before='',
55
- limit=''):
56
- # 构建请求参数字典
57
- params = {'algoOrdType': algoOrdType, 'algoId': algoId, 'instId': instId, 'instType': instType,
58
- 'after': after, 'before': before, 'limit': limit}
59
- # 发送GET请求,获取网格策略历史订单
27
+ def grid_orders_algo_history(self, algoOrdType = '', algoId = '', instId = '', instType = '', after = '', before = '', limit = ''):
28
+ params = {'algoOrdType': algoOrdType, 'algoId': algoId, 'instId': instId, 'instType': instType, 'after': after, 'before': before, 'limit': limit}
60
29
  return self._request_with_params(GET, GRID_ORDERS_ALGO_HISTORY, params)
61
30
 
62
- # 获取网格策略订单详情
63
- def grid_orders_algo_details(self, algoOrdType='', algoId=''):
64
- # 构建请求参数字典
31
+ def grid_orders_algo_details(self, algoOrdType = '', algoId = ''):
65
32
  params = {'algoOrdType': algoOrdType, 'algoId': algoId}
66
- # 发送GET请求,获取网格策略订单详情
67
33
  return self._request_with_params(GET, GRID_ORDERS_ALGO_DETAILS, params)
68
34
 
69
- # 获取网格子订单列表
70
- def grid_sub_orders(self, algoId='', algoOrdType='', type='', groupId='', after='', before='', limit=''):
71
- # 构建请求参数字典
72
- params = {'algoId': algoId, 'algoOrdType': algoOrdType, 'type': type, 'groupId': groupId, 'after': after,
73
- 'before': before, 'limit': limit}
74
- # 发送GET请求,获取网格子订单
35
+ def grid_sub_orders(self, algoId = '', algoOrdType = '', type = '', groupId = '', after = '', before = '', limit = ''):
36
+ params = {'algoId': algoId, 'algoOrdType': algoOrdType, 'type': type, 'groupId': groupId, 'after': after, 'before': before, 'limit': limit}
75
37
  return self._request_with_params(GET, GRID_SUB_ORDERS, params)
76
38
 
77
- # 获取网格策略持仓信息
78
- def grid_positions(self, algoOrdType='', algoId=''):
79
- # 构建请求参数字典
39
+ def grid_positions(self, algoOrdType = '', algoId = ''):
80
40
  params = {'algoOrdType': algoOrdType, 'algoId': algoId}
81
- # 发送GET请求,获取网格策略持仓
82
41
  return self._request_with_params(GET, GRID_POSITIONS, params)
83
42
 
84
- # 提取网格策略收益
85
- def grid_withdraw_income(self, algoId=''):
86
- # 构建请求参数字典
43
+ def grid_withdraw_income(self, algoId = ''):
87
44
  params = {'algoId': algoId}
88
- # 发送POST请求,提取网格策略收益
89
45
  return self._request_with_params(POST, GRID_WITHDRAW_INCOME, params)
90
46
 
91
- # 计算网格策略的保证金余额
92
- def grid_compute_margin_balance(self, algoId='', type='', amt=''):
93
- # 构建请求参数字典
94
- params = {'algoId': algoId, 'type': type, 'amt': amt}
95
- # 发送POST请求,计算网格策略保证金余额
47
+ def grid_compute_margin_balance(self, algoId = '', type = '', amt = ''):
48
+ params = {'algoId': algoId, 'type':type, 'amt':amt}
96
49
  return self._request_with_params(POST, GRID_COMPUTE_MARGIN_BALANCE, params)
97
50
 
98
- # 调整网格策略的保证金
99
- def grid_margin_balance(self, algoId='', type='', amt='', percent=''):
100
- # 构建请求参数字典
101
- params = {'algoId': algoId, 'type': type, 'amt': amt, 'percent': percent}
102
- # 发送POST请求,调整网格策略保证金
51
+ def grid_margin_balance(self, algoId = '', type = '', amt = '', percent = ''):
52
+ params = {'algoId': algoId, 'type':type, 'amt':amt, 'percent':percent}
103
53
  return self._request_with_params(POST, GRID_MARGIN_BALANCE, params)
104
54
 
105
- # 获取网格策略AI参数
106
- def grid_ai_param(self, algoOrdType='', instId='', direction='', duration=''):
107
- # 构建请求参数字典
108
- params = {'algoOrdType': algoOrdType, 'instId': instId, 'direction': direction, 'duration': duration}
109
- # 发送GET请求,获取网格策略AI参数
55
+ def grid_ai_param(self, algoOrdType = '', instId = '', direction = '', duration = ''):
56
+ params = {'algoOrdType': algoOrdType, 'instId':instId, 'direction':direction, 'duration':duration}
110
57
  return self._request_with_params(GET, GRID_AI_PARAM, params)
111
58
 
112
59
  # POST /api/v5/tradingBot/grid/adjust-investment
113
- # 调整网格策略的投入资金
114
- def grid_adjust_investment(self, algoId='', amt=''):
115
- # 构建请求参数字典
116
- params = {'algoId': algoId, 'amt': amt}
117
- # 发送POST请求,调整网格策略投入资金
60
+ def grid_adjust_investment(self, algoId = '', amt = ''):
61
+ params = {'algoId': algoId, 'amt':amt}
118
62
  return self._request_with_params(POST, GRID_ADJUST_INVESTMETN, params)
119
63
 
120
64
  # GET /api/v5/tradingBot/grid/grid-quantity
121
- # 获取网格策略的网格数量
122
- def grid_quantity(self, instId='', runType='', algoOrdType='', maxPx='', minPx='', lever=''):
123
- # 构建请求参数字典
124
- params = {'instId': instId, 'runType': runType, 'algoOrdType': algoOrdType, 'maxPx': maxPx, 'minPx': minPx,
125
- 'lever': lever}
126
- # 发送GET请求,获取网格策略网格数量
65
+ def grid_quantity(self, instId = '', runType = '', algoOrdType = '', maxPx = '', minPx = '', lever = ''):
66
+ params = {'instId': instId, 'runType': runType, 'algoOrdType': algoOrdType, 'maxPx': maxPx, 'minPx': minPx, 'lever': lever}
127
67
  return self._request_with_params(GET, GRID_QUANTITY, params)
okxv5/TradingData_api.py CHANGED
@@ -1,120 +1,77 @@
1
- # 从.client模块导入Client类
2
1
  from .client import Client
3
- # 从.consts模块导入所有常量
4
2
  from .consts import *
5
3
 
6
4
 
7
- # 交易数据API类,继承自Client
8
5
  class TradingDataAPI(Client):
9
6
 
10
- # 构造函数
11
7
  def __init__(self, api_key, api_secret_key, passphrase, use_server_time=False, flag='1'):
12
- # 调用父类Client的构造函数
13
8
  Client.__init__(self, api_key, api_secret_key, passphrase, use_server_time, flag)
14
9
 
15
- # 获取支持的币种
16
10
  def get_support_coin(self):
17
11
  return self._request_without_params(GET, SUPPORT_COIN)
18
12
 
19
13
  # GET /api/v5/rubik/stat/contracts/open-interest-history
20
- # 获取合约持仓量历史
21
14
  def get_open_interest_history(self, instId = '', period = '', end = '', begin = '', limit = ''):
22
- # 构建请求参数
23
15
  params = {'instId': instId, 'period': period, 'end': end, 'begin': begin, 'limit': limit}
24
- # 发送带参数的GET请求
25
16
  return self._request_with_params(GET, GET_OPEN_INTEREST_HISTORY, params)
26
17
 
27
- # 获取Taker成交量
28
18
  def get_taker_volume(self, ccy, instType, begin='', end='', period=''):
29
- # 构建请求参数
30
19
  params = {'ccy': ccy, 'instType': instType, 'begin': begin, 'end': end, 'period': period}
31
- # 发送带参数的GET请求
32
20
  return self._request_with_params(GET, TAKER_VOLUME, params)
33
21
 
34
22
  # GET /api/v5/rubik/stat/taker-volume-contract
35
- # 获取合约Taker成交量
36
23
  def get_taker_volume_contract(self, instId, period = '', unit='', end='', begin='', limit = ''):
37
- # 构建请求参数
38
24
  params = {'instId': instId, 'period': period, 'unit': unit, 'end': end, 'begin': begin,'limit':limit}
39
- # 发送带参数的GET请求
40
25
  return self._request_with_params(GET, GET_TAKER_VOLUME_CONTRACT, params)
41
26
 
42
- # 获取杠杆借贷比率
43
27
  def get_margin_lending_ratio(self, ccy, begin='', end='', period=''):
44
- # 构建请求参数
45
28
  params = {'ccy': ccy, 'begin': begin, 'end': end, 'period': period}
46
- # 发送带参数的GET请求
47
29
  return self._request_with_params(GET, MARGIN_LENDING_RATIO, params)
48
30
 
49
31
  # GET /api/v5/rubik/stat/contracts/long-short-account-ratio-contract-top-trader
50
- # 获取合约多空账户比率-顶尖交易员
51
32
  def get_long_short_account_ratio_contract_top_trader(self, instId = '', period = '', end = '', begin = '', limit = ''):
52
- # 构建请求参数
53
33
  params = {'instId': instId, 'period': period, 'end': end, 'begin': begin,'limit':limit}
54
- # 发送带参数的GET请求
55
34
  return self._request_with_params(GET, GET_LONG_SHORT_ACCOUNT_RADIO_CONTRACT_TOP_TRADER, params)
56
35
 
57
36
  # GET /api/v5/rubik/stat/contracts/long-short-position-ratio-contract-top-trader
58
- # 获取合约多空持仓比率-顶尖交易员
59
37
  def get_long_short_position_ratio_contract_top_trader(self, instId = '', period = '', end = '', begin = '', limit = ''):
60
- # 构建请求参数
61
38
  params = {'instId': instId, 'period': period, 'end': end, 'begin': begin,'limit':limit}
62
- # 发送带参数的GET请求
63
39
  return self._request_with_params(GET, GET_LONG_SHORT_POSTION_RADIO_CONTRACT_TOP_TRADER, params)
64
40
 
65
41
  # GET /api/v5/rubik/stat/contracts/long-short-account-ratio-contract
66
- # 获取合约多空账户比率
67
42
  def get_long_short_account_ratio_contract(self, instId = '', period = '', end = '', begin = '', limit = ''):
68
- # 构建请求参数
69
43
  params = {'instId': instId, 'period': period, 'end': end, 'begin': begin,'limit':limit}
70
- # 发送带参数的GET请求
71
44
  return self._request_with_params(GET, GET_LONG_SHORT_ACCOUNT_RADIO_CONTRACT, params)
72
45
 
73
- # 获取多空比率
74
46
  def get_long_short_ratio(self, ccy, begin='', end='', period=''):
75
- # 构建请求参数
76
47
  params = {'ccy': ccy, 'begin': begin, 'end': end, 'period': period}
77
- # 发送带参数的GET请求
78
48
  return self._request_with_params(GET, LONG_SHORT_RATIO, params)
79
49
 
80
- # 获取合约持仓量和交易量
81
50
  def get_contracts_interest_volume(self, ccy, begin='', end='', period=''):
82
- # 构建请求参数
83
51
  params = {'ccy': ccy, 'begin': begin, 'end': end, 'period': period}
84
- # 发送带参数的GET请求
85
52
  return self._request_with_params(GET, CONTRACTS_INTEREST_VOLUME, params)
86
53
 
87
- # 获取期权持仓量和交易量
88
54
  def get_options_interest_volume(self, ccy, period=''):
89
- # 构建请求参数
90
55
  params = {'ccy': ccy, 'period': period}
91
- # 发送带参数的GET请求
92
56
  return self._request_with_params(GET, OPTIONS_INTEREST_VOLUME, params)
93
57
 
94
- # 获取看跌/看涨比率
95
58
  def get_put_call_ratio(self, ccy, period=''):
96
- # 构建请求参数
97
59
  params = {'ccy': ccy, 'period': period}
98
- # 发送带参数的GET请求
99
60
  return self._request_with_params(GET, PUT_CALL_RATIO, params)
100
61
 
101
- # 获取按到期日划分的持仓量和交易量
102
62
  def get_interest_volume_expiry(self, ccy, period=''):
103
- # 构建请求参数
104
63
  params = {'ccy': ccy, 'period': period}
105
- # 发送带参数的GET请求
106
64
  return self._request_with_params(GET, OPEN_INTEREST_VOLUME_EXPIRY, params)
107
65
 
108
- # 获取按行权价划分的持仓量和交易量
109
66
  def get_interest_volume_strike(self, ccy, expTime, period=''):
110
- # 构建请求参数
111
67
  params = {'ccy': ccy, 'expTime': expTime, 'period': period}
112
- # 发送带参数的GET请求
113
68
  return self._request_with_params(GET, INTEREST_VOLUME_STRIKE, params)
114
69
 
115
- # 获取Taker资金流
116
70
  def get_taker_flow(self, ccy, period=''):
117
- # 构建请求参数
118
71
  params = {'ccy': ccy, 'period': period}
119
- # 发送带参数的GET请求
120
- return self._request_with_params(GET, TAKER_FLOW, params)
72
+ return self._request_with_params(GET, TAKER_FLOW, params)
73
+
74
+
75
+
76
+
77
+
okxv5/client.py CHANGED
@@ -1,120 +1,66 @@
1
- import requests # 导入requests库,用于发送HTTP请求
2
- import json # 导入json库,用于处理JSON数据
3
- import datetime # 导入datetime库,用于时间戳处理
4
- import time # 导入time库,用于获取本地时间戳
5
- from . import consts as c, utils, exceptions # 从当前包导入consts模块(别名为c)、utils模块和exceptions模块
1
+ import requests
2
+ import json
3
+ from . import consts as c, utils, exceptions
4
+
6
5
 
7
6
  class Client(object):
8
- """
9
- API客户端类,用于与API进行交互
10
- """
11
-
12
- def __init__(self, api_key, api_secret_key, passphrase, use_server_time=False, flag='0'): # 1为实盘,0为模拟盘
13
- """
14
- 构造函数,初始化客户端
15
- :param api_key: API密钥
16
- :param api_secret_key: API私钥
17
- :param passphrase: 交易密码
18
- :param use_server_time: 是否使用服务器时间,默认为False
19
- :param flag: 请求标记,默认为'0'
20
- """
21
- self.API_KEY = api_key # 设置API密钥
22
- self.API_SECRET_KEY = api_secret_key # 设置API私钥
23
- self.PASSPHRASE = passphrase # 设置交易密码
24
- self.use_server_time = use_server_time # 设置是否使用服务器时间
25
- self.flag = flag # 设置请求标记
7
+
8
+ def __init__(self, api_key, api_secret_key, passphrase, use_server_time=False, flag='1'):
9
+
10
+ self.API_KEY = api_key
11
+ self.API_SECRET_KEY = api_secret_key
12
+ self.PASSPHRASE = passphrase
13
+ self.use_server_time = use_server_time
14
+ self.flag = flag
26
15
 
27
16
  def _request(self, method, request_path, params):
28
- """
29
- 私有方法,用于发送HTTP请求
30
- :param method: HTTP请求方法(GET或POST)
31
- :param request_path: 请求路径
32
- :param params: 请求参数
33
- :return: API响应的JSON数据
34
- :raise exceptions.OkxAPIException: 如果API返回非2xx状态码
35
- """
17
+
36
18
  if method == c.GET:
37
- # 如果是GET请求,将参数解析为字符串并附加到请求路径
38
19
  request_path = request_path + utils.parse_params_to_str(params)
39
- # 拼接完整的URL
20
+ # url
40
21
  url = c.API_URL + request_path
41
22
 
42
- # 确定最终用于请求头和签名的 ISO 8601 格式时间戳
43
- final_iso8601_timestamp = ""
23
+ timestamp = utils.get_timestamp()
44
24
 
25
+ # sign & header
45
26
  if self.use_server_time:
46
- # 获取服务器时间(返回 Unix 毫秒字符串)
47
- server_ts_ms_str = self._get_timestamp()
48
- if server_ts_ms_str:
49
- try:
50
- ms = int(server_ts_ms_str)
51
- dt_object = datetime.datetime.fromtimestamp(ms / 1000, tz=datetime.timezone.utc)
52
- final_iso8601_timestamp = dt_object.isoformat(timespec='milliseconds').replace('+00:00', 'Z')
53
- except ValueError:
54
- print(f"Error: Could not convert server timestamp '{server_ts_ms_str}' to ISO 8601. Using raw for signing/header.")
55
- final_iso8601_timestamp = server_ts_ms_str # 转换失败时,回退使用原始值
56
- else:
57
- # 如果获取服务器时间失败,则回退到本地 UTC 时间
58
- print("Warning: Failed to get server time. Falling back to local UTC time for timestamp.")
59
- final_iso8601_timestamp = utils.get_timestamp() # utils.get_timestamp() 已经返回 ISO 8601 格式
60
- else:
61
- # 使用本地时间(utils.get_timestamp() 已经返回 ISO 8601 格式)
62
- final_iso8601_timestamp = utils.get_timestamp()
27
+ timestamp = self._get_timestamp()
63
28
 
64
- # 根据请求方法决定请求体
65
29
  body = json.dumps(params) if method == c.POST else ""
66
30
 
67
- # 生成签名,使用ISO 8601格式的时间戳
68
- sign = utils.sign(utils.pre_hash(final_iso8601_timestamp, method, request_path, str(body)), self.API_SECRET_KEY)
69
- # 获取请求头,使用ISO 8601格式的时间戳
70
- header = utils.get_header(self.API_KEY, sign, final_iso8601_timestamp, self.PASSPHRASE, self.flag)
31
+ sign = utils.sign(utils.pre_hash(timestamp, method, request_path, str(body)), self.API_SECRET_KEY)
32
+ header = utils.get_header(self.API_KEY, sign, timestamp, self.PASSPHRASE, self.flag)
71
33
 
72
- # 发送请求
34
+ # send request
73
35
  response = None
74
36
 
37
+ print("url:", url)
38
+ # print("headers:", header)
39
+ print("body:", body)
40
+
75
41
  if method == c.GET:
76
- # 发送GET请求
77
42
  response = requests.get(url, headers=header)
78
43
  elif method == c.POST:
79
- # 发送POST请求
80
44
  response = requests.post(url, data=body, headers=header)
81
45
 
46
+ # exception handle
47
+ # print(response.headers)
48
+
82
49
  if not str(response.status_code).startswith('2'):
83
- # 如果响应状态码不是2xx,则抛出API异常
84
50
  raise exceptions.OkxAPIException(response)
85
51
 
86
- # 返回JSON格式的响应数据
87
52
  return response.json()
88
53
 
89
54
  def _request_without_params(self, method, request_path):
90
- """
91
- 私有方法,发送不带参数的HTTP请求
92
- :param method: HTTP请求方法
93
- :param request_path: 请求路径
94
- :return: API响应的JSON数据
95
- """
96
55
  return self._request(method, request_path, {})
97
56
 
98
57
  def _request_with_params(self, method, request_path, params):
99
- """
100
- 私有方法,发送带参数的HTTP请求
101
- :param method: HTTP请求方法
102
- :param request_path: 请求路径
103
- :param params: 请求参数
104
- :return: API响应的JSON数据
105
- """
106
58
  return self._request(method, request_path, params)
107
59
 
108
60
  def _get_timestamp(self):
109
- """
110
- 私有方法,获取服务器时间戳
111
- :return: 服务器时间戳字符串 (Unix毫秒)
112
- """
113
- url = c.API_URL + c.SERVER_TIMESTAMP_URL # 拼接获取服务器时间戳的URL
114
- response = requests.get(url) # 发送GET请求获取服务器时间
61
+ url = c.API_URL + c.SERVER_TIMESTAMP_URL
62
+ response = requests.get(url)
115
63
  if response.status_code == 200:
116
- # 如果请求成功,返回时间戳
117
64
  return response.json()['data'][0]['ts']
118
65
  else:
119
- # 如果请求失败,返回空字符串
120
- return ""
66
+ return ""