stock
version: 1
disable_existing_loggers: False
formatters:
simple:
format: "%(asctime)s - %(name)s - %(levelname)s - %(threadName)s - %(lineno)d - %(message)s"
handlers:
console:
class: logging.StreamHandler
level: DEBUG
formatter: simple
stream: ext://sys.stdout
info_file_handler:
class: logging.handlers.RotatingFileHandler
level: INFO
formatter: simple
filename: info.log
maxBytes: 10485760
backupCount: 20
encoding: utf8
error_file_handler:
class: logging.handlers.RotatingFileHandler
level: ERROR
formatter: simple
filename: errors.log
maxBytes: 10485760
backupCount: 20
encoding: utf8
loggers:
my_module:
level: ERROR
handlers: [info_file_handler]
propagate: no
root:
level: INFO
handlers: [console,info_file_handler,error_file_handler]
log_config.yaml
# encoding: utf-8
import requests
import logging
import logging.config
import random
import os
import yaml
import time
import threading class Observer(object):
open_price_last_1 = ''
close_price_last_1 = ''
highest_price_last_1 = ''
minimum_price_last_1 = ''
ding_fen_xing = []
di_fen_xing = []
not_ding_di = []
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36'} def __init__(self):
self.stop_flag = False def get_stock_data(self,stock_code,scale):
"""
获取K 线数据
:param stock_code: 代码
:param scale: 级别
:return: k线数据
"""
#url = 'http://ifzq.gtimg.cn/appstock/app/kline/mkline?param=sh600030,m30,,320&_var=m30_today&r=0.1700474168906776'
url = 'http://ifzq.gtimg.cn/appstock/app/kline/mkline'
params = {
'param': '{},m{},,320'.format(stock_code,scale),
'_var': 'm{}_today'.format(scale),
'r': '0.1700474{}'.format("".join(random.choice("") for i in range(10)))
}
logging.info('url:%s \t params:%s',url,params)
res = requests.get(url,params=params,headers=self.headers)
logging.info('response:%s:',res.content.decode('unicode_escape').rstrip()) def get_stock_code(self,a_type):
"""
获取两市股票代码
:param a_type: sh or sz
:return: stock_code
"""
#url = 'http://stock.gtimg.cn/data/index.php?appn=rank&t=rankash/chr&p=1&o=0&l=40&v=list_data'
url = 'http://stock.gtimg.cn/data/index.php'
params = {
'appn': 'rank',
't': 'ranka{}/chr'.format(a_type),
'p': 1,
'o': 0,
'l': 3000,
'v': 'list_data'
}
logging.info('url:%s \t params:%s', url, params)
res = requests.get(url, params=params, headers=self.headers)
logging.info('response:%s:',res.content.decode('unicode_escape').rstrip()) def get_plate_data(self,stock_code):
"""
获取盘中数据,如果出现大于80万的买单弹框提示
:param stock_code:
:return:
"""
#url = 'http://web.sqt.gtimg.cn/q=sh601208?r=0.9884275211413494'
url = 'http://web.sqt.gtimg.cn'
params = {
'q': stock_code,
'r': '0.1700474{}'.format("".join(random.choice("") for i in range(10)))
}
logging.info('url:%s \t params:%s', url, params)
res = requests.get(url, params=params, headers=self.headers)
res_text = res.content.decode('GBK')
logging.info('response:%s:',res_text.rstrip())
plate_data = res_text.split('~')
stock_name_this = plate_data[1]
stock_code_this = plate_data[2]
for list_data in plate_data:
if '|' in list_data:
plate_date_strike = list_data.split('|')
#logging.info(plate_date_strike )
buy_list = []
for plate_date_strike_detail in plate_date_strike:
if 'B' in plate_date_strike_detail :
buy_list.append(int(plate_date_strike_detail.split('/')[4]))
logging.info(buy_list)
if buy_list and max(buy_list) > 800000:
logging.info('%s %s 出现了80万以上的买单' % (stock_name_this, stock_code_this))
self.alert_msg('%s %s 出现了80万以上的买单' % (stock_name_this, stock_code_this))
self.stop_flag = True
else:
logging.info('%s %s 没有出现80万以上的买单' % (stock_name_this, stock_code_this)) def alert_msg(self,msg):
commond = 'msg * %s'%msg
os.system(commond) class MonitorThread(threading.Thread):
def __init__(self,stock_code):
threading.Thread.__init__(self)
self.name = stock_code
self.stock_code = stock_code def run(self):
logging.info(self.name + '监控开始...')
o = Observer()
while 1:
o.get_plate_data(self.stock_code)
if o.stop_flag:
break
time.sleep(5)
logging.info(self.name + '监控结束!') if __name__ == '__main__':
path = 'logging.yaml'
value = os.getenv('LOG_CFG', None)
if value:
path = value
if os.path.exists(path):
with open(path, "r") as f:
config = yaml.load(f)
logging.config.dictConfig(config)
else:
print('log config file not found!') monitor_list = ['sz002464','sh603008']
for stock_code in monitor_list:
thread_a = MonitorThread(stock_code)
thread_a.start()
# encoding: utf-8
import requests
import logging
import logging.config
import random
import os
import yaml
import time
import threading class Observer(object):
open_price_last_1 = ''
close_price_last_1 = ''
highest_price_last_1 = ''
minimum_price_last_1 = ''
ding_fen_xing = []
di_fen_xing = []
not_ding_di = []
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36'} def __init__(self):
self.stop_flag = False def get_stock_data(self,stock_code,scale):
"""
获取K 线数据
:param stock_code: 代码
:param scale: 级别
:return: k线数据
"""
#url = 'http://ifzq.gtimg.cn/appstock/app/kline/mkline?param=sh600030,m30,,320&_var=m30_today&r=0.1700474168906776'
url = 'http://ifzq.gtimg.cn/appstock/app/kline/mkline'
params = {
'param': '{},m{},,320'.format(stock_code,scale),
'_var': 'm{}_today'.format(scale),
'r': '0.1700474{}'.format("".join(random.choice("") for i in range(10)))
}
logging.info('url:%s \t params:%s',url,params)
res = requests.get(url,params=params,headers=self.headers)
res_str = res.content.decode('unicode_escape').rstrip()
#logging.info('response:%s:',res_str)
res_dict = eval(res_str[res_str.index("={")+1:res_str.index("}}}")+3])
scale_data = res_dict['data'][stock_code]['m'+scale]
#logging.info(scale_data)
return scale_data def get_stock_code(self,a_type):
"""
获取两市股票代码
:param a_type: sh or sz
:return: stock_code
"""
#url = 'http://stock.gtimg.cn/data/index.php?appn=rank&t=rankash/chr&p=1&o=0&l=40&v=list_data'
url = 'http://stock.gtimg.cn/data/index.php'
params = {
'appn': 'rank',
't': 'ranka{}/chr'.format(a_type),
'p': 1,
'o': 0,
'l': 3000,
'v': 'list_data'
}
logging.info('url:%s \t params:%s', url, params)
res = requests.get(url, params=params, headers=self.headers)
res_str = res.content.decode('unicode_escape').rstrip()
#logging.info('response:%s:',res_str)
res_str_list = res_str[res_str.index("data:'") + 6:res_str.index("'}")].split(',')
logging.info(res_str_list)
return res_str_list def get_plate_data(self,stock_code):
"""
获取盘中数据,如果出现大于80万的买单弹框提示
:param stock_code:
:return:
"""
#url = 'http://web.sqt.gtimg.cn/q=sh601208?r=0.9884275211413494'
url = 'http://web.sqt.gtimg.cn'
params = {
'q': stock_code,
'r': '0.1700474{}'.format("".join(random.choice("") for i in range(10)))
}
logging.info('url:%s \t params:%s', url, params)
res = requests.get(url, params=params, headers=self.headers)
res_text = res.content.decode('GBK')
logging.info('response:%s:',res_text.rstrip())
plate_data = res_text.split('~')
stock_name_this = plate_data[1]
stock_code_this = plate_data[2]
for list_data in plate_data:
if '|' in list_data:
plate_date_strike = list_data.split('|')
#logging.info(plate_date_strike )
buy_list = []
for plate_date_strike_detail in plate_date_strike:
if 'B' in plate_date_strike_detail :
buy_list.append(int(plate_date_strike_detail.split('/')[4]))
logging.info(buy_list)
if buy_list and max(buy_list) > 800000:
logging.info('%s %s 出现了80万以上的买单' % (stock_name_this, stock_code_this))
self.alert_msg('%s %s 出现了80万以上的买单' % (stock_name_this, stock_code_this))
self.stop_flag = True
else:
logging.info('%s %s 没有出现80万以上的买单' % (stock_name_this, stock_code_this)) def alert_msg(self,msg):
commond = 'msg * %s'%msg
os.system(commond) class MonitorThread(threading.Thread):
def __init__(self,stock_code):
threading.Thread.__init__(self)
self.name = stock_code
self.stock_code = stock_code def run(self):
logging.info(self.name + '监控开始...')
o = Observer()
while 1:
o.get_plate_data(self.stock_code)
if o.stop_flag:
break
time.sleep(5)
logging.info(self.name + '监控结束!') if __name__ == '__main__':
path = 'logging.yaml'
value = os.getenv('LOG_CFG', None)
if value:
path = value
if os.path.exists(path):
with open(path, "r") as f:
config = yaml.load(f)
logging.config.dictConfig(config)
else:
print('log config file not found!') # monitor_list = ['sz002464','sh603008']
# for stock_code in monitor_list:
# thread_a = MonitorThread(stock_code)
# thread_a.start()
o = Observer()
code_list_sh = o.get_stock_code('sh')
code_list_sz = o.get_stock_code('sz')
code_list = code_list_sh + code_list_sz
code_list_keguanzhu = []
for stock_code in code_list:
m30_data = o.get_stock_data(stock_code, '')
#倒数第二个k线最低点是最后三根k线最低点中最低且最后一根k线收盘价高于中间一个k线的最高价
if min(float(m30_data[-1][4]), float(m30_data[-2][4]), float(m30_data[-3][4])) == float(m30_data[-2][4]) and float(m30_data[-1][2]) > float(m30_data[-2][3]):
logging.info('%s可以关注'%stock_code)
code_list_keguanzhu.append(stock_code)
logging.info('可关注的%d个票:%s'%(len(code_list_keguanzhu),str(code_list_keguanzhu)))
选股
stock的更多相关文章
- [LeetCode] Best Time to Buy and Sell Stock with Cooldown 买股票的最佳时间含冷冻期
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LeetCode] Best Time to Buy and Sell Stock IV 买卖股票的最佳时间之四
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LeetCode] Best Time to Buy and Sell Stock III 买股票的最佳时间之三
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LeetCode] Best Time to Buy and Sell Stock II 买股票的最佳时间之二
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LeetCode] Best Time to Buy and Sell Stock 买卖股票的最佳时间
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- [LeetCode] Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- 4 Best Time to Buy and Sell Stock III_Leetcode
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LintCode] Best Time to Buy and Sell Stock II 买股票的最佳时间之二
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LintCode] Best Time to Buy and Sell Stock 买卖股票的最佳时间
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- [LeetCode] Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
随机推荐
- Express学习(1) ------Express 入门
Express 是node 第三方框架,大家都知道,框架的意义就在于能大大简化程序地开发.那么我们就看一下Express是怎么简化node程序开发的. 1,用Express写一个hello world ...
- python第三方库的四种安装方法
1,直接pip install安装 2,在python-->default setting-->project interprer-->add 3,在这个链接里找到需要的包,下载 h ...
- memcached安装报错 error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory解决
我是从其他服务器scp来的memcached(~~~整个文件夹的那种,windows用多了的后遗症) 在准备运行 ./memcached -d -u root -l localhost -m 800 ...
- 微信小程序——使用vue构建小程序【外传】
文档 http://mpvue.com/mpvue/ 根据文档构建完成的页面如下 更多的,还要继续看下文档~
- ContOS7编译安装python3,配置虚拟环境
Python36编译安装 一,下载python源码包 网址:https://www.python.org/downloads/release/python-367/ # 软件包下载到/opt目录 cd ...
- ☆ [POJ2411] Mondriaan's Dream 「状压DP」
传送门 >Here< 题意:用1*2的砖块铺满n*m的地板有几种方案 思路分析 状压经典题! 我们以$f[i][j]$作为状态,表示第i行之前全部填完并且第i行状态为j(状压)时的方案数. ...
- FPGA时序分析相关
什么叫时序? 时间与动作的相互关系,什么时间干什么活. 同步时序:单一时钟源,所有寄存器在单一时钟源下同步工作. 异步时序:多个时钟源,除使用带时钟的触发器之外,还可以使用不带时钟的触发器与延时元件作 ...
- Codeforces Round #541 (Div. 2) D(并查集+拓扑排序) F (并查集)
D. Gourmet choice 链接:http://codeforces.com/contest/1131/problem/D 思路: = 的情况我们用并查集把他们扔到一个集合,然后根据 > ...
- PHP require php > 5.3.0
项目版本要求 在5.3版本以上,如果是用 phpStudy 环境,那么直接切换版本即可
- MT【262】一道常见错题
若$f(x^2)$的定义域为$[-1,1]$,则函数$f(x)$的定义域为______ 设$a>0$构造$f(x)=\sqrt{x(1-x)(a+x)}$,此时$f(x^2)$的定义域为$[-1 ...