def __init__(self): self.tools = sTools() self.benchmart_start = time.clock() self.__read_config() mysql_db = self.config['mysql']['stock'] self.mysql = sMysql(mysql_db['host'], mysql_db['user'], mysql_db['password'], mysql_db['dbname'])
def init(self, setting): self.mysql = sMysql(MYSQL_DB['host'], MYSQL_DB['user'], MYSQL_DB['password'], MYSQL_DB['dbname']) limit = 100 if 'limit' in setting.keys(): limit = setting['limit'] _where = [] if setting['start'] == setting['end']: _where.append(" dateline = %s" % setting['end']) else: last_day = " dateline = %s" % self.tools.d_date('%Y%m%d') if 'end' in setting.keys(): last_day = " dateline <= %s" % setting['end'] _where.append(last_day) if 'start' in setting.keys(): _where.append(" dateline >= %s" % setting['start']) if 'universe' in setting.keys(): s_codes = " s_code in(%s)" % self.___set_universe(setting['universe']) _where.append(s_codes) _wheres = ' AND '.join(_where) print "=======截止天数===%s====" % setting['end'] date_sql = "select dateline FROM s_opening_day WHERE dateline <=%s order by dateline desc limit %s" % (setting['end'], limit) print date_sql temp = self.mysql.getRecord(date_sql) self.lastDay = temp[0][0] self.yestoday = temp[1][0] pandas.set_option('display.width', 200) sql_data = "select s_code,code,dateline,chg_m,chg,open,close,high,low,last_close,name FROM s_stock_trade WHERE %s " % _wheres print sql_data tmpdf = pandas.read_sql(sql_data, self.mysql.db) #print tmpdf #sys.exit() #历史除权数据计算 if ('is_open_chuquan' in setting.keys()) and setting['is_open_chuquan']: self._chQ = self.getChuQuan() #print self._chQ #sys.exit() self.df = tmpdf.apply(self.format_chuquan_hanlder, axis=1) #print self.df #sys.exit() else: self.df = tmpdf self.todayDF = self.df[self.df.dateline == int(self.lastDay)] self.yestodayDF = self.df[self.df.dateline == int(self.yestoday)] #sys.exit() print "========init Days & init stock trader Done."
def get_five_sb(abc): ''' 获取实时5档买卖盘口 python realtime.py get_five_sb 页数 ''' config = __read_config() mysql_db = config['mysql']['stock'] mysql = sMysql(mysql_db['host'], mysql_db['user'], mysql_db['password'], mysql_db['dbname']) mcache = memcache.Client(['127.0.0.1:11211']) #print mcache.set('say','hello,memcache') #display - True while 1: HandicapSpider().run(mysql, mcache)
arr['sql'] = "SELECT user_id FROM user_xq WHERE 1 " arr['limit'] = 15 arr['run_script'] = "php /htdocs/soga/trader/index.php XueQiu get_xq_user_from_follows %s " return arr def get_xq_title(params): arr = {} arr['sql'] = "SELECT user_id FROM user_xq WHERE original_count>30 and followers_count >=80 ORDER BY original_count DESC" arr['limit'] = 15 arr['run_script'] = "php /htdocs/soga/trader/index.php XueQiu get_xq_title %s " return arr if __name__ == '__main__': mysql = sMysql('127.0.0.1', 'root', '1234asdf', 'stock') spider = SpiderEngine() sTools = sTools() print sys.argv function = eval(sys.argv[1]) params = 0 if (len(sys.argv) == 3): params = sys.argv[2] #build params script = function(params) run_worker_template(script)
def __init__(self): self.mysql = sMysql(MYSQL_DB['host'], MYSQL_DB['user'], MYSQL_DB['password'], MYSQL_DB['dbname']) self.headers = []
def __init__(self): self.mysql = sMysql(MYSQL_DB['host'], MYSQL_DB['user'], MYSQL_DB['password'], MYSQL_DB['dbname'])
def __init__(self): self.tools = sTools() self.benchmart_start = time.clock() self.__read_config() mysql_db = self.config['mysql']['stock'] self.mysql = sMysql(mysql_db['host'], mysql_db['user'], mysql_db['password'], mysql_db['dbname'])
arr = {} arr['sql'] = "SELECT user_id FROM user_xq WHERE 1 " arr['limit'] = 15 arr['run_script'] = "php /htdocs/soga/trader/index.php XueQiu get_xq_user_from_follows %s " return arr def get_xq_title(params): arr = {} arr['sql'] = "SELECT user_id FROM user_xq WHERE original_count>30 and followers_count >=80 ORDER BY original_count DESC" arr['limit'] = 15 arr['run_script'] = "php /htdocs/soga/trader/index.php XueQiu get_xq_title %s " return arr if __name__ == '__main__': mysql = sMysql('127.0.0.1', 'root', '1234asdf', 'stock') spider = SpiderEngine() sTools = sTools() print sys.argv function = eval(sys.argv[1]) params = 0 if(len(sys.argv) == 3): params = sys.argv[2] #build params script = function(params) run_worker_template(script)
# -*- coding: utf-8 -*- import os import sys import time import datetime from decimal import Decimal from quant.spider.TdxAnalyse import * from quant.strategy.Average import * from quant.core.DB import sMysql from quant.tools.Util import sTools from elasticsearch import Elasticsearch from settings import * mysql = sMysql(MYSQL_DB['host'], MYSQL_DB['user'], MYSQL_DB['password'], MYSQL_DB['dbname']) def k_average(indate): a = Average() a.main_report(indate) #每日收盘价在均线之上 def k_ma_count(indate): _data = mysql.getRecord("select s_code,dateline,ma5,ma10,ma20,ma30,ma60 from s_stock_average where dateline = %s" % indate) _st_data = mysql.getRecord("select s_code,close from s_stock_trade where dateline= %s" % indate) b = {} for i in range(len(_st_data)): b[str(_st_data[i][0])] = _st_data[i][1] for j in range(len(_data)):