繁簡切換您正在訪問的是FX168財經網,本網站所提供的內容及信息均遵守中華人民共和國香港特別行政區當地法律法規。

FX168财经网>人物频道>帖子

画图tick级实时吃单砸盘(level1)

作者/SCSDV_d 2019-10-12 00:00 0 来源: FX168财经网人物频道
#下载数据
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')
分享到:
举报财经168客户端下载

全部回复

0/140

投稿 您想发表你的观点和看法?

更多人气分析师

  • 张亦巧

    人气2184文章4145粉丝45

    暂无个人简介信息

  • 梁孟梵

    人气2176文章3177粉丝39

    qq:2294906466 了解群指导添加微信mfmacd

  • 指导老师

    人气1864文章4423粉丝52

    暂无个人简介信息

  • 李冉晴

    人气2320文章3821粉丝34

    李冉晴,专业现贷实盘分析师。

  • 刘钥钥1

    人气2024文章3119粉丝34

    专业从事现货黄金、现货白银模似实盘操作分析指导

  • 张迎妤

    人气1896文章3305粉丝34

    个人专注于行情技术分析,消息面解读剖析,给予您第一时间方向...

  • 金泰铬J

    人气2328文章3925粉丝51

    投资问答解咨询金泰铬V/信tgtg67即可获取每日的实时资讯、行情...

  • 金算盘

    人气2696文章7761粉丝125

    高级分析师,混过名校,厮杀于股市和期货、证券市场多年,专注...

  • 金帝财神

    人气4760文章8329粉丝119

    本文由资深分析师金帝财神微信:934295330,指导黄金,白银,...

FX168财经

FX168财经学院

FX168财经

FX168北美