Skip to content

Commit

Permalink
Merge pull request #1794 from yutiansut/master
Browse files Browse the repository at this point in the history
refactor
  • Loading branch information
yutiansut authored May 18, 2022
2 parents 7d42fcb + 5e5a907 commit 61e176c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 23 deletions.
19 changes: 10 additions & 9 deletions QUANTAXIS/QAStrategy/qactabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import QUANTAXIS as QA
from QUANTAXIS.QAStrategy.util import QA_data_futuremin_resample
from QUANTAXIS.QIFI.QifiAccount import ORDER_DIRECTION, QIFI_Account
from QUANTAXIS.QAMarket.market_preset import MARKET_PRESET
from QUANTAXIS.QAEngine.QAThreadEngine import QA_Thread
from QUANTAXIS.QAUtil.QAParameter import MARKET_TYPE, RUNNING_ENVIRONMENT

Expand Down Expand Up @@ -62,7 +63,7 @@ def __init__(self, code='rb2005', frequence='1min', strategy_id='QA_STRATEGY', r

self.running_time = ''

self.market_preset = QA.QAARP.MARKET_PRESET()
self.market_preset = MARKET_PRESET()
self._market_data = []
self.risk_check_gap = risk_check_gap
self.latest_price = {}
Expand Down Expand Up @@ -231,14 +232,14 @@ def x1(self, item):

def debug_t0(self):
self.running_mode = 'backtest'
self.database = pymongo.MongoClient(mongo_ip).QUANTAXIS
user = QA_User(username=self.username, password=self.password)
port = user.new_portfolio(self.portfolio)
self.acc = port.new_accountpro(
account_cookie=self.strategy_id, init_cash=self.init_cash, init_hold={
self.code: 100000},
market_type=self.market_type, running_environment=RUNNING_ENVIRONMENT.TZERO)
self.positions = self.acc.get_position(self.code)
# self.database = pymongo.MongoClient(mongo_ip).QUANTAXIS
# user = QA_User(username=self.username, password=self.password)
# port = user.new_portfolio(self.portfolio)
# self.acc = port.new_accountpro(
# account_cookie=self.strategy_id, init_cash=self.init_cash, init_hold={
# self.code: 100000},
# market_type=self.market_type, running_environment=RUNNING_ENVIRONMENT.TZERO)
# self.positions = self.acc.get_position(self.code)
data = QA.QA_quotation(self.code.upper(), self.start, self.end, source=QA.DATASOURCE.MONGO,
frequence=self.frequence, market=self.market_type, output=QA.OUTPUT_FORMAT.DATASTRUCT)

Expand Down
20 changes: 10 additions & 10 deletions QUANTAXIS/QAStrategy/qamultibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
from QUANTAXIS.QAUtil.QAParameter import MARKET_TYPE, RUNNING_ENVIRONMENT, ORDER_DIRECTION
from QAPUBSUB.consumer import subscriber_topic, subscriber_routing
from QAPUBSUB.producer import publisher_routing
from QUANTAXIS.QAStrategy.qactabase import QAStrategyCTABase
from QUANTAXIS.QAStrategy.qactabase import QAStrategyCtaBase
from QUANTAXIS.QIFI.QifiAccount import QIFI_Account


class QAStrategyStockBase(QAStrategyCTABase):
class QAStrategyStockBase(QAStrategyCtaBase):

def __init__(self, code=['000001'], frequence='1min', strategy_id='QA_STRATEGY', risk_check_gap=1, portfolio='default',
start='2019-01-01', end='2019-10-21', send_wx=False, market_type='stock_cn',
Expand Down Expand Up @@ -141,16 +141,16 @@ def run(self):

def debug(self):
self.running_mode = 'backtest'
self.database = pymongo.MongoClient(mongo_ip).QUANTAXIS
user = QA_User(username="admin", password='admin')
port = user.new_portfolio(self.portfolio)
self.acc = port.new_accountpro(
account_cookie=self.strategy_id, init_cash=self.init_cash, market_type=self.market_type, frequence= self.frequence)
#self.positions = self.acc.get_position(self.code)
# self.database = pymongo.MongoClient(mongo_ip).QUANTAXIS
# user = QA_User(username="admin", password='admin')
# port = user.new_portfolio(self.portfolio)
# self.acc = port.new_accountpro(
# account_cookie=self.strategy_id, init_cash=self.init_cash, market_type=self.market_type, frequence= self.frequence)
# #self.positions = self.acc.get_position(self.code)

print(self.acc)
# print(self.acc)

print(self.acc.market_type)
# print(self.acc.market_type)
data = QA.QA_quotation(self.code, self.start, self.end, source=QA.DATASOURCE.MONGO,
frequence=self.frequence, market=self.market_type, output=QA.OUTPUT_FORMAT.DATASTRUCT)

Expand Down
41 changes: 39 additions & 2 deletions QUANTAXIS/QAWebServer/qifiserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from QUANTAXIS.QIFI.QifiManager import QA_QIFIMANAGER, QA_QIFISMANAGER
class QAQIFI_Handler(QABaseHandler):
#manager = QA_QIFIMANAGER(mongo_ip)
manager = QA_QIFISMANAGER(mongo_ip)
manager = QA_QIFISMANAGER(mongo_ip,model='BACKTEST')

def get(self):
action = self.get_argument('action', 'acchistory')
Expand Down Expand Up @@ -99,7 +99,44 @@ def get(self):

class QAQIFIS_Handler(QABaseHandler):
#manager = QA_QIFIMANAGER(mongo_ip)
manager = QA_QIFISMANAGER(mongo_ip)
manager = QA_QIFISMANAGER(mongo_ip,model='BACKTEST')

def get(self):
action = self.get_argument('action', 'acchistory')

if action == 'accountlist':
res = self.manager.get_allaccountname()
self.write({'res': res})
elif action == 'portfoliolist':
res = self.manager.get_allportfolio()
self.write({'res': res})
elif action == 'accountinportfolio':
portfolio = self.get_argument('portfolio', 't12')
res = self.manager.get_portfolio_panel(portfolio)

self.write({'res': QA_util_to_json_from_pandas(res)})

def post(self):
action = self.get_argument('action', 'change_name')
if action == 'drop_account':

account_cookie = self.get_argument('account_cookie')
res = self.manager.drop_account(account_cookie)
self.write({
'res': res,
'status': 200
})
elif action == 'drop_many':
account_cookies = self.get_argument('account_cookies')
res = self.manager.drop_many(account_cookies)
self.write({
'res': res,
'status': 200
})

class QAQIFIS_REALTIME_Handler(QABaseHandler):
#manager = QA_QIFIMANAGER(mongo_ip)
manager = QA_QIFISMANAGER(mongo_ip,model='REALTIME')

def get(self):
action = self.get_argument('action', 'acchistory')
Expand Down
3 changes: 2 additions & 1 deletion QUANTAXIS/QAWebServer/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from QUANTAXIS.QAWebServer.schedulehandler import (QAScheduleQuery,
QASchedulerHandler,
init_scheduler)
from QUANTAXIS.QAWebServer.qifiserver import QAQIFI_Handler, QAQIFIS_Handler
from QUANTAXIS.QAWebServer.qifiserver import QAQIFI_Handler, QAQIFIS_Handler, QAQIFIS_REALTIME_Handler
from tornado.options import (define, options, parse_command_line,
parse_config_file)
from tornado.web import Application, RequestHandler, authenticated
Expand Down Expand Up @@ -71,6 +71,7 @@ def get(self):
(r"/scheduler/query", QAScheduleQuery),
(r"/qifi", QAQIFI_Handler),
(r"/qifis", QAQIFIS_Handler),
(r"/qifirealtime", QAQIFIS_REALTIME_Handler),
(r"/user", QAUserhander)

]
Expand Down
3 changes: 2 additions & 1 deletion QUANTAXIS/QIFI/QifiManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ def query_re(self, text) -> list:

def get_portfolio_panel(self, portfolio) -> pd.DataFrame:
r = self.get_portfolio_account(portfolio)

rp = [self.database.find_one({'account_cookie': i}, {
"accounts": 1, 'trading_day': 1, '_id': 0}) for i in r]
return pd.DataFrame([mergex(i['accounts'], {'trading_day': i['trading_day']}) for i in rp])
return pd.DataFrame([mergex(i['accounts'], {'trading_day': i['trading_day']}) for i in rp]).query('user_id in {}'.format(r))

def get_allaccountname(self) -> list:
return list(set([i['account_cookie'] for i in self.database.find({}, {'account_cookie': 1, '_id': 0})]))
Expand Down

0 comments on commit 61e176c

Please sign in to comment.