Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IT里的交易员
Python_edgetts
提交
3d0d5c63
P
Python_edgetts
项目概览
IT里的交易员
/
Python_edgetts
与 Fork 源项目一致
Fork自
inscode / Python
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Python_edgetts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
3d0d5c63
编写于
5月 07, 2023
作者:
6
62ddd5581cad725575cc5387
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Sun May 7 02:21:00 UTC 2023 inscode
上级
becd727a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
139 addition
and
1 deletion
+139
-1
main.py
main.py
+139
-1
未找到文件。
main.py
浏览文件 @
3d0d5c63
print
(
'欢迎来到 InsCode'
)
\ No newline at end of file
print
(
'欢迎来到 InsCode'
)
# -*- coding: utf-8 -*-
'''
通达信-小达
使用浏览器登录https://wenda.tdx.com.cn/,并按F12查看网络,复制cookie,替换后即可使用。
'''
import
prettytable
as
pt
# ===============表格美化输出===============
def
df_table
(
df
,
index
):
#利用prettytable对输出结果进行美化,index为索引列名:df_table(df,'market')
tb
=
pt
.
PrettyTable
()
# 如果为trade_time为index转换为日期类型,其它不用管。
if
index
==
"trade_time"
:
df
=
df
.
set_index
(
index
)
df
.
index
=
pd
.
DatetimeIndex
(
df
.
index
)
# df.reset_index(level=None, drop=True, inplace=True, col_level=0, col_fill='')
df
=
df
.
reset_index
(
drop
=
True
)
tb
.
add_column
(
index
,
df
.
index
)
#按date排序
for
col
in
df
.
columns
.
values
:
#df.columns.values的意思是获取列的名称
# print('col',col)
# print('df[col]',df[col])
tb
.
add_column
(
col
,
df
[
col
])
print
(
tb
)
import
requests
import
pandas
as
pd
import
json
,
os
# 增加UserAgent,防止被反爬虫拦截
from
fake_useragent
import
UserAgent
class
TDX_xiaoda
:
def
__init__
(
self
,
cookie
=
'Hm_lvt_5c4c948b141e4d66943a8430c3d600d0=1683343445; Hm_lpvt_5c4c948b141e4d66943a8430c3d600d0=1683343445; Token=a83cb29c37c54675883f20e7f7e474e7_1_JX_2; TDXID=R2302141428276685425IEYT; ATYPE=999; BTYPE=300; NICK=; LST=11; LOGID=@ec0:IZTanHlrWliPVC3nbJ+DhUKrc5uZJHC5; ASPSessionID=3683314944918358529'
):
self
.
cookie
=
cookie
def
_get_ua
(
self
):
# 构造useragent,为避免网络访问时延及报错,fake_useragent.json存放到本地
location
=
os
.
path
.
dirname
(
__file__
)
+
'/fake_useragent.json'
ua
=
UserAgent
(
cache_path
=
location
)
return
ua
.
random
def
set_headers
(
self
):
self
.
headers
=
{
'Cookie'
:
self
.
cookie
,
# 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.70'
'User-Agent'
:
self
.
_get_ua
()
}
return
self
.
headers
def
get_data_option
(
self
,
word
=
'涨停股票'
):
'''
获取提示参考
:param word:
:return:
'''
data
=
[{
"op_flag"
:
1
,
"question"
:
word
,
"POS"
:
0
,
"COUNT"
:
10
,
"RANG"
:
"AG"
}]
url
=
'https://wenda.tdx.com.cn/TQL?Entry=NLPSE.QuestionImagine&RI='
headers
=
self
.
set_headers
()
res
=
requests
.
post
(
url
=
url
,
data
=
json
.
dumps
(
data
),
headers
=
headers
)
text
=
res
.
json
()
return
text
def
get_word_code
(
self
,
name
=
'换手率2.8~15,量比2~20,OBV指标创新高,涨幅2~7,股价2~30'
):
'''
:param name:
:return:
'''
data
=
[{
"message"
:
name
,
"TDXID"
:
""
,
"wdbk"
:
""
,
"RANG"
:
"AG"
}]
url
=
'https://wenda.tdx.com.cn/TQL?Entry=NLPSE.StockSelect&RI='
headers
=
self
.
set_headers
()
res
=
requests
.
post
(
url
=
url
,
headers
=
headers
,
data
=
json
.
dumps
(
data
))
text
=
res
.
json
()
print
(
text
)
code
=
text
[
-
1
][
0
]
return
code
def
get_all_option_data
(
self
,):
'''
获取全部参考
:return:
'''
url
=
'https://wenda.tdx.com.cn/TQL?Entry=NLPSE.SmartQuery&RI='
headers
=
self
.
set_headers
()
data
=
[{
"op_flag"
:
1
,
"order_field"
:
""
,
"order_flag"
:
1
,
"cond_json"
:
""
,
"POS"
:
0
,
"COUNT"
:
-
1
,
"RANG"
:
"AG"
}]
res
=
requests
.
post
(
url
=
url
,
headers
=
headers
,
data
=
json
.
dumps
(
data
))
text
=
res
.
json
()
df
=
pd
.
DataFrame
(
text
)
df
=
df
.
iloc
[
1
:]
df2
=
df
.
rename
(
columns
=
df
.
iloc
[
0
])
df3
=
df2
.
iloc
[
1
:]
return
df3
def
get_word_result
(
self
,
word
=
'北向资金'
):
'''
获取数据
:param word:
:return:
'''
while
True
:
url
=
'https://wenda.tdx.com.cn/TQL?Entry=NLPSE.NLPQuery&RI=6BFD'
code
=
self
.
get_word_code
(
name
=
word
)
headers
=
self
.
set_headers
()
data
=
[{
"nlpse_id"
:
code
,
"POS"
:
0
,
"COUNT"
:
100000
,
"order_field"
:
""
,
"dynamic_order"
:
""
,
"order_flag"
:
""
,
"timestamps"
:
0
,
"op_flag"
:
1
,
"screen_type"
:
1
,
"RANG"
:
"AG"
}]
res
=
requests
.
post
(
url
=
url
,
headers
=
headers
,
data
=
json
.
dumps
(
data
))
text
=
res
.
content
.
decode
(
'utf-8'
)
text
=
json
.
loads
(
text
)
data_len
=
len
(
text
)
if
data_len
<
4
:
print
(
'连接失败,再次尝试连接*********'
+
str
(
text
))
else
:
print
(
text
)
df
=
pd
.
DataFrame
(
text
)
break
df
=
df
.
iloc
[
1
:]
df2
=
df
.
rename
(
columns
=
df
.
iloc
[
0
])
df3
=
df2
.
iloc
[
2
:]
return
df3
if
__name__
==
'__main__'
:
#获取参考
xd
=
TDX_xiaoda
()
if
0
:
#可能获取不到
df1
=
xd
.
get_data_option
(
word
=
'沪深A股,换手率1%~5%'
)
print
(
df1
)
# [[0, '', 10, '', ''], ['POS', 'question'], [], ['1', '沪深A股,换手率5%~10%'], ['2', '换手率1%~5%'], ['3', '换手率1%~5%'], ['4', '沪深A股'], ['5', '沪深A股'], ['6', '沪深A股,电力'], ['7', '沪深A股,化工'], ['8', '换手率1%~5%,量比1~3'], ['9', '换手率5%~10%'], ['10', '换手率大于5%']]
#获取问题转代码
df2
=
xd
.
get_word_code
(
name
=
'沪深A股,换手率1%~5%'
)
print
(
df2
)
#获取全部的参考,具体看通达信
df3
=
xd
.
get_all_option_data
()
print
(
df3
)
df_table
(
df3
,
'df'
)
#获取问题的结果
df4
=
xd
.
get_word_result
(
word
=
'今日涨停'
)
print
(
df4
)
df_table
(
df4
,
'df'
)
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录