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的更多相关文章

  1. [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 ...

  2. [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 ...

  3. [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 ...

  4. [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 ...

  5. [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 ...

  6. [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 ...

  7. 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 ...

  8. [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 ...

  9. [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 ...

  10. [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 ...

随机推荐

  1. 集成Javascript Logging on MVC or Core

    ASP.NET Core provides us a rich Logging APIs which have a set of logger providers including: Console ...

  2. Servlet篇 之 web服务器

    创建web项目,在web项目中创建html页面,然后把项目部署到web服务器里面,启动服务器之后,可以使用浏览器通过URL地址的方式,访问到web项目中的html页面了 Web服务器: 常用tomca ...

  3. Nginx IP地址透传

    L:119

  4. 【深入Java虚拟机】之一:Java内存模型

    [深入Java虚拟机]之:Java内存区域与内存溢出 内存区域 Java虚拟机在执行Java程序的过程中会把他所管理的内存划分为若干个不同的数据区域.Java虚拟机规范将JVM所管理的内存分为以下几个 ...

  5. 静态变量setter注入

    1.java中静态方法调用非静态成员变量.非静态方法 public class Circle { private double radius = 1.0; double getAre() { retu ...

  6. MT【249】离心率两题

    椭圆$\dfrac{x^2}{a^2}+\dfrac{y^2}{b^2}=1,(a>b>0)$的一个焦点为$F$,过$F$的直线交椭圆于$A,B$两点,$M$是点$A$关于原点的对称点.若 ...

  7. MT【154】拉格朗日配方

    (清华2017.4.29标准学术能力测试24) 设$x,y\in\mathbb{R}$,函数$f(x,y)=x^2+6y^2-2xy-14x-6y+72$的值域为$M$,则______ A.$1\in ...

  8. Vert.x系列(三)--ClusteredEventBus源码分析

    前言:因为ClusteredEventBus涉及集群,有必产生网络问题,从而引入了NetServer.ServerID等涉及网络,端口的类.在之前的EventBusImpl中, 使用的数据结构是以ad ...

  9. rt-thread之 for (fn_ptr = &__rt_init_rti_board_start; fn_ptr < &__rt_init_rti_board_end; fn_ptr++) 理解

    @2019-01-30 [小记] 利用宏 INIT_EXPORT() --- __attribute__() 将函数重新放置在自定义段,执行时去该段获取函数地址 RT-Thread 的 INIT_BO ...

  10. cf1088E Ehab and a component choosing problem (树形dp)

    题意(考试时看错了对着样例wa了好久..):从树上选k个连通块,使得权值的平均值最大的基础上,选的块数最多 如果不考虑块数最多的限制,肯定是只选一个权值最大的块是最好的 然后只要看这个权值最大的块有多 ...