Skip to content

Commit fad4682

Browse files
committed
remove python2 compatible code
1 parent 49339e5 commit fad4682

32 files changed

+60
-178
lines changed

requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
six==1.16.0
21
simplejson==3.17.3
32
delorean==1.0.0
43
pandas==1.3.0
@@ -7,5 +6,4 @@ pytz==2021.1
76
pyasn1==0.4.8
87
rsa==4.7.2
98
stomp.py==4.1.24
10-
enum34==1.1.10
119
getmac==0.8.2

tigeropen/common/consts/__init__.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,11 @@
55
@author: gaoan
66
"""
77
import threading
8-
import platform
98
from enum import Enum, unique
10-
from .quote_keys import QuoteChangeKey, QuoteKeyType
9+
1110
from .fundamental_fields import Valuation, Income, Balance, CashFlow, BalanceSheetRatio, Growth, \
1211
Leverage, Profitability
13-
14-
python_version = platform.python_version()
15-
16-
if python_version.startswith("3"):
17-
PYTHON_VERSION_3 = True
18-
else:
19-
PYTHON_VERSION_3 = False
12+
from .quote_keys import QuoteChangeKey, QuoteKeyType
2013

2114
OPEN_API_SDK_VERSION = "2.0"
2215

tigeropen/common/util/signature_utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import rsa
1515

16-
from tigeropen.common.consts import PYTHON_VERSION_3
1716
from tigeropen.common.util.string_utils import add_start_end
1817

1918

@@ -58,8 +57,7 @@ def fill_public_key_marker(public_key):
5857

5958

6059
def sign_with_rsa(private_key, sign_content, charset):
61-
if PYTHON_VERSION_3:
62-
sign_content = sign_content.encode(charset)
60+
sign_content = sign_content.encode(charset)
6361
try:
6462
private_key = rsa.PrivateKey.load_pkcs1(fill_private_key_marker(private_key), format='PEM')
6563
except binascii.Error:
@@ -68,9 +66,7 @@ def sign_with_rsa(private_key, sign_content, charset):
6866

6967
signature = rsa.sign(sign_content, private_key, 'SHA-1')
7068

71-
sign = base64.b64encode(signature)
72-
if PYTHON_VERSION_3:
73-
sign = str(sign, encoding=charset)
69+
sign = str(base64.b64encode(signature), encoding=charset)
7470
return sign
7571

7672

tigeropen/common/util/string_utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
"""
77
import re
88

9-
from tigeropen.common.consts import PYTHON_VERSION_3
10-
119

1210
def add_start_end(key, start_marker, end_marker):
1311
if key.find(start_marker) < 0:
@@ -24,7 +22,5 @@ def camel_to_underline(hunp_str):
2422

2523

2624
def get_string(value):
27-
if PYTHON_VERSION_3:
28-
return value
29-
else:
30-
return value.encode('utf-8')
25+
return value
26+

tigeropen/common/util/web_utils.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
@author: gaoan
66
"""
77
import json
8-
from tigeropen.common.consts import PYTHON_VERSION_3, THREAD_LOCAL
8+
9+
from tigeropen.common.consts import THREAD_LOCAL
910
from tigeropen.common.exceptions import RequestException, ResponseException
1011

1112
try:
@@ -28,10 +29,7 @@ def url_encode(params, charset):
2829
value = v
2930
if not isinstance(value, str):
3031
value = json.dumps(value, ensure_ascii=False)
31-
if PYTHON_VERSION_3:
32-
value = quote_plus(value, encoding=charset)
33-
else:
34-
value = quote_plus(value)
32+
value = quote_plus(value, encoding=charset)
3533
query_string += ("&" + k + "=" + value)
3634
query_string = query_string[1:]
3735
return query_string
@@ -69,7 +67,7 @@ def do_post(url, query_string=None, headers=None, params=None, timeout=15, chars
6967
result = response.read()
7068

7169
if response.status != 200:
72-
if PYTHON_VERSION_3 and charset:
70+
if charset:
7371
result = result.decode(charset)
7472
raise ResponseException('[' + THREAD_LOCAL.uuid + ']invalid http status ' + str(response.status) +
7573
',detail body:' + result)

tigeropen/fundamental/response/financial_daily_response.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# -*- coding: utf-8 -*-
22

33
import pandas as pd
4-
import six
54

65
from tigeropen.common.response import TigerResponse
7-
from tigeropen.common.util.string_utils import get_string
86

97
COLUMNS = ['symbol', 'field', 'date', 'value']
108

@@ -25,8 +23,6 @@ def parse_response_content(self, response_content):
2523
for item in self.data:
2624
item_values = dict()
2725
for key, value in item.items():
28-
if isinstance(value, six.string_types):
29-
value = get_string(value)
3026
item_values[key] = value
3127
items.append(item_values)
3228
self.financial_daily = pd.DataFrame(items, columns=COLUMNS)

tigeropen/fundamental/response/financial_report_response.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
import pandas as pd
4-
import six
5-
from tigeropen.common.util.string_utils import get_string
4+
65
from tigeropen.common.response import TigerResponse
76

87
COLUMNS = ['symbol', 'currency', 'field', 'value', 'period_end_date', 'filing_date']
@@ -25,8 +24,6 @@ def parse_response_content(self, response_content):
2524
for item in self.data:
2625
item_values = dict()
2726
for key, value in item.items():
28-
if isinstance(value, six.string_types):
29-
value = get_string(value)
3027
item_values[key] = value
3128
items.append(item_values)
3229
self.financial_report = pd.DataFrame(items).rename(columns=REPORT_FIELD_MAPPINGS)[COLUMNS]

tigeropen/push/push_client.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@
44
55
@author: gaoan
66
"""
7-
import sys
87
import json
8+
import logging
9+
import sys
910
from collections import defaultdict
1011

1112
import stomp
12-
import six
13-
import logging
1413
from stomp.exception import ConnectFailedException
1514

15+
from tigeropen.common.consts import OrderStatus
1616
from tigeropen.common.consts.push_destinations import QUOTE, QUOTE_DEPTH, QUOTE_FUTURE, QUOTE_OPTION, TRADE_ASSET, \
1717
TRADE_ORDER, TRADE_POSITION
18-
from tigeropen.common.util.signature_utils import sign_with_rsa
19-
from tigeropen.common.util.order_utils import get_order_status
2018
from tigeropen.common.consts.push_types import RequestType, ResponseType
2119
from tigeropen.common.consts.quote_keys import QuoteChangeKey, QuoteKeyType
22-
from tigeropen.common.consts import OrderStatus
20+
from tigeropen.common.util.order_utils import get_order_status
21+
from tigeropen.common.util.signature_utils import sign_with_rsa
2322

2423
HOUR_TRADING_QUOTE_KEYS_MAPPINGS = {'hourTradingLatestPrice': 'latest_price', 'hourTradingPreClose': 'pre_close',
2524
'hourTradingLatestTime': 'latest_time', 'hourTradingVolume': 'volume',
@@ -166,8 +165,7 @@ def on_message(self, headers, body):
166165
# 期货行情推送的价格都乘了 10 的 offset 次方变成了整数, 需要除回去变为正常单位的价格
167166
if offset:
168167
for key, value in data.items():
169-
if (key == 'latestTime' or key == 'hourTradingLatestTime') and \
170-
isinstance(value, six.string_types):
168+
if key == 'latestTime' or key == 'hourTradingLatestTime':
171169
continue
172170
if key in QUOTE_KEYS_MAPPINGS:
173171
key = QUOTE_KEYS_MAPPINGS.get(key)
@@ -183,8 +181,7 @@ def on_message(self, headers, body):
183181
items.append((key, value))
184182
else:
185183
for key, value in data.items():
186-
if (key == 'latestTime' or key == 'hourTradingLatestTime') and \
187-
isinstance(value, six.string_types):
184+
if key == 'latestTime' or key == 'hourTradingLatestTime':
188185
continue
189186
if key in QUOTE_KEYS_MAPPINGS:
190187
key = QUOTE_KEYS_MAPPINGS.get(key)
@@ -305,7 +302,7 @@ def subscribe_quote(self, symbols, quote_key_type=QuoteKeyType.TRADE, focus_keys
305302
if focus_keys:
306303
keys = list()
307304
for key in focus_keys:
308-
if isinstance(key, six.string_types):
305+
if isinstance(key, str):
309306
keys.append(key)
310307
else:
311308
keys.append(key.value)

tigeropen/quote/quote_client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import re
1010

1111
import delorean
12-
import six
1312

1413
from tigeropen.common.consts import Market, Language, QuoteRight, BarPeriod
1514
from tigeropen.common.consts import THREAD_LOCAL, SecurityType, CorporateActionType, IndustryLevel
@@ -50,8 +49,8 @@
5049
from tigeropen.quote.response.option_quote_ticks_response import OptionTradeTickResponse
5150
from tigeropen.quote.response.quote_bar_response import QuoteBarResponse
5251
from tigeropen.quote.response.quote_brief_response import QuoteBriefResponse
53-
from tigeropen.quote.response.quote_grab_permission_response import QuoteGrabPermissionResponse
5452
from tigeropen.quote.response.quote_depth_response import DepthQuoteResponse
53+
from tigeropen.quote.response.quote_grab_permission_response import QuoteGrabPermissionResponse
5554
from tigeropen.quote.response.quote_ticks_response import TradeTickResponse
5655
from tigeropen.quote.response.quote_timeline_response import QuoteTimelineResponse
5756
from tigeropen.quote.response.stock_briefs_response import StockBriefsResponse
@@ -533,7 +532,7 @@ def get_option_chain(self, symbol, expiry):
533532
params = MultipleContractParams()
534533
param = SingleContractParams()
535534
param.symbol = symbol
536-
if isinstance(expiry, six.string_types) and re.match('[0-9]{4}\-[0-9]{2}\-[0-9]{2}', expiry):
535+
if isinstance(expiry, str) and re.match('[0-9]{4}-[0-9]{2}-[0-9]{2}', expiry):
537536
param.expiry = int(delorean.parse(expiry, timezone=eastern, dayfirst=False).datetime.timestamp() * 1000)
538537
else:
539538
param.expiry = expiry

tigeropen/quote/response/future_briefs_response.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
55
@author: gaoan
66
"""
7-
import six
87
import pandas as pd
8+
99
from tigeropen.common.response import TigerResponse
10-
from tigeropen.common.util.string_utils import get_string
1110

1211
COLUMNS = ['identifier', 'ask_price', 'ask_size', 'bid_price', 'bid_size', 'pre_close', 'latest_price', 'latest_size',
1312
'latest_time', 'volume', 'open_interest', 'open', 'high', 'low', 'limit_up', 'limit_down']
@@ -35,8 +34,6 @@ def parse_response_content(self, response_content):
3534
for key, value in item.items():
3635
if value is None:
3736
continue
38-
if isinstance(value, six.string_types):
39-
value = get_string(value)
4037
tag = BRIEF_FIELD_MAPPINGS[key] if key in BRIEF_FIELD_MAPPINGS else key
4138
item_values[tag] = value
4239
brief_data.append([item_values.get(tag) for tag in COLUMNS])
@@ -45,8 +42,6 @@ def parse_response_content(self, response_content):
4542
for key, value in self.data.items():
4643
if value is None:
4744
continue
48-
if isinstance(value, six.string_types):
49-
value = get_string(value)
5045
tag = BRIEF_FIELD_MAPPINGS[key] if key in BRIEF_FIELD_MAPPINGS else key
5146
item_values[tag] = value
5247
brief_data.append([item_values.get(tag) for tag in COLUMNS])

0 commit comments

Comments
 (0)