Example #1
0
def processDayCompleteInfo(stockCode, code, stockName, note, holdFlag):
    beforeStartDate = beforeDate + " 09:30:00"
    beforeEndDate = beforeDate + " 15:00:00"
    openStockTime = beforeDate + " 09:31:00"
    body = {
        "method": "get_price_period",
        "token": getToken(),
        "code": code,
        "unit": "1d",
        "date": beforeStartDate,
        "end_date": beforeEndDate,
        "fq_ref_date": beforeDate
    }
    cursor.execute(
        "SELECT yesterday_price,start_price  FROM stock_day_base_info WHERE stock_code='%s' AND DATE(create_time)='%s'"
        % (stockCode, baseDate))
    existFlag = cursor.fetchone()
    if existFlag:
        if existFlag[1]:
            return existFlag[0]
        else:
            cursor.execute(
                "update stock_day_base_info A ,stock_data B SET A.start_price = B.start_price where A.stock_code='%s' AND  A.stock_code=B.stock_code AND B.now_time='%s' "
                % (stockCode, openStockTime))
            db.commit()
        return existFlag[0]
    else:
        response = requests.post(url, data=json.dumps(body))
        dataArray = response.text.split('\n')
        yesterDayPrice = response.text[3]
        del dataArray[0]
        if len(dataArray) == 0:
            return
        yesterDayPriceArray = dataArray[0].split(',')
        yesterDayPrice = yesterDayPriceArray[2]
        cursor.execute(
            "SELECT A.maxPrice FROM (select max(high_price) as maxPrice,stock_code,stock_name from hold_stock_day_info where deal_date>=(SELECT * FROM (select deal_date from trade_days where deal_date<=DATE(now()) ORDER BY deal_date DESC limit 12) A ORDER BY A.deal_date limit 1) GROUP BY  stock_code) A where A.stock_code = '%s'"
            % (stockCode))
        max12Price = cursor.fetchone()
        print(stockCode, stockName, yesterDayPrice, note, baseDate, holdFlag,
              max12Price)
        cursor.execute(
            "INSERT INTO stock_day_base_info(stock_code,stock_name,yesterday_price,note,create_time,update_time,hold_flag,max_12_price) VALUES (%s,%s,%s,%s,%s,now(),%s,%s)",
            (stockCode, stockName, yesterDayPrice, note, baseDate, holdFlag,
             str(max12Price[0])))
        db.commit()
        return yesterDayPrice
Example #2
0
def processDayCompleteInfo(stockCode,code,stockName,baseDate):
   startTime = baseDate + " 09:30:00"
   body={
      "method": "get_price_period",
      "token": getToken(),
      "code": code,
      "unit": "1d",
      "date": startTime,
      "end_date": endTime,
      "fq_ref_date": baseDate
    }
   #print(stockCode)
   response = requests.post(url, data = json.dumps(body))
   dataArray = response.text.split('\n')
   print(dataArray)
   yesterDayPrice = response.text[3]
   del dataArray[0]
   if len(dataArray)==0 :
     return
   insertValues = []
   for data in dataArray:
     smallDataArray = data.split(',')
     dealDate = smallDataArray[0]
     if dealDate!=baseDate:
       continue
     openPrice = smallDataArray[1]
     endPrice = smallDataArray[2]
     highPrice = smallDataArray[3]
     lowPrice = smallDataArray[4]
     highLimit = smallDataArray[8]
     if len(smallDataArray)<=11:
       yesterdayPrice = '0'
     else:
       yesterdayPrice = smallDataArray[11]
     insertValues.append((stockCode,stockName,openPrice,endPrice,highPrice,lowPrice,yesterdayPrice,dealDate)) 
   cursor.executemany("INSERT INTO hold_stock_day_info(stock_code,stock_name,open_price,end_price,high_price,low_price,yesterday_price,deal_date) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",insertValues)
   db.commit()
Example #3
0
import time
import datetime
import decimal
from decimal import *
import constant
from tokenInfo import getToken

url = "https://dataapi.joinquant.com/apis"

db = pymysql.connect(constant.host,
                     constant.userName,
                     constant.password,
                     "market",
                     charset="utf8")
#获取调用凭证
token = getToken()

cursor = db.cursor()

beforeDate = "2021-12-09"


def doJob():
    #5分钟同步一次
    synNewStock()


def synNewStock():
    print("=========执行同步已发行最新股票 开始============")
    dict = {'00': 'XSHE', '30': 'XSHG', '60': 'XSHG', '688': 'XSHG'}
    rangeNum = {
Example #4
0
def prosessSinbleStockAllInfo(stockCode, code, stockName, yesterDayPrice,
                              holdFlag):
    startDate = baseDate + " 09:30:00"
    cursor = db.cursor()
    cursor.execute(
        "SELECT date_format(DATE_ADD(max(now_time),INTERVAL 1 MINUTE), '%%Y-%%m-%%d %%H:%%i:%%s') FROM stock_data WHERE stock_code='%s' "
        % (stockCode))
    startDateFetch = cursor.fetchone()
    if startDateFetch[0] is not None:
        startDate = startDateFetch[0]
    now = datetime.datetime.now()
    endDate = now.strftime('%Y-%m-%d %H:%M:%S')
    #endDate = baseDate + " 15:00:00"
    body = {
        "method": "get_price_period",
        "token": getToken(),
        "code": code,
        "unit": "1m",
        "date": startDate,
        "end_date": endDate,
        "fq_ref_date": baseDate
    }
    response = requests.post(url, data=json.dumps(body))
    dataArray = response.text.split('\n')
    del dataArray[0]
    for data in dataArray:
        smallDataArray = data.split(',')
        nowTime = smallDataArray[0]
        startPrice = smallDataArray[1]
        endPrice = smallDataArray[2]
        currentHighestPrice = smallDataArray[3]
        currentLowestPrice = smallDataArray[4]
        volume = smallDataArray[5]
        money = smallDataArray[6]
        avgPrice = (float(startPrice) + float(endPrice) +
                    float(currentHighestPrice) + float(currentLowestPrice)) / 4
        cursor = db.cursor()
        cursor.execute(
            "SELECT (start_price+end_price+lowest_price+highest_price)/4 as price,rise_point,down_point FROM stock_data WHERE stock_code ='%s' order by now_time desc limit 1"
            % (stockCode))
        preMinuteAveregePriceFetchOne = cursor.fetchone()
        if preMinuteAveregePriceFetchOne:
            preMinuteAveregePrice = preMinuteAveregePriceFetchOne[0]
            nowAveregePrice = (float(startPrice) + float(endPrice) +
                               float(currentHighestPrice) +
                               float(currentLowestPrice)) / 4
            currentAmplitude = (
                (nowAveregePrice - float(preMinuteAveregePrice)) /
                float(yesterDayPrice)) * 100
            risePoint = preMinuteAveregePriceFetchOne[1]
            downPoint = preMinuteAveregePriceFetchOne[2]
        else:
            currentAmplitude = ((float(endPrice) - float(startPrice)) /
                                float(yesterDayPrice)) * 100
            risePoint = 0
            downPoint = 0
        currentLatitude = (
            (decimal.Decimal(endPrice) - decimal.Decimal(yesterDayPrice)) /
            decimal.Decimal(yesterDayPrice)) * 100
        cursor.execute(
            "SELECT ((max(highest_price)-%s)/yesterday_price)*100>13 as flag FROM stock_data where stock_code='%s'"
            % (currentLowestPrice, stockCode))
        flag = cursor.fetchone()
        #达到位置0.75短信通知
        sevenFiveProcess(stockCode, currentLowestPrice, nowTime)
        if flag:
            if flag[0] == 1:
                #smsVerifySend(stockCode,nowTime,baseDate)
                logging.info("买入 stockName=" + stockName + " code=" +
                             stockCode + " 时间=" + nowTime + " 当前低位" +
                             str(round(currentLatitude, 2)) + "两点半后慎重考虑")
        if currentLatitude <= -6:
            logging.info("买入参考 name=" + stockName + " code=" + stockCode +
                         " 时间=" + nowTime + " 当前低位" +
                         str(round(currentLatitude, 2)))
        if currentAmplitude >= 1:
            risePoint = risePoint + 1
            if risePoint > 1 and currentLatitude < 3 and holdFlag > 0:
                smsVerifySend(stockCode, nowTime, baseDate)
            logging.info("name=" + stockName + " code=" + stockCode + " 时间=" +
                         nowTime + " 涨跌幅:" + str(round(currentLatitude, 2)) +
                         " 上扬次数:" + str(risePoint) + " 分钟级别上扬:" +
                         str(round(currentAmplitude, 2)))
            cursor.execute(
                "select *  from minute_level where stock_code='%s' and now_time='%s' "
                % (stockCode, nowTime))
            existLevel = cursor.fetchone()
            if not existLevel:
                cursor.execute(
                    "INSERT INTO minute_level (stock_code, stock_name, rise_point, down_point, current_amplitude_rise, current_latitude, now_time,deal_date,hold_flag) VALUES (%s, %s, %s, %s, %s, %s, %s,%s,%s)",
                    (stockCode, stockName, str(risePoint), str(downPoint),
                     str(round(currentAmplitude, 2)),
                     str(round(currentLatitude,
                               2)), nowTime, baseDate, str(holdFlag)))
                db.commit()
        if currentAmplitude <= -1:
            downPoint = downPoint + 1
            cursor.execute(
                "select * from minute_level where stock_code='%s' and now_time='%s' "
                % (stockCode, nowTime))
            existLevel = cursor.fetchone()
            if not existLevel:
                cursor.execute(
                    "INSERT INTO minute_level (stock_code, stock_name, rise_point, down_point, current_amplitude_down,current_latitude, now_time,deal_date,hold_flag) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
                    (stockCode, stockName, str(risePoint), str(downPoint),
                     str(round(currentAmplitude, 2)),
                     str(round(currentLatitude,
                               2)), nowTime, baseDate, str(holdFlag)))
                db.commit()
            if holdFlag > 0:
                smsVerifySend(stockCode, nowTime, baseDate)
            logging.info("name=" + stockName + " code=" + stockCode + " 时间=" +
                         nowTime + " 涨跌幅:" + str(round(currentLatitude, 2)) +
                         " 下挫次数:" + str(downPoint) + " 分钟级别下挫:" +
                         str(round(currentAmplitude, 2)))
        effectRow = cursor.execute(
            "INSERT INTO stock_data (stock_code,now_time,start_price,end_price,lowest_price,highest_price,yesterday_price,current_amplitude,current_latitude,create_time,rise_point,down_point,volume,money,avg_price) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
            (stockCode, nowTime, startPrice, endPrice, currentLowestPrice,
             currentHighestPrice, yesterDayPrice, currentAmplitude,
             currentLatitude, nowTime, risePoint, downPoint, volume, money,
             str(round(avgPrice, 2))))
        db.commit()