• 大小: 42KB
    文件类型: .rar
    金币: 2
    下载: 3 次
    发布日期: 2021-05-24
  • 语言: Python
  • 标签: python  分时图  K线图  

资源简介

python 实现股票分时图K线图及抓取免费level2行情

资源截图

代码片段和文件信息

# -*- coding: utf-8 -*-
import sys
from PyQt5 import QtCore QtGui
from PyQt5.QtWidgets import QWidget QApplicationQMainWindowQHBoxLayout
from Public.RequestUtils import StocksRequest

# 绘制行情类
class K线图工具类(QWidget):
    左侧补丁边距 = 45
    右侧补丁边距 = 45
    顶部补丁边距 = 25
    底部补丁边距 = 1
    总宽 = 左侧补丁边距 + 右侧补丁边距
    总高 = 顶部补丁边距 + 底部补丁边距
    主窗宽 = 0
    主窗高 = 0
    表格高度 = 0
    表格宽度 = 0


    def __init__(self parent):
        # 初始化
        super(K线图工具类 self).__init__()
        self.parent = parent
        self.paint = QtGui.QPainter()
        # 度量尺对象
        self.metrics = self.paint.fontMetrics()
        self.字体库 = dict()
        self.字体库[‘默认字体‘] = QtGui.QFont(‘Serif‘ 9 QtGui.QFont.Light)
        self.字体库[‘雅黑加粗字体‘] = QtGui.QFont(‘Serif‘ 12 QtGui.QFont.Bold)
        self.字体库[‘雅黑字体‘] = QtGui.QFont(‘Serif‘ 12 QtGui.QFont.Light)
        self.设置当前字体(‘默认字体‘)
        # 设置笔刷样式库
        self.笔刷样式库 = dict()
        # 红色 1px粗  1px点 2px距 线条
        self.笔刷样式库[‘红色1px虚线‘] = QtGui.QPen(QtCore.Qt.red 1 QtCore.Qt.DashLine)
        self.笔刷样式库[‘红色1px虚线‘].setDashPattern([1 2])
        self.笔刷样式库[‘红色1px线‘] = QtGui.QPen(QtCore.Qt.red 1 QtCore.Qt.SolidLine)
        self.笔刷样式库[‘白色1px线‘] = QtGui.QPen(QtCore.Qt.white 1 QtCore.Qt.SolidLine)
        self.笔刷样式库[‘绿色1px线‘] = QtGui.QPen(QtCore.Qt.green 1 QtCore.Qt.SolidLine)
        self.笔刷样式库[‘黄色1px线‘] = QtGui.QPen(QtCore.Qt.yellow 1 QtCore.Qt.SolidLine)
        self.笔刷样式库[‘亮蓝1px线‘] = QtGui.QPen(QtCore.Qt.cyan 1 QtCore.Qt.SolidLine)

    def 开始绘制(self):
        self.绘制表格()
        self.绘制表格上方的股票信息()
        self.绘制K线()
        self.绘制MACD()
        self.绘制VOL()
    def paintEvent(self event):
        # 获得窗口的长和宽
        主窗口大小 = self.parent.size()
        self.主窗宽 = 主窗口大小.width()
        self.主窗高 = 主窗口大小.height()
        self.表格高度 = self.主窗高 - self.总高
        self.表格宽度 = self.主窗宽 - self.总宽
        self.paint.begin(self)
        self.开始绘制()
        self.paint.end()  # 结束

    def 绘制表格(self):
        self.设置当前笔刷(‘红色1px线‘)
        self.paint.setBrush(QtCore.Qt.NoBrush)
        self.paint.drawRect(0 0 self.主窗宽 - 1 self.主窗高 - 1)
        # 画分主边框
        self.paint.drawRect(self.左侧补丁边距 self.顶部补丁边距 self.主窗宽 - self.总宽 self.主窗高 - self.总高)
        # 成交量和走势的分界线(成交量和走势三七割)
        self.paint.drawLine(self.左侧补丁边距 self.表格高度 * 0.6 + self.顶部补丁边距 self.主窗宽 - self.右侧补丁边距
                            self.表格高度 * 0.6 + self.顶部补丁边距)
        self.paint.drawLine(self.左侧补丁边距 self.表格高度 * 0.8 + self.顶部补丁边距 self.主窗宽 - self.右侧补丁边距
                            self.表格高度 * 0.8 + self.顶部补丁边距)

    def 设置当前字体(self code=‘默认字体‘):
        self.paint.setFont(self.字体库[code])

    def 设置当前笔刷(self code=‘default‘):
        self.paint.setPen(self.笔刷样式库[code])

    def 绘制表格上方的股票信息(self):
        self.设置当前笔刷(‘黄色1px线‘)
        self.paint.drawText(4 + self.左侧补丁边距 self.顶部补丁边距 - 4 str(self.parent.股票数据[‘股票名称‘]))  # 股票名称
        self.paint.drawText(4 + self.左侧补丁边距 + 140

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件          9  2017-03-17 21:04  leve2Demo\.idea\.name

     文件        228  2017-03-21 09:11  leve2Demo\.idea\inspectionProfiles\profiles_settings.xml

     文件        398  2017-03-21 09:11  leve2Demo\.idea\leve2Demo.iml

     文件        212  2017-03-21 09:23  leve2Demo\.idea\misc.xml

     文件        270  2017-03-17 21:04  leve2Demo\.idea\modules.xml

     文件        164  2017-03-17 21:04  leve2Demo\.idea\vcs.xml

     文件      54789  2017-03-28 13:59  leve2Demo\.idea\workspace.xml

     文件      11691  2017-03-27 17:35  leve2Demo\K线图.py

     文件      13250  2017-03-18 22:00  leve2Demo\Public\Public.py

     文件       7817  2017-03-27 16:48  leve2Demo\Public\RequestUtils.py

     文件         28  2013-04-20 07:52  leve2Demo\Public\__init__.py

     文件      16986  2017-03-18 22:00  leve2Demo\Public\__pycache__\Public.cpython-35.pyc

     文件       6767  2017-03-27 16:48  leve2Demo\Public\__pycache__\RequestUtils.cpython-35.pyc

     文件        125  2017-03-18 21:57  leve2Demo\Public\__pycache__\__init__.cpython-35.pyc

     文件       1846  2017-03-24 11:53  leve2Demo\sinatest.py

     文件      11818  2017-03-24 11:47  leve2Demo\test.py

     文件       8535  2017-03-27 17:36  leve2Demo\__pycache__\K线图.cpython-35.pyc

     文件      13635  2017-03-27 17:36  leve2Demo\__pycache__\分时图.cpython-35.pyc

     文件       4838  2017-03-28 13:59  leve2Demo\主窗口.py

     文件      20070  2017-03-27 17:35  leve2Demo\分时图.py

     目录          0  2017-03-21 09:11  leve2Demo\.idea\inspectionProfiles

     目录          0  2017-03-27 16:48  leve2Demo\Public\__pycache__

     目录          0  2017-03-28 13:59  leve2Demo\.idea

     目录          0  2017-03-27 16:48  leve2Demo\Public

     目录          0  2017-03-27 17:36  leve2Demo\__pycache__

     目录          0  2017-03-28 13:59  leve2Demo

----------- ---------  ---------- -----  ----

               173476                    26


评论

共有 条评论