将沪深龙虎榜数据导入通达信的自选板块,并标注于K线图上

原理:python读取前一次处理完的计算5日后涨跌幅输出的csv文件

文件名前加"[paint]"

安照通达信的画图文件和板块文件格式,输出文件

用通达信的导入功能,导入画图文件和板块文件即可

事前数据截图:

处理后所得文件:

导入通达信后板块截图:

k线截图:

代码:

  1. #coding=utf-8
  2.  
  3. #读取'[paint]'开头的csv文件
  4. #copyright @ WangXinsheng
  5. #http://www.cnblogs.com/wangxinsheng/
  6. import os
  7. import struct
  8. import time
  9. import datetime
  10.  
  11. def getPriceByte(infile,arg,code,ss,day):
  12. dirc = {"-5":-3,"-3":-2,"-1":-1,"":1,"":2,"":3,"":4,"":5,"":6}
  13. first = 0
  14. second = 0
  15. a = float(arg)
  16. for i in [-5,-3,-1,1,3,5,7,9,11]:
  17. ib = i - 2
  18. if(a>=2**ib and a<2**i):
  19. #print(str(a)+":["+str(2**ib)+","+str(2**i)+"]"+"i:"+str(i)+" ib:"+str(ib))
  20. first = ib
  21. break;
  22. #print(first)
  23. chushu = 2**first
  24. if(arg >= chushu*2):
  25. second = arg / chushu
  26. #print(second)
  27. second = int(second*64)
  28. else:
  29. second = arg / chushu -1
  30. #print(second)
  31. second = int(second*128)
  32.  
  33. if(first<0):
  34. first = 64 + dirc[str(first)]
  35. else:
  36. first = 63 + dirc[str(first)]
  37. '''
  38. print(first)
  39. print(second)
  40. print(struct.pack('B',first))
  41. print(struct.pack('B',second))
  42. '''
  43. #print(struct.pack('B',first))
  44. #print(struct.pack('B',second))
  45.  
  46. infile.write(struct.pack('B',ss))
  47. infile.write(code.encode())
  48. infile.write(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
  49. infile.write(b'\x03')
  50. infile.write('STANDK'.encode())
  51. infile.write(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
  52. infile.write(b'\x04')
  53. infile.write(b'\x00')
  54. infile.write(b'\x1a\x10\x00\x00')
  55. infile.write(struct.pack('i',int(day)))
  56. infile.write(b'\x00\x00')
  57. infile.write(struct.pack('B',second))
  58. infile.write(struct.pack('B',first))
  59. infile.write(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xdcz3\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
  60.  
  61. print(str(code)+':已在 '+day+"日,价格:"+str(arg)+"加入标记")
  62. #infile = open("tdxline.eld","rw")
  63. #getPriceByte(5.55)
  64. file = open("WXSline.eld","wb")
  65. zxg = ''
  66. path=r'.'
  67. files = os.listdir(path)
  68. files.sort()
  69. j=0
  70. for f in files:
  71. if(f.startswith('[paint]') and f.endswith('.csv')):
  72. print('读取文件:'+path+'/'+f)
  73.  
  74. f=open(path+'/'+f,'rt')
  75. infos = f.readlines()
  76. f.close()
  77. i=0
  78. for info in infos:
  79. if(i==0):
  80. i=i+1
  81. continue
  82. tmp = info.split(',')
  83. if(len(tmp)<2):
  84. continue
  85. code = str(tmp[1].replace('"','').replace("'",""))
  86. if(code.startswith('')):
  87. ss = 1
  88. else:
  89. ss = 0
  90. addzxg = ''
  91. try:
  92. zxg.index(str(ss)+code)
  93. except:
  94. addzxg = str(ss)+code+"\n"
  95.  
  96. if(addzxg!=''):
  97. zxg = zxg + str(ss)+code+"\n"
  98. if(len(tmp)<10):
  99. continue
  100.  
  101. days = tmp[0].split('-')
  102. if(len(days)<2):
  103. days = tmp[0].split('/')
  104.  
  105. if(len(days)<2):
  106. continue
  107.  
  108. if(len(days[1])<2):
  109. days[1] = ''+days[1]
  110. if(len(days[2])<2):
  111. days[2] = ''+days[2]
  112. day = days[0]+days[1]+days[2]
  113. #print(day)
  114.  
  115. priceArr = tmp[9].replace('"','').split('%')
  116. if(len(priceArr)<2):
  117. continue
  118. a = float(priceArr[1].replace('[','').replace(']',''))*(1-float(priceArr[0].replace('%',''))/100)
  119. a = round(a,2)
  120. code = str(tmp[1].replace('"','').replace("'",""))
  121. if(code.startswith('')):
  122. ss = 1
  123. else:
  124. ss = 0
  125.  
  126. getPriceByte(file,a,code,ss,day)
  127. '''
  128. if(j>3):
  129. break
  130. else:
  131. j=j+1
  132. '''
  133.  
  134. fileA = open("WXS条件股.ebk","w")
  135. fileA.write(zxg)
  136. fileA.close()
  137. file.close()
  138. print('处理完了\n画图文件地址:./WXSline.eld')
  139. print('\n板块文件地址:./WXS条件股.ebk')

[python]沪深龙虎榜数据导入通达信的自选板块,并标注于K线图上的更多相关文章

  1. [python]沪深龙虎榜数据进一步处理,计算日后5日的涨跌幅

    沪深龙虎榜数据进一步处理,计算日后5日的涨跌幅 事前数据: 前面处理得到的csv文件 文件名前加入“[wait]”等待程序处理 python代码从雅虎股票历史数据api获取数据,计算后面5日的涨跌幅 ...

  2. [python]数据整理,将取得的众多的沪深龙虎榜数据整一整

    将昨日取得的众多的沪深龙虎榜数据整一整 提取文件夹内所有抓取下来的沪深龙虎榜数据,整理出沪深两市(含中小创)涨幅榜股票及前5大买入卖出资金净值,保存到csv文件 再手动使用数据透视表进行统计 原始数据 ...

  3. Python数学建模-02.数据导入

    数据导入是所有数模编程的第一步,比你想象的更重要. 先要学会一种未必最佳,但是通用.安全.简单.好学的方法. 『Python 数学建模 @ Youcans』带你从数模小白成为国赛达人. 1. 数据导入 ...

  4. python pandas 画图、显示中文、股票K线图

    目录: 1.pandas官方画图链接 2.标记图中数据点 3.画图显示中文 4.画股票K线图 5.matplotlib基本用法 6.format输出 6.format输出例子 eps_range=[0 ...

  5. 使用Python的pandas模块、mplfinance模块、matplotlib模块绘制K线图

    目录 pandas模块.mplfinance模块和matplotlib模块介绍 pandas模块 mplfinance模块和matplotlib模块 安装mplfinance模块.pandas模块和m ...

  6. C#下如何用NPlot绘制期货股票K线图(2):读取数据文件让K线图自动更新

    [内容介绍]上一篇介绍了K线图的基本绘制方法,但很不完善,本篇增加了它直接读取数据的功能,这对于金融市场的数据量大且又需要动态刷新功能的实现很重要. [实现方法] 1.需要一个数据文件,这里用的是直接 ...

  7. 【Python 数据分析】pandas数据导入

    导入CSV文件数据 环境 C:\Users\Thinkpad\Desktop\Data\信息表.csv 语法 pd.read_csv(filename):从CSV文件导入数据 实现代码 import ...

  8. python twisted异步将数据导入到数据库中

    from twisted.enterprise import adbapi from twisted.internet import reactor def creat_conn(): # 数据库基本 ...

  9. python读取csv文件数据绘制图像,例子绘制天气每天最高最低气温气象图

随机推荐

  1. CSS3新特性,绘制常见图形

    前言:最近准备做一个自己的网页,设计稿中导航我准备设计成矩形,也有hover样式展示的矩形,当中一些头像等等.以前除了画圆,好像真没认真画过其他图形,今天就画画我们常见到的几个图形. 在此之前我们有必 ...

  2. Mesh Data Structure in OpenCascade

    Mesh Data Structure in OpenCascade eryar@163.com 摘要Abstract:本文对网格数据结构作简要介绍,并结合使用OpenCascade中的数据结构,将网 ...

  3. SpringMVC+FreeMarker

    前言: 最近在学习SpringMVC,模板引擎用的是FreeMarker,之前没有接触过.利用SpringMVC开发其实还有许多的步骤,比如控制层,服务层,持久化层,实体等等,先弄了一个小demo来总 ...

  4. 引用类型-RegExp类型

    JavaScript高级程序设计(第三版)笔记-第五章-RegExp类型 定义正则表达式有两种方式 1.用字面量形式定义正则表达式: ver expression = /patterns/flags; ...

  5. tn文本分析语言(四) 实现自然语言计算器

    tn是desert和tan共同开发的一种用于匹配,转写和抽取文本的语言.解释器使用Python实现,代码不超过1000行. github地址:https://github.com/ferventdes ...

  6. UWP开发之Mvvmlight实践四:{x:bind}和{Binding}区别详解

    {x:bind}是随着UWP被推出而被添加的,可以说是Win10 UWP开发专有扩展.虽然 {x:Bind} 缺少{Binding} 中的一些功能,但它运行时所花费的时间和使用的内存量均比 {Bind ...

  7. CDH安装失败了,如何重新安装

    1> 删除Agent节点的UUID # rm -rf /opt/cm-5.4.7/lib/cloudera-scm-agent/* 2>  清空主节点CM数据库 进入主节点的Mysql数据 ...

  8. C语言 第三章 基础编程测试与练习

    1.屏幕上输出:This is a C program 2.输入两个整数,求两个数的和,如下所示:请输入第1个数:5请输入第2个数:3 3加5的和是8 3.完成华氏温度与摄氏温度间的转换,如下所示:请 ...

  9. Opencv VideoCapture实时捕捉摄像头信息

    #include "opencv2/highgui/highgui.hpp" #include <iostream> using namespace cv; using ...

  10. 相克军_Oracle体系_随堂笔记005-Database buffer cache

    本章主要阐述SGA中的Database buffer cache. Buffer cache { 1.pin (读写瞬间的状态) 2.clean 3.dirty 4.unused } --Databa ...