Exemplo n.º 1
0
def getStockHistoryInfo():
    stockList = loadJsonConfig(
        os.path.abspath(
            os.path.join(os.getcwd(), "../config/newStockList.json")))
    startDate = '2014-07-01'
    endDate = '2017-07-06'
    writeLog(unicode("开始查询股票历史行情数据,股票池:{0}").format(stockList))
    for stock in stockList:
        code = stock[0]
        data = getHistoryData(code, startDate, endDate)

        insertSql = unicode(
            "INSERT INTO s_stock VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
        )
        parameters = []
        for i in range(0, len(data)):
            date = data.index[i]
            open = data.iloc[i]['open']
            close = data.iloc[i]['close']
            high = data.iloc[i]['high']
            low = data.iloc[i]['low']
            volume = data.iloc[i]['volume']
            changePercent = data.iloc[i]['p_change']
            turnover = data.iloc[i]['turnover']
            parameters.append([
                code, date, -1, -1, -1, volume, -1, high, low, open, close,
                changePercent, -1, turnover, -1, -1, -1, -1, -1, -1, -1,
                int(time.mktime(time.strptime(date, '%Y-%m-%d'))), -1, -1, -1,
                -1, -1, -1, -1, -1, -1, -1
            ])

        batchInsert(insertSql, parameters)
    writeLog(unicode("查询股票历史行情数据完成"))
Exemplo n.º 2
0
def initMysql():
    global MYSQLCONNECTION
    config = loadJsonConfig(
        os.path.abspath(os.path.join(os.getcwd(), "../config/db.json")))
    MYSQLCONNECTION = MySqlConnection(config['host'], config['port'],
                                      config['user'], config['password'],
                                      config['database'])
Exemplo n.º 3
0
def runTask():
    if datetime.today().weekday() < 5 and datetime.now(
    ).hour >= 9 and datetime.now().hour < 10 and datetime.now().minute <= 20:
        begin = datetime.now()
        sendMessageToMySelf(unicode("启动均线数据提醒"))

        initMysql()
        stockList = loadJsonConfig(
            os.path.abspath(
                os.path.join(os.getcwd(), "../config/avglineReminder.json")))
        checkAvgline(stockList)
        disconnect()

        end = datetime.now()
        sendMessageToMySelf(
            unicode("今日均线数据提醒程序运行结束,当前时间:{0},执行用时:{1}").format(
                datetime.now(), end - begin))

    t = Timer(900, runTask)
    t.start()
Exemplo n.º 4
0
def updateNewList():
    oldList = loadJsonConfig(
        os.path.abspath(
            os.path.join(
                os.getcwd(), "../backup/goodStockList_" +
                datetime.now().strftime('%Y-%m-%d') + ".json")))
    dic = {}
    for item in oldList:
        dic[item[0]] = 1

    stockList = select(
        unicode("SELECT code,name from s_stock_info")
    )  # loadJsonConfig(os.path.abspath(os.path.join(os.getcwd(), "../config/goodStockList.json")))
    newList = []
    for item in stockList:
        if item[0] not in dic:
            newList.append([item[0], item[1]])

    saveFileName = os.path.abspath(
        os.path.join(os.getcwd(), "../config/newStockList.json"))
    writeFile(saveFileName, json.dumps(newList))
Exemplo n.º 5
0
def getMSCI():
    msci = loadJsonConfig(
        os.path.abspath(os.path.join(os.getcwd(), "../config/msci.json")))
    msciResult = handleSpecifiedStock(msci)
    saveFile("msci.csv", msciResult)
    saveToDb(8, msciResult)
Exemplo n.º 6
0
def getSh300():
    sh300 = loadJsonConfig(
        os.path.abspath(os.path.join(os.getcwd(), "../config/sh300.json")))
    sh300Result = handleSpecifiedStock(sh300)
    saveFile("sh300.csv", sh300Result)
    saveToDb(7, sh300Result)
Exemplo n.º 7
0
def getStockHistoryInfoFromConfig():
    stockList = loadJsonConfig(
        os.path.abspath(
            os.path.join(os.getcwd(), "../config/newStockList.json")))
    updateStockHistoryInfoByTHS(stockList)