#下载数据
import jqdata
import pandas
data=get_ticks('601595.XSHG', start_dt='2018-09-24',end_dt='2019-09-27',
fields=['time', 'current', 'high', 'low', 'volume', 'money','a1_v','a2_v','a3_v','a4_v',
'a5_v','a1_p','a2_p','a3_p','a4_p','a5_p','b1_v','b2_v','b3_v','b4_v',
'b5_v','b1_p','b2_p','b3_p','b4_p','b5_p'])
data=pandas.DataFrame(data)
data.to_csv('data2.csv')
#重复行删除
import pandas as pd
df=pd.read_csv('data2.csv')
import datetime
df2=df.drop_duplicates(['time'])
df2.to_csv('new(2).csv')
#吃单,砸盘分类
import datetime
import time
import pandas as pd
import plotly
import plotly.graph_objs as go
df2=pd.read_csv('new(2).csv')
vol=50000
a=[]
b=[]
c=[]
a1_p=[]
a2_p=[]
a3_p=[]
a4_p=[]
a5_p=[]
a1_v=[]
a2_v=[]
a3_v=[]
a4_v=[]
a5_v=[]
b1_p=[]
b2_p=[]
b3_p=[]
b4_p=[]
b5_p=[]
b1_v=[]
b2_v=[]
b3_v=[]
b4_v=[]
b5_v=[]
for i in range(1,len(df2)):
k1=str(df2.time[i-1])
k2=str(df2.time[i])
if df2.current[i]!=0:
t1 = datetime.datetime.strptime(k1, '%Y%m%d%H%M%S.%f')
t2 = datetime.datetime.strptime(k2, '%Y%m%d%H%M%S.%f')
#print(i, t2, t2 - t1)
a.append(t1)
b.append(df2.current[i])
c.append(df2.volume[i]-df2.volume[i-1])
a1_p.append(df2.a1_p[i])
a2_p.append(df2.a2_p[i])
a3_p.append(df2.a3_p[i])
a4_p.append(df2.a4_p[i])
a5_p.append(df2.a5_p[i])
a1_v.append(df2.a1_v[i])
a2_v.append(df2.a2_v[i])
a3_v.append(df2.a3_v[i])
a4_v.append(df2.a4_v[i])
a5_v.append(df2.a5_v[i])
b1_p.append(df2.b1_p[i])
b2_p.append(df2.b2_p[i])
b3_p.append(df2.b3_p[i])
b4_p.append(df2.b4_p[i])
b5_p.append(df2.b5_p[i])
b1_v.append(df2.b1_v[i])
b2_v.append(df2.b2_v[i])
b3_v.append(df2.b3_v[i])
b4_v.append(df2.b4_v[i])
b5_v.append(df2.b5_v[i])
new_1=[]
new_2=[]
new_4=[]
#吃单
for i in range(len(c)):
if a2_p[i]>=0 and a1_p[i]==a1_p[i-1] and a1_v[i-1]-a1_v[i]>=vol \
and b[i]>b[i-1]:#卖一=前卖一,卖一减少
new_1.append(a[i])
new_2.append(b[i])
new_4.append(round((a1_v[i-1]-a1_v[i])/100,0))
if b[i]>=0 and b1_v[i]-b1_v[i-1]>=vol and b1_p[i]==b1_p[i-1]\
and b[i]>b[i-1] :#买一==前买一,买单增加
new_1.append(a[i])
new_2.append(b[i])
new_4.append(round((b1_v[i]-b1_v[i-1])/100,0))
if b[i] > 0 and b1_v[i]+c[i] >= vol and b1_p[i] == a1_p[i - 1]\
and b[i]>b[i-1] :#买一==前卖一,买单增加
new_1.append(a[i])
new_2.append(b[i])
new_4.append(round((b1_v[i]+c[i])/100,0))
if b[i] > 0 and b1_v[i]+b2_v[i]+c[i] >= vol and b1_p[i] == a2_p[i - 1]\
and b[i]>b[i-1] :#买一==前卖二,买单增加
new_1.append(a[i])
new_2.append(b[i])
new_4.append(round((b1_v[i]+b2_v[i]+c[i])/100,0))
if b[i] > 0 and b1_v[i]+b2_v[i]+b3_v[i]+c[i] >= vol and b1_p[i] == a3_p[i - 1]\
and b[i]>b[i-1] :#买一==前卖三,买单增加
new_1.append(a[i])
new_2.append(b[i])
new_4.append(round((b1_v[i]+b2_v[i]+b3_v[i]+c[i])/100,0))
if b[i] > 0 and b1_v[i]+b2_v[i]+b3_v[i]+b4_v[i]+c[i] >= vol and b1_p[i] == a4_p[i - 1]\
and b[i]>b[i-1] :#买一==前卖四,买单增加
new_1.append(a[i])
new_2.append(b[i])
new_4.append(round((b1_v[i]+b2_v[i]+b3_v[i]+b4_v[i]+c[i])/100,0))
new_1=pd.DataFrame(new_1)
new_2=pd.DataFrame(new_2)
new_4=pd.DataFrame(new_4)
new=pd.concat([new_1,new_2,new_4],axis=1)
new.columns=["time","current","changed"]
new=new.set_index(["time"])
new.to_csv("500手吃单.csv")
#砸盘#a卖b买
za_1 = []
za_2 = []
za_4 = []
for i in range(len(c)):
if a2_p[i]>=0 and a1_p[i]==a1_p[i-1] and a1_v[i]-a1_v[i-1]>=vol \
and b[i]<b[i-1]:#卖一=前卖一,卖一增加
za_1.append(a[i])
za_2.append(b[i])
za_4.append(round((a1_v[i]-a1_v[i-1])/100,0))
if a2_p[i]>0 and a1_p[i]==b1_p[i-1] and a1_v[i]+c[i]>=vol \
and b[i]<b[i-1]:#卖一=前买一,卖出挂单增加
za_1.append(a[i])
za_2.append(b[i])
za_4.append(round((a1_v[i]+c[i])/100,0))
if a2_p[i]>0 and a1_p[i]==b2_p[i-1] and a1_v[i]+a2_v[i]+c[i]>=vol \
and b[i]<b[i-1] :#卖一=前买二,卖出挂单增加
za_1.append(a[i])
za_2.append(b[i])
za_4.append(round((a1_v[i]+a2_v[i]+c[i])/100,0))
if a2_p[i]>0 and a1_p[i]==a4_p[i-1] and a1_v[i]+a2_v[i]+a3_v[i]+c[i]>=vol \
and b[i]<b[i-1] :#卖一=前卖三,卖出挂单增加
za_1.append(a[i])
za_2.append(b[i])
za_4.append(round((a1_v[i]+a2_v[i]+a3_v[i]+c[i])/100,0))
if a2_p[i]>0 and a1_p[i]==a5_p[i-1] and a1_v[i]+a2_v[i]+a3_v[i]+a4_v[i]+c[i]>=vol \
and b[i]<b[i-1] :#卖一=前卖四,卖出挂单增加
za_1.append(a[i])
za_2.append(b[i])
za_4.append(round((a1_v[i]+a2_v[i]+a3_v[i]+a4_v[i]+c[i])/100,0))
za_1=pd.DataFrame(za_1)
za_2=pd.DataFrame(za_2)
za_4=pd.DataFrame(za_4)
za=pd.concat([za_1,za_2,za_4],axis=1)
za.columns=["time","current","changed"]
za=za.set_index(["time"])
za.to_csv("500手砸盘.csv")
#plotly画图
import datetime
import time
import pandas as pd
import plotly
import plotly.graph_objs as go
df2=pd.read_csv('new(2).csv')
a=[]
b=[]
c=[]
a1_p=[]
a2_p=[]
a3_p=[]
a4_p=[]
a5_p=[]
a1_v=[]
a2_v=[]
a3_v=[]
a4_v=[]
a5_v=[]
b1_p=[]
b2_p=[]
b3_p=[]
b4_p=[]
b5_p=[]
b1_v=[]
b2_v=[]
b3_v=[]
b4_v=[]
b5_v=[]
for i in range(1,len(df2)):
k1=str(df2.time[i-1])
k2=str(df2.time[i])
if df2.current[i]!=0:
t1 = datetime.datetime.strptime(k1, '%Y%m%d%H%M%S.%f')
t2 = datetime.datetime.strptime(k2, '%Y%m%d%H%M%S.%f')
#print(i, t2, t2 - t1)
a.append(t1)
b.append(df2.current[i])
c.append(df2.volume[i]-df2.volume[i-1])
a1_p.append(df2.a1_p[i])
a2_p.append(df2.a2_p[i])
a3_p.append(df2.a3_p[i])
a4_p.append(df2.a4_p[i])
a5_p.append(df2.a5_p[i])
a1_v.append(df2.a1_v[i])
a2_v.append(df2.a2_v[i])
a3_v.append(df2.a3_v[i])
a4_v.append(df2.a4_v[i])
a5_v.append(df2.a5_v[i])
b1_p.append(df2.b1_p[i])
b2_p.append(df2.b2_p[i])
b3_p.append(df2.b3_p[i])
b4_p.append(df2.b4_p[i])
b5_p.append(df2.b5_p[i])
b1_v.append(df2.b1_v[i])
b2_v.append(df2.b2_v[i])
b3_v.append(df2.b3_v[i])
b4_v.append(df2.b4_v[i])
b5_v.append(df2.b5_v[i])
put=pd.read_csv('500手砸盘.csv')
call=pd.read_csv('500手吃单.csv')
#zhic=pd.read_csv('100手支撑.csv')
put_time=[]
for i in put.time:
w2=datetime.datetime.strptime(i, '%Y-%m-%d %H:%M:%S.%f')
#w2 = datetime.datetime.strptime(i, '%Y-%m-%d %H:%M:%S')
put_time.append(w2)
call_time=[]
for i in call.time:
w12=datetime.datetime.strptime(i, '%Y-%m-%d %H:%M:%S.%f')
print(w12)
#w12 = datetime.datetime.strptime(i, '%Y-%m-%d %H:%M:%S')
call_time.append(w12)
trace = go.Scatter(
x=a,
y=b,
name='price',
xaxis='x1',
yaxis='y1',
line=dict(width=2, color='#509BFF')
)
trace4 = go.Scatter(x=put_time,y=put.current,xaxis='x1',yaxis='y1',
text=put.changed,textposition='top right', textfont=dict(color='#00FF00'),
mode='markers+text',line=dict(width=2, color='#00FF00'),name='砸盘')
trace42 = go.Scatter(x=put_time,y=put.current,xaxis='x1',yaxis='y1',
text="砸盘",textposition='top left', textfont=dict(color='#00FF00'),
mode='markers+text',line=dict(width=2, color='#00FF00'),name='砸盘')
trace5 = go.Scatter(x=call_time,y=call.current,xaxis='x1',yaxis='y1',
text=call.changed,textposition='bottom right', textfont=dict(color='#FF5108'),
mode='markers+text',line=dict(width=2, color='#FF5108'),name='吃单')
trace52 = go.Scatter(x=call_time,y=call.current,xaxis='x1',yaxis='y1',
text="吃单",textposition='bottom left', textfont=dict(color='#FF5108'),
mode='markers+text',line=dict(width=2, color='#FF5108'),name='吃单')
'''trace6 = go.Scatter(x=zhic_time,y=zhic.current,xaxis='x1',yaxis='y1',
text=call.changed,textposition='bottom right', textfont=dict(color='#509BFF'),
mode='markers+text',line=dict(width=2, color='#509BFF'),name='支撑')
trace62 = go.Scatter(x=zhic_time,y=zhic.current,xaxis='x1',yaxis='y1',
text="支撑",textposition='bottom left', textfont=dict(color='#509BFF'),
mode='markers+text',line=dict(width=2, color='#509BFF'),name='支撑')'''
trace2 = go.Bar(
x=call_time,
y=call.changed,
name='吃单量',
xaxis='x1',
yaxis='y2',
marker=dict(color='#EEEEEE', line=dict(color='#FF5108', width=1)),
opacity=0.6
)
trace3 = go.Bar(
x=put_time,
y=put.changed,
name='砸盘量',
xaxis='x1',
yaxis='y2',
marker=dict(color='#EEEEEE', line=dict(color='#00FF00', width=1)),
opacity=0.6
)
axis=dict(
showline=True,
zeroline=False,
showgrid=True,
mirror=True,
ticklen=4,
gridcolor='#ffffff',
tickfont=dict(size=10)
)
layout1 = dict(
width=1600,
height=800,
autosize=False,
title='tick',
margin = dict(t=100),
showlegend=False,
xaxis1=dict(axis, **dict(anchor='y1', type = "category",showticklabels=False)),
yaxis1=dict(axis, **dict(anchor='x1')),
yaxis2=dict(
overlaying='y1',
side='right'
),
)
fig1 = dict(data=[trace,trace2,trace3,trace4,trace42,trace5,trace52], layout=layout1)
plotly.offline.plot(fig1, filename='tick.html')
本社区仅针对特定人员开放
查看需注册登录并通过风险意识测评
5秒后跳转登录页面...