MA_HLFX_order.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. from jqdatasdk import *
  2. from datetime import datetime as dt
  3. import pandas as pd
  4. from sqlalchemy import create_engine
  5. auth('18616891214', 'Ea?*7f68nD.dafcW34d!')
  6. fre = ['30m', '1d']
  7. engine_hlfx_pool = create_engine('mysql+pymysql://root:r6kEwqWU9!v3@localhost:3307/hlfx_pool?charset=utf8')
  8. engine_stock = create_engine('mysql+pymysql://root:r6kEwqWU9!v3@localhost:3307/stocks?charset=utf8')
  9. fut = locals()
  10. print(dt.now(), '开始赋值!')
  11. for fre in ['1d']:
  12. try:
  13. stock_pool = pd.read_sql_query(
  14. 'select value from `%s`' % fre, engine_hlfx_pool)
  15. print(stock_pool)
  16. stock_pool = stock_pool.iloc[-1, 0].split(",")
  17. print(stock_pool)
  18. except BaseException:
  19. continue
  20. for stock in stock_pool[0:1]:
  21. print(stock)
  22. df_stock=df = get_bars(stock, count=10, unit=fre, fields=['date', 'open', 'close','high','low' ], include_now=True, df=True)
  23. price = df_stock.iloc[-1].at['close']
  24. price_open = df_stock.iloc[-1].at['open']
  25. MA5_1 = df_stock['close'][-7:-2].mean()
  26. MA5 = df_stock['close'][-6:-1].mean()
  27. MA10 = df_stock['close'].mean()
  28. print(price,price_open, 'ma5_1:',MA5_1, 'ma5:', MA5,MA10)
  29. if (price > price_open) & (price > MA5) & (MA5 > MA5_1) & (price < MA5 * 1.07):
  30. print('BUY')
  31. print(dt.now(), '数据库数据已赋值!')
  32. # print(fut['IF9999.CCFX'])
  33. # start = dt.now()
  34. # print(start)
  35. # for f in futures:
  36. # fut[f] = pd.concat([fut[f], pd.DataFrame(columns=['MA5', 'derta'])],axis=1)
  37. # print(fut[f])
  38. #
  39. # for i in range(len(fut[f])):
  40. # MA1 = MA(f, check_date=fut[f].loc[i, 'date'], timeperiod=5)
  41. # MA1 = MA1[f]
  42. # fut[f].loc[i, 'MA5'] = MA1
  43. # # print(fut[f].loc[i, ['close','high','low']])
  44. # if fut[f].loc[i, 'close'] > MA1:
  45. # derta = fut[f].loc[i, 'high']/MA1 - 1
  46. # else:
  47. # derta = (fut[f].loc[i, 'low']/MA1 -1)
  48. # fut[f].loc[i, 'derta'] = derta
  49. # print('___________________________________')
  50. # print(fut[f])
  51. # fut[f].to_excel('/Users/daniel/Downloads/MA_derta/30m_%s.xlsx'% f)
  52. #
  53. # end= dt.now()
  54. # print('总时长:', (end - start).seconds)
  55. # MA1 = MA('MA9999.XZCE', check_date='2022-09-25', timeperiod=5)
  56. # print(MA1['MA9999.XZCE'])