TempIndexRestData.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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/tempindex/" + 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. elif current_time > time4:
  25. try:
  26. fileName = "/www/wwwroot/csqdata/tempindex/after/" + str(round(time.time() * 1000000)) + ".txt"
  27. with open(fileName, 'w', encoding="utf-8") as file:
  28. file.write(str(quantdata.Data))
  29. except Exception as e:
  30. print(str(e))
  31. # elif current_time < time1:
  32. # # 盘前数据
  33. # try:
  34. # fileName = "/www/wwwroot/csqdata/bond/InFront/" + str(round(time.time() * 1000000)) + ".txt"
  35. # with open(fileName, 'w', encoding="utf-8") as file:
  36. # file.write(str(quantdata.Data))
  37. # except Exception as e:
  38. # print(str(e))
  39. class TempIndexRestData:
  40. # 指数数据抓取
  41. def toGet(self):
  42. try:
  43. # 上证指数 深圳指数 创业板指数 沪深300 中小板指 深证综指
  44. data = c.csq("000001.SH,399001.SZ,399006.SZ,399300.SZ,399005.SZ,399106.SZ,159982.SZ,IXIC.GI,US30USD.FX,159919.SZ,159912.SZ,510050.SH,159922.SZ,HSI.HI","Date,Time,Now,High,Low,Open,PreClose,Roundlot,Volume,Amount,Change,PctChange,Speed",'Pushtype=2',csqCallback)
  45. print(data)
  46. except Exception as ee:
  47. print("error >>>",ee)
  48. traceback.print_exc()