❶ 怎麼在我的電腦上監控伺服器上運行的一個用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都寫好了,所以差這交易指令介面最後一步。對於股票的散戶,正規的法子是華寶,國信,興業這樣願意給介面的券商,但貌似開戶費很高才給這權利,而且只有lts,ctp這樣的c++介面,沒python版就需要你自己封裝。
方法二
是wind這樣的軟體也有直接的介面,支持部分券商,但也貴,幾萬一年是要的。
方法三
滑鼠鍵盤模擬法,很復雜的,就是模擬鍵盤滑鼠去操作一些軟體,比如券商版交易軟體和大智慧之類的。
方法四
就是找到這些軟體的關於交易指令的底層代碼並更改,不過T+1的規則下,預測准確率的重要性高於交易的及時性,花功夫做數據分析就好,交易就人工完成吧
❼ 有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的用戶界面讓您可以可視化管道的依賴關系、監控進度、觸發任務等。
來個小總結