bondRestData.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. __author__ = 'weijie'
  2. from EmQuantAPI import *
  3. from datetime import timedelta, datetime
  4. import time
  5. import traceback
  6. import json
  7. from StockRestPojo import StockRestPojo
  8. from dbOperation import dbOperation
  9. from threading import Thread
  10. import db_config
  11. def csqCallback(quantdata):
  12. current_time = datetime.strftime(datetime.now(),"%H:%M:%S")
  13. time1 = "09:15:00"
  14. time2 = "11:30:00"
  15. time3 = "12:59:00"
  16. time4 = "15:00:00"
  17. if (current_time > time1 and current_time < time2) or (current_time > time3 and current_time < time4):
  18. try:
  19. fileName = "/www/wwwroot/csqdata/bond/" + str(round(time.time() * 1000000)) + ".txt"
  20. with open(fileName, 'w', encoding="utf-8") as file:
  21. file.write(str(quantdata.Data))
  22. except Exception as e:
  23. print(str(e))
  24. class BondRestData:
  25. def toGet(self):
  26. try:
  27. db = dbOperation(db_config.db_zhaiquan)
  28. 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")
  29. # 拼接证券代码
  30. codesStr = ""
  31. i = 0
  32. for stockPojo in stockPojoList:
  33. i = i + 1
  34. codesStr = codesStr + stockPojo['code'] + ','
  35. if 0 == i%500 or str(i) == str(len(stockPojoList)):
  36. #实时行情订阅使用范例
  37. codesStr = codesStr[:-1]
  38. 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)
  39. print(data)
  40. codesStr = ""
  41. db.close()
  42. except Exception as ee:
  43. print("error >>>",ee)
  44. traceback.print_exc()