ths_api.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import hug
  2. from bottle import route, run,NORUN
  3. from WindPy import w
  4. import iFinDPy as THS
  5. import json
  6. import pandas as pd
  7. import time
  8. import os
  9. import sys
  10. hug.API(__name__).http.output_format = hug.output_format.json
  11. @hug.get('/hz_server')
  12. def hello():
  13. return 1
  14. # return 'wind true'
  15. # 同花顺登录函数
  16. def thslogindemo():
  17. # 输入用户的帐号和密码
  18. thsLogin = THS.THS_iFinDLogin("hzmd150", "689719")
  19. print(thsLogin)
  20. if (thsLogin == 0 or thsLogin == -201):
  21. print('ths 登录成功')
  22. else:
  23. print('ths 登录失败')
  24. @hug.get('/edbInfo/ths')
  25. def GetEdbDataByThs(EdbCode, StartDate, EndDate):
  26. print("GetEdbDataByThs")
  27. thsLogin = THS.THS_iFinDLogin("账号", "密码")
  28. thsEDBDataQuery = THS.THS_EDBQuery(EdbCode, StartDate, EndDate, True)
  29. print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ":start GetEdbDataByThs")
  30. print("thsEDBDataQuery")
  31. print(thsEDBDataQuery)
  32. thsEDBDataQuery = thsEDBDataQuery.decode("unicode_escape")
  33. result = json.loads(thsEDBDataQuery)
  34. print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ":end GetEdbDataByThs")
  35. return result
  36. @hug.get('/edbInfo/ths/future_good')
  37. def GetFutureGoodEdbDataByThs(EdbCode, StartDate, EndDate):
  38. print("THS_HistoryQuotes start")
  39. thsLogin = THS.THS_iFinDLogin("账号", "密码")
  40. filed = 'lastclose,open,high,low,close,avgprice,change,changeper,volume,amount,hsl,lastsettlement,settlement,zdsettlement,zdfsettlement,ccl,ccbd,zf,zjlx,zjcd'
  41. # filed = 'open,high,low,close,volume,amount,settlement,ccl,zjlx'
  42. params = 'Interval:D,CPS:1,baseDate:1900-01-01,Currency:YSHB,fill:Previous'
  43. # params = 'YSHB;Tradedays'
  44. # print(params)
  45. thsEDBDataQuery = THS.THS_HistoryQuotes(EdbCode, filed, params, StartDate, EndDate, True)
  46. # thsEDBDataQuery = THS.THS_HQ(EdbCode, filed, params, StartDate, EndDate)
  47. # thsEDBDataQuery = THS.THS_EDBQuery(EdbCode, StartDate, EndDate, True)
  48. print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ":start GetFutureGoodEdbDataByThs")
  49. print("THS_HistoryQuotes end")
  50. print(thsEDBDataQuery)
  51. thsEDBDataQuery = thsEDBDataQuery.decode("unicode_escape")
  52. result = json.loads(thsEDBDataQuery)
  53. print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ":end GetFutureGoodEdbDataByThs")
  54. return result
  55. if __name__ == "__main__":
  56. # ths登录函数
  57. thslogindemo()
  58. app = __hug__.http.server()
  59. run(app=app, reloader=True, port=7000)