lt_api.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import eikon as ek
  2. import hug
  3. from bottle import route, run
  4. import json
  5. import pandas as pd
  6. import urllib.parse
  7. hug.API(__name__).http.output_format = hug.output_format.json
  8. # 填写路透的key
  9. key = ""
  10. @hug.get('/hz_server')
  11. def hello():
  12. ek_port = ek.get_port_number()
  13. if ek_port is None:
  14. # 如果检测不到路透终端的端口,那么就返回检测失败(可能电脑重启了)
  15. return "ek false"
  16. return 'ek true'
  17. @hug.get('/edbInfo/ek')
  18. def GetEdbDataFromEk(EdbCode, StartDate, EndDate ,Frequency="daily"):
  19. EdbCode = urllib.parse.unquote(EdbCode)
  20. # print("EdbCode:", EdbCode, ";StartDate:", StartDate, ";EndDate:", EndDate, ";Frequency:", Frequency)
  21. # print("req start")
  22. if Frequency == "":
  23. Frequency = "daily"
  24. data = ek.get_timeseries(EdbCode, fields='*', start_date=StartDate, end_date=EndDate, interval=Frequency)
  25. # print("result start\n", data)
  26. if data is None:
  27. print("数据查询失败:", data)
  28. return False
  29. # print("是否唯一索引:", data.index.is_unique)
  30. if data.index.is_unique is False:
  31. # print("开始去重")
  32. data = data.groupby(data.index).first()
  33. # print("结束去重")
  34. # print(data)
  35. # print("result end")
  36. data_json = data.to_json()
  37. result = json.loads(data_json)
  38. return result
  39. if __name__ == "__main__":
  40. ek.set_app_key(key)
  41. ek.set_timeout(120)
  42. app = __hug__.http.server()
  43. run(app=app, reloader=True, host='0.0.0.0', port=7002)