ths_api.py 2.4 KB

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