导航:首页 > 期指持仓 > python开发股票监控软件

python开发股票监控软件

发布时间:2022-05-08 20:52:09

❶ 怎么在我的电脑上监控服务器上运行的一个用Python写的股票自动化交易的文件运行的各种参数和运行情况

http://www.supervisord.org/

❷ 有没有会用Python编写一个简单的建模股票价格的小程序能够对股票数据进行简单预测即可!求助!

虽然懂python 但是不懂股票,
采用random()可以么,哈哈

❸ 如何使用python抓取炒股软件中资金数据

这个说来有点复杂,用fiddle监控软件跟服务器间的通讯,找到数据源地址,然后用excel或python抓这个源地址数据,可能还要加上反扒代码,构造时间戳等等,你网上找python网抓视频教程看看就知道了。

❹ 用python开发视频监控管理系统,如海康8600平台,需要怎样的思路开发难度多大

直接买海康威视现成的模块好了,Python可以做这个,但不是很简单的事。运行效率也不高,对于需要实时报警的视频预警系统来说,Py很吃资源的。

❺ 怎样用python处理股票

用Python处理股票需要获取股票数据,以国内股票数据为例,可以安装Python的第三方库:tushare;一个国内股票数据获取包。可以在网络中搜索“Python tushare”来查询相关资料,或者在tushare的官网上查询说明文档。

❻ 怎样用 Python 写一个股票自动交易的程序

❼ 有python开发的监控工具吗

在公司里做的一个接口系统,主要是对接第三方的系统接口,所以,这个系统里会和很多其他公司的项目交互。随之而来一个很蛋疼的问题,这么多公司的接口,不同公司接口的稳定性差别很大,访问量大的时候,有的不怎么行的接口就各种出错了。
这个接口系统刚刚开发不久,整个系统中,处于比较边缘的位置,不像其他项目,有日志库,还有短信告警,一旦出问题,很多情况下都是用户反馈回来,所以,我的想法是,拿起python,为这个项目写一个监控。如果在调用某个第三方接口的过程中,大量出错了,说明这个接口有有问题了,就可以更快的采取措施。
项目的也是有日志库的,所有的info,error日志都是每隔一分钟扫描入库,日志库是用的mysql,表里有几个特别重要的字段:
有日志库,就不用自己去线上环境扫日志分析了,直接从日志库入手。由于日志库在线上时每隔1分钟扫,那我就去日志库每隔2分钟扫一次,如果扫到有一定数量的error日志就报警,如果只有一两条错误就可以无视了,也就是短时间爆发大量错误日志,就可以断定系统有问题了。报警方式就用发送邮件,所以,需要做下面几件事情:
1. 操作MySql。
2. 发送邮件。
3. 定时任务。
4. 日志。
5. 运行脚本。
明确了以上几件事情,就可以动手了。
操作数据库
使用MySQLdb这个驱动,直接操作数据库,主要就是查询操作。
获取数据库的连接:

def get_con():
host = "127.0.0.1"
port = 3306
logsdb = "logsdb"
user = "root"
password = "never tell you"
con = MySQLdb.connect(host=host, user=user, passwd=password, db=logsdb, port=port, charset="utf8")
return con

从日志库里获取数据,获取当前时间之前2分钟的数据,首先,根据当前时间进行计算一下时间。之前,计算有问题,现在已经修改。

def calculate_time():

now = time.mktime(datetime.now().timetuple())-60*2
result = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(now))
return result

然后,根据时间和日志级别去日志库查询数据

def get_data():
select_time = calculate_time()
logger.info("select time:"+select_time)
sql = "select file_name,message from logsdb.app_logs_record " \
"where log_time >"+"'"+select_time+"'" \
"and level="+"'ERROR'" \
"order by log_time desc"
conn = get_con()

cursor = conn.cursor()
cursor.execute(sql)
results = cursor.fetchall()

cursor.close()
conn.close()

return results

发送邮件
使用python发送邮件比较简单,使用标准库smtplib就可以
这里使用163邮箱进行发送,你可以使用其他邮箱或者企业邮箱都行,不过host和port要设置正确。

def send_email(content):

sender = "[email protected]"
receiver = ["[email protected]", "[email protected]"]
host = 'smtp.163.com'
port = 465
msg = MIMEText(content)
msg['From'] = "[email protected]"
msg['To'] = "[email protected],[email protected]"
msg['Subject'] = "system error warning"

try:
smtp = smtplib.SMTP_SSL(host, port)
smtp.login(sender, '123456')
smtp.sendmail(sender, receiver, msg.as_string())
logger.info("send email success")
except Exception, e:
logger.error(e)

定时任务
使用一个单独的线程,每2分钟扫描一次,如果ERROR级别的日志条数超过5条,就发邮件通知。

def task():
while True:
logger.info("monitor running")

results = get_data()
if results is not None and len(results) > 5:
content = "recharge error:"
logger.info("a lot of error,so send mail")
for r in results:
content += r[1]+'\n'
send_email(content)
sleep(2*60)

日志
为这个小小的脚本配置一下日志log.py,让日志可以输出到文件和控制台中。
# coding=utf-8
import logging

logger = logging.getLogger('mylogger')
logger.setLevel(logging.DEBUG)

fh = logging.FileHandler('monitor.log')
fh.setLevel(logging.INFO)

ch = logging.StreamHandler()
ch.setLevel(logging.INFO)

formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)

logger.addHandler(fh)
logger.addHandler(ch)

所以,最后,这个监控小程序就是这样的app_monitor.py
# coding=utf-8
import threading
import MySQLdb
from datetime import datetime
import time
import smtplib
from email.mime.text import MIMEText
from log import logger

def get_con():
host = "127.0.0.1"
port = 3306
logsdb = "logsdb"
user = "root"
password = "never tell you"
con = MySQLdb.connect(host=host, user=user, passwd=password, db=logsdb, port=port, charset="utf8")
return con

def calculate_time():

now = time.mktime(datetime.now().timetuple())-60*2
result = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(now))
return result

def get_data():
select_time = calculate_time()
logger.info("select time:"+select_time)
sql = "select file_name,message from logsdb.app_logs_record " \
"where log_time >"+"'"+select_time+"'" \
"and level="+"'ERROR'" \
"order by log_time desc"
conn = get_con()

cursor = conn.cursor()
cursor.execute(sql)
results = cursor.fetchall()

cursor.close()
conn.close()

return results

def send_email(content):

sender = "[email protected]"
receiver = ["[email protected]", "[email protected]"]
host = 'smtp.163.com'
port = 465
msg = MIMEText(content)
msg['From'] = "[email protected]"
msg['To'] = "[email protected],[email protected]"
msg['Subject'] = "system error warning"

try:
smtp = smtplib.SMTP_SSL(host, port)
smtp.login(sender, '123456')
smtp.sendmail(sender, receiver, msg.as_string())
logger.info("send email success")
except Exception, e:
logger.error(e)

def task():
while True:
logger.info("monitor running")
results = get_data()
if results is not None and len(results) > 5:
content = "recharge error:"
logger.info("a lot of error,so send mail")
for r in results:
content += r[1]+'\n'
send_email(content)
time.sleep(2*60)

def run_monitor():
monitor = threading.Thread(target=task)
monitor.start()

if __name__ == "__main__":
run_monitor()

运行脚本
脚本在服务器上运行,使用supervisor进行管理。
在服务器(centos6)上安装supervisor,然后在/etc/supervisor.conf中加入一下配置:

复制代码代码如下:
[program:app-monitor]
command = python /root/monitor/app_monitor.py
directory = /root/monitor
user = root

然后在终端中运行supervisord启动supervisor。
在终端中运行supervisorctl,进入shell,运行status查看脚本的运行状态。
总结
这个小监控思路很清晰,还可以继续修改,比如:监控特定的接口,发送短信通知等等。
因为有日志库,就少了去线上正式环境扫描日志的麻烦,所以,如果没有日志库,就要自己上线上环境扫描,在正式线上环境一定要小心哇~

❽ 怎样用 Python 写一个股票自动交易的程序

股票自动交易助手提供了一个 Python 自动下单接口,参考代码

#股票自动交易助手Python自动下单使用例子
#把此脚本和StockOrderApi.pyOrder.dll放到你自己编写的脚本同一目录

fromStockOrderApiimport*

#买入测试
#Buy(u"600000",100,0,1,0)

#卖出测试,是持仓股才会有动作
#Sell(u"000100",100,0,1,0)

#账户信息
print("股票自动交易接口测试")
print("账户信息")
print("--------------------------------")

arrAccountInfo=["总资产","可用资金","持仓总市值","总盈利金额","持仓数量"];
foriinrange(0,len(arrAccountInfo)):
value=GetAccountInfo(u"",i,0)
print("%s%f"%(arrAccountInfo[i],value))

print("--------------------------------")
print("")

print("股票持仓")
print("--------------------------------")
#取出所有的持仓股票代码,结果以','隔开的
allStockCode=GetAllPositionCode(0)
allStockCodeArray=allStockCode.split(',')
foriinrange(0,len(allStockCodeArray)):
vol=GetPosInfo(allStockCodeArray[i],0,0)
changeP=GetPosInfo(allStockCodeArray[i],4,0)
print("%s%d%.2f%%"%(allStockCodeArray[i],vol,changeP))

print("--------------------------------")

❾ 如何用python做一个设备运维软件

Python开发的jumpserver跳板机

使用python语言编写的调度和监控工作流的平台内部用来创建、监控和调整数据管道。任何工作流都可以在这个使用Python来编写的平台上运行。

企业主要用于解决:通俗点说就是规范运维的操作,加入审批,一步一步操作的概念。

是一种允许工作流开发人员轻松创建、维护和周期性地调度运行工作流(即有向无环图或成为DAGs)的工具。这些工作流包括了如数据存储、增长分析、Email发送、A/B测试等等这些跨越多部门的用例。

这个平台拥有和 Hive、Presto、MySQL、HDFS、Postgres和S3交互的能力,并且提供了钩子使得系统拥有很好地扩展性。除了一个命令行界面,该工具还提供了一个基于Web的用户界面让您可以可视化管道的依赖关系、监控进度、触发任务等。

来个小总结

阅读全文

与python开发股票监控软件相关的资料

热点内容
股票双顶走势图 浏览:540
股票炒股手机app的swot分析 浏览:510
股票转增需要什么条件 浏览:274
股票开盘第一涨停怎么样 浏览:107
个人股票行权延期交个税时间 浏览:572
股票庄家资金博客 浏览:872
东方财富app股票开户流程 浏览:633
同花顺股票软件诈骗 浏览:161
中国中冶股票的10日均线 浏览:75
st股票摘星是利好吗 浏览:971
我们投资的股票有分红吗 浏览:768
买茅台股票散户资金有多少 浏览:173
慧球科技股票重组 浏览:863
做兼职帮人注册股票app 浏览:554
股票基金分红释放了什么信息 浏览:578
银泰银行股票 浏览:393
股票上市所需要的条件 浏览:719
判断股票是否涨停的秘诀 浏览:884
香港股票00449实时行情 浏览:207
海通证券可以登录万得股票交易吗 浏览:959