Skip to content

Commit

Permalink
Merge pull request rainx#91 from wopalm/feature/fix_nature_name
Browse files Browse the repository at this point in the history
Feature/fix nature name 修正期货和港股的nature_name解析问题
  • Loading branch information
rainx authored Oct 27, 2017
2 parents 264fdc2 + cda2369 commit af0afdf
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 19 deletions.
50 changes: 35 additions & 15 deletions pytdx/parser/ex_get_history_transaction_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,39 +48,56 @@ def parseResponse(self, body_buf):
if value == 0:
direction = 1
if zengcang > 0:
natrue_name = "多开"
if volume > zengcang:
nature_name = "多开"
elif volume == zengcang:
nature_name = "双开"
elif zengcang == 0:
natrue_name = "多换"
nature_name = "多换"
else:
if volume == -zengcang:
natrue_name = "双平"
nature_name = "双平"
else:
natrue_name = "空平"
nature_name = "空平"
elif value == 1:
direction = -1
if zengcang > 0:
natrue_name = "空开"
if volume > zengcang:
nature_name = "空开"
elif volume == zengcang:
nature_name = "双开"
elif zengcang == 0:
natrue_name = "空换"
nature_name = "空换"
else:
if volume == -zengcang:
natrue_name = "双平"
nature_name = "双平"
else:
natrue_name = "多平"
nature_name = "多平"
else:
direction = 0
if zengcang > 0:
if volume > zengcang:
natrue_name = "开仓"
nature_name = "开仓"
elif volume == zengcang:
natrue_name = "双开"
nature_name = "双开"
elif zengcang < 0:
if volume > -zengcang:
natrue_name = "平仓"
nature_name = "平仓"
elif volume == -zengcang:
natrue_name = "双平"
nature_name = "双平"
else:
natrue_name = "换手"
nature_name = "换手"

if market in [31,48]:
if nature == 0:
direction = 1
nature_name = 'B'
elif nature == 256:
direction = -1
nature_name = 'S'
else: #512
direction = 0
nature_name = ''

result.append(OrderedDict([
("date", date),
Expand All @@ -89,7 +106,7 @@ def parseResponse(self, body_buf):
("price", price),
("volume", volume),
("zengcang", zengcang),
("natrue_name", natrue_name),
("natrue_name", nature_name),
("direction", direction),
("nature", nature),

Expand All @@ -104,5 +121,8 @@ def parseResponse(self, body_buf):

api = TdxExHq_API()
with api.connect('121.14.110.210', 7727):
# print(api.to_df(api.get_history_transaction_data(4, 'SR61099D', 20171025))[["date","price","volume",'zengcang','nature','t1','t2']])

print(api.to_df(api.get_history_transaction_data(47, 'IFL0', 20170811)))
print(api.to_df(api.get_history_transaction_data(31, "00020", 20170811)))
#print(api.to_df(api.get_history_transaction_data(31, "01918", 20171026))[["date","price","volume",'zengcang','nature']])
#api.to_df(api.get_history_transaction_data(47, 'IFL0', 20170810)).to_excel('//Users//wy//data//iflo.xlsx')
26 changes: 22 additions & 4 deletions pytdx/parser/ex_get_transaction_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ def parseResponse(self, body_buf):
date = datetime.datetime.combine(datetime.date.today(), datetime.time(hour,minute,second))

value = direction // 10000

if value == 0:
direction = 1
if zengcang > 0:
nature_name = "多开"
if volume > zengcang:
nature_name = "多开"
elif volume == zengcang:
nature_name = "双开"
elif zengcang == 0:
nature_name = "多换"
else:
Expand All @@ -52,7 +56,10 @@ def parseResponse(self, body_buf):
elif value == 1:
direction = -1
if zengcang > 0:
nature_name = "空开"
if volume > zengcang:
nature_name = "空开"
elif volume == zengcang:
nature_name = "双开"
elif zengcang == 0:
nature_name = "空换"
else:
Expand All @@ -75,6 +82,17 @@ def parseResponse(self, body_buf):
else:
nature_name = "换手"

if market in [31,48]:
if nature == 0:
direction = 1
nature_name = 'B'
elif nature == 256:
direction = -1
nature_name = 'S'
else: #512
direction = 0
nature_name = ''


result.append(OrderedDict([
("date", date),
Expand All @@ -99,5 +117,5 @@ def parseResponse(self, body_buf):

api = TdxExHq_API()
with api.connect('121.14.110.210', 7727):
print(api.to_df(api.get_transaction_data(47, 'IF1709')))
print(api.to_df(api.get_transaction_data(31, "00020")))
print(api.to_df(api.get_transaction_data(47, 'IFL9')))
# print(api.to_df(api.get_transaction_data(31, "00020")))

0 comments on commit af0afdf

Please sign in to comment.