__author__ = 'weijie' from EmQuantAPI import * from datetime import timedelta, datetime import time import traceback import json from StockRestPojo import StockRestPojo from dbOperation import dbOperation from threading import Thread import db_config def csqCallback(quantdata): try: fileName = "/www/wwwroot/csqdata/stock/" + str(round(time.time() * 1000000)) + ".txt" with open(fileName, 'w', encoding="utf-8") as file: file.write(quantdata.Data) except Exception as e: print(str(e)) class StockRestData: def toGet(self): try: db = dbOperation(db_config.db_gupiao) stockPojoList = db.query_list("select id, code, name, list_date listDate, seralid from t_stock_base_info where is_rest_add = 0 order by id asc") # 拼接证券代码 codesStr = "" i = 1 for stockPojo in stockPojoList: if 0 != i%500 : codesStr = codesStr + stockPojo['code'] + ',' if 0 == i%500 or str(i) == str(len(stockPojoList)): if(codesStr != ""): #实时行情订阅使用范例 codesStr = codesStr[:-1] data = c.csq(codesStr, 'date,time,now,high,low,open,preclose,roundlot,change,pctchange,volume,amount,volumeratio,commissionratio,commissiondiff,tradestatus,outvolume,involume,highlimit,lowlimit,speed,averageprice,buyprice1,buyprice2,buyprice3,buyprice4,buyprice5,buyvolume1,buyvolume2,buyvolume3,buyvolume4,buyvolume5,sellprice1,sellprice2,sellprice3,sellprice4,sellprice5,sellvolume1,sellvolume2,sellvolume3,sellvolume4,sellvolume5,closedtime,closedvolume,closedamount','Pushtype=2',csqCallback) print(data) codesStr = "" i = i + 1 db.close() except Exception as ee: print("error >>>",ee) traceback.print_exc()