123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- __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):
- current_time = datetime.strftime(datetime.now(),"%H:%M:%S")
- time1 = "09:15:00"
- time2 = "11:30:00"
- time3 = "12:59:00"
- time4 = "15:00:00"
- if (current_time > time1 and current_time < time2) or (current_time > time3 and current_time < time4):
- try:
- fileName = "/www/wwwroot/csqdata/bond/" + str(round(time.time() * 1000000)) + ".txt"
- with open(fileName, 'w', encoding="utf-8") as file:
- file.write(str(quantdata.Data))
- except Exception as e:
- print(str(e))
-
- class BondRestData:
- def toGet(self):
- try:
- db = dbOperation(db_config.db_zhaiquan)
- 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 = 0
- for stockPojo in stockPojoList:
- i = i + 1
- codesStr = codesStr + stockPojo['code'] + ','
- if 0 == i%500 or str(i) == str(len(stockPojoList)):
- #实时行情订阅使用范例
- codesStr = codesStr[:-1]
- data = c.csq(codesStr, 'Date,Time,Now,High,Low,Open,PreClose,Roundlot,Change,PctChange,Volume,Amount,BuyPrice1,BuyPrice2,BuyPrice3,BuyPrice4,BuyPrice5,BuyVolume1,BuyVolume2,BuyVolume3,BuyVolume4,BuyVolume5,SellPrice1,SellPrice2,SellPrice3,SellPrice4,SellPrice5,SellVolume1,SellVolume2,SellVolume3,SellVolume4,SellVolume5','Pushtype=2',csqCallback)
- print(data)
- codesStr = ""
- db.close()
- except Exception as ee:
- print("error >>>",ee)
- traceback.print_exc()
|