# -*-coding=utf-8-*- __author__ = 'Rocky' ''' http://30daydo.com Contact: [email protected] ''' # 模拟买入 纯粹纪录。 import os, sys, chardet import pandas as pd import datetime import numpy as np import tushare as ts from send_mail import sender_139 from setting import get_engine, get_mysql_conn, is_holiday, llogger, DATA_PATH logger = llogger(__file__) class Simulation(): def __init__(self): # path=os.path.join(os.getcwd(),'data') path = DATA_PATH if os.path.exists(path) == False: os.mkdir(path) os.chdir(path) self.name = 'simulation.xls' self.df = pd.read_excel(self.name) self.df[u'代码'] = self.df[u'代码'].map(lambda x: str(x).zfill(6)) self.engine = get_engine('db_stock')
# -*-coding=utf-8-*- import re import time import datetime import requests import pandas as pd from setting import get_engine, llogger, is_holiday,get_mysql_conn import six from send_mail import sender_139 from sqlalchemy import VARCHAR import os engine = get_engine('db_jisilu') logger = llogger('log/'+'jisilu') # 爬取集思录 可转债的数据 class Jisilu(object): def __init__(self): self.check_holiday() # py2 if six.PY2: self.timestamp = long(time.time() * 1000) else: self.timestamp = int(time.time() * 1000) self.headers = { 'User-Agent': 'User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36', 'X-Requested-With': 'XMLHttpRequest'} self.url = 'https://www.jisilu.cn/data/cbnew/cb_list/?___jsl=LST___t={}'.format(self.timestamp)
# -*-coding=utf-8-*- # 估价达到自己的设定值,发邮件通知, 每天2.45发邮件 import tushare as ts from setting import get_engine, trading_time, llogger, is_holiday, get_mysql_conn import datetime import time import pandas as pd import numpy as np import os dirname = os.path.dirname(__file__) full_name = os.path.join(dirname, 'alert_me_{}.log'.format(datetime.date.today())) logger = llogger(full_name) # 循环检测时间 LOOP_TIME = 60 EXECEPTION_TIME = 20 MARKET_OPENING = 0 # ALERT_PERCENTAGE = 3 DELTA_TIME = 30 ZG_ALERT_PERCENT = 5 ZZ_ALERT_PERCENT = 4 CW_ALERT_PERCENT = -5 DIFF_DELTA_TIME = 30 # ALERT_PERCENT_POOL = 3 DIFF_V = 40 # quote 接口以千为单位 file = 'D:\OneDrive\Stock\gj_hold.xls' # 可转债市场的监控 和 自选池
# -*-coding=utf-8-*- __author__ = 'Rocky' ''' http://30daydo.com Contact: [email protected] ''' # 获取每天的行情信息 import tushare as ts import pandas as pd import time import datetime import os from setting import get_engine, llogger, is_holiday, DATA_PATH filename = os.path.basename(__file__) logger = llogger('log/' + filename) class FetchDaily(object): def __init__(self): self.today = datetime.datetime.now().strftime('%Y-%m-%d') self.path = DATA_PATH if not os.path.exists(self.path): os.mkdir(self.path) self.df_today_all = pd.DataFrame() self.TIMEOUT = 10 def gettodaymarket(self, re_try=10): while re_try > 0:
''' import pandas as pd import talib import tushare as ts import matplotlib as mpl from mpl_finance import candlestick2_ochl, volume_overlay import matplotlib.pyplot as plt from setting import get_engine mpl.rcParams['font.sans-serif'] = ['simhei'] mpl.rcParams['axes.unicode_minus'] = False from setting import llogger filename=os.path.basename(__file__) logger = llogger('log/'+filename) engine = get_engine('db_stock', local=True) base_info = pd.read_sql('tb_basic_info', engine, index_col='index') def plot_stock_line(api,code, name, table_name, current, start='2017-10-01', save=False): title = '{} {} {} {}'.format(current, code, name, table_name) title = title.replace('*', '_') if os.path.exists(title + '.png'): return
# -*-coding=utf-8-*- # 股市黑名单 from setting import get_mysql_conn,llogger,DATA_PATH import os import codecs logger = llogger(__file__) def create_tb(conn): cmd = '''CREATE TABLE IF NOT EXISTS `tb_blacklist` (DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP,CODE VARCHAR(6) PRIMARY KEY,NAME VARCHAR(60),REASON TEXT);''' cur = conn.cursor() try: cur.execute(cmd) conn.commit() except Exception as e: logger.info(e) conn.rollback() def update_data(filename,conn): cur = conn.cursor() with codecs.open(filename, 'r',encoding='utf8') as f: content = f.readlines() if not content: return for line in content: (code, name, reason) = line.strip().split(';') cmd = '''INSERT INTO `tb_blacklist` (CODE,NAME,REASON) VALUES (\"%s\",\"%s\",\"%s\")''' % (code, name, reason)
# -*-coding=utf-8-*- # 估价达到自己的设定值,发邮件通知, 每天2.45发邮件 import tushare as ts from setting import get_engine, trading_time, llogger, is_holiday import datetime import time import pandas as pd import numpy as np import os dirname=os.path.dirname(__file__) full_name = os.path.join(dirname,'alert_me_{}.log'.format(datetime.date.today())) logger = llogger(full_name) # 循环检测时间 LOOP_TIME = 60 EXECEPTION_TIME = 20 MARKET_OPENING = 0 # ALERT_PERCENTAGE = 3 DELTA_TIME = 20 ZG_ALERT_PERCENT = 5 ZZ_ALERT_PERCENT = 3 DIFF_DELTA_TIME=10 # ALERT_PERCENT_POOL = 3 DIFF_V = 20 # quote 接口以千为单位 file = 'D:\OneDrive\Stock\gj_hold.xls' # 可转债市场的监控 和 自选池 class ReachTarget():
#-*-coding=utf-8-*- # 每天收盘收运行 import datetime import time __author__ = 'Rocky' import tushare as ts import os from setting import get_engine, llogger, is_holiday, DATA_PATH import pandas as pd logger = llogger('collect_data.log') class SaveData(): today = datetime.datetime.now().strftime("%Y-%m-%d") daily_engine = get_engine('db_daily') def __init__(self): work_space = DATA_PATH if os.path.exists(work_space) == False: os.mkdir(work_space) os.chdir(work_space) @staticmethod def daily_market(): df = ts.get_today_all() try: df.to_sql(SaveData.today, SaveData.daily_engine, if_exists='replace') except Exception as e:
#-*-coding=utf-8-*- # 每天收盘收运行 import datetime import time __author__ = 'Rocky' import tushare as ts import os from setting import get_engine,llogger,is_holiday,DATA_PATH import pandas as pd logger=llogger('collect_data.log') class SaveData(): today = datetime.datetime.now().strftime("%Y-%m-%d") daily_engine = get_engine('db_daily') def __init__(self): work_space=DATA_PATH if os.path.exists(work_space) ==False: os.mkdir(work_space) os.chdir(work_space) @staticmethod def daily_market(): df = ts.get_today_all() try: df.to_sql(SaveData.today,SaveData.daily_engine,if_exists='replace') except Exception as e: logger.info(e) logger.info("Save {} data to MySQL".format(SaveData.today))
# -*-coding=utf-8-*- # @Time : 2019/2/11 14:28 # @File : cb_index.py # 可转债指数 import datetime import re import pandas as pd import requests from setting import get_mysql_conn, llogger import tushare as ts logger = llogger('log/' + 'bond_statistic') # 获取当天的记录 def today(): url = 'https://www.jisilu.cn/data/cbnew/cb_index_quote/' headers = { 'Host': 'www.jisilu.cn', 'X-Requested-With': 'XMLHttpRequest', 'Referer': 'https://www.jisilu.cn/data/cbnew/', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36' } r = requests.get(url=url, headers=headers) # print(r.text) data_ = r.json()