Showing preview only (599K chars total). Download the full file or copy to clipboard to get everything.
Repository: yutiansut/QAStrategy
Branch: master
Commit: e792b86947a5
Files: 25
Total size: 572.0 KB
Directory structure:
gitextract_l2j75egg/
├── .github/
│ └── workflows/
│ └── pythonpackage.yml
├── .gitignore
├── LICENSE
├── QAStrategy/
│ ├── __init__.py
│ ├── qactabase.py
│ ├── qahedgebase.py
│ ├── qastockbase.py
│ ├── qastrategybase.py
│ ├── strategywithreal.py
│ └── util.py
├── README.md
├── doc/
│ ├── Account.md
│ ├── MarketData.md
│ ├── Order.md
│ ├── Position.md
│ └── QAStrategyCTA.md
├── example/
│ ├── CCI_EXample.py
│ ├── DoubleMA_Example.py
│ ├── MACD_Example.py
│ ├── Stock_Example.py
│ ├── realtime_hedge.py
│ └── realtime_hedge_tick.py
├── jupytertest/
│ ├── debug_for_sendorder.ipynb
│ └── test_stock.ipynb
└── setup.py
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/workflows/pythonpackage.yml
================================================
name: Python package
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.5, 3.6, 3.7]
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install quantaxis
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pip install pytest
pytest
================================================
FILE: .gitignore
================================================
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
.vscode/settings.json
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
real/*
.idea/*
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2019 Vincent yu
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: QAStrategy/__init__.py
================================================
__version__ = '0.0.25'
__author__ = 'yutiansut'
from QAStrategy.util import QA_data_futuremin_resample
from QAStrategy.qactabase import QAStrategyCTABase
================================================
FILE: QAStrategy/qactabase.py
================================================
import copy
import datetime
import json
import os
import re
import sys
import threading
import time
import uuid
import pandas as pd
import pymongo
import requests
from qaenv import (eventmq_amqp, eventmq_ip, eventmq_password, eventmq_port,
eventmq_username, mongo_ip, mongo_uri)
from QAPUBSUB.consumer import subscriber, subscriber_routing, subscriber_topic
from QAPUBSUB.producer import publisher_routing, publisher_topic
import QUANTAXIS as QA
from QAStrategy.util import QA_data_futuremin_resample
from QIFIAccount import ORDER_DIRECTION, QIFI_Account
from QUANTAXIS.QAARP import QA_Risk, QA_User
from QUANTAXIS.QAEngine.QAThreadEngine import QA_Thread
from QUANTAXIS.QAUtil.QAParameter import MARKET_TYPE, RUNNING_ENVIRONMENT
class QAStrategyCTABase():
def __init__(self, code='rb2005', frequence='1min', strategy_id='QA_STRATEGY', risk_check_gap=1, portfolio='default',
start='2020-01-01', end='2020-05-21', init_cash=1000000, send_wx=False,
data_host=eventmq_ip, data_port=eventmq_port, data_user=eventmq_username, data_password=eventmq_password,
trade_host=eventmq_ip, trade_port=eventmq_port, trade_user=eventmq_username, trade_password=eventmq_password,
taskid=None, mongo_ip=mongo_ip, model='py'):
"""
code 可以传入单个标的 也可以传入一组标的(list)
会自动基于code来判断是什么市场
TODO: 支持多个市场同时存在
self.trade_host 交易所在的eventmq的ip [挂ORDER_ROUTER的]
/
"""
self.username = 'admin'
self.password = 'admin'
self.trade_host = trade_host
self.code = code
self.frequence = frequence
self.strategy_id = strategy_id
self.portfolio = portfolio
self.data_host = data_host
self.data_port = data_port
self.data_user = data_user
self.data_password = data_password
self.trade_host = trade_host
self.trade_port = trade_port
self.trade_user = trade_user
self.trade_password = trade_password
self.start = start
self.end = end
self.init_cash = init_cash
self.taskid = taskid
self.running_time = ''
self.market_preset = QA.QAARP.MARKET_PRESET()
self._market_data = []
self.risk_check_gap = risk_check_gap
self.latest_price = {}
self.isupdate = False
self.model = model
self.new_data = {}
self._systemvar = {}
self._signal = []
self.send_wx = send_wx
if isinstance(self.code, str):
self.last_order_towards = {self.code: {'BUY': '', 'SELL': ''}}
else:
self.last_order_towards = dict(
zip(self.code, [{'BUY': '', 'SELL': ''} for i in range(len(self.code))]))
self.dt = ''
if isinstance(self.code, str):
self.market_type = MARKET_TYPE.FUTURE_CN if re.search(
r'[a-zA-z]+', self.code) else MARKET_TYPE.STOCK_CN
else:
self.market_type = MARKET_TYPE.FUTURE_CN if re.search(
r'[a-zA-z]+', self.code[0]) else MARKET_TYPE.STOCK_CN
self.bar_order = {'BUY_OPEN': 0, 'SELL_OPEN': 0,
'BUY_CLOSE': 0, 'SELL_CLOSE': 0}
self._num_cached = 120
self._cached_data = []
self.user_init()
@property
def bar_id(self):
return len(self._market_data)
@property
def BarsSinceEntryLong(self):
return self.bar_id - self.bar_order.get('BUY_OPEN', self.bar_id)
@property
def BarsSinceEntryShort(self):
return self.bar_id - self.bar_order.get('SELL_OPEN', self.bar_id)
@property
def EntryPriceLong(self):
code = self.get_code()
return self.get_positions(code).open_price_long
@property
def EntryPriceShort(self):
code = self.get_code()
return self.get_positions(code).open_price_short
def on_sync(self):
if self.running_mode != 'backtest':
self.pubacc.pub(json.dumps(self.acc.message),
routing_key=self.strategy_id)
def _debug_sim(self):
self.running_mode = 'sim'
if self.frequence.endswith('min'):
if isinstance(self.code, str):
self._old_data = QA.QA_fetch_get_future_min('tdx', self.code.upper(), QA.QA_util_get_last_day(
QA.QA_util_get_real_date(str(datetime.date.today()))), str(datetime.datetime.now()), self.frequence)[:-1].set_index(['datetime', 'code'])
self._old_data = self._old_data.assign(volume=self._old_data.trade).loc[:, [
'open', 'high', 'low', 'close', 'volume']]
else:
self._old_data = pd.concat([QA.QA_fetch_get_future_min('tdx', item.upper(), QA.QA_util_get_last_day(
QA.QA_util_get_real_date(str(datetime.date.today()))), str(datetime.datetime.now()), self.frequence)[:-1].set_index(['datetime', 'code']) for item in self.code], sort=False)
self._old_data = self._old_data.assign(volume=self._old_data.trade).loc[:, [
'open', 'high', 'low', 'close', 'volume']]
else:
self._old_data = pd.DataFrame()
self.database = pymongo.MongoClient(mongo_ip).QAREALTIME
self.client = self.database.account
self.subscriber_client = self.database.subscribe
self.acc = QIFI_Account(
username=self.strategy_id, password=self.strategy_id, trade_host=mongo_ip, init_cash=self.init_cash)
self.acc.initial()
self.acc.on_sync = self.on_sync
self.pub = publisher_routing(exchange='QAORDER_ROUTER', host=self.trade_host,
port=self.trade_port, user=self.trade_user, password=self.trade_password)
self.pubacc = publisher_topic(exchange='QAAccount', host=self.trade_host,
port=self.trade_port, user=self.trade_user, password=self.trade_password)
if isinstance(self.code, str):
self.subscribe_data(self.code.lower(), self.frequence, self.data_host,
self.data_port, self.data_user, self.data_password, self.model)
else:
self.subscribe_multi(self.code, self.frequence, self.data_host,
self.data_port, self.data_user, self.data_password, self.model)
print('account {} start sim'.format(self.strategy_id))
self.database.strategy_schedule.job_control.update(
{'strategy_id': self.strategy_id},
{'strategy_id': self.strategy_id, 'taskid': self.taskid,
'filepath': os.path.abspath(__file__), 'status': 200}, upsert=True)
def debug_sim(self):
self._debug_sim()
threading.Thread(target=self.sub.start, daemon=True).start()
def run_sim(self):
self._debug_sim()
self.sub.start()
def run_backtest(self):
self.debug()
self.acc.save()
risk = QA_Risk(self.acc)
risk.save()
try:
"""add rank flow if exist
QARank是我们内部用于评价策略ELO的库 此处并不影响正常使用
"""
from QARank import QA_Rank
QA_Rank(self.acc).send()
except:
pass
def user_init(self):
"""
用户自定义的init过程
"""
pass
def debug(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, market_type=self.market_type, frequence=self.frequence)
self.positions = self.acc.get_position(self.code)
print(self.acc)
print(self.acc.market_type)
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)
data.data.apply(self.x1, axis=1)
def x1(self, item):
self.latest_price[item.name[1]] = item['close']
if str(item.name[0])[0:10] != str(self.running_time)[0:10]:
self.on_dailyclose()
self.on_dailyopen()
if self.market_type == QA.MARKET_TYPE.STOCK_CN:
print('backtest: Settle!')
self.acc.settle()
self._on_1min_bar()
self._market_data.append(copy.deepcopy(item))
self.running_time = str(item.name[0])
self.on_bar(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)
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)
def x1(item):
self.latest_price[item.name[1]] = item['close']
if str(item.name[0])[0:10] != str(self.running_time)[0:10]:
self.on_dailyclose()
for order in self.acc.close_positions_order:
order.trade('closebySys', order.price,
order.amount, order.datetime)
self.on_dailyopen()
if self.market_type == QA.MARKET_TYPE.STOCK_CN:
print('backtest: Settle!')
self.acc.settle()
self._on_1min_bar()
self._market_data.append(copy.deepcopy(item))
self.running_time = str(item.name[0])
self.on_bar(item)
data.data.apply(x1, axis=1)
def debug_currenttick(self, freq):
data = QA.QA_fetch_get_future_transaction_realtime(
'tdx', self.code.upper())
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.strategy_id = self.strategy_id + \
'currenttick_{}_{}'.format(str(datetime.date.today()), freq)
self.acc = port.new_accountpro(
account_cookie=self.strategy_id, init_cash=self.init_cash, market_type=self.market_type)
self.positions = self.acc.get_position(self.code)
data = data.assign(price=data.price/1000).loc[:, ['code', 'price', 'volume']].resample(
freq).apply({'code': 'last', 'price': 'ohlc', 'volume': 'sum'}).dropna()
data.columns = data.columns.droplevel(0)
data = data.reset_index().set_index(['datetime', 'code'])
def x1(item):
self.latest_price[item.name[1]] = item['close']
if str(item.name[0])[0:10] != str(self.running_time)[0:10]:
self.on_dailyclose()
self.on_dailyopen()
self._on_1min_bar()
self._market_data.append(copy.deepcopy(item))
self.running_time = str(item.name[0])
self.on_bar(item)
data.apply(x1, axis=1)
def debug_histick(self, freq):
data = QA.QA_fetch_get_future_transaction(
'tdx', self.code.upper(), self.start, self.end)
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.strategy_id = self.strategy_id + \
'histick_{}_{}_{}'.format(self.start, self.end, freq)
self.acc = port.new_accountpro(
account_cookie=self.strategy_id, init_cash=self.init_cash, market_type=self.market_type)
self.positions = self.acc.get_position(self.code)
data = data.assign(price=data.price/1000).loc[:, ['code', 'price', 'volume']].resample(
freq).apply({'code': 'last', 'price': 'ohlc', 'volume': 'sum'}).dropna()
data.columns = data.columns.droplevel(0)
data = data.reset_index().set_index(['datetime', 'code'])
def x1(item):
self.latest_price[item.name[1]] = item['close']
if str(item.name[0])[0:10] != str(self.running_time)[0:10]:
self.on_dailyclose()
self.on_dailyopen()
self._on_1min_bar()
self._market_data.append(copy.deepcopy(item))
self.running_time = str(item.name[0])
self.on_bar(item)
data.apply(x1, axis=1)
def subscribe_data(self, code, frequence, data_host, data_port, data_user, data_password, model='py'):
"""[summary]
Arguments:
code {[type]} -- [description]
frequence {[type]} -- [description]
"""
if frequence.endswith('min'):
if model == 'py':
self.sub = subscriber(exchange='realtime_{}_{}'.format(
frequence, code), host=data_host, port=data_port, user=data_user, password=data_password)
elif model == 'rust':
self.sub = subscriber_routing(exchange='realtime_{}'.format(
code), routing_key=frequence, host=data_host, port=data_port, user=data_user, password=data_password)
self.sub.callback = self.callback
elif frequence.endswith('s'):
import re
self._num_cached = 2*int(re.findall(r'\d+', self.frequence)[0])
self.sub = subscriber_routing(
exchange='CTPX', routing_key=code, host=data_host, port=data_port, user=data_user, password=data_password)
self.sub.callback = self.second_callback
elif frequence.endswith('tick'):
self._num_cached = 1
self.sub = subscriber_routing(
exchange='CTPX', routing_key=code, host=data_host, port=data_port, user=data_user, password=data_password)
self.sub.callback = self.tick_callback
def subscribe_multi(self, codelist, frequence, data_host, data_port, data_user, data_password, model='py'):
if frequence.endswith('min'):
if model == 'rust':
self.sub = subscriber_routing(exchange='realtime_{}'.format(
codelist[0]), routing_key=frequence, host=data_host, port=data_port, user=data_user, password=data_password)
for item in codelist[1:]:
self.sub.add_sub(exchange='realtime_{}'.format(
item), routing_key=frequence)
elif model == 'py':
self.sub = subscriber_routing(exchange='realtime_{}'.format(
codelist[0].lower()), routing_key=frequence, host=data_host, port=data_port, user=data_user, password=data_password)
for item in codelist[1:]:
self.sub.add_sub(exchange='realtime_{}'.format(
item.lower()), routing_key=frequence)
self.sub.callback = self.callback
elif frequence.endswith('tick'):
self._num_cached = 1
self.sub = subscriber_routing(exchange='CTPX', routing_key=codelist[0].lower(
), host=data_host, port=data_port, user=data_user, password=data_password)
for item in codelist[1:]:
self.sub.add_sub(exchange='CTPX', routing_key=item.lower())
self.sub.callback = self.tick_callback
@property
def old_data(self):
return self._old_data
def update(self):
"""
此处是切换bar的时候的节点
"""
self._old_data = self._market_data
self._on_1min_bar()
@property
def market_datetime(self):
"""计算的market时间点 此api慎用 因为会惰性计算全市场的值
Returns:
[type] -- [description]
"""
return self.market_data.index.levels[0]
@property
def market_data(self):
if self.running_mode == 'sim':
return self._market_data
elif self.running_mode == 'backtest':
return pd.concat(self._market_data[-100:], axis=1, sort=False).T
def force_close(self):
# 强平
if self.positions.volume_long > 0:
self.send_order('SELL', 'CLOSE', price=self.positions.last_price,
volume=self.positions.volume_long)
if self.positions.volume_short > 0:
self.send_order('BUY', 'CLOSE', price=self.positions.last_price,
volume=self.positions.volume_short)
def upcoming_data(self, new_bar):
"""upcoming_bar :
在这一步中, 我们主要进行的是
1. 更新self._market_data
2. 更新账户
3. 更新持仓
4. 通知on_bar
Arguments:
new_bar {pd.DataFrame} -- [description]
"""
code = new_bar.index.levels[1][0]
if len(self._old_data) > 0:
self._market_data = pd.concat(
[self._old_data, new_bar], sort=False)
else:
self._market_data = new_bar
# QA.QA_util_log_info(self._market_data)
if self.isupdate:
self.update()
self.isupdate = False
self.update_account()
if isinstance(self.code, str):
self.positions.on_price_change(float(self.latest_price[code]))
else:
for item in self.code:
self.acc.get_position(item).on_price_change(
float(self.latest_price[code]))
self.on_bar(json.loads(
new_bar.reset_index().to_json(orient='records'))[0])
def ind2str(self, ind, ind_type):
z = ind.tail(1).reset_index().to_dict(orient='records')[0]
return json.dumps({'topic': ind_type, 'code': self.code, 'type': self.frequence, 'data': z})
def second_callback(self, a, b, c, body):
"""在strategy的callback中,我们需要的是
1. 更新数据
2. 更新bar
3. 更新策略状态
4. 推送事件
Arguments:
a {[type]} -- [description]
b {[type]} -- [description]
c {[type]} -- [description]
body {[type]} -- [description]
second ==> 2*second tick
b'{"ask_price_1": 4145.0, "ask_price_2": 0, "ask_price_3": 0, "ask_price_4": 0, "ask_price_5": 0,
"ask_volume_1": 69, "ask_volume_2": 0, "ask_volume_3": 0, "ask_volume_4": 0, "ask_volume_5": 0,
"average_price": 61958.14258714826,
"bid_price_1": 4143.0, "bid_price_2": 0, "bid_price_3": 0, "bid_price_4": 0, "bid_price_5": 0,
"bid_volume_1": 30, "bid_volume_2": 0, "bid_volume_3": 0, "bid_volume_4": 0, "bid_volume_5": 0,
"datetime": "2019-11-20 01:57:08", "exchange": "SHFE", "gateway_name": "ctp",
"high_price": 4152.0, "last_price": 4144.0, "last_volume": 0,
"limit_down": 3872.0, "limit_up": 4367.0, "local_symbol": "ag1912.SHFE",
"low_price": 4105.0, "name": "", "open_interest": 277912.0, "open_price": 4140.0,
"preSettlementPrice": 4120.0, "pre_close": 4155.0,
"symbol": "ag1912",
"volume": 114288}'
tick 会基于热数据的量 self._num_cached 来判断更新/重采样
"""
self.new_data = json.loads(str(body, encoding='utf-8'))
self._cached_data.append(self.new_data)
self.latest_price[self.new_data['symbol']
] = self.new_data['last_price']
# if len(self._cached_data) == self._num_cached:
# self.isupdate = True
if len(self._cached_data) > 3*self._num_cached:
# 控制缓存数据量
self._cached_data = self._cached_data[self._num_cached:]
data = pd.DataFrame(self._cached_data).loc[:, [
'datetime', 'last_price', 'volume']]
data = data.assign(datetime=pd.to_datetime(data.datetime)).set_index('datetime').resample(
self.frequence).apply({'last_price': 'ohlc', 'volume': 'last'}).dropna()
data.columns = data.columns.droplevel(0)
data = data.assign(volume=data.volume.diff(),
code=self.new_data['symbol'])
data = data.reset_index().set_index(['datetime', 'code'])
self.acc.on_price_change(
self.new_data['symbol'], self.latest_price[self.new_data['symbol']])
# .loc[:, ['open', 'high', 'low', 'close', 'volume', 'tradetime']]
now = datetime.datetime.now()
if now.hour == 20 and now.minute == 59 and now.second < 10:
self.daily_func()
time.sleep(10)
self.running_time = self.new_data['datetime']
# print(data.iloc[-1].index[0])
if self.dt != data.index[-1][0]:
self.isupdate = True
self.dt = data.index[-1][0]
self.upcoming_data(data.tail(1))
def tick_callback(self, a, b, c, body):
self.new_data = json.loads(str(body, encoding='utf-8'))
self.latest_price[self.new_data['symbol']
] = self.new_data['last_price']
self.running_time = self.new_data['datetime']
self.on_tick(self.new_data)
def get_code_marketdata(self, code):
return self.market_data.loc[(slice(None), code), :]
def get_current_marketdata(self):
return self.market_data.loc[(self.running_time, slice(None)), :]
def callback(self, a, b, c, body):
"""在strategy的callback中,我们需要的是
1. 更新数据
2. 更新bar
3. 更新策略状态
4. 推送事件
Arguments:
a {[type]} -- [description]
b {[type]} -- [description]
c {[type]} -- [description]
body {[type]} -- [description]
"""
self.new_data = json.loads(str(body, encoding='utf-8'))
self.latest_price[self.new_data['code']] = self.new_data['close']
if self.dt != str(self.new_data['datetime'])[0:16]:
# [0:16]是分钟线位数
self.dt = str(self.new_data['datetime'])[0:16]
self.isupdate = True
self.acc.on_price_change(self.new_data['code'], self.new_data['close'])
# .loc[:, ['open', 'high', 'low', 'close', 'volume', 'tradetime']]
bar = pd.DataFrame([self.new_data]).set_index(['datetime', 'code'])
now = datetime.datetime.now()
if now.hour == 20 and now.minute == 59 and now.second < 10:
self.daily_func()
time.sleep(10)
# res = self.job_control.find_one(
# {'strategy_id': self.strategy_id, 'strategy_id': self.strategy_id})
# self.control_status(res)
self.running_time = self.new_data['datetime']
self.upcoming_data(bar)
def control_status(self, res):
print(res)
def add_subscriber(self, qaproid):
"""Add a subscriber
增加订阅者的QAPRO_ID
"""
self.subscriber_client.insert_one(
{'strategy_id': self.strategy_id, 'user_id': qaproid})
@property
def subscriber_list(self):
"""订阅者
Returns:
[type] -- [description]
"""
return list(set([item['user_id'] for item in self.subscriber_client.find({'strategy_id': self.strategy_id})]))
def load_strategy(self):
raise NotImplementedError
def on_dailyopen(self):
pass
def on_dailyclose(self):
pass
def on_bar(self, bar):
raise NotImplementedError
def on_tick(self, tick):
raise NotImplementedError
def _on_1min_bar(self):
#raise NotImplementedError
if len(self._systemvar.keys()) > 0:
self._signal.append(copy.deepcopy(self._systemvar))
try:
self.on_1min_bar()
except:
pass
def on_deal(self, order):
"""
order is a dict type
"""
print('------this is on deal message ------')
print(order)
def on_1min_bar(self):
raise NotImplementedError
def on_5min_bar(self):
raise NotImplementedError
def on_15min_bar(self):
raise NotImplementedError
def on_30min_bar(self):
raise NotImplementedError
def order_handler(self):
self._orders = {}
def daily_func(self):
QA.QA_util_log_info('DAILY FUNC')
def risk_check(self):
pass
def plot(self, name, data, format):
""" plot是可以存储你的临时信息的接口, 后期会接入可视化
Arguments:
name {[type]} -- [description]
data {[type]} -- [description]
format {[type]} -- [description]
"""
self._systemvar[name] = {'datetime': copy.deepcopy(str(
self.running_time)), 'value': data, 'format': format}
def get_code(self):
if isinstance(self.code, str):
return self.code
else:
return self.code[0]
def check_order(self, direction, offset, code=None):
"""[summary]
同方向不开仓 只对期货市场做限制
buy - open
sell - close
"""
if code == None:
code = self.get_code()
if self.market_type == QA.MARKET_TYPE.FUTURE_CN:
if self.last_order_towards[code][direction] == str(offset):
return False
else:
return True
else:
return True
def on_ordererror(self, direction, offset, price, volume):
print('order Error ')
def receive_simpledeal(self,
code: str,
trade_time,
trade_amount,
direction,
offset,
trade_price,
message='sell_open'):
self.send_order(direction=direction, offset=offset,
volume=trade_amount, price=trade_price, order_id=QA.QA_util_random_with_topic(self.strategy_id))
def send_order(self, direction='BUY', offset='OPEN', price=3925, volume=10, order_id='', code=None):
if code == None:
code = self.get_code()
towards = eval('ORDER_DIRECTION.{}_{}'.format(direction, offset))
order_id = str(uuid.uuid4()) if order_id == '' else order_id
if isinstance(price, float):
pass
elif isinstance(price, pd.Series):
price = price.values[0]
if self.running_mode == 'sim':
# 在此处拦截无法下单的订单
if (direction == 'BUY' and self.latest_price[code] <= price) or (direction == 'SELL' and self.latest_price[code] >= price):
QA.QA_util_log_info(
'============ {} SEND ORDER =================='.format(order_id))
QA.QA_util_log_info('direction{} offset {} price{} volume{}'.format(
direction, offset, price, volume))
if self.check_order(direction, offset, code=code):
#self.last_order_towards = {'BUY': '', 'SELL': ''}
self.last_order_towards[code][direction] = offset
now = str(datetime.datetime.now())
order = self.acc.send_order(
code=code, towards=towards, price=price, amount=volume, order_id=order_id)
print(order)
order['topic'] = 'send_order'
self.pub.pub(
json.dumps(order), routing_key=self.strategy_id)
self.acc.make_deal(order)
self.on_deal(order)
self.bar_order['{}_{}'.format(
direction, offset)] = self.bar_id
if self.send_wx:
for user in self.subscriber_list:
QA.QA_util_log_info(self.subscriber_list)
try:
requests.post('http://www.yutiansut.com/signal?user_id={}&template={}&strategy_id={}&realaccount={}&code={}&order_direction={}&order_offset={}&price={}&volume={}&order_time={}'.format(
user, "xiadan_report", self.strategy_id, self.acc.user_id, code.lower(), direction, offset, price, volume, now))
except Exception as e:
QA.QA_util_log_info(e)
else:
QA.QA_util_log_info('failed in ORDER_CHECK')
else:
self.on_ordererror(direction, offset, price, volume)
elif self.running_mode == 'backtest':
self.bar_order['{}_{}'.format(direction, offset)] = self.bar_id
if self.market_type == 'stock_cn':
order = self.acc.send_order(
code=code, amount=volume, time=self.running_time, towards=towards, price=price)
order.trade(order.order_id, order.price,
order.amount, order.datetime)
self.on_deal(order.to_dict())
else:
self.acc.receive_simpledeal(
code=code, trade_time=self.running_time, trade_towards=towards, trade_amount=volume, trade_price=price, order_id=order_id, realorder_id=order_id, trade_id=order_id)
self.on_deal({
'code': code,
'trade_time': self.running_time,
'trade_towards': towards,
'trade_amount': volume,
'trade_price': price,
'order_id': order_id,
'realorder_id': order_id,
'trade_id': order_id
})
self.positions = self.acc.get_position(code)
def update_account(self):
if self.running_mode == 'sim':
QA.QA_util_log_info('{} UPDATE ACCOUNT'.format(
str(datetime.datetime.now())))
self.accounts = self.acc.account_msg
self.orders = self.acc.orders
if isinstance(self.code, str):
self.positions = self.acc.get_position(self.code)
else:
pass
self.trades = self.acc.trades
self.updatetime = self.acc.dtstr
self.on_sync()
elif self.running_mode == 'backtest':
if isinstance(self.code, str):
self.positions = self.acc.get_position(self.code)
else:
pass
def get_exchange(self, code):
return self.market_preset.get_exchange(code)
def get_positions(self, code):
if self.running_mode == 'sim':
self.update_account()
return self.acc.get_position(code)
elif self.running_mode == 'backtest':
return self.acc.get_position(code)
def get_cash(self):
if self.running_mode == 'sim':
self.update_account()
return self.accounts.get('available', '')
elif self.running_mode == 'backtest':
return self.acc.cash_available
def run(self):
while True:
time.sleep(self.risk_check_gap)
self.risk_check()
if __name__ == '__main__':
QAStrategyCTABase(code='rb2005').run()
================================================
FILE: QAStrategy/qahedgebase.py
================================================
================================================
FILE: QAStrategy/qastockbase.py
================================================
#
"""
stock_base
"""
import uuid
import datetime
import json
import os
import threading
import requests
import pandas as pd
import pymongo
from qaenv import (eventmq_ip, eventmq_password, eventmq_port,
eventmq_username, mongo_ip)
import QUANTAXIS as QA
from QUANTAXIS.QAARP import QA_Risk, QA_User
from QUANTAXIS.QAEngine.QAThreadEngine import QA_Thread
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 QAStrategy.qactabase import QAStrategyCTABase
from QIFIAccount import QIFI_Account
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',
data_host=eventmq_ip, data_port=eventmq_port, data_user=eventmq_username, data_password=eventmq_password,
trade_host=eventmq_ip, trade_port=eventmq_port, trade_user=eventmq_username, trade_password=eventmq_password,
taskid=None, mongo_ip=mongo_ip):
super().__init__(code=code, frequence=frequence, strategy_id=strategy_id, risk_check_gap=risk_check_gap, portfolio=portfolio,
start=start, end=end, send_wx=send_wx,
data_host=eventmq_ip, data_port=eventmq_port, data_user=eventmq_username, data_password=eventmq_password,
trade_host=eventmq_ip, trade_port=eventmq_port, trade_user=eventmq_username, trade_password=eventmq_password,
taskid=taskid, mongo_ip=mongo_ip)
self.code = code
self.send_wx = send_wx
def subscribe_data(self, code, frequence, data_host, data_port, data_user, data_password):
"""[summary]
Arguments:
code {[type]} -- [description]
frequence {[type]} -- [description]
"""
self.sub = subscriber_topic(exchange='realtime_stock_{}'.format(
frequence), host=data_host, port=data_port, user=data_user, password=data_password, routing_key='')
for item in code:
self.sub.add_sub(exchange='realtime_stock_{}'.format(
frequence), routing_key=item)
self.sub.callback = self.callback
def upcoming_data(self, new_bar):
"""upcoming_bar :
Arguments:
new_bar {json} -- [description]
"""
self._market_data = pd.concat([self._old_data, new_bar])
# QA.QA_util_log_info(self._market_data)
if self.isupdate:
self.update()
self.isupdate = False
self.update_account()
# self.positions.on_price_change(float(new_bar['close']))
self.on_bar(new_bar)
def ind2str(self, ind, ind_type):
z = ind.tail(1).reset_index().to_dict(orient='records')[0]
return json.dumps({'topic': ind_type, 'code': self.code, 'type': self.frequence, 'data': z})
def callback(self, a, b, c, body):
"""在strategy的callback中,我们需要的是
1. 更新数据
2. 更新bar
3. 更新策略状态
4. 推送事件
Arguments:
a {[type]} -- [description]
b {[type]} -- [description]
c {[type]} -- [description]
body {[type]} -- [description]
"""
self.new_data = json.loads(str(body, encoding='utf-8'))
self.latest_price[self.new_data['code']] = self.new_data['close']
self.running_time = self.new_data['datetime']
if self.dt != str(self.new_data['datetime'])[0:16]:
# [0:16]是分钟线位数
print('update!!!!!!!!!!!!')
self.dt = str(self.new_data['datetime'])[0:16]
self.isupdate = True
self.acc.on_price_change(self.new_data['code'], self.new_data['close'])
bar = pd.DataFrame([self.new_data]).set_index(['datetime', 'code']
).loc[:, ['open', 'high', 'low', 'close', 'volume']]
self.upcoming_data(bar)
def _debug_sim(self):
self.running_mode = 'sim'
self._old_data = QA.QA_fetch_stock_min(self.code, QA.QA_util_get_last_day(
QA.QA_util_get_real_date(str(datetime.date.today()))), str(datetime.datetime.now()), format='pd', frequence=self.frequence).set_index(['datetime', 'code'])
self._old_data = self._old_data.loc[:, [
'open', 'high', 'low', 'close', 'volume']]
self.database = pymongo.MongoClient(mongo_ip).QAREALTIME
self.client = self.database.account
self.subscriber_client = self.database.subscribe
self.acc = QIFI_Account(
username=self.strategy_id, password=self.strategy_id, trade_host=mongo_ip)
self.acc.initial()
self.pub = publisher_routing(exchange='QAORDER_ROUTER', host=self.trade_host,
port=self.trade_port, user=self.trade_user, password=self.trade_password)
self.subscribe_data(self.code, self.frequence, self.data_host,
self.data_port, self.data_user, self.data_password)
self.database.strategy_schedule.job_control.update(
{'strategy_id': self.strategy_id},
{'strategy_id': self.strategy_id, 'taskid': self.taskid,
'filepath': os.path.abspath(__file__), 'status': 200}, upsert=True)
# threading.Thread(target=, daemon=True).start()
self.sub.start()
def run(self):
while True:
pass
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)
print(self.acc)
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)
data.data.apply(self.x1, axis=1)
def update_account(self):
if self.running_mode == 'sim':
QA.QA_util_log_info('{} UPDATE ACCOUNT'.format(
str(datetime.datetime.now())))
self.accounts = self.acc.account_msg
self.orders = self.acc.orders
self.positions = self.acc.positions
self.trades = self.acc.trades
self.updatetime = self.acc.dtstr
elif self.running_mode == 'backtest':
#self.positions = self.acc.get_position(self.code)
self.positions = self.acc.positions
def send_order(self, direction='BUY', offset='OPEN', code=None, price=3925, volume=10, order_id='',):
towards = eval('ORDER_DIRECTION.{}_{}'.format(direction, offset))
order_id = str(uuid.uuid4()) if order_id == '' else order_id
if self.market_type == QA.MARKET_TYPE.STOCK_CN:
"""
在此对于股票的部分做一些转换
"""
if towards == ORDER_DIRECTION.SELL_CLOSE:
towards = ORDER_DIRECTION.SELL
elif towards == ORDER_DIRECTION.BUY_OPEN:
towards = ORDER_DIRECTION.BUY
if isinstance(price, float):
pass
elif isinstance(price, pd.Series):
price = price.values[0]
if self.running_mode == 'sim':
QA.QA_util_log_info(
'============ {} SEND ORDER =================='.format(order_id))
QA.QA_util_log_info('direction{} offset {} price{} volume{}'.format(
direction, offset, price, volume))
if self.check_order(direction, offset):
self.last_order_towards = {'BUY': '', 'SELL': ''}
self.last_order_towards[direction] = offset
now = str(datetime.datetime.now())
order = self.acc.send_order(
code=code, towards=towards, price=price, amount=volume, order_id=order_id)
order['topic'] = 'send_order'
self.pub.pub(
json.dumps(order), routing_key=self.strategy_id)
self.acc.make_deal(order)
self.bar_order['{}_{}'.format(direction, offset)] = self.bar_id
else:
QA.QA_util_log_info('failed in ORDER_CHECK')
elif self.running_mode == 'backtest':
self.bar_order['{}_{}'.format(direction, offset)] = self.bar_id
self.acc.receive_simpledeal(
code=code, trade_time=self.running_time, trade_towards=towards, trade_amount=volume, trade_price=price, order_id=order_id)
#self.positions = self.acc.get_position(self.code)
if __name__ == '__main__':
QAStrategyStockBase(code=['000001', '000002']).run_sim()
================================================
FILE: QAStrategy/qastrategybase.py
================================================
import datetime
import json
import os
import re
import sys
import threading
import time
import copy
import uuid
import pandas as pd
import pymongo
import requests
from qaenv import (eventmq_amqp, eventmq_ip, eventmq_password, eventmq_port,
eventmq_username, mongo_ip, mongo_uri)
import QUANTAXIS as QA
from QAPUBSUB.consumer import subscriber, subscriber_routing, subscriber_topic
from QAPUBSUB.producer import publisher_routing, publisher_topic
from QAStrategy.util import QA_data_futuremin_resample
from QIFIAccount import ORDER_DIRECTION, QIFI_Account
from QUANTAXIS.QAARP import QA_Risk, QA_User
from QUANTAXIS.QAEngine.QAThreadEngine import QA_Thread
from QUANTAXIS.QAUtil.QAParameter import MARKET_TYPE, RUNNING_ENVIRONMENT
class QAStrategyCTABase():
def __init__(self, code='rb1905', frequence='1min', strategy_id='QA_STRATEGY', risk_check_gap=1, portfolio='default',
start='2019-01-01', end='2019-10-21', init_cash=1000000, send_wx=False,
data_host=eventmq_ip, data_port=eventmq_port, data_user=eventmq_username, data_password=eventmq_password,
trade_host=eventmq_ip, trade_port=eventmq_port, trade_user=eventmq_username, trade_password=eventmq_password,
taskid=None, mongo_ip=mongo_ip):
self.trade_host = trade_host
self.code = code
self.frequence = frequence
self.strategy_id = strategy_id
self.portfolio = portfolio
self.data_host = data_host
self.data_port = data_port
self.data_user = data_user
self.data_password = data_password
self.trade_host = trade_host
self.trade_port = trade_port
self.trade_user = trade_user
self.trade_password = trade_password
self.start = start
self.end = end
self.init_cash = init_cash
self.taskid = taskid
self.running_time = ''
self.market_preset = QA.QAARP.MARKET_PRESET()
self._market_data = []
self.risk_check_gap = risk_check_gap
self.isupdate = False
self.new_data = {}
self._systemvar = {}
self._signal = []
self.send_wx = send_wx
self.last_order_towards = {'BUY': '', 'SELL': ''}
self.dt = ''
if isinstance(self.code, str):
self.market_type = MARKET_TYPE.FUTURE_CN if re.search(
r'[a-zA-z]+', self.code) else MARKET_TYPE.STOCK_CN
else:
self.market_type = MARKET_TYPE.FUTURE_CN if re.search(
r'[a-zA-z]+', self.code[0]) else MARKET_TYPE.STOCK_CN
self.bar_order = {'BUY_OPEN': 0, 'SELL_OPEN': 0,
'BUY_CLOSE': 0, 'SELL_CLOSE': 0}
@property
def bar_id(self):
return len(self._market_data)
def _debug_sim(self):
self.running_mode = 'sim'
if self.frequence.endswith('min'):
self._old_data = QA.QA_fetch_get_future_min('tdx', self.code.upper(), QA.QA_util_get_last_day(
QA.QA_util_get_real_date(str(datetime.date.today()))), str(datetime.datetime.now()), self.frequence)[:-1].set_index(['datetime', 'code'])
self._old_data = self._old_data.assign(volume=self._old_data.trade).loc[:, [
'open', 'high', 'low', 'close', 'volume']]
else:
pass
self.database = pymongo.MongoClient(mongo_ip).QAREALTIME
self.client = self.database.account
self.subscriber_client = self.database.subscribe
self.acc = QIFI_Account(
username=self.strategy_id, password=self.strategy_id, trade_host=mongo_ip, init_cash=self.init_cash)
self.acc.initial()
self.pub = publisher_routing(exchange='QAORDER_ROUTER', host=self.trade_host,
port=self.trade_port, user=self.trade_user, password=self.trade_password)
self.pubacc = publisher_topic(exchange='QAAccount', host=self.trade_host,
port=self.trade_port, user=self.trade_user, password=self.trade_password)
self.subscribe_data(self.code.lower(), self.frequence, self.data_host,
self.data_port, self.data_user, self.data_password)
self.database.strategy_schedule.job_control.update(
{'strategy_id': self.strategy_id},
{'strategy_id': self.strategy_id, 'taskid': self.taskid,
'filepath': os.path.abspath(__file__), 'status': 200}, upsert=True)
def debug_sim(self):
self._debug_sim()
threading.Thread(target=self.sub.start, daemon=True).start()
def run_sim(self):
self._debug_sim()
self.sub.start()
def run_backtest(self):
self.debug()
self.acc.save()
risk = QA_Risk(self.acc)
risk.save()
try:
"""add rank flow if exist
QARank是我们内部用于评价策略ELO的库 此处并不影响正常使用
"""
from QARank import QA_Rank
QA_Rank(self.acc).send()
except:
pass
def on_sync(self):
if self.running_mode != 'backtest':
self.pubacc.pub(json.dumps(self.acc.message),
routing_key=self.strategy_id)
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)
self.positions = self.acc.get_position(self.code)
print(self.acc)
print(self.acc.market_type)
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)
def x1(item):
# print(data)
if str(item.name[0])[0:10] != str(self.running_time)[0:10]:
self.on_dailyclose()
self.on_dailyopen()
if self.market_type == QA.MARKET_TYPE.STOCK_CN:
print('backtest: Settle!')
self.acc.settle()
self._on_1min_bar()
self._market_data.append(item)
self.running_time = str(item.name[0])
self.on_bar(item)
data.data.apply(x1, axis=1)
def subscribe_data(self, code, frequence, data_host, data_port, data_user, data_password):
"""[summary]
Arguments:
code {[type]} -- [description]
frequence {[type]} -- [description]
"""
self.sub = subscriber(exchange='realtime_{}_{}'.format(
frequence, code), host=data_host, port=data_port, user=data_user, password=data_password)
self.sub.callback = self.callback
def subscribe_multi(self, codelist, frequence, data_host, data_port, data_user, data_password):
self.sub = subscriber_topic(exchange='realtime_{}'.format(
frequence), host=data_host, port=data_port, user=data_user, password=data_password)
for item in codelist:
self.sub.add_sub(exchange='realtime_{}'.format(
frequence), routing_key=item)
self.sub.callback = self.callback
@property
def old_data(self):
return self._old_data
def update(self):
"""
此处是切换bar的时候的节点
"""
self._old_data = self._market_data
self._on_1min_bar()
@property
def market_datetime(self):
return self.market_data.index.levels[0]
@property
def market_data(self):
if self.running_mode == 'sim':
return self._market_data
elif self.running_mode == 'backtest':
return pd.concat(self._market_data[-100:], axis=1, sort=False).T
def force_close(self):
# 强平
if self.positions.volume_long > 0:
self.send_order('SELL', 'CLOSE', price=self.positions.last_price,
volume=self.positions.volume_long)
if self.positions.volume_short > 0:
self.send_order('BUY', 'CLOSE', price=self.positions.last_price,
volume=self.positions.volume_short)
def upcoming_data(self, new_bar):
"""upcoming_bar :
Arguments:
new_bar {json} -- [description]
"""
self._market_data = pd.concat([self._old_data, new_bar])
# QA.QA_util_log_info(self._market_data)
if self.isupdate:
self.update()
self.isupdate = False
self.update_account()
self.positions.on_price_change(float(self.new_data['close']))
self.on_bar(self.new_data)
def ind2str(self, ind, ind_type):
z = ind.tail(1).reset_index().to_dict(orient='records')[0]
return json.dumps({'topic': ind_type, 'code': self.code, 'type': self.frequence, 'data': z})
def callback(self, a, b, c, body):
"""在strategy的callback中,我们需要的是
1. 更新数据
2. 更新bar
3. 更新策略状态
4. 推送事件
Arguments:
a {[type]} -- [description]
b {[type]} -- [description]
c {[type]} -- [description]
body {[type]} -- [description]
"""
self.new_data = json.loads(str(body, encoding='utf-8'))
if self.dt != str(self.new_data['datetime'])[0:16]:
print('update!!!!!!!!!!!!')
self.dt = str(self.new_data['datetime'])[0:16]
self.isupdate = True
self.acc.on_price_change(self.code, self.new_data['close'])
# .loc[:, ['open', 'high', 'low', 'close', 'volume', 'tradetime']]
bar = pd.DataFrame([self.new_data]).set_index(['datetime', 'code'])
now = datetime.datetime.now()
if now.hour == 20 and now.minute == 59 and now.second < 10:
self.daily_func()
time.sleep(10)
# res = self.job_control.find_one(
# {'strategy_id': self.strategy_id, 'strategy_id': self.strategy_id})
# self.control_status(res)
self.running_time = self.new_data['datetime']
self.upcoming_data(bar)
def control_status(self, res):
print(res)
def add_subscriber(self, qaproid):
"""Add a subscriber
增加订阅者的QAPRO_ID
"""
self.subscriber_client.insert_one(
{'strategy_id': self.strategy_id, 'user_id': qaproid})
@property
def subscriber_list(self):
"""订阅者
Returns:
[type] -- [description]
"""
return list(set([item['user_id'] for item in self.subscriber_client.find({'strategy_id': self.strategy_id})]))
def load_strategy(self):
raise NotImplementedError
def on_dailyopen(self):
pass
def on_dailyclose(self):
pass
def on_bar(self, bar):
raise NotImplementedError
def _on_1min_bar(self):
#raise NotImplementedError
if len(self._systemvar.keys()) > 0:
self._signal.append(copy.deepcopy(self._systemvar))
def on_1min_bar(self):
raise NotImplementedError
def on_5min_bar(self):
raise NotImplementedError
def on_15min_bar(self):
raise NotImplementedError
def on_30min_bar(self):
raise NotImplementedError
def order_handler(self):
self._orders = {}
def daily_func(self):
QA.QA_util_log_info('DAILY FUNC')
def risk_check(self):
pass
def plot(self, name, data, format):
""" plot是可以存储你的临时信息的接口, 后期会接入可视化
Arguments:
name {[type]} -- [description]
data {[type]} -- [description]
format {[type]} -- [description]
"""
self._systemvar[name] = {'datetime': copy.deepcopy(str(
self.running_time)), 'value': data, 'format': format}
def check_order(self, direction, offset):
"""[summary]
同方向不开仓 只对期货市场做限制
buy - open
sell - close
"""
if self.market_type == QA.MARKET_TYPE.FUTURE_CN:
if self.last_order_towards[direction] == str(offset):
return False
else:
return True
else:
return True
def receive_simpledeal(self,
code: str,
trade_time,
trade_amount,
direction,
offset,
trade_price,
message='sell_open'):
self.send_order(direction=direction, offset=offset,
volume=trade_amount, price=trade_price, order_id=QA.QA_util_random_with_topic(self.strategy_id))
def send_order(self, direction='BUY', offset='OPEN', price=3925, volume=10, order_id='',):
towards = eval('ORDER_DIRECTION.{}_{}'.format(direction, offset))
order_id = str(uuid.uuid4()) if order_id == '' else order_id
if isinstance(price, float):
pass
elif isinstance(price, pd.Series):
price = price.values[0]
if self.running_mode == 'sim':
QA.QA_util_log_info(
'============ {} SEND ORDER =================='.format(order_id))
QA.QA_util_log_info('direction{} offset {} price{} volume{}'.format(
direction, offset, price, volume))
if self.check_order(direction, offset):
self.last_order_towards = {'BUY': '', 'SELL': ''}
self.last_order_towards[direction] = offset
now = str(datetime.datetime.now())
order = self.acc.send_order(
code=self.code, towards=towards, price=price, amount=volume, order_id=order_id)
order['topic'] = 'send_order'
self.pub.pub(
json.dumps(order), routing_key=self.strategy_id)
self.acc.make_deal(order)
self.bar_order['{}_{}'.format(direction, offset)] = self.bar_id
if self.send_wx:
for user in self.subscriber_list:
QA.QA_util_log_info(self.subscriber_list)
try:
"oL-C4w2WlfyZ1vHSAHLXb2gvqiMI"
"""http://www.yutiansut.com/signal?user_id=oL-C4w1HjuPRqTIRcZUyYR0QcLzo&template=xiadan_report&\
strategy_id=test1&realaccount=133496&code=rb1910&order_direction=BUY&\
order_offset=OPEN&price=3600&volume=1&order_time=20190909
"""
requests.post('http://www.yutiansut.com/signal?user_id={}&template={}&strategy_id={}&realaccount={}&code={}&order_direction={}&order_offset={}&price={}&volume={}&order_time={}'.format(
user, "xiadan_report", self.strategy_id, self.acc.user_id, self.code.lower(), direction, offset, price, volume, now))
except Exception as e:
QA.QA_util_log_info(e)
else:
QA.QA_util_log_info('failed in ORDER_CHECK')
elif self.running_mode == 'backtest':
self.bar_order['{}_{}'.format(direction, offset)] = self.bar_id
self.acc.receive_simpledeal(
code=self.code, trade_time=self.running_time, trade_towards=towards, trade_amount=volume, trade_price=price, order_id=order_id)
self.positions = self.acc.get_position(self.code)
def update_account(self):
if self.running_mode == 'sim':
QA.QA_util_log_info('{} UPDATE ACCOUNT'.format(
str(datetime.datetime.now())))
self.accounts = self.acc.account_msg
self.orders = self.acc.orders
self.positions = self.acc.get_position(self.code)
self.trades = self.acc.trades
self.updatetime = self.acc.dtstr
elif self.running_mode == 'backtest':
self.positions = self.acc.get_position(self.code)
def get_exchange(self, code):
return self.market_preset.get_exchange(code)
def get_positions(self, code):
if self.running_mode == 'sim':
self.update_account()
return self.positions
elif self.running_mode == 'backtest':
return self.acc.get_position(code)
def get_cash(self):
if self.running_mode == 'sim':
self.update_account()
return self.accounts.get('available', '')
elif self.running_mode == 'backtest':
return self.acc.cash_available
def run(self):
while True:
time.sleep(self.risk_check_gap)
self.risk_check()
if __name__ == '__main__':
QAStrategyCTABase(code='rb2005').run()
================================================
FILE: QAStrategy/strategywithreal.py
================================================
from QAPUBSUB.consumer import subscriber_routing
from QAPUBSUB.producer import publisher_routing
from qaenv import eventmq_ip
import json
class QAStrategySyncOrders():
"""
订单同步器
如何挂实盘账户请看 QATrader
http://www.yutiansut.com:3000/topic/5dc865e8c466af76e9e3bdd1
你可以理解成这是一个流处理的过程
simid 被跟单的策略的id
realid 实盘账户id
realamount 实盘账户的订单数量
"""
def __init__(self, simid, realid, realamount=1):
self.sub = subscriber_routing(
exchange='QAORDER_ROUTER', host=eventmq_ip, routing_key=simid)
self.pub = publisher_routing(
exchange='QAORDER_ROUTER', host=eventmq_ip, routing_key=realid)
self.realamount = realamount
self.realid = realid
self.simid = simid
def add_subscriber(self, simid):
self.sub.add_sub('QAORDER_ROUTER', simid)
def callback(self, a, b, c, data):
d = json.loads(data, encoding='utf-8')
if d['topic'] == 'send_order':
self.on_order(d)
def on_order(self, order):
"""在此处理你的订单逻辑
如果你订阅了多个策略账户 则order['account_cookie']不相同
Arguments:
order {[type]} -- [description]
"""
self.send_order(order)
def send_order(self, order):
order['topic'] = 'sendorder'
order['code'] = order['instrument_id']
order['account_cookie'] = self.realid
order['user_id'] = self.realid
order['volume'] = self.realamount
order['order_direction'] = order['direction']
order['order_offset'] = order['offset']
self.pub.pub(json.dumps(order), routing_key=self.realid)
def start(self):
self.sub.callback = self.callback
self.sub.start()
================================================
FILE: QAStrategy/util.py
================================================
import pandas as pd
def QA_data_futuremin_resample(min_data, type_='5min'):
"""期货分钟线采样成大周期
分钟线采样成子级别的分钟线
future:
vol ==> trade
amount X
"""
min_data.tradeime = pd.to_datetime(min_data.tradetime)
CONVERSION = {'code': 'first', 'open': 'first', 'high': 'max', 'low': 'min',
'close': 'last', 'trade': 'sum', 'tradetime': 'last', 'date': 'last'}
resx = min_data.resample(type_, closed='right',
loffset=type_).apply(CONVERSION)
return resx.dropna().reset_index().set_index(['datetime', 'code'])
================================================
FILE: README.md
================================================
# QAStrategy
策略基类/ 基于QAAccount/QACEPEnging/QASPMS/QAREALTIMECollector/QATRADER
_QAStrategy支持[```QIFI```](http://github.com/quantaxis/qifi)协议_
> QAStrategy 的实盘使用天勤的下单网关(Open-Trade-Gateway) 如果是天勤的用户 你可以理解为这是另一个版本的tqsdk
> QAStrategy 的回测也兼容QUANTAXIS的QAAccount 以及QACommunity的可视化内容
QAStrategy 是QUANTAXIS 第一个面向交易员/策略开发者的 用户友好型项目, 致力于降低使用门槛和成本,
```快速编写/测试/模拟你的策略```
当你用QAStrategy写完一个回测 你可以无缝的把他直接改成一个实时模拟策略
QAStrategy 面向场景, 主要有3个策略基类
(PS: 股票日内回转(有底仓的情况) QAStrategy也一并支持, 默认给予10万股, 使用debug_t0()/run_backtestt0())
- QAStrategyCTABase cta模板/ 单标的模板 支持股票/期货
- QAStrategyStockBase 股票池模板/ 多标的模板 支持股票/期货
- QAStrategyHedgeBase 对冲模板/ 双标的模板 (目前没写完)
策略开发者/交易员 只需要面向你自己的主要方向, 选择一个你想要的模板, 继承并开发即可快速在2分钟内完成一个简单策略
## 为什么使用QAStrategy
1. 你们根本不会用quantaxis 大部分人还停留在pandas都不会用的阶段
2. quantaxis 项目过于灵活, 并且文档缺失较多 除非二次开发人员和我自己 都不推荐直接使用quantaxis
3. 你应该专注在策略开发上 而不是先学个python
4. QAStrategy是 无缝兼容回测/模拟/实盘的 你可以较为快速的直接上手
5. 支持QAStrategy的周边手机APP即将上线, QACommunity桌面端也是无缝兼容的
> 书生造反 十年不成 不要总是在想这个难那个不好用了 just do it 现在开始比什么都重要 !#
> 如果你在QAStrategy的过程中遇到了任何问题 都可以直接发issue要求群主给你解决!
## 如何使用QAStrategy
我们推荐你使用QUANTAXIS的docker环境来直接上手
如果你希望手动部署 可以参考QUANTAXIS项目中的issue 部署好行情网关 数据更新以及相应其他的设置(mq/db)
当你通过QUANTAXIS DOCKER打开了 81界面, 即可进入研究选项
QAStrategy是内置在本docker环境中的, 直接调用即可
在每个策略基类中 有一些是 大家共享的公共变量 还有一些是基类自己的变量
=====================================================================================
## varibles 一些变量
- self.market_data 此变量为公共变量 记录策略的历史数据 [回测/实时均可用]
- self.send_order 此函数为公共函数 但是在不同的基类中, 参数不同
- self.running_time 当前运行时间
- self.acc 此变量为公共变量 代表了账户
- self.market_datetime
- self.bar_id 在回测中使用, 及bar的id数
- self.latest_price 一个json格式的最新价格变量 一般在实时模拟中使用
- self.isupdate
- self.dt 当前时间(datetime的缩写)
[可以在user_init中重写的变量]
- self.username 此为回测的时候的账户名
- self.password 此为回测的时候的密码
## 一些比较重要的变量[篇幅较长 在首页我就不展开讲 可以移步链接中的教程]
### [持仓Position](doc/Position.md)
### [账户 Account](doc/Account.md)
### [数据 MarketData](doc/MarketData.md)
### [订单 Order](doc/Order.md)
## functions 常用函数
- 画图函数 self.plot(name, data, format)
- 获取当前code self.get_code()
- self.ind2str(ind, ind_type)
- 获取品种所在的交易所 self.get_exchange(code)
- 获取品种持仓 self.get_positions(code)
- 获取当前现金 self.get_cash()
- 获取某个品种的marketdata self.get_code_marketdata(code)
- 获取当前的maretdata切片 self.get_current_marketdata()
- 订阅数据 (实时模拟用/ 回测不需要) self.subscribe_data(code, frequence, data_host, data_port, data_user, data_password, model='py')
- 用当日tick数据进行回测(期货) self.debug_currenttick(freq)
- 用历史tick数据进行回测(期货) self.debug_histick(freq)
- 使用t0模式进行回测 self.debug_t0()
- 回测(不存储账户数据的模式) self.debug()
- 回测(存储账户数据的模式) self.run_backtest()
- 实时模拟(阻塞形式 不能同时多开很多个) self.run_sim()
- 实时模拟(非阻塞模式 可以同时开很多个) self.debug_sim()
## inherit functions 常用继承函数 (一般来说 就是你需要自定义的函数)
用户初始化函数
```python
def user_init(self):
```
每日开盘前运行的函数 默认是自带的 你可以改写
```python
def on_dailyopen(self):
pass
```
每日收盘后运行的函数 默认是自带的 你可以改写
```python
def on_dailyclose(self):
pass
```
在你订阅分钟级别的数据的时候, 你需要继承并改写on_bar函数
```python
def on_bar(self, bar):
print(bar)
```
在你订阅tick级别的数据的时候, 你需要继承并改写on_tick函数
```python
def on_tick(self, tick):
pass
```
强制平仓函数 默认是自带的 你可以改写
```python
def force_close(self):
pass
```
在发单后会运行的函数 默认是自带的 你可以改写
```python
def check_order(self, direction, offset, code= None):
pass
```
当发单失败的时候运行的函数 默认是自带的 你可以改写
```python
def on_ordererror(self, direction, offset, price, volume):
pass
```
=====================================================================================
一个常见的示例如下 更多的示例可以参考 /example 中的例子
```python
from QAStrategy import QAStrategyCTABase
import QUANTAXIS as QA
class CCI(QAStrategyCTABase):
def on_bar(self, bar):
"""你的大部分策略逻辑都是在此写的
"""
res = self.cci()
print(res.iloc[-1])
if res.CCI[-1] < -100:
print('LONG')
if self.positions.volume_long == 0:
self.send_order('BUY', 'OPEN', price=bar['close'], volume=1)
if self.positions.volume_short > 0:
self.send_order('BUY', 'CLOSE', price=bar['close'], volume=1)
elif res.CCI[-1] > 100:
print('SHORT')
if self.positions.volume_short == 0:
self.send_order('SELL', 'OPEN', price=bar['close'], volume=1)
if self.positions.volume_long > 0:
self.send_order('SELL', 'CLOSE', price=bar['close'], volume=1)
def cci(self,):
"""你可以自定义你想要的函数
"""
return QA.QA_indicator_CCI(self.market_data, 61)
strategy = CCI(code='rb2005', frequence='1min',
strategy_id='a3916de0-bd28-4b9c-bea1-94d91f1744ac')
strategy.run_backtest()
```
更多详细信息参考教程
================================================
FILE: doc/Account.md
================================================
你需要注意的是, self.acc 在不同的模式下是不一样的
在回测模式: self.acc是一个实例化的 QUANTAXIS.QAAccountPro 类
在模拟模式: self.acc是一个实例化的 qifiaccount 账户
实时的账户的历史成交 self.acc.trade
回测的账户的历史成交 self.acc.history_table
================================================
FILE: doc/MarketData.md
================================================
================================================
FILE: doc/Order.md
================================================
================================================
FILE: doc/Position.md
================================================
# Postions 关于你的持仓的一切
当我们开始写策略的时候, 必不可少的, 我们会跟持仓打交道,
- 当行情变化的时候, 持仓的盈亏的计算(成本的统计视角)
- 当我们要平仓的时候, 持仓(今仓/昨仓)的判断
- 我们预估浮盈浮亏的时候, 对于仓位开仓的信号点进行的判断
- 我们进行对冲/对锁操作时, 对于双向开仓的需求
等等, 因此, QAPositions 就是面向这个需求来解决问题的, 我们把对于一个品种的持仓成为一个positions, 在一个position中你可以有开多和开空两种独立的状态
## 如何获取到持仓?
你可以用
```python
positions = self.get_position(code)
```
在单标的基类中, 你可以直接调用 positions, 如果是多标的基类 会需要使用 self.acc.get_position(code)
position 在回测/模拟中都是一样的 属于 QAPostion类
## 如何使用QAPosition?
如果你需要查询当前的仓位: positions.cur_vol / positions.hold_detail
如果你需要查询仓位的全部信息: self.positons.static_message
如果你需要知道详细的基于当前价格的动态信息: self.position.realtime_message
以下列出了一些你可以直接调用的信息, 这些信息在行情更新/下单成交的时候都已经自动计算好了
```python
positions.volume_long #当前持的多单
positions.volume_short #当前持仓的空单数量
positions.volume_long_today #今日多单数量
positions.volume_long_his #今日多单数量
positions.volume_short_today #今日空单数量
positions.volume_short_his #今日空单数量
positions.position_price_long # 基于结算价计算的多头成本价
positions.position_cost_long # 基于结算价计算的多头总成本(总市值)
positions.position_price_short # 基于结算价计算的空头开仓均价
positions.position_cost_short # 基于结算价计算的空头成本
positions.open_price_long # 基于开仓价计算的多头开仓价
positions.open_cost_long # 基于开仓价计算的多头开仓价
positions.open_price_short # 基于开仓价计算的多头开仓价空头开仓价
positions.open_cost_short # 基于开仓价计算的多头开仓价空头成本
```
## Position 原理是什么
本质是QAPosition 属于 ```QUANTAXIS.QAMarket.QAPosition```
================================================
FILE: doc/QAStrategyCTA.md
================================================
## 1. QAStrategyCTABase
QAStrategy是被设计成(起码我是这么想的)成 """支持股票期货/ 支持一个函数切换回测/模拟/SIM/实盘"""的基类
QAStrategyCTABase 是面向常见cta场景
一般是期货场景/ 兼容股票
- 单标的
- 事件驱动
- 不进行选股/ 大量的择时操作
### 1.1 如何使用QAStrategyCTABase:
1. docker用户需要先拉起期货/股票的docker, 具体的区别见之前的教程:
http://www.yutiansut.com:3000/topic/5dc5da7dc466af76e9e3bc5d
2. 非docker用户需要自行部署, 具体部署流程参见之前的教程
https://github.com/QUANTAXIS/QUANTAXIS/issues/1349
简单来说, 使用QAStrategy 你需要两步
- 搭建本地的行情推送服务器
回测环境 由QUANTAXIS 自身项目提供, 需要先手动save数据
模拟环境/实盘环境 由QAREALTIME_COllECTOR项目提供, 内置在docker
SIM环境(随机tick/ 真实tick) 由QAREALTIME_COLLECTOR/ QARANDOM_PRICE 提供, 内置在docker
- 使用QAStrategy 提供行情流推送来的数据处理节点(策略)
### 1.2 一个简单的示例
```python
from QAStrategy import QAStrategyCTABase
import QUANTAXIS as QA
class Strategy(QAStrategyCTABase):
def on_bar(self, bar):
print(bar)
s = Strategy(code='rb2005', frequence='1min', strategy_id= 'xxx1' )
s.debug_sim()
```
你可以看到 由这几行代码 你就可以实现一个realtime的实时模拟策略 当然 这个策略只干了一个事情, 就是当行情来的时候, 打印行情价格
当然, 如果这是个回测代码, 你需要继续指定下开始和结束时间
```python
from QAStrategy import QAStrategyCTABase
import QUANTAXIS as QA
class Strategy(QAStrategyCTABase):
def on_bar(self, bar):
print(bar)
s = Strategy(code='rb2005', frequence='1min', strategy_id= 'xxx1', start='2019-10-01', end='2019-11-01')
s.run_backtest()
```
你可以看到 当我们切换模式的时候, 策略主体并没有发生任何改变 如果当你已经理解了这个代码 我们可以逐步的往下介绍新的API给你
### 1.3 下单/行情/账户/指标 的常见API
为了降低理解难度, 方便你一步一步的理解这个QAStrategy, 我在最开始的时候, 并不会考虑介绍太多的api给你, 也不会讲述底层实现过程, 我希望你可以只知道5个函数你也能一样的写策略
- 当前策略时间点: ```self.running_time```
- 下单: ```self.send_order```
- 接受到的数据: ```self.market_data```
- 账户: ```self.acc``
在这里, 账户的内容是非常多的, 此处并不细讲, 在后面逐步展开
- 实时的账户的历史成交 ```self.acc.trade```
- 回测的账户的历史成交 ```self.acc.history_table```
- 持仓: ```self.poistions```
- 指标: 你可以直接使用QA_Indicator系列, 加载到self.market_data上
#### 1.3.1 下单函数 send_order
下单函数被设计的非常简单:
```self.send_order('BUY', 'OPEN', price=bar['close'], volume=1)```
只需要4个函数你就可以下单了, 当然 这个场景是CTABase的, 在多标的的stockbase中, 你还需要带上你的code 这个在当前不讨论
#### 1.3.2 接受到的行情数据 self.market_data
self.market_data 是一个惰性计算的函数(@property), 因此当你收到这个数据, 你需要先复制一份来使用
这是一个multiindex的 dataframe, 如果你熟悉QUANTAXIS的 QADataStruct, 你会非常熟悉, 因为multiindex可以方便的承载多个时间/多个标的的数据
```python
def on_bar(self, bar):
market_data = self.market_data
print(market_data)
```
#### 1.3.3 账户 self.acc
你需要注意的是, self.acc 在不同的模式下是不一样的
在回测模式: self.acc是一个实例化的 QUANTAXIS.QAAccountPro 类
在模拟模式: self.acc是一个实例化的 qifiaccount 账户
#### 1.3.4 持仓 self.positions
在单标的基类中, 你可以直接调用 self.positions, 如果是多标的基类 会需要使用 self.acc.get_position(code)
position 在回测/模拟中都是一样的 属于 QAPostion类
如果你需要查询当前的仓位: self.positions.cur_vol / self.positions.hold_detail
如果你需要查询仓位的全部信息: self.positons.static_message
如果你需要知道详细的基于当前价格的动态信息: self.position.realtime_message
以下列出了一些你可以直接调用的信息, 这些信息在行情更新/下单成交的时候都已经自动计算好了
```python
self.positions.volume_long #当前持的多单
self.positions.volume_short #当前持仓的空单数量
self.positions.volume_long_today #今日多单数量
self.positions.volume_long_his #今日多单数量
self.positions.volume_short_today #今日空单数量
self.positions.volume_short_his #今日空单数量
self.positions.position_price_long # 基于结算价计算的多头成本价
self.positions.position_cost_long # 基于结算价计算的多头总成本(总市值)
self.positions.position_price_short # 基于结算价计算的空头开仓均价
self.positions.position_cost_short # 基于结算价计算的空头成本
self.positions.open_price_long # 基于开仓价计算的多头开仓价
self.positions.open_cost_long # 基于开仓价计算的多头开仓价
self.positions.self.open_price_short # 基于开仓价计算的多头开仓价空头开仓价
self.positions.open_cost_short # 基于开仓价计算的多头开仓价空头成本
```
### 1.3.5 指标
让我们回归到上面的market_data, 我们来计算一个指标
```python
import QUANTAXIS as QA
def on_bar(self, bar):
market_data = self.market_data
print(market_data)
print(QA.QA_Indicator_MACD(market_data, 12, 26, 9))
```
================================================
FILE: example/CCI_EXample.py
================================================
from QAStrategy import QAStrategyCTABase
import QUANTAXIS as QA
import pprint
class CCI(QAStrategyCTABase):
def on_bar(self, bar):
res = self.cci()
#print(res.iloc[-1])
if res.CCI[-1] < -100:
#print('LONG')
if self.positions.volume_long == 0:
self.send_order('BUY', 'OPEN', price=bar['close'], volume=1)
if self.positions.volume_short > 0:
self.send_order('BUY', 'CLOSE', price=bar['close'], volume=1)
else:
#print('SHORT')
if self.positions.volume_short == 0:
self.send_order('SELL', 'OPEN', price=bar['close'], volume=1)
if self.positions.volume_long > 0:
self.send_order('SELL', 'CLOSE', price=bar['close'], volume=1)
def cci(self,):
return QA.QA_indicator_CCI(self.market_data, 61)
def risk_check(self):
pass
# pprint.pprint(self.qifiacc.message)
if __name__ == '__main__':
strategy = CCI(code='RBL8', frequence='1min',
strategy_id='a3916de0-bx8-4b19c-bxxax1-94d91f1744ac', start='2020-01-01', end='2020-02-05')
"""测试 一般在jupyter中用
"""
import datetime
t1 = datetime.datetime.now()
strategy.debug()
print(datetime.datetime.now() - t1)
"""
之后你可以用strategy.acc.history_table 这些以前qa回测的东西来查看
"""
""" 回测
"""
# strategy.run_backtest()
# """ 模拟
# """
# strategy = CCI(code='rb2005', frequence='1min',
# strategy_id='a3916de0-bd28-4b9c-bea1-94d91f1744ac', send_wx=True,)
# strategy.debug_sim()
# strategy.add_subscriber("你的wechatid 在QARPO中获取")
"""debugsim是非阻塞的
在进程中 用run_sim
"""
================================================
FILE: example/DoubleMA_Example.py
================================================
from QAStrategy import QAStrategyCTABase
import QUANTAXIS as QA
import pprint
class DMA(QAStrategyCTABase):
def on_bar(self, bar):
res = self.ma()
print(res.iloc[-1])
if res.MA2[-1] > res.MA5[-1]:
print('LONG')
if self.positions.volume_long == 0:
self.send_order('BUY', 'OPEN', price=bar['close'], volume=1)
if self.positions.volume_short > 0:
self.send_order('BUY', 'CLOSE', price=bar['close'], volume=1)
else:
print('SHORT')
if self.positions.volume_short == 0:
self.send_order('SELL', 'OPEN', price=bar['close'], volume=1)
if self.positions.volume_long > 0:
self.send_order('SELL', 'CLOSE', price=bar['close'], volume=1)
def ma(self,):
return QA.QA_indicator_MA(self.market_data, 2, 5)
def risk_check(self):
pass
# pprint.pprint(self.qifiacc.message)
if __name__ == '__main__':
DMA = DMA(code='rb2005', frequence='1min',
strategy_id='1dd8b22d-7902-4a85-adb2-fbac4bb977fe', start='2019-10-01', end='2019-11-01')
DMA.run_backtest()
================================================
FILE: example/MACD_Example.py
================================================
import pprint
import QUANTAXIS as QA
from QAStrategy import QAStrategyCTABase
class MACD(QAStrategyCTABase):
def on_bar(self, bar):
res = self.macd()
print(res.iloc[-1])
if res.DIF[-1] > res.DEA[-1]:
print('LONG')
if self.positions.volume_long == 0:
self.send_order('BUY', 'OPEN', price=bar['close'], volume=1)
if self.positions.volume_short > 0:
self.send_order('BUY', 'CLOSE', price=bar['close'], volume=1)
else:
print('SHORT')
if self.positions.volume_short == 0:
self.send_order('SELL', 'OPEN', price=bar['close'], volume=1)
if self.positions.volume_long > 0:
self.send_order('SELL', 'CLOSE', price=bar['close'], volume=1)
def macd(self,):
return QA.QA_indicator_MACD(self.market_data)
def risk_check(self):
pass
# pprint.pprint(self.qifiacc.message)
if __name__ == '__main__':
MACD = MACD(code='rb2005', frequence='1min', data_host='192.168.2.118', mongo_ip='192.168.2.118', trade_host='192.168.2.118', send_wx=True,
strategy_id='1dds1s2d-7902-4a85-adb2-fbac4bb977fe', start='2019-10-01', end='2019-11-01', model= 'rust')
MACD.run_sim()
================================================
FILE: example/Stock_Example.py
================================================
import QUANTAXIS as QA
from QAStrategy.qastockbase import QAStrategyStockBase
class strategy(QAStrategyStockBase):
def on_bar(self, data):
print(data)
print(self.get_positions('000001'))
print(self.market_data)
code = data.name[1]
print('---------------under is 当前全市场的market_data --------------')
print(self.get_current_marketdata())
print('---------------under is 当前品种的market_data --------------')
print(self.get_code_marketdata(code))
print(code)
#print(self.running_time)
input()
if __name__ == '__main__':
s = strategy(code=['000001', '000002'], frequence='day', start='2019-01-01', end='2019-02-01', strategy_id='x')
s.debug()
"""
portfolio with user_cookie USER_QoZ8TDrF already exist!!
< QA_AccountPRO x market: stock_cn>
stock_cn
backtest: Settle!
open 9.390000e+00
high 9.420000e+00
low 9.160000e+00
close 9.190000e+00
volume 5.393860e+05
amount 4.986951e+08
Name: (2019-01-02 00:00:00, 000001), dtype: float64
< QAPOSITION 000001 amount 0/0 >
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 498695104.0
---------------under is 当前全市场的market_data --------------
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 498695104.0
---------------under is 当前品种的market_data --------------
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 498695104.0
000001
open 2.383000e+01
high 2.409000e+01
low 2.367000e+01
close 2.390000e+01
volume 2.470100e+05
amount 5.893846e+08
Name: (2019-01-02 00:00:00, 000002), dtype: float64
< QAPOSITION 000001 amount 0/0 >
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 498695104.0
000002 23.83 24.09 23.67 23.90 247010.0 589384576.0
---------------under is 当前全市场的market_data --------------
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 498695104.0
000002 23.83 24.09 23.67 23.90 247010.0 589384576.0
---------------under is 当前品种的market_data --------------
open high low close volume amount
2019-01-02 000002 23.83 24.09 23.67 23.9 247010.0 589384576.0
000002
backtest: Settle!
open 9.180000e+00
high 9.330000e+00
low 9.150000e+00
close 9.280000e+00
volume 4.155370e+05
amount 3.844577e+08
Name: (2019-01-03 00:00:00, 000001), dtype: float64
< QAPOSITION 000001 amount 0/0 >
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 498695104.0
000002 23.83 24.09 23.67 23.90 247010.0 589384576.0
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 384457696.0
---------------under is 当前全市场的market_data --------------
open high low close volume amount
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 384457696.0
---------------under is 当前品种的market_data --------------
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 498695104.0
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 384457696.0
000001
open 2.379000e+01
high 2.450000e+01
low 2.371000e+01
close 2.407000e+01
volume 2.223530e+05
amount 5.363333e+08
Name: (2019-01-03 00:00:00, 000002), dtype: float64
< QAPOSITION 000001 amount 0/0 >
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 498695104.0
000002 23.83 24.09 23.67 23.90 247010.0 589384576.0
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 384457696.0
000002 23.79 24.50 23.71 24.07 222353.0 536333280.0
---------------under is 当前全市场的market_data --------------
open high low close volume amount
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 384457696.0
000002 23.79 24.50 23.71 24.07 222353.0 536333280.0
---------------under is 当前品种的market_data --------------
open high low close volume amount
2019-01-02 000002 23.83 24.09 23.67 23.90 247010.0 589384576.0
2019-01-03 000002 23.79 24.50 23.71 24.07 222353.0 536333280.0
000002
backtest: Settle!
open 9.240000e+00
high 9.820000e+00
low 9.220000e+00
close 9.750000e+00
volume 1.481159e+06
amount 1.422150e+09
Name: (2019-01-04 00:00:00, 000001), dtype: float64
< QAPOSITION 000001 amount 0/0 >
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08
000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08
000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
---------------under is 当前全市场的market_data --------------
open high low close volume amount
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
---------------under is 当前品种的market_data --------------
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
000001
open 2.391000e+01
high 2.500000e+01
low 2.385000e+01
close 2.493000e+01
volume 3.777270e+05
amount 9.270117e+08
Name: (2019-01-04 00:00:00, 000002), dtype: float64
< QAPOSITION 000001 amount 0/0 >
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08
000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08
000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08
---------------under is 当前全市场的market_data --------------
open high low close volume amount
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08
---------------under is 当前品种的market_data --------------
open high low close volume amount
2019-01-02 000002 23.83 24.09 23.67 23.90 247010.0 589384576.0
2019-01-03 000002 23.79 24.50 23.71 24.07 222353.0 536333280.0
2019-01-04 000002 23.91 25.00 23.85 24.93 377727.0 927011712.0
000002
backtest: Settle!
open 9.840000e+00
high 9.850000e+00
low 9.630000e+00
close 9.740000e+00
volume 8.656870e+05
amount 8.411664e+08
Name: (2019-01-07 00:00:00, 000001), dtype: float64
< QAPOSITION 000001 amount 0/0 >
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08
000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08
000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08
2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08
---------------under is 当前全市场的market_data --------------
open high low close volume amount
2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 841166400.0
---------------under is 当前品种的market_data --------------
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08
000001
open 2.529000e+01
high 2.553000e+01
low 2.499000e+01
close 2.505000e+01
volume 4.271540e+05
amount 1.077909e+09
Name: (2019-01-07 00:00:00, 000002), dtype: float64
< QAPOSITION 000001 amount 0/0 >
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08
000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08
000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08
2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08
000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09
---------------under is 当前全市场的market_data --------------
open high low close volume amount
2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08
000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09
---------------under is 当前品种的market_data --------------
open high low close volume amount
2019-01-02 000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08
2019-01-03 000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08
2019-01-04 000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08
2019-01-07 000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09
000002
backtest: Settle!
open 9.730000e+00
high 9.740000e+00
low 9.620000e+00
close 9.660000e+00
volume 4.023880e+05
amount 3.892478e+08
Name: (2019-01-08 00:00:00, 000001), dtype: float64
< QAPOSITION 000001 amount 0/0 >
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08
000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08
000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08
2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08
000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09
2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 3.892478e+08
---------------under is 当前全市场的market_data --------------
open high low close volume amount
2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 389247808.0
---------------under is 当前品种的market_data --------------
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08
2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 3.892478e+08
000001
open 2.505000e+01
high 2.520000e+01
low 2.463000e+01
close 2.500000e+01
volume 2.143820e+05
amount 5.336044e+08
Name: (2019-01-08 00:00:00, 000002), dtype: float64
< QAPOSITION 000001 amount 0/0 >
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08
000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08
000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08
2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08
000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09
2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 3.892478e+08
000002 25.05 25.20 24.63 25.00 214382.0 5.336044e+08
---------------under is 当前全市场的market_data --------------
open high low close volume amount
2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 389247808.0
000002 25.05 25.20 24.63 25.00 214382.0 533604352.0
---------------under is 当前品种的market_data --------------
open high low close volume amount
2019-01-02 000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08
2019-01-03 000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08
2019-01-04 000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08
2019-01-07 000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09
2019-01-08 000002 25.05 25.20 24.63 25.00 214382.0 5.336044e+08
000002
backtest: Settle!
open 9.740000e+00
high 1.008000e+01
low 9.700000e+00
close 9.940000e+00
volume 1.233486e+06
amount 1.229465e+09
Name: (2019-01-09 00:00:00, 000001), dtype: float64
< QAPOSITION 000001 amount 0/0 >
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08
000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08
000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08
2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08
000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09
2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 3.892478e+08
000002 25.05 25.20 24.63 25.00 214382.0 5.336044e+08
2019-01-09 000001 9.74 10.08 9.70 9.94 1233486.0 1.229465e+09
---------------under is 当前全市场的market_data --------------
open high low close volume amount
2019-01-09 000001 9.74 10.08 9.7 9.94 1233486.0 1.229465e+09
---------------under is 当前品种的market_data --------------
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08
2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 3.892478e+08
2019-01-09 000001 9.74 10.08 9.70 9.94 1233486.0 1.229465e+09
000001
open 2.540000e+01
high 2.588000e+01
low 2.511000e+01
close 2.533000e+01
volume 3.401400e+05
amount 8.670814e+08
Name: (2019-01-09 00:00:00, 000002), dtype: float64
< QAPOSITION 000001 amount 0/0 >
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08
000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08
000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08
2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08
000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09
2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 3.892478e+08
000002 25.05 25.20 24.63 25.00 214382.0 5.336044e+08
2019-01-09 000001 9.74 10.08 9.70 9.94 1233486.0 1.229465e+09
000002 25.40 25.88 25.11 25.33 340140.0 8.670814e+08
---------------under is 当前全市场的market_data --------------
open high low close volume amount
2019-01-09 000001 9.74 10.08 9.70 9.94 1233486.0 1.229465e+09
000002 25.40 25.88 25.11 25.33 340140.0 8.670814e+08
---------------under is 当前品种的market_data --------------
open high low close volume amount
2019-01-02 000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08
2019-01-03 000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08
2019-01-04 000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08
2019-01-07 000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09
2019-01-08 000002 25.05 25.20 24.63 25.00 214382.0 5.336044e+08
2019-01-09 000002 25.40 25.88 25.11 25.33 340140.0 8.670814e+08
000002
backtest: Settle!
open 9.870000e+00
high 1.020000e+01
low 9.860000e+00
close 1.010000e+01
volume 1.071817e+06
amount 1.079711e+09
Name: (2019-01-10 00:00:00, 000001), dtype: float64
< QAPOSITION 000001 amount 0/0 >
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08
000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08
000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08
2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08
000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09
2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 3.892478e+08
000002 25.05 25.20 24.63 25.00 214382.0 5.336044e+08
2019-01-09 000001 9.74 10.08 9.70 9.94 1233486.0 1.229465e+09
000002 25.40 25.88 25.11 25.33 340140.0 8.670814e+08
2019-01-10 000001 9.87 10.20 9.86 10.10 1071817.0 1.079711e+09
---------------under is 当前全市场的market_data --------------
open high low close volume amount
2019-01-10 000001 9.87 10.2 9.86 10.1 1071817.0 1.079711e+09
---------------under is 当前品种的market_data --------------
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08
2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 3.892478e+08
2019-01-09 000001 9.74 10.08 9.70 9.94 1233486.0 1.229465e+09
2019-01-10 000001 9.87 10.20 9.86 10.10 1071817.0 1.079711e+09
000001
open 2.522000e+01
high 2.556000e+01
low 2.503000e+01
close 2.511000e+01
volume 2.246490e+05
amount 5.689526e+08
Name: (2019-01-10 00:00:00, 000002), dtype: float64
< QAPOSITION 000001 amount 0/0 >
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08
000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08
000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08
2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08
000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09
2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 3.892478e+08
000002 25.05 25.20 24.63 25.00 214382.0 5.336044e+08
2019-01-09 000001 9.74 10.08 9.70 9.94 1233486.0 1.229465e+09
000002 25.40 25.88 25.11 25.33 340140.0 8.670814e+08
2019-01-10 000001 9.87 10.20 9.86 10.10 1071817.0 1.079711e+09
000002 25.22 25.56 25.03 25.11 224649.0 5.689526e+08
---------------under is 当前全市场的market_data --------------
open high low close volume amount
2019-01-10 000001 9.87 10.20 9.86 10.10 1071817.0 1.079711e+09
000002 25.22 25.56 25.03 25.11 224649.0 5.689526e+08
---------------under is 当前品种的market_data --------------
open high low close volume amount
2019-01-02 000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08
2019-01-03 000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08
2019-01-04 000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08
2019-01-07 000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09
2019-01-08 000002 25.05 25.20 24.63 25.00 214382.0 5.336044e+08
2019-01-09 000002 25.40 25.88 25.11 25.33 340140.0 8.670814e+08
2019-01-10 000002 25.22 25.56 25.03 25.11 224649.0 5.689526e+08
000002
backtest: Settle!
open 1.011000e+01
high 1.022000e+01
low 1.005000e+01
close 1.020000e+01
volume 6.963640e+05
amount 7.080018e+08
Name: (2019-01-11 00:00:00, 000001), dtype: float64
< QAPOSITION 000001 amount 0/0 >
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08
000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08
000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08
2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08
000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09
2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 3.892478e+08
000002 25.05 25.20 24.63 25.00 214382.0 5.336044e+08
2019-01-09 000001 9.74 10.08 9.70 9.94 1233486.0 1.229465e+09
000002 25.40 25.88 25.11 25.33 340140.0 8.670814e+08
2019-01-10 000001 9.87 10.20 9.86 10.10 1071817.0 1.079711e+09
000002 25.22 25.56 25.03 25.11 224649.0 5.689526e+08
2019-01-11 000001 10.11 10.22 10.05 10.20 696364.0 7.080018e+08
---------------under is 当前全市场的market_data --------------
open high low close volume amount
2019-01-11 000001 10.11 10.22 10.05 10.2 696364.0 708001792.0
---------------under is 当前品种的market_data --------------
open high low close volume amount
2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08
2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08
2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09
2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08
2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 3.892478e+08
2019-01-09 000001 9.74 10.08 9.70 9.94 1233486.0 1.229465e+09
2019-01-10 000001 9.87 10.20 9.86 10.10 1071817.0 1.079711e+09
2019-01-11 000001 10.11 10.22 10.05 10.20 696364.0 7.080018e+08
"""
================================================
FILE: example/realtime_hedge.py
================================================
from QAStrategy import QAStrategyCTABase
import QUANTAXIS as QA
class CCI(QAStrategyCTABase):
def on_bar(self, bar):
print(bar)
current_code = bar['code']
res = self.cci(current_code)
if res.CCI[-1] < -100:
if self.get_positions(current_code).volume_long == 0:
self.send_order('BUY', 'OPEN', price=bar['close'], volume=1, code= current_code)
if self.get_positions(current_code).volume_short > 0:
self.send_order('BUY', 'CLOSE', price=bar['close'], volume=1, code= current_code)
else:
#print('SHORT')
if self.get_positions(current_code).volume_short == 0:
self.send_order('SELL', 'OPEN', price=bar['close'], volume=1, code= current_code)
if self.get_positions(current_code).volume_long > 0:
self.send_order('SELL', 'CLOSE', price=bar['close'], volume=1, code= current_code)
def cci(self, code):
market_data = self.get_code_marketdata(code)
return QA.QA_indicator_CCI(market_data, 61)
if __name__ == '__main__':
strategy = CCI(code=['rb2005', 'j2005'], frequence='1min', model='rust',
strategy_id='a3916de0-bx8-4b19c-bxxax1-94d91f1744ac', start='2019-10-01', end='2019-11-01')
strategy.run_sim()
================================================
FILE: example/realtime_hedge_tick.py
================================================
from QAStrategy import QAStrategyCTABase
import QUANTAXIS as QA
class CCI(QAStrategyCTABase):
def on_tick(self, tick):
print(tick)
def cci(self, code):
market_data = self.get_code_marketdata(code)
return QA.QA_indicator_CCI(market_data, 61)
if __name__ == '__main__':
strategy = CCI(code=['au2006', 'ag2002'], frequence='tick', model='rust',
strategy_id='a3916de0-bx8-4b19c-bxxax1-94d91f1744ac', start='2019-10-01', end='2019-11-01')
strategy.run_sim()
================================================
FILE: jupytertest/debug_for_sendorder.ipynb
================================================
{"cells":[{"cell_type":"code","execution_count":1,"metadata":{},"outputs":[],"source":"import QAStrategy"},{"cell_type":"code","execution_count":2,"metadata":{},"outputs":[],"source":"from QAStrategy.qactabase import QAStrategyCTABase"},{"cell_type":"code","execution_count":3,"metadata":{},"outputs":[],"source":"class x(QAStrategyCTABase):\n def on_bar(self, data):\n \n print(data)"},{"cell_type":"code","execution_count":32,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":"Create new Account\n"}],"source":"account = x(code= 'rb2005',frequence='1min', strategy_id='testfordebug4')\n\n\n"},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":""},{"cell_type":"code","execution_count":16,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":"<class 'int'>\nQUANTAXIS>> ============ c91378f9-f987-4736-838b-bad3329e269b SEND ORDER ==================\nQUANTAXIS>> directionBUY offset OPEN price3350 volume1\n{'volume_long': 0, 'volume_short': 0, 'volume_long_frozen': 0, 'volume_short_frozen': 0}\n{'volume_long': 0, 'volume_short': 0}\n下单成功 c91378f9-f987-4736-838b-bad3329e269b\n全部成交 c91378f9-f987-4736-838b-bad3329e269b\nQUANTAXIS>> ['oL-C4w1HjuPRqTIRcZUyYR0QcLzo']\n"}],"source":"account.send_order('BUY','OPEN',3350, 1)"},{"cell_type":"code","execution_count":17,"metadata":{},"outputs":[],"source":"import json\n\n"},{"cell_type":"code","execution_count":9,"metadata":{},"outputs":[{"data":{"text/plain":"b'{\"code\": \"rb2005\", \"open\": 3341, \"high\": 3351, \"low\": 3341, \"close\": 3351, \"datetime\": \"2019-10-14 09:00:00:000000\"}'"},"execution_count":9,"metadata":{},"output_type":"execute_result"}],"source":"bytes(json.dumps({'code':'rb2005','open': 3341, 'high': 3351, 'low': 3341, 'close': 3351, 'datetime':'2019-10-14 09:00:00:000000'}), encoding='utf-8')"},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":""},{"cell_type":"code","execution_count":18,"metadata":{},"outputs":[{"name":"stderr","output_type":"stream","text":"C:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexing.py:969: FutureWarning: \nPassing list-likes to .loc or [] with any missing label will raise\nKeyError in the future, you can use .reindex() as an alternative.\n\nSee the documentation here:\nhttps://pandas.pydata.org/pandas-docs/stable/indexing.html#deprecate-loc-reindex-listlike\n return self._getitem_nested_tuple(tup)\nQUANTAXIS>> 2019-10-13 10:12:09.197626 UPDATE ACCOUNT\n open high low close volume\ndatetime code \n2019-10-14 09:00:00:000000 rb2005 3341 3351 3341 3351 NaN\n"}],"source":"account.callback('a','b', 'c',b'{\"code\": \"rb2005\", \"open\": 3341, \"high\": 3351, \"low\": 3341, \"close\": 3351, \"datetime\": \"2019-10-14 09:00:00:000000\"}')\n\n\n"},{"cell_type":"code","execution_count":19,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":"<class 'int'>\nQUANTAXIS>> ============ c2b95936-585e-48ef-9170-d4621b8bc203 SEND ORDER ==================\nQUANTAXIS>> directionSELL offset CLOSE price3352 volume1\n{'volume_long': 1.0, 'volume_short': 0, 'volume_long_frozen': 0, 'volume_short_frozen': 0}\n{'volume_long': 1.0, 'volume_short': 0}\n下单成功 c2b95936-585e-48ef-9170-d4621b8bc203\n全部成交 c2b95936-585e-48ef-9170-d4621b8bc203\n{'volume_long': 2.0, 'volume_short': 0, 'volume_long_frozen': 1, 'volume_short_frozen': 0}\nQUANTAXIS>> ['oL-C4w1HjuPRqTIRcZUyYR0QcLzo']\n"}],"source":"account.send_order('SELL', 'CLOSE', 3352, 1)"},{"cell_type":"code","execution_count":12,"metadata":{},"outputs":[{"data":{"text/plain":"{'code': 'rb2005',\n 'instrument_id': 'rb2005',\n 'user_id': 'quantaxis',\n 'portfolio_cookie': 'portfolio',\n 'username': 'quantaxis',\n 'position_id': 'dd63df35-724d-4694-9985-1ed474132c89',\n 'account_cookie': 'quantaxis',\n 'frozen': {},\n 'name': None,\n 'spms_id': None,\n 'oms_id': None,\n 'market_type': 'future_cn',\n 'exchange_id': None,\n 'moneypreset': 100000,\n 'moneypresetLeft': 100020.0,\n 'lastupdatetime': '',\n 'volume_long_today': 0.0,\n 'volume_long_his': 0,\n 'volume_long': 0.0,\n 'volume_short_today': 0,\n 'volume_short_his': 0,\n 'volume_short': 0,\n 'volume_long_frozen_today': 0.0,\n 'volume_long_frozen_his': 0,\n 'volume_long_frozen': 0.0,\n 'volume_short_frozen_today': 0,\n 'volume_short_frozen_his': 0,\n 'volume_short_frozen': 0,\n 'margin_long': 0.0,\n 'margin_short': 0,\n 'margin': 0.0,\n 'position_price_long': 3350.0,\n 'position_cost_long': 16750.0,\n 'position_price_short': 0,\n 'position_cost_short': 0,\n 'open_price_long': 3350.0,\n 'open_cost_long': 16750.0,\n 'open_price_short': 0,\n 'open_cost_short': 0,\n 'trades': [],\n 'orders': {},\n 'last_price': 3352.0,\n 'float_profit_long': -16750.0,\n 'float_profit_short': 0.0,\n 'float_profit': -16750.0,\n 'position_profit_long': -16750.0,\n 'position_profit_short': 0.0,\n 'position_profit': -16750.0}"},"execution_count":12,"metadata":{},"output_type":"execute_result"}],"source":"account.positions.message"},{"cell_type":"code","execution_count":13,"metadata":{},"outputs":[{"data":{"text/plain":"{'ba2c5fc0-8bf7-4ebf-b6db-64abd1527325': {'account_cookie': 'testfordebug2',\n 'user_id': 'testfordebug2',\n 'instrument_id': 'rb2005',\n 'towards': 2,\n 'exchange_id': 'SHFE',\n 'order_time': '2019-10-13 10:10:34.308027',\n 'volume': 1.0,\n 'price': 3350.0,\n 'order_id': 'ba2c5fc0-8bf7-4ebf-b6db-64abd1527325',\n 'seqno': 1,\n 'direction': 'BUY',\n 'offset': 'OPEN',\n 'volume_orign': 1.0,\n 'price_type': 'LIMIT',\n 'limit_price': 3350.0,\n 'time_condition': 'GFD',\n 'volume_condition': 'ANY',\n 'insert_date_time': '2019-10-13 10:10:34.308027',\n 'exchange_order_id': 'ac8b8a3d-30cb-4871-b870-91f1b23a5bcb',\n 'status': 300,\n 'volume_left': 0.0,\n 'last_msg': '全部成交',\n 'topic': 'send_order'},\n '9ee1e41c-6ee7-4229-b6ed-29e3d57c51c2': {'account_cookie': 'testfordebug2',\n 'user_id': 'testfordebug2',\n 'instrument_id': 'rb2005',\n 'towards': -3,\n 'exchange_id': 'SHFE',\n 'order_time': '2019-10-13 10:10:44.753856',\n 'volume': 1.0,\n 'price': 3352.0,\n 'order_id': '9ee1e41c-6ee7-4229-b6ed-29e3d57c51c2',\n 'seqno': 3,\n 'direction': 'SELL',\n 'offset': 'CLOSE',\n 'volume_orign': 1.0,\n 'price_type': 'LIMIT',\n 'limit_price': 3352.0,\n 'time_condition': 'GFD',\n 'volume_condition': 'ANY',\n 'insert_date_time': '2019-10-13 10:10:44.753856',\n 'exchange_order_id': 'b5e98a10-0078-4ccc-b364-d62ab90bf8ad',\n 'status': 300,\n 'volume_left': 0.0,\n 'last_msg': '全部成交',\n 'topic': 'send_order'}}"},"execution_count":13,"metadata":{},"output_type":"execute_result"}],"source":"account.orders"},{"cell_type":"code","execution_count":14,"metadata":{},"outputs":[{"data":{"text/plain":"20.0"},"execution_count":14,"metadata":{},"output_type":"execute_result"}],"source":"account.qifiacc.close_profit"},{"cell_type":"code","execution_count":35,"metadata":{},"outputs":[{"ename":"AttributeError","evalue":"'x' object has no attribute 'bank_id'","output_type":"error","traceback":["\u001b[1;31m---------------------------------------------------------------------------\u001b[0m","\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)","\u001b[1;32m<ipython-input-35-b7dbc424ae4b>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0macc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbank_id\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[1;31mAttributeError\u001b[0m: 'x' object has no attribute 'bank_id'"]}],"source":"acc.bank_id"},{"cell_type":"code","execution_count":33,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":"{'volume_long': 0, 'volume_short': 0, 'volume_long_frozen': 0, 'volume_short_frozen': 0}\n{'volume_long': 0, 'volume_short': 0}\n下单成功 orx1\n"}],"source":"order = account.qifiacc.send_order(\n code=account.code, towards=-2, price=3850, amount=1, order_id='orx1')"},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":""},{"cell_type":"code","execution_count":34,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":"全部成交 orx1\n"}],"source":"account.qifiacc.make_deal(order)"},{"cell_type":"code","execution_count":35,"metadata":{},"outputs":[{"data":{"text/plain":"1000000.0"},"execution_count":35,"metadata":{},"output_type":"execute_result"}],"source":"account.qifiacc.balance\n"},{"cell_type":"code","execution_count":41,"metadata":{},"outputs":[{"name":"stderr","output_type":"stream","text":"QUANTAXIS>> 2019-10-13 10:32:15.482087 UPDATE ACCOUNT\n"}],"source":"account.update_account()"},{"cell_type":"code","execution_count":44,"metadata":{},"outputs":[{"data":{"text/plain":"{'code': 'rb2005',\n 'instrument_id': 'rb2005',\n 'user_id': 'quantaxis',\n 'portfolio_cookie': 'portfolio',\n 'username': 'quantaxis',\n 'position_id': '35bc79fc-6ac1-439b-a03f-c391a78b37a3',\n 'account_cookie': 'quantaxis',\n 'frozen': {},\n 'name': None,\n 'spms_id': None,\n 'oms_id': None,\n 'market_type': 'future_cn',\n 'exchange_id': None,\n 'moneypreset': 100000,\n 'moneypresetLeft': 96535.0,\n 'lastupdatetime': '',\n 'volume_long_today': 0,\n 'volume_long_his': 0,\n 'volume_long': 0,\n 'volume_short_today': 1.0,\n 'volume_short_his': 0,\n 'volume_short': 1.0,\n 'volume_long_frozen_today': 0,\n 'volume_long_frozen_his': 0,\n 'volume_long_frozen': 0,\n 'volume_short_frozen_today': 0,\n 'volume_short_frozen_his': 0,\n 'volume_short_frozen': 0,\n 'margin_long': 0,\n 'margin_short': 3465.0,\n 'margin': 3465.0,\n 'position_price_long': 0,\n 'position_cost_long': 0,\n 'position_price_short': 3850.0,\n 'position_cost_short': 38500.0,\n 'open_price_long': 0,\n 'open_cost_long': 0,\n 'open_price_short': 3850.0,\n 'open_cost_short': 38500.0,\n 'trades': [],\n 'orders': {},\n 'last_price': 3850.0,\n 'float_profit_long': 0.0,\n 'float_profit_short': 0.0,\n 'float_profit': 0.0,\n 'position_profit_long': 0.0,\n 'position_profit_short': 0.0,\n 'position_profit': 0.0}"},"execution_count":44,"metadata":{},"output_type":"execute_result"}],"source":"account.positions.message"},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":"account.update_account()"},{"cell_type":"code","execution_count":46,"metadata":{},"outputs":[{"data":{"text/plain":"{'code': 'rb2005',\n 'instrument_id': 'rb2005',\n 'user_id': 'quantaxis',\n 'portfolio_cookie': 'portfolio',\n 'username': 'quantaxis',\n 'position_id': '35bc79fc-6ac1-439b-a03f-c391a78b37a3',\n 'account_cookie': 'quantaxis',\n 'frozen': {},\n 'name': None,\n 'spms_id': None,\n 'oms_id': None,\n 'market_type': 'future_cn',\n 'exchange_id': None,\n 'moneypreset': 100000,\n 'moneypresetLeft': 96535.0,\n 'lastupdatetime': '',\n 'volume_long_today': 0,\n 'volume_long_his': 0,\n 'volume_long': 0,\n 'volume_short_today': 1.0,\n 'volume_short_his': 0,\n 'volume_short': 2.0,\n 'volume_long_frozen_today': 0,\n 'volume_long_frozen_his': 0,\n 'volume_long_frozen': 0,\n 'volume_short_frozen_today': 1,\n 'volume_short_frozen_his': 0,\n 'volume_short_frozen': 1,\n 'margin_long': 0,\n 'margin_short': 3465.0,\n 'margin': 3465.0,\n 'position_price_long': 0,\n 'position_cost_long': 0,\n 'position_price_short': 3850.0,\n 'position_cost_short': 38500.0,\n 'open_price_long': 0,\n 'open_cost_long': 0,\n 'open_price_short': 3850.0,\n 'open_cost_short': 38500.0,\n 'trades': [],\n 'orders': {},\n 'last_price': 3850.0,\n 'float_profit_long': 0.0,\n 'float_profit_short': -38500.0,\n 'float_profit': -38500.0,\n 'position_profit_long': 0.0,\n 'position_profit_short': -38500.0,\n 'position_profit': -38500.0}"},"execution_count":46,"metadata":{},"output_type":"execute_result"}],"source":"account.positions.message"},{"cell_type":"code","execution_count":45,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":"{'volume_long': 0, 'volume_short': 1.0, 'volume_long_frozen': 0, 'volume_short_frozen': 0}\n{'volume_long': 0, 'volume_short': 1.0}\n下单成功 orx1\n"}],"source":"order = account.qifiacc.send_order(\n code=account.code, towards=3, price=3840, amount=1, order_id='orx1')"},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":""},{"cell_type":"code","execution_count":25,"metadata":{},"outputs":[{"data":{"text/plain":"944770.0"},"execution_count":25,"metadata":{},"output_type":"execute_result"}],"source":"account.qifiacc.balance"},{"cell_type":"code","execution_count":29,"metadata":{},"outputs":[{"data":{"text/plain":"-16750.0"},"execution_count":29,"metadata":{},"output_type":"execute_result"}],"source":"account.positions.float_profit_long"},{"cell_type":"code","execution_count":30,"metadata":{},"outputs":[{"data":{"text/plain":"-38500.0"},"execution_count":30,"metadata":{},"output_type":"execute_result"}],"source":"account.positions.float_profit_short"}],"nbformat":4,"nbformat_minor":2,"metadata":{"language_info":{"name":"python","codemirror_mode":{"name":"ipython","version":3}},"orig_nbformat":2,"file_extension":".py","mimetype":"text/x-python","name":"python","npconvert_exporter":"python","pygments_lexer":"ipython3","version":3}}
================================================
FILE: jupytertest/test_stock.ipynb
================================================
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"no display found. Using non-interactive Agg backend\n",
"if you use ssh, you can use ssh with -X parmas to avoid this issue\n"
]
}
],
"source": [
"import QUANTAXIS as QA"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from QAStrategy import QAStrategyCTABase\n",
"from QAStrategy.qastockbase import QAStrategyStockBase"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"class strategy(QAStrategyStockBase):\n",
" def on_bar(self, data):\n",
" print(data)\n",
"\n",
" \n",
" code = data.name[1]\n",
" pos = self.get_positions(code)\n",
" print('---------------under is 当前全市场的market_data --------------')\n",
" \n",
" print(self.get_current_marketdata())\n",
" print('---------------under is 当前品种的market_data --------------')\n",
" print(self.get_code_marketdata(code))\n",
" print(code)\n",
" \n",
" \n",
" \n",
" if random.random() > 0.5:\n",
" self.send_order('BUY', 'OPEN', code, price=data['close'], volume=1000)\n",
" else:\n",
" if pos.volume_long > 0:\n",
" self.send_order('SELL', 'CLOSE', code, price=data['close'], volume=pos.volume_long)\n",
" \n",
" print('---------------under is 账户情况和持仓情况 -------------------')\n",
" print(self.get_positions(code).message)\n",
" print(self.acc.history_table)\n",
" \n",
" #print(self.running_time)\n",
" input()\n",
" \n",
" \n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"s = strategy(code=['000001', '000002'], frequence='day', start='2019-01-01', end='2019-02-01', strategy_id='x')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" prortfolio with user_cookie USER_QoZ8TDrF already exist!!\n",
"< QA_AccountPRO x market: stock_cn>\n",
"stock_cn\n",
"backtest: Settle!\n",
"open 9.390000e+00\n",
"high 9.420000e+00\n",
"low 9.160000e+00\n",
"close 9.190000e+00\n",
"volume 5.393860e+05\n",
"amount 4.986951e+08\n",
"Name: (2019-01-02 00:00:00, 000001), dtype: float64\n",
"---------------under is 当前全市场的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 498695104.0\n",
"---------------under is 当前品种的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 498695104.0\n",
"000001\n",
"---------------under is 账户情况和持仓情况 -------------------\n",
"{'code': '000001', 'instrument_id': '000001', 'user_id': 'x', 'portfolio_cookie': 'default', 'username': 'quantaxis', 'position_id': 'd2b24d5c-fb1e-4a2e-97eb-f19b04f544ec', 'account_cookie': 'x', 'frozen': {}, 'name': None, 'spms_id': None, 'oms_id': None, 'market_type': 'stock_cn', 'exchange_id': None, 'moneypreset': 100000, 'moneypresetLeft': 100000, 'lastupdatetime': '', 'volume_long_today': 1000, 'volume_long_his': 0, 'volume_long': 1000, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'margin_long': 9190.0, 'margin_short': 0, 'margin': 9190.0, 'position_price_long': 9.19, 'position_cost_long': 9190.0, 'position_price_short': 0, 'position_cost_short': 0, 'open_price_long': 9.19, 'open_cost_long': 9190.0, 'open_price_short': 0, 'open_cost_short': 0, 'trades': [], 'orders': {}, 'last_price': 9.19, 'float_profit_long': 0.0, 'float_profit_short': 0.0, 'float_profit': 0.0, 'position_profit_long': 0.0, 'position_profit_short': 0.0, 'position_profit': 0.0}\n",
" datetime code price amount cash \\\n",
"0 2019-01-02 00:00:00 000001 9.19 1000 990805.0 \n",
"\n",
" order_id realorder_id trade_id account_cookie \\\n",
"0 e23f9e01-e8d2-4a05-93ef-9163ce7a83ee None None x \n",
"\n",
" commission tax message frozen direction total_frozen \n",
"0 5 0 None 0 1 0 \n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"open 2.383000e+01\n",
"high 2.409000e+01\n",
"low 2.367000e+01\n",
"close 2.390000e+01\n",
"volume 2.470100e+05\n",
"amount 5.893846e+08\n",
"Name: (2019-01-02 00:00:00, 000002), dtype: float64\n",
"---------------under is 当前全市场的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 498695104.0\n",
" 000002 23.83 24.09 23.67 23.90 247010.0 589384576.0\n",
"---------------under is 当前品种的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-02 000002 23.83 24.09 23.67 23.9 247010.0 589384576.0\n",
"000002\n",
"---------------under is 账户情况和持仓情况 -------------------\n",
"{'code': '000002', 'instrument_id': '000002', 'user_id': 'x', 'portfolio_cookie': 'default', 'username': 'quantaxis', 'position_id': '5aa694d0-3861-43a8-9efc-84f380138bea', 'account_cookie': 'x', 'frozen': {}, 'name': None, 'spms_id': None, 'oms_id': None, 'market_type': 'stock_cn', 'exchange_id': None, 'moneypreset': 100000, 'moneypresetLeft': 100000, 'lastupdatetime': '', 'volume_long_today': 1000, 'volume_long_his': 0, 'volume_long': 1000, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'margin_long': 23900.0, 'margin_short': 0, 'margin': 23900.0, 'position_price_long': 23.9, 'position_cost_long': 23900.0, 'position_price_short': 0, 'position_cost_short': 0, 'open_price_long': 23.9, 'open_cost_long': 23900.0, 'open_price_short': 0, 'open_cost_short': 0, 'trades': [], 'orders': {}, 'last_price': 23.9, 'float_profit_long': 0.0, 'float_profit_short': 0.0, 'float_profit': 0.0, 'position_profit_long': 0.0, 'position_profit_short': 0.0, 'position_profit': 0.0}\n",
" datetime code price amount cash \\\n",
"0 2019-01-02 00:00:00 000001 9.19 1000 990805.000 \n",
"1 2019-01-02 00:00:00 000002 23.90 1000 966899.025 \n",
"\n",
" order_id realorder_id trade_id account_cookie \\\n",
"0 e23f9e01-e8d2-4a05-93ef-9163ce7a83ee None None x \n",
"1 1f430faa-86d1-440b-abf7-a7feddc17954 None None x \n",
"\n",
" commission tax message frozen direction total_frozen \n",
"0 5.000 0 None 0 1 0 \n",
"1 5.975 0 None 0 1 0 \n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"backtest: Settle!\n",
"open 9.180000e+00\n",
"high 9.330000e+00\n",
"low 9.150000e+00\n",
"close 9.280000e+00\n",
"volume 4.155370e+05\n",
"amount 3.844577e+08\n",
"Name: (2019-01-03 00:00:00, 000001), dtype: float64\n",
"---------------under is 当前全市场的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 384457696.0\n",
"---------------under is 当前品种的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 498695104.0\n",
"2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 384457696.0\n",
"000001\n",
"---------------under is 账户情况和持仓情况 -------------------\n",
"{'code': '000001', 'instrument_id': '000001', 'user_id': 'x', 'portfolio_cookie': 'default', 'username': 'quantaxis', 'position_id': 'd2b24d5c-fb1e-4a2e-97eb-f19b04f544ec', 'account_cookie': 'x', 'frozen': {}, 'name': None, 'spms_id': None, 'oms_id': None, 'market_type': 'stock_cn', 'exchange_id': None, 'moneypreset': 100000, 'moneypresetLeft': 100000, 'lastupdatetime': '', 'volume_long_today': 2000, 'volume_long_his': 0, 'volume_long': 2000, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'margin_long': 18470.0, 'margin_short': 0, 'margin': 18470.0, 'position_price_long': 9.235, 'position_cost_long': 18470.0, 'position_price_short': 0, 'position_cost_short': 0, 'open_price_long': 9.235, 'open_cost_long': 18470.0, 'open_price_short': 0, 'open_cost_short': 0, 'trades': [], 'orders': {}, 'last_price': 9.28, 'float_profit_long': 90.0, 'float_profit_short': 0.0, 'float_profit': 90.0, 'position_profit_long': 90.0, 'position_profit_short': 0.0, 'position_profit': 90.0}\n",
" datetime code price amount cash \\\n",
"0 2019-01-02 00:00:00 000001 9.19 1000 990805.000 \n",
"1 2019-01-02 00:00:00 000002 23.90 1000 966899.025 \n",
"2 2019-01-03 00:00:00 000001 9.28 1000 957614.025 \n",
"\n",
" order_id realorder_id trade_id account_cookie \\\n",
"0 e23f9e01-e8d2-4a05-93ef-9163ce7a83ee None None x \n",
"1 1f430faa-86d1-440b-abf7-a7feddc17954 None None x \n",
"2 0230d608-91cc-422e-8deb-218f4faef3d7 None None x \n",
"\n",
" commission tax message frozen direction total_frozen \n",
"0 5.000 0 None 0 1 0 \n",
"1 5.975 0 None 0 1 0 \n",
"2 5.000 0 None 0 1 0 \n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"open 2.379000e+01\n",
"high 2.450000e+01\n",
"low 2.371000e+01\n",
"close 2.407000e+01\n",
"volume 2.223530e+05\n",
"amount 5.363333e+08\n",
"Name: (2019-01-03 00:00:00, 000002), dtype: float64\n",
"---------------under is 当前全市场的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 384457696.0\n",
" 000002 23.79 24.50 23.71 24.07 222353.0 536333280.0\n",
"---------------under is 当前品种的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-02 000002 23.83 24.09 23.67 23.90 247010.0 589384576.0\n",
"2019-01-03 000002 23.79 24.50 23.71 24.07 222353.0 536333280.0\n",
"000002\n",
"---------------under is 账户情况和持仓情况 -------------------\n",
"{'code': '000002', 'instrument_id': '000002', 'user_id': 'x', 'portfolio_cookie': 'default', 'username': 'quantaxis', 'position_id': '5aa694d0-3861-43a8-9efc-84f380138bea', 'account_cookie': 'x', 'frozen': {}, 'name': None, 'spms_id': None, 'oms_id': None, 'market_type': 'stock_cn', 'exchange_id': None, 'moneypreset': 100000, 'moneypresetLeft': 100000, 'lastupdatetime': '', 'volume_long_today': 1000, 'volume_long_his': 0, 'volume_long': 1000, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'margin_long': 23900.0, 'margin_short': 0, 'margin': 23900.0, 'position_price_long': 23.9, 'position_cost_long': 23900.0, 'position_price_short': 0, 'position_cost_short': 0, 'open_price_long': 23.9, 'open_cost_long': 23900.0, 'open_price_short': 0, 'open_cost_short': 0, 'trades': [], 'orders': {}, 'last_price': 24.07, 'float_profit_long': 170.0, 'float_profit_short': 0.0, 'float_profit': 170.0, 'position_profit_long': 170.0, 'position_profit_short': 0.0, 'position_profit': 170.0}\n",
" datetime code price amount cash \\\n",
"0 2019-01-02 00:00:00 000001 9.19 1000 990805.0000 \n",
"1 2019-01-02 00:00:00 000002 23.90 1000 966899.0250 \n",
"2 2019-01-03 00:00:00 000001 9.28 1000 957614.0250 \n",
"3 2019-01-03 00:00:00 000002 24.07 -1000 981653.9375 \n",
"\n",
" order_id realorder_id trade_id account_cookie \\\n",
"0 e23f9e01-e8d2-4a05-93ef-9163ce7a83ee None None x \n",
"1 1f430faa-86d1-440b-abf7-a7feddc17954 None None x \n",
"2 0230d608-91cc-422e-8deb-218f4faef3d7 None None x \n",
"3 427f1eed-b3bd-4078-94e3-156bf3ae21a6 None None x \n",
"\n",
" commission tax message frozen direction total_frozen \n",
"0 5.0000 0.00 None 0 1 0 \n",
"1 5.9750 0.00 None 0 1 0 \n",
"2 5.0000 0.00 None 0 1 0 \n",
"3 6.0175 24.07 None 0 -1 0 \n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"backtest: Settle!\n",
"open 9.240000e+00\n",
"high 9.820000e+00\n",
"low 9.220000e+00\n",
"close 9.750000e+00\n",
"volume 1.481159e+06\n",
"amount 1.422150e+09\n",
"Name: (2019-01-04 00:00:00, 000001), dtype: float64\n",
"---------------under is 当前全市场的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09\n",
"---------------under is 当前品种的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08\n",
"2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08\n",
"2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09\n",
"000001\n",
"---------------under is 账户情况和持仓情况 -------------------\n",
"{'code': '000001', 'instrument_id': '000001', 'user_id': 'x', 'portfolio_cookie': 'default', 'username': 'quantaxis', 'position_id': 'd2b24d5c-fb1e-4a2e-97eb-f19b04f544ec', 'account_cookie': 'x', 'frozen': {}, 'name': None, 'spms_id': None, 'oms_id': None, 'market_type': 'stock_cn', 'exchange_id': None, 'moneypreset': 100000, 'moneypresetLeft': 100000, 'lastupdatetime': '', 'volume_long_today': 2000, 'volume_long_his': 0, 'volume_long': 2000, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'margin_long': 18470.0, 'margin_short': 0, 'margin': 18470.0, 'position_price_long': 9.235, 'position_cost_long': 18470.0, 'position_price_short': 0, 'position_cost_short': 0, 'open_price_long': 9.235, 'open_cost_long': 18470.0, 'open_price_short': 0, 'open_cost_short': 0, 'trades': [], 'orders': {}, 'last_price': 9.75, 'float_profit_long': 1030.0, 'float_profit_short': 0.0, 'float_profit': 1030.0, 'position_profit_long': 1030.0, 'position_profit_short': 0.0, 'position_profit': 1030.0}\n",
" datetime code price amount cash \\\n",
"0 2019-01-02 00:00:00 000001 9.19 1000 9.908050e+05 \n",
"1 2019-01-02 00:00:00 000002 23.90 1000 9.668990e+05 \n",
"2 2019-01-03 00:00:00 000001 9.28 1000 9.576140e+05 \n",
"3 2019-01-03 00:00:00 000002 24.07 -1000 9.816539e+05 \n",
"4 2019-01-04 00:00:00 000001 9.75 -2000 1.001129e+06 \n",
"\n",
" order_id realorder_id trade_id account_cookie \\\n",
"0 e23f9e01-e8d2-4a05-93ef-9163ce7a83ee None None x \n",
"1 1f430faa-86d1-440b-abf7-a7feddc17954 None None x \n",
"2 0230d608-91cc-422e-8deb-218f4faef3d7 None None x \n",
"3 427f1eed-b3bd-4078-94e3-156bf3ae21a6 None None x \n",
"4 48fd88b8-e3c0-4df5-94ef-62b936345bd9 None None x \n",
"\n",
" commission tax message frozen direction total_frozen \n",
"0 5.0000 0.00 None 0 1 0 \n",
"1 5.9750 0.00 None 0 1 0 \n",
"2 5.0000 0.00 None 0 1 0 \n",
"3 6.0175 24.07 None 0 -1 0 \n",
"4 5.0000 19.50 None 0 -1 0 \n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"open 2.391000e+01\n",
"high 2.500000e+01\n",
"low 2.385000e+01\n",
"close 2.493000e+01\n",
"volume 3.777270e+05\n",
"amount 9.270117e+08\n",
"Name: (2019-01-04 00:00:00, 000002), dtype: float64\n",
"---------------under is 当前全市场的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09\n",
" 000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08\n",
"---------------under is 当前品种的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-02 000002 23.83 24.09 23.67 23.90 247010.0 589384576.0\n",
"2019-01-03 000002 23.79 24.50 23.71 24.07 222353.0 536333280.0\n",
"2019-01-04 000002 23.91 25.00 23.85 24.93 377727.0 927011712.0\n",
"000002\n",
"---------------under is 账户情况和持仓情况 -------------------\n",
"{'code': '000002', 'instrument_id': '000002', 'user_id': 'x', 'portfolio_cookie': 'default', 'username': 'quantaxis', 'position_id': '5aa694d0-3861-43a8-9efc-84f380138bea', 'account_cookie': 'x', 'frozen': {}, 'name': None, 'spms_id': None, 'oms_id': None, 'market_type': 'stock_cn', 'exchange_id': None, 'moneypreset': 100000, 'moneypresetLeft': 100000, 'lastupdatetime': '', 'volume_long_today': 2000, 'volume_long_his': 0, 'volume_long': 2000, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'margin_long': 48830.0, 'margin_short': 0, 'margin': 48830.0, 'position_price_long': 24.415, 'position_cost_long': 48830.0, 'position_price_short': 0, 'position_cost_short': 0, 'open_price_long': 24.415, 'open_cost_long': 48830.0, 'open_price_short': 0, 'open_cost_short': 0, 'trades': [], 'orders': {}, 'last_price': 24.93, 'float_profit_long': 1030.0, 'float_profit_short': 0.0, 'float_profit': 1030.0, 'position_profit_long': 1030.0, 'position_profit_short': 0.0, 'position_profit': 1030.0}\n",
" datetime code price amount cash \\\n",
"0 2019-01-02 00:00:00 000001 9.19 1000 9.908050e+05 \n",
"1 2019-01-02 00:00:00 000002 23.90 1000 9.668990e+05 \n",
"2 2019-01-03 00:00:00 000001 9.28 1000 9.576140e+05 \n",
"3 2019-01-03 00:00:00 000002 24.07 -1000 9.816539e+05 \n",
"4 2019-01-04 00:00:00 000001 9.75 -2000 1.001129e+06 \n",
"5 2019-01-04 00:00:00 000002 24.93 1000 9.761932e+05 \n",
"\n",
" order_id realorder_id trade_id account_cookie \\\n",
"0 e23f9e01-e8d2-4a05-93ef-9163ce7a83ee None None x \n",
"1 1f430faa-86d1-440b-abf7-a7feddc17954 None None x \n",
"2 0230d608-91cc-422e-8deb-218f4faef3d7 None None x \n",
"3 427f1eed-b3bd-4078-94e3-156bf3ae21a6 None None x \n",
"4 48fd88b8-e3c0-4df5-94ef-62b936345bd9 None None x \n",
"5 d9aff179-9bc3-4268-b2d5-37eee8de309f None None x \n",
"\n",
" commission tax message frozen direction total_frozen \n",
"0 5.0000 0.00 None 0 1 0 \n",
"1 5.9750 0.00 None 0 1 0 \n",
"2 5.0000 0.00 None 0 1 0 \n",
"3 6.0175 24.07 None 0 -1 0 \n",
"4 5.0000 19.50 None 0 -1 0 \n",
"5 6.2325 0.00 None 0 1 0 \n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"backtest: Settle!\n",
"open 9.840000e+00\n",
"high 9.850000e+00\n",
"low 9.630000e+00\n",
"close 9.740000e+00\n",
"volume 8.656870e+05\n",
"amount 8.411664e+08\n",
"Name: (2019-01-07 00:00:00, 000001), dtype: float64\n",
"---------------under is 当前全市场的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 841166400.0\n",
"---------------under is 当前品种的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08\n",
"2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08\n",
"2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09\n",
"2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08\n",
"000001\n",
"---------------under is 账户情况和持仓情况 -------------------\n",
"{'code': '000001', 'instrument_id': '000001', 'user_id': 'x', 'portfolio_cookie': 'default', 'username': 'quantaxis', 'position_id': 'd2b24d5c-fb1e-4a2e-97eb-f19b04f544ec', 'account_cookie': 'x', 'frozen': {}, 'name': None, 'spms_id': None, 'oms_id': None, 'market_type': 'stock_cn', 'exchange_id': None, 'moneypreset': 100000, 'moneypresetLeft': 100000, 'lastupdatetime': '', 'volume_long_today': 3000, 'volume_long_his': 0, 'volume_long': 3000, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'margin_long': 28210.0, 'margin_short': 0, 'margin': 28210.0, 'position_price_long': 9.403333333333334, 'position_cost_long': 28210.0, 'position_price_short': 0, 'position_cost_short': 0, 'open_price_long': 9.403333333333334, 'open_cost_long': 28210.0, 'open_price_short': 0, 'open_cost_short': 0, 'trades': [], 'orders': {}, 'last_price': 9.74, 'float_profit_long': 1010.0, 'float_profit_short': 0.0, 'float_profit': 1010.0, 'position_profit_long': 1010.0, 'position_profit_short': 0.0, 'position_profit': 1010.0}\n",
" datetime code price amount cash \\\n",
"0 2019-01-02 00:00:00 000001 9.19 1000 9.908050e+05 \n",
"1 2019-01-02 00:00:00 000002 23.90 1000 9.668990e+05 \n",
"2 2019-01-03 00:00:00 000001 9.28 1000 9.576140e+05 \n",
"3 2019-01-03 00:00:00 000002 24.07 -1000 9.816539e+05 \n",
"4 2019-01-04 00:00:00 000001 9.75 -2000 1.001129e+06 \n",
"5 2019-01-04 00:00:00 000002 24.93 1000 9.761932e+05 \n",
"6 2019-01-07 00:00:00 000001 9.74 1000 9.664482e+05 \n",
"\n",
" order_id realorder_id trade_id account_cookie \\\n",
"0 e23f9e01-e8d2-4a05-93ef-9163ce7a83ee None None x \n",
"1 1f430faa-86d1-440b-abf7-a7feddc17954 None None x \n",
"2 0230d608-91cc-422e-8deb-218f4faef3d7 None None x \n",
"3 427f1eed-b3bd-4078-94e3-156bf3ae21a6 None None x \n",
"4 48fd88b8-e3c0-4df5-94ef-62b936345bd9 None None x \n",
"5 d9aff179-9bc3-4268-b2d5-37eee8de309f None None x \n",
"6 41f23955-b920-4f04-bcb7-ca1cd960aa45 None None x \n",
"\n",
" commission tax message frozen direction total_frozen \n",
"0 5.0000 0.00 None 0 1 0 \n",
"1 5.9750 0.00 None 0 1 0 \n",
"2 5.0000 0.00 None 0 1 0 \n",
"3 6.0175 24.07 None 0 -1 0 \n",
"4 5.0000 19.50 None 0 -1 0 \n",
"5 6.2325 0.00 None 0 1 0 \n",
"6 5.0000 0.00 None 0 1 0 \n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"open 2.529000e+01\n",
"high 2.553000e+01\n",
"low 2.499000e+01\n",
"close 2.505000e+01\n",
"volume 4.271540e+05\n",
"amount 1.077909e+09\n",
"Name: (2019-01-07 00:00:00, 000002), dtype: float64\n",
"---------------under is 当前全市场的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08\n",
" 000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09\n",
"---------------under is 当前品种的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-02 000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08\n",
"2019-01-03 000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08\n",
"2019-01-04 000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08\n",
"2019-01-07 000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09\n",
"000002\n",
"---------------under is 账户情况和持仓情况 -------------------\n",
"{'code': '000002', 'instrument_id': '000002', 'user_id': 'x', 'portfolio_cookie': 'default', 'username': 'quantaxis', 'position_id': '5aa694d0-3861-43a8-9efc-84f380138bea', 'account_cookie': 'x', 'frozen': {}, 'name': None, 'spms_id': None, 'oms_id': None, 'market_type': 'stock_cn', 'exchange_id': None, 'moneypreset': 100000, 'moneypresetLeft': 100000, 'lastupdatetime': '', 'volume_long_today': 2000, 'volume_long_his': 0, 'volume_long': 2000, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'margin_long': 48830.0, 'margin_short': 0, 'margin': 48830.0, 'position_price_long': 24.415, 'position_cost_long': 48830.0, 'position_price_short': 0, 'position_cost_short': 0, 'open_price_long': 24.415, 'open_cost_long': 48830.0, 'open_price_short': 0, 'open_cost_short': 0, 'trades': [], 'orders': {}, 'last_price': 25.05, 'float_profit_long': 1270.0, 'float_profit_short': 0.0, 'float_profit': 1270.0, 'position_profit_long': 1270.0, 'position_profit_short': 0.0, 'position_profit': 1270.0}\n",
" datetime code price amount cash \\\n",
"0 2019-01-02 00:00:00 000001 9.19 1000 9.908050e+05 \n",
"1 2019-01-02 00:00:00 000002 23.90 1000 9.668990e+05 \n",
"2 2019-01-03 00:00:00 000001 9.28 1000 9.576140e+05 \n",
"3 2019-01-03 00:00:00 000002 24.07 -1000 9.816539e+05 \n",
"4 2019-01-04 00:00:00 000001 9.75 -2000 1.001129e+06 \n",
"5 2019-01-04 00:00:00 000002 24.93 1000 9.761932e+05 \n",
"6 2019-01-07 00:00:00 000001 9.74 1000 9.664482e+05 \n",
"7 2019-01-07 00:00:00 000002 25.05 -2000 1.016486e+06 \n",
"\n",
" order_id realorder_id trade_id account_cookie \\\n",
"0 e23f9e01-e8d2-4a05-93ef-9163ce7a83ee None None x \n",
"1 1f430faa-86d1-440b-abf7-a7feddc17954 None None x \n",
"2 0230d608-91cc-422e-8deb-218f4faef3d7 None None x \n",
"3 427f1eed-b3bd-4078-94e3-156bf3ae21a6 None None x \n",
"4 48fd88b8-e3c0-4df5-94ef-62b936345bd9 None None x \n",
"5 d9aff179-9bc3-4268-b2d5-37eee8de309f None None x \n",
"6 41f23955-b920-4f04-bcb7-ca1cd960aa45 None None x \n",
"7 cb2fdd74-7326-41d9-812f-9d88da447741 None None x \n",
"\n",
" commission tax message frozen direction total_frozen \n",
"0 5.0000 0.00 None 0 1 0 \n",
"1 5.9750 0.00 None 0 1 0 \n",
"2 5.0000 0.00 None 0 1 0 \n",
"3 6.0175 24.07 None 0 -1 0 \n",
"4 5.0000 19.50 None 0 -1 0 \n",
"5 6.2325 0.00 None 0 1 0 \n",
"6 5.0000 0.00 None 0 1 0 \n",
"7 12.5250 50.10 None 0 -1 0 \n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"backtest: Settle!\n",
"open 9.730000e+00\n",
"high 9.740000e+00\n",
"low 9.620000e+00\n",
"close 9.660000e+00\n",
"volume 4.023880e+05\n",
"amount 3.892478e+08\n",
"Name: (2019-01-08 00:00:00, 000001), dtype: float64\n",
"---------------under is 当前全市场的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 389247808.0\n",
"---------------under is 当前品种的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08\n",
"2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08\n",
"2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09\n",
"2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08\n",
"2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 3.892478e+08\n",
"000001\n",
"---------------under is 账户情况和持仓情况 -------------------\n",
"{'code': '000001', 'instrument_id': '000001', 'user_id': 'x', 'portfolio_cookie': 'default', 'username': 'quantaxis', 'position_id': 'd2b24d5c-fb1e-4a2e-97eb-f19b04f544ec', 'account_cookie': 'x', 'frozen': {}, 'name': None, 'spms_id': None, 'oms_id': None, 'market_type': 'stock_cn', 'exchange_id': None, 'moneypreset': 100000, 'moneypresetLeft': 100000, 'lastupdatetime': '', 'volume_long_today': 3000, 'volume_long_his': 0, 'volume_long': 3000, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'margin_long': 28210.0, 'margin_short': 0, 'margin': 28210.0, 'position_price_long': 9.403333333333334, 'position_cost_long': 28210.0, 'position_price_short': 0, 'position_cost_short': 0, 'open_price_long': 9.403333333333334, 'open_cost_long': 28210.0, 'open_price_short': 0, 'open_cost_short': 0, 'trades': [], 'orders': {}, 'last_price': 9.66, 'float_profit_long': 770.0, 'float_profit_short': 0.0, 'float_profit': 770.0, 'position_profit_long': 770.0, 'position_profit_short': 0.0, 'position_profit': 770.0}\n",
" datetime code price amount cash \\\n",
"0 2019-01-02 00:00:00 000001 9.19 1000 9.908050e+05 \n",
"1 2019-01-02 00:00:00 000002 23.90 1000 9.668990e+05 \n",
"2 2019-01-03 00:00:00 000001 9.28 1000 9.576140e+05 \n",
"3 2019-01-03 00:00:00 000002 24.07 -1000 9.816539e+05 \n",
"4 2019-01-04 00:00:00 000001 9.75 -2000 1.001129e+06 \n",
"5 2019-01-04 00:00:00 000002 24.93 1000 9.761932e+05 \n",
"6 2019-01-07 00:00:00 000001 9.74 1000 9.664482e+05 \n",
"7 2019-01-07 00:00:00 000002 25.05 -2000 1.016486e+06 \n",
"8 2019-01-08 00:00:00 000001 9.66 -3000 1.045429e+06 \n",
"\n",
" order_id realorder_id trade_id account_cookie \\\n",
"0 e23f9e01-e8d2-4a05-93ef-9163ce7a83ee None None x \n",
"1 1f430faa-86d1-440b-abf7-a7feddc17954 None None x \n",
"2 0230d608-91cc-422e-8deb-218f4faef3d7 None None x \n",
"3 427f1eed-b3bd-4078-94e3-156bf3ae21a6 None None x \n",
"4 48fd88b8-e3c0-4df5-94ef-62b936345bd9 None None x \n",
"5 d9aff179-9bc3-4268-b2d5-37eee8de309f None None x \n",
"6 41f23955-b920-4f04-bcb7-ca1cd960aa45 None None x \n",
"7 cb2fdd74-7326-41d9-812f-9d88da447741 None None x \n",
"8 8ef82ee7-87b8-4f7d-8a01-374f52b60cbb None None x \n",
"\n",
" commission tax message frozen direction total_frozen \n",
"0 5.0000 0.00 None 0 1 0 \n",
"1 5.9750 0.00 None 0 1 0 \n",
"2 5.0000 0.00 None 0 1 0 \n",
"3 6.0175 24.07 None 0 -1 0 \n",
"4 5.0000 19.50 None 0 -1 0 \n",
"5 6.2325 0.00 None 0 1 0 \n",
"6 5.0000 0.00 None 0 1 0 \n",
"7 12.5250 50.10 None 0 -1 0 \n",
"8 7.2450 28.98 None 0 -1 0 \n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"open 2.505000e+01\n",
"high 2.520000e+01\n",
"low 2.463000e+01\n",
"close 2.500000e+01\n",
"volume 2.143820e+05\n",
"amount 5.336044e+08\n",
"Name: (2019-01-08 00:00:00, 000002), dtype: float64\n",
"---------------under is 当前全市场的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 389247808.0\n",
" 000002 25.05 25.20 24.63 25.00 214382.0 533604352.0\n",
"---------------under is 当前品种的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-02 000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08\n",
"2019-01-03 000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08\n",
"2019-01-04 000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08\n",
"2019-01-07 000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09\n",
"2019-01-08 000002 25.05 25.20 24.63 25.00 214382.0 5.336044e+08\n",
"000002\n",
"---------------under is 账户情况和持仓情况 -------------------\n",
"{'code': '000002', 'instrument_id': '000002', 'user_id': 'x', 'portfolio_cookie': 'default', 'username': 'quantaxis', 'position_id': '5aa694d0-3861-43a8-9efc-84f380138bea', 'account_cookie': 'x', 'frozen': {}, 'name': None, 'spms_id': None, 'oms_id': None, 'market_type': 'stock_cn', 'exchange_id': None, 'moneypreset': 100000, 'moneypresetLeft': 100000, 'lastupdatetime': '', 'volume_long_today': 2000, 'volume_long_his': 0, 'volume_long': 2000, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'margin_long': 48830.0, 'margin_short': 0, 'margin': 48830.0, 'position_price_long': 24.415, 'position_cost_long': 48830.0, 'position_price_short': 0, 'position_cost_short': 0, 'open_price_long': 24.415, 'open_cost_long': 48830.0, 'open_price_short': 0, 'open_cost_short': 0, 'trades': [], 'orders': {}, 'last_price': 25.0, 'float_profit_long': 1170.0, 'float_profit_short': 0.0, 'float_profit': 1170.0, 'position_profit_long': 1170.0, 'position_profit_short': 0.0, 'position_profit': 1170.0}\n",
" datetime code price amount cash \\\n",
"0 2019-01-02 00:00:00 000001 9.19 1000 9.908050e+05 \n",
"1 2019-01-02 00:00:00 000002 23.90 1000 9.668990e+05 \n",
"2 2019-01-03 00:00:00 000001 9.28 1000 9.576140e+05 \n",
"3 2019-01-03 00:00:00 000002 24.07 -1000 9.816539e+05 \n",
"4 2019-01-04 00:00:00 000001 9.75 -2000 1.001129e+06 \n",
"5 2019-01-04 00:00:00 000002 24.93 1000 9.761932e+05 \n",
"6 2019-01-07 00:00:00 000001 9.74 1000 9.664482e+05 \n",
"7 2019-01-07 00:00:00 000002 25.05 -2000 1.016486e+06 \n",
"8 2019-01-08 00:00:00 000001 9.66 -3000 1.045429e+06 \n",
"9 2019-01-08 00:00:00 000002 25.00 -2000 1.095367e+06 \n",
"\n",
" order_id realorder_id trade_id account_cookie \\\n",
"0 e23f9e01-e8d2-4a05-93ef-9163ce7a83ee None None x \n",
"1 1f430faa-86d1-440b-abf7-a7feddc17954 None None x \n",
"2 0230d608-91cc-422e-8deb-218f4faef3d7 None None x \n",
"3 427f1eed-b3bd-4078-94e3-156bf3ae21a6 None None x \n",
"4 48fd88b8-e3c0-4df5-94ef-62b936345bd9 None None x \n",
"5 d9aff179-9bc3-4268-b2d5-37eee8de309f None None x \n",
"6 41f23955-b920-4f04-bcb7-ca1cd960aa45 None None x \n",
"7 cb2fdd74-7326-41d9-812f-9d88da447741 None None x \n",
"8 8ef82ee7-87b8-4f7d-8a01-374f52b60cbb None None x \n",
"9 1f63fa52-f56b-4814-8eb3-5e4de849f3cb None None x \n",
"\n",
" commission tax message frozen direction total_frozen \n",
"0 5.0000 0.00 None 0 1 0 \n",
"1 5.9750 0.00 None 0 1 0 \n",
"2 5.0000 0.00 None 0 1 0 \n",
"3 6.0175 24.07 None 0 -1 0 \n",
"4 5.0000 19.50 None 0 -1 0 \n",
"5 6.2325 0.00 None 0 1 0 \n",
"6 5.0000 0.00 None 0 1 0 \n",
"7 12.5250 50.10 None 0 -1 0 \n",
"8 7.2450 28.98 None 0 -1 0 \n",
"9 12.5000 50.00 None 0 -1 0 \n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"backtest: Settle!\n",
"open 9.740000e+00\n",
"high 1.008000e+01\n",
"low 9.700000e+00\n",
"close 9.940000e+00\n",
"volume 1.233486e+06\n",
"amount 1.229465e+09\n",
"Name: (2019-01-09 00:00:00, 000001), dtype: float64\n",
"---------------under is 当前全市场的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-09 000001 9.74 10.08 9.7 9.94 1233486.0 1.229465e+09\n",
"---------------under is 当前品种的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08\n",
"2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08\n",
"2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09\n",
"2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08\n",
"2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 3.892478e+08\n",
"2019-01-09 000001 9.74 10.08 9.70 9.94 1233486.0 1.229465e+09\n",
"000001\n",
"---------------under is 账户情况和持仓情况 -------------------\n",
"{'code': '000001', 'instrument_id': '000001', 'user_id': 'x', 'portfolio_cookie': 'default', 'username': 'quantaxis', 'position_id': 'd2b24d5c-fb1e-4a2e-97eb-f19b04f544ec', 'account_cookie': 'x', 'frozen': {}, 'name': None, 'spms_id': None, 'oms_id': None, 'market_type': 'stock_cn', 'exchange_id': None, 'moneypreset': 100000, 'moneypresetLeft': 100000, 'lastupdatetime': '', 'volume_long_today': 4000, 'volume_long_his': 0, 'volume_long': 4000, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'margin_long': 38150.0, 'margin_short': 0, 'margin': 38150.0, 'position_price_long': 9.5375, 'position_cost_long': 38150.0, 'position_price_short': 0, 'position_cost_short': 0, 'open_price_long': 9.5375, 'open_cost_long': 38150.0, 'open_price_short': 0, 'open_cost_short': 0, 'trades': [], 'orders': {}, 'last_price': 9.94, 'float_profit_long': 1610.0, 'float_profit_short': 0.0, 'float_profit': 1610.0, 'position_profit_long': 1610.0, 'position_profit_short': 0.0, 'position_profit': 1610.0}\n",
" datetime code price amount cash \\\n",
"0 2019-01-02 00:00:00 000001 9.19 1000 9.908050e+05 \n",
"1 2019-01-02 00:00:00 000002 23.90 1000 9.668990e+05 \n",
"2 2019-01-03 00:00:00 000001 9.28 1000 9.576140e+05 \n",
"3 2019-01-03 00:00:00 000002 24.07 -1000 9.816539e+05 \n",
"4 2019-01-04 00:00:00 000001 9.75 -2000 1.001129e+06 \n",
"5 2019-01-04 00:00:00 000002 24.93 1000 9.761932e+05 \n",
"6 2019-01-07 00:00:00 000001 9.74 1000 9.664482e+05 \n",
"7 2019-01-07 00:00:00 000002 25.05 -2000 1.016486e+06 \n",
"8 2019-01-08 00:00:00 000001 9.66 -3000 1.045429e+06 \n",
"9 2019-01-08 00:00:00 000002 25.00 -2000 1.095367e+06 \n",
"10 2019-01-09 00:00:00 000001 9.94 1000 1.085422e+06 \n",
"\n",
" order_id realorder_id trade_id account_cookie \\\n",
"0 e23f9e01-e8d2-4a05-93ef-9163ce7a83ee None None x \n",
"1 1f430faa-86d1-440b-abf7-a7feddc17954 None None x \n",
"2 0230d608-91cc-422e-8deb-218f4faef3d7 None None x \n",
"3 427f1eed-b3bd-4078-94e3-156bf3ae21a6 None None x \n",
"4 48fd88b8-e3c0-4df5-94ef-62b936345bd9 None None x \n",
"5 d9aff179-9bc3-4268-b2d5-37eee8de309f None None x \n",
"6 41f23955-b920-4f04-bcb7-ca1cd960aa45 None None x \n",
"7 cb2fdd74-7326-41d9-812f-9d88da447741 None None x \n",
"8 8ef82ee7-87b8-4f7d-8a01-374f52b60cbb None None x \n",
"9 1f63fa52-f56b-4814-8eb3-5e4de849f3cb None None x \n",
"10 13e77d45-9e2c-4ef3-89f5-7fa63cc3b808 None None x \n",
"\n",
" commission tax message frozen direction total_frozen \n",
"0 5.0000 0.00 None 0 1 0 \n",
"1 5.9750 0.00 None 0 1 0 \n",
"2 5.0000 0.00 None 0 1 0 \n",
"3 6.0175 24.07 None 0 -1 0 \n",
"4 5.0000 19.50 None 0 -1 0 \n",
"5 6.2325 0.00 None 0 1 0 \n",
"6 5.0000 0.00 None 0 1 0 \n",
"7 12.5250 50.10 None 0 -1 0 \n",
"8 7.2450 28.98 None 0 -1 0 \n",
"9 12.5000 50.00 None 0 -1 0 \n",
"10 5.0000 0.00 None 0 1 0 \n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"open 2.540000e+01\n",
"high 2.588000e+01\n",
"low 2.511000e+01\n",
"close 2.533000e+01\n",
"volume 3.401400e+05\n",
"amount 8.670814e+08\n",
"Name: (2019-01-09 00:00:00, 000002), dtype: float64\n",
"---------------under is 当前全市场的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-09 000001 9.74 10.08 9.70 9.94 1233486.0 1.229465e+09\n",
" 000002 25.40 25.88 25.11 25.33 340140.0 8.670814e+08\n",
"---------------under is 当前品种的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-02 000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08\n",
"2019-01-03 000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08\n",
"2019-01-04 000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08\n",
"2019-01-07 000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09\n",
"2019-01-08 000002 25.05 25.20 24.63 25.00 214382.0 5.336044e+08\n",
"2019-01-09 000002 25.40 25.88 25.11 25.33 340140.0 8.670814e+08\n",
"000002\n",
"---------------under is 账户情况和持仓情况 -------------------\n",
"{'code': '000002', 'instrument_id': '000002', 'user_id': 'x', 'portfolio_cookie': 'default', 'username': 'quantaxis', 'position_id': '5aa694d0-3861-43a8-9efc-84f380138bea', 'account_cookie': 'x', 'frozen': {}, 'name': None, 'spms_id': None, 'oms_id': None, 'market_type': 'stock_cn', 'exchange_id': None, 'moneypreset': 100000, 'moneypresetLeft': 100000, 'lastupdatetime': '', 'volume_long_today': 3000, 'volume_long_his': 0, 'volume_long': 3000, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'margin_long': 74160.0, 'margin_short': 0, 'margin': 74160.0, 'position_price_long': 24.72, 'position_cost_long': 74160.0, 'position_price_short': 0, 'position_cost_short': 0, 'open_price_long': 24.72, 'open_cost_long': 74160.0, 'open_price_short': 0, 'open_cost_short': 0, 'trades': [], 'orders': {}, 'last_price': 25.33, 'float_profit_long': 1830.0, 'float_profit_short': 0.0, 'float_profit': 1830.0, 'position_profit_long': 1830.0, 'position_profit_short': 0.0, 'position_profit': 1830.0}\n",
" datetime code price amount cash \\\n",
"0 2019-01-02 00:00:00 000001 9.19 1000 9.908050e+05 \n",
"1 2019-01-02 00:00:00 000002 23.90 1000 9.668990e+05 \n",
"2 2019-01-03 00:00:00 000001 9.28 1000 9.576140e+05 \n",
"3 2019-01-03 00:00:00 000002 24.07 -1000 9.816539e+05 \n",
"4 2019-01-04 00:00:00 000001 9.75 -2000 1.001129e+06 \n",
"5 2019-01-04 00:00:00 000002 24.93 1000 9.761932e+05 \n",
"6 2019-01-07 00:00:00 000001 9.74 1000 9.664482e+05 \n",
"7 2019-01-07 00:00:00 000002 25.05 -2000 1.016486e+06 \n",
"8 2019-01-08 00:00:00 000001 9.66 -3000 1.045429e+06 \n",
"9 2019-01-08 00:00:00 000002 25.00 -2000 1.095367e+06 \n",
"10 2019-01-09 00:00:00 000001 9.94 1000 1.085422e+06 \n",
"11 2019-01-09 00:00:00 000002 25.33 1000 1.060086e+06 \n",
"\n",
" order_id realorder_id trade_id account_cookie \\\n",
"0 e23f9e01-e8d2-4a05-93ef-9163ce7a83ee None None x \n",
"1 1f430faa-86d1-440b-abf7-a7feddc17954 None None x \n",
"2 0230d608-91cc-422e-8deb-218f4faef3d7 None None x \n",
"3 427f1eed-b3bd-4078-94e3-156bf3ae21a6 None None x \n",
"4 48fd88b8-e3c0-4df5-94ef-62b936345bd9 None None x \n",
"5 d9aff179-9bc3-4268-b2d5-37eee8de309f None None x \n",
"6 41f23955-b920-4f04-bcb7-ca1cd960aa45 None None x \n",
"7 cb2fdd74-7326-41d9-812f-9d88da447741 None None x \n",
"8 8ef82ee7-87b8-4f7d-8a01-374f52b60cbb None None x \n",
"9 1f63fa52-f56b-4814-8eb3-5e4de849f3cb None None x \n",
"10 13e77d45-9e2c-4ef3-89f5-7fa63cc3b808 None None x \n",
"11 7e714c35-83a4-4cb4-8ab5-d4fb2b31ccb7 None None x \n",
"\n",
" commission tax message frozen direction total_frozen \n",
"0 5.0000 0.00 None 0 1 0 \n",
"1 5.9750 0.00 None 0 1 0 \n",
"2 5.0000 0.00 None 0 1 0 \n",
"3 6.0175 24.07 None 0 -1 0 \n",
"4 5.0000 19.50 None 0 -1 0 \n",
"5 6.2325 0.00 None 0 1 0 \n",
"6 5.0000 0.00 None 0 1 0 \n",
"7 12.5250 50.10 None 0 -1 0 \n",
"8 7.2450 28.98 None 0 -1 0 \n",
"9 12.5000 50.00 None 0 -1 0 \n",
"10 5.0000 0.00 None 0 1 0 \n",
"11 6.3325 0.00 None 0 1 0 \n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"backtest: Settle!\n",
"open 9.870000e+00\n",
"high 1.020000e+01\n",
"low 9.860000e+00\n",
"close 1.010000e+01\n",
"volume 1.071817e+06\n",
"amount 1.079711e+09\n",
"Name: (2019-01-10 00:00:00, 000001), dtype: float64\n",
"---------------under is 当前全市场的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-10 000001 9.87 10.2 9.86 10.1 1071817.0 1.079711e+09\n",
"---------------under is 当前品种的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08\n",
"2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08\n",
"2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09\n",
"2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08\n",
"2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 3.892478e+08\n",
"2019-01-09 000001 9.74 10.08 9.70 9.94 1233486.0 1.229465e+09\n",
"2019-01-10 000001 9.87 10.20 9.86 10.10 1071817.0 1.079711e+09\n",
"000001\n",
"---------------under is 账户情况和持仓情况 -------------------\n",
"{'code': '000001', 'instrument_id': '000001', 'user_id': 'x', 'portfolio_cookie': 'default', 'username': 'quantaxis', 'position_id': 'd2b24d5c-fb1e-4a2e-97eb-f19b04f544ec', 'account_cookie': 'x', 'frozen': {}, 'name': None, 'spms_id': None, 'oms_id': None, 'market_type': 'stock_cn', 'exchange_id': None, 'moneypreset': 100000, 'moneypresetLeft': 100000, 'lastupdatetime': '', 'volume_long_today': 5000, 'volume_long_his': 0, 'volume_long': 5000, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'margin_long': 48250.0, 'margin_short': 0, 'margin': 48250.0, 'position_price_long': 9.65, 'position_cost_long': 48250.0, 'position_price_short': 0, 'position_cost_short': 0, 'open_price_long': 9.65, 'open_cost_long': 48250.0, 'open_price_short': 0, 'open_cost_short': 0, 'trades': [], 'orders': {}, 'last_price': 10.1, 'float_profit_long': 2250.0, 'float_profit_short': 0.0, 'float_profit': 2250.0, 'position_profit_long': 2250.0, 'position_profit_short': 0.0, 'position_profit': 2250.0}\n",
" datetime code price amount cash \\\n",
"0 2019-01-02 00:00:00 000001 9.19 1000 9.908050e+05 \n",
"1 2019-01-02 00:00:00 000002 23.90 1000 9.668990e+05 \n",
"2 2019-01-03 00:00:00 000001 9.28 1000 9.576140e+05 \n",
"3 2019-01-03 00:00:00 000002 24.07 -1000 9.816539e+05 \n",
"4 2019-01-04 00:00:00 000001 9.75 -2000 1.001129e+06 \n",
"5 2019-01-04 00:00:00 000002 24.93 1000 9.761932e+05 \n",
"6 2019-01-07 00:00:00 000001 9.74 1000 9.664482e+05 \n",
"7 2019-01-07 00:00:00 000002 25.05 -2000 1.016486e+06 \n",
"8 2019-01-08 00:00:00 000001 9.66 -3000 1.045429e+06 \n",
"9 2019-01-08 00:00:00 000002 25.00 -2000 1.095367e+06 \n",
"10 2019-01-09 00:00:00 000001 9.94 1000 1.085422e+06 \n",
"11 2019-01-09 00:00:00 000002 25.33 1000 1.060086e+06 \n",
"12 2019-01-10 00:00:00 000001 10.10 1000 1.049981e+06 \n",
"\n",
" order_id realorder_id trade_id account_cookie \\\n",
"0 e23f9e01-e8d2-4a05-93ef-9163ce7a83ee None None x \n",
"1 1f430faa-86d1-440b-abf7-a7feddc17954 None None x \n",
"2 0230d608-91cc-422e-8deb-218f4faef3d7 None None x \n",
"3 427f1eed-b3bd-4078-94e3-156bf3ae21a6 None None x \n",
"4 48fd88b8-e3c0-4df5-94ef-62b936345bd9 None None x \n",
"5 d9aff179-9bc3-4268-b2d5-37eee8de309f None None x \n",
"6 41f23955-b920-4f04-bcb7-ca1cd960aa45 None None x \n",
"7 cb2fdd74-7326-41d9-812f-9d88da447741 None None x \n",
"8 8ef82ee7-87b8-4f7d-8a01-374f52b60cbb None None x \n",
"9 1f63fa52-f56b-4814-8eb3-5e4de849f3cb None None x \n",
"10 13e77d45-9e2c-4ef3-89f5-7fa63cc3b808 None None x \n",
"11 7e714c35-83a4-4cb4-8ab5-d4fb2b31ccb7 None None x \n",
"12 380f932e-7871-4c72-94d3-5077861c9f53 None None x \n",
"\n",
" commission tax message frozen direction total_frozen \n",
"0 5.0000 0.00 None 0 1 0 \n",
"1 5.9750 0.00 None 0 1 0 \n",
"2 5.0000 0.00 None 0 1 0 \n",
"3 6.0175 24.07 None 0 -1 0 \n",
"4 5.0000 19.50 None 0 -1 0 \n",
"5 6.2325 0.00 None 0 1 0 \n",
"6 5.0000 0.00 None 0 1 0 \n",
"7 12.5250 50.10 None 0 -1 0 \n",
"8 7.2450 28.98 None 0 -1 0 \n",
"9 12.5000 50.00 None 0 -1 0 \n",
"10 5.0000 0.00 None 0 1 0 \n",
"11 6.3325 0.00 None 0 1 0 \n",
"12 5.0000 0.00 None 0 1 0 \n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"open 2.522000e+01\n",
"high 2.556000e+01\n",
"low 2.503000e+01\n",
"close 2.511000e+01\n",
"volume 2.246490e+05\n",
"amount 5.689526e+08\n",
"Name: (2019-01-10 00:00:00, 000002), dtype: float64\n",
"---------------under is 当前全市场的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-10 000001 9.87 10.20 9.86 10.10 1071817.0 1.079711e+09\n",
" 000002 25.22 25.56 25.03 25.11 224649.0 5.689526e+08\n",
"---------------under is 当前品种的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-02 000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08\n",
"2019-01-03 000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08\n",
"2019-01-04 000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08\n",
"2019-01-07 000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09\n",
"2019-01-08 000002 25.05 25.20 24.63 25.00 214382.0 5.336044e+08\n",
"2019-01-09 000002 25.40 25.88 25.11 25.33 340140.0 8.670814e+08\n",
"2019-01-10 000002 25.22 25.56 25.03 25.11 224649.0 5.689526e+08\n",
"000002\n",
"---------------under is 账户情况和持仓情况 -------------------\n",
"{'code': '000002', 'instrument_id': '000002', 'user_id': 'x', 'portfolio_cookie': 'default', 'username': 'quantaxis', 'position_id': '5aa694d0-3861-43a8-9efc-84f380138bea', 'account_cookie': 'x', 'frozen': {}, 'name': None, 'spms_id': None, 'oms_id': None, 'market_type': 'stock_cn', 'exchange_id': None, 'moneypreset': 100000, 'moneypresetLeft': 100000, 'lastupdatetime': '', 'volume_long_today': 4000, 'volume_long_his': 0, 'volume_long': 4000, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'margin_long': 99270.0, 'margin_short': 0, 'margin': 99270.0, 'position_price_long': 24.8175, 'position_cost_long': 99270.0, 'position_price_short': 0, 'position_cost_short': 0, 'open_price_long': 24.8175, 'open_cost_long': 99270.0, 'open_price_short': 0, 'open_cost_short': 0, 'trades': [], 'orders': {}, 'last_price': 25.11, 'float_profit_long': 1170.0, 'float_profit_short': 0.0, 'float_profit': 1170.0, 'position_profit_long': 1170.0, 'position_profit_short': 0.0, 'position_profit': 1170.0}\n",
" datetime code price amount cash \\\n",
"0 2019-01-02 00:00:00 000001 9.19 1000 9.908050e+05 \n",
"1 2019-01-02 00:00:00 000002 23.90 1000 9.668990e+05 \n",
"2 2019-01-03 00:00:00 000001 9.28 1000 9.576140e+05 \n",
"3 2019-01-03 00:00:00 000002 24.07 -1000 9.816539e+05 \n",
"4 2019-01-04 00:00:00 000001 9.75 -2000 1.001129e+06 \n",
"5 2019-01-04 00:00:00 000002 24.93 1000 9.761932e+05 \n",
"6 2019-01-07 00:00:00 000001 9.74 1000 9.664482e+05 \n",
"7 2019-01-07 00:00:00 000002 25.05 -2000 1.016486e+06 \n",
"8 2019-01-08 00:00:00 000001 9.66 -3000 1.045429e+06 \n",
"9 2019-01-08 00:00:00 000002 25.00 -2000 1.095367e+06 \n",
"10 2019-01-09 00:00:00 000001 9.94 1000 1.085422e+06 \n",
"11 2019-01-09 00:00:00 000002 25.33 1000 1.060086e+06 \n",
"12 2019-01-10 00:00:00 000001 10.10 1000 1.049981e+06 \n",
"13 2019-01-10 00:00:00 000002 25.11 1000 1.024864e+06 \n",
"\n",
" order_id realorder_id trade_id account_cookie \\\n",
"0 e23f9e01-e8d2-4a05-93ef-9163ce7a83ee None None x \n",
"1 1f430faa-86d1-440b-abf7-a7feddc17954 None None x \n",
"2 0230d608-91cc-422e-8deb-218f4faef3d7 None None x \n",
"3 427f1eed-b3bd-4078-94e3-156bf3ae21a6 None None x \n",
"4 48fd88b8-e3c0-4df5-94ef-62b936345bd9 None None x \n",
"5 d9aff179-9bc3-4268-b2d5-37eee8de309f None None x \n",
"6 41f23955-b920-4f04-bcb7-ca1cd960aa45 None None x \n",
"7 cb2fdd74-7326-41d9-812f-9d88da447741 None None x \n",
"8 8ef82ee7-87b8-4f7d-8a01-374f52b60cbb None None x \n",
"9 1f63fa52-f56b-4814-8eb3-5e4de849f3cb None None x \n",
"10 13e77d45-9e2c-4ef3-89f5-7fa63cc3b808 None None x \n",
"11 7e714c35-83a4-4cb4-8ab5-d4fb2b31ccb7 None None x \n",
"12 380f932e-7871-4c72-94d3-5077861c9f53 None None x \n",
"13 3966e418-9017-4565-b24f-ed9455ef5593 None None x \n",
"\n",
" commission tax message frozen direction total_frozen \n",
"0 5.0000 0.00 None 0 1 0 \n",
"1 5.9750 0.00 None 0 1 0 \n",
"2 5.0000 0.00 None 0 1 0 \n",
"3 6.0175 24.07 None 0 -1 0 \n",
"4 5.0000 19.50 None 0 -1 0 \n",
"5 6.2325 0.00 None 0 1 0 \n",
"6 5.0000 0.00 None 0 1 0 \n",
"7 12.5250 50.10 None 0 -1 0 \n",
"8 7.2450 28.98 None 0 -1 0 \n",
"9 12.5000 50.00 None 0 -1 0 \n",
"10 5.0000 0.00 None 0 1 0 \n",
"11 6.3325 0.00 None 0 1 0 \n",
"12 5.0000 0.00 None 0 1 0 \n",
"13 6.2775 0.00 None 0 1 0 \n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"backtest: Settle!\n",
"open 1.011000e+01\n",
"high 1.022000e+01\n",
"low 1.005000e+01\n",
"close 1.020000e+01\n",
"volume 6.963640e+05\n",
"amount 7.080018e+08\n",
"Name: (2019-01-11 00:00:00, 000001), dtype: float64\n",
"---------------under is 当前全市场的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-11 000001 10.11 10.22 10.05 10.2 696364.0 708001792.0\n",
"---------------under is 当前品种的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-02 000001 9.39 9.42 9.16 9.19 539386.0 4.986951e+08\n",
"2019-01-03 000001 9.18 9.33 9.15 9.28 415537.0 3.844577e+08\n",
"2019-01-04 000001 9.24 9.82 9.22 9.75 1481159.0 1.422150e+09\n",
"2019-01-07 000001 9.84 9.85 9.63 9.74 865687.0 8.411664e+08\n",
"2019-01-08 000001 9.73 9.74 9.62 9.66 402388.0 3.892478e+08\n",
"2019-01-09 000001 9.74 10.08 9.70 9.94 1233486.0 1.229465e+09\n",
"2019-01-10 000001 9.87 10.20 9.86 10.10 1071817.0 1.079711e+09\n",
"2019-01-11 000001 10.11 10.22 10.05 10.20 696364.0 7.080018e+08\n",
"000001\n",
"---------------under is 账户情况和持仓情况 -------------------\n",
"{'code': '000001', 'instrument_id': '000001', 'user_id': 'x', 'portfolio_cookie': 'default', 'username': 'quantaxis', 'position_id': 'd2b24d5c-fb1e-4a2e-97eb-f19b04f544ec', 'account_cookie': 'x', 'frozen': {}, 'name': None, 'spms_id': None, 'oms_id': None, 'market_type': 'stock_cn', 'exchange_id': None, 'moneypreset': 100000, 'moneypresetLeft': 100000, 'lastupdatetime': '', 'volume_long_today': 6000, 'volume_long_his': 0, 'volume_long': 6000, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'margin_long': 58450.0, 'margin_short': 0, 'margin': 58450.0, 'position_price_long': 9.741666666666667, 'position_cost_long': 58450.0, 'position_price_short': 0, 'position_cost_short': 0, 'open_price_long': 9.741666666666667, 'open_cost_long': 58450.0, 'open_price_short': 0, 'open_cost_short': 0, 'trades': [], 'orders': {}, 'last_price': 10.2, 'float_profit_long': 2749.9999999999927, 'float_profit_short': 0.0, 'float_profit': 2749.9999999999927, 'position_profit_long': 2749.9999999999927, 'position_profit_short': 0.0, 'position_profit': 2749.9999999999927}\n",
" datetime code price amount cash \\\n",
"0 2019-01-02 00:00:00 000001 9.19 1000 9.908050e+05 \n",
"1 2019-01-02 00:00:00 000002 23.90 1000 9.668990e+05 \n",
"2 2019-01-03 00:00:00 000001 9.28 1000 9.576140e+05 \n",
"3 2019-01-03 00:00:00 000002 24.07 -1000 9.816539e+05 \n",
"4 2019-01-04 00:00:00 000001 9.75 -2000 1.001129e+06 \n",
"5 2019-01-04 00:00:00 000002 24.93 1000 9.761932e+05 \n",
"6 2019-01-07 00:00:00 000001 9.74 1000 9.664482e+05 \n",
"7 2019-01-07 00:00:00 000002 25.05 -2000 1.016486e+06 \n",
"8 2019-01-08 00:00:00 000001 9.66 -3000 1.045429e+06 \n",
"9 2019-01-08 00:00:00 000002 25.00 -2000 1.095367e+06 \n",
"10 2019-01-09 00:00:00 000001 9.94 1000 1.085422e+06 \n",
"11 2019-01-09 00:00:00 000002 25.33 1000 1.060086e+06 \n",
"12 2019-01-10 00:00:00 000001 10.10 1000 1.049981e+06 \n",
"13 2019-01-10 00:00:00 000002 25.11 1000 1.024864e+06 \n",
"14 2019-01-11 00:00:00 000001 10.20 1000 1.014659e+06 \n",
"\n",
" order_id realorder_id trade_id account_cookie \\\n",
"0 e23f9e01-e8d2-4a05-93ef-9163ce7a83ee None None x \n",
"1 1f430faa-86d1-440b-abf7-a7feddc17954 None None x \n",
"2 0230d608-91cc-422e-8deb-218f4faef3d7 None None x \n",
"3 427f1eed-b3bd-4078-94e3-156bf3ae21a6 None None x \n",
"4 48fd88b8-e3c0-4df5-94ef-62b936345bd9 None None x \n",
"5 d9aff179-9bc3-4268-b2d5-37eee8de309f None None x \n",
"6 41f23955-b920-4f04-bcb7-ca1cd960aa45 None None x \n",
"7 cb2fdd74-7326-41d9-812f-9d88da447741 None None x \n",
"8 8ef82ee7-87b8-4f7d-8a01-374f52b60cbb None None x \n",
"9 1f63fa52-f56b-4814-8eb3-5e4de849f3cb None None x \n",
"10 13e77d45-9e2c-4ef3-89f5-7fa63cc3b808 None None x \n",
"11 7e714c35-83a4-4cb4-8ab5-d4fb2b31ccb7 None None x \n",
"12 380f932e-7871-4c72-94d3-5077861c9f53 None None x \n",
"13 3966e418-9017-4565-b24f-ed9455ef5593 None None x \n",
"14 99048106-f032-45a2-92c6-5a076f899a8a None None x \n",
"\n",
" commission tax message frozen direction total_frozen \n",
"0 5.0000 0.00 None 0 1 0 \n",
"1 5.9750 0.00 None 0 1 0 \n",
"2 5.0000 0.00 None 0 1 0 \n",
"3 6.0175 24.07 None 0 -1 0 \n",
"4 5.0000 19.50 None 0 -1 0 \n",
"5 6.2325 0.00 None 0 1 0 \n",
"6 5.0000 0.00 None 0 1 0 \n",
"7 12.5250 50.10 None 0 -1 0 \n",
"8 7.2450 28.98 None 0 -1 0 \n",
"9 12.5000 50.00 None 0 -1 0 \n",
"10 5.0000 0.00 None 0 1 0 \n",
"11 6.3325 0.00 None 0 1 0 \n",
"12 5.0000 0.00 None 0 1 0 \n",
"13 6.2775 0.00 None 0 1 0 \n",
"14 5.0000 0.00 None 0 1 0 \n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"open 2.510000e+01\n",
"high 2.554000e+01\n",
"low 2.501000e+01\n",
"close 2.530000e+01\n",
"volume 2.406940e+05\n",
"amount 6.069947e+08\n",
"Name: (2019-01-11 00:00:00, 000002), dtype: float64\n",
"---------------under is 当前全市场的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-11 000001 10.11 10.22 10.05 10.2 696364.0 708001792.0\n",
" 000002 25.10 25.54 25.01 25.3 240694.0 606994688.0\n",
"---------------under is 当前品种的market_data --------------\n",
" open high low close volume amount\n",
"2019-01-02 000002 23.83 24.09 23.67 23.90 247010.0 5.893846e+08\n",
"2019-01-03 000002 23.79 24.50 23.71 24.07 222353.0 5.363333e+08\n",
"2019-01-04 000002 23.91 25.00 23.85 24.93 377727.0 9.270117e+08\n",
"2019-01-07 000002 25.29 25.53 24.99 25.05 427154.0 1.077909e+09\n",
"2019-01-08 000002 25.05 25.20 24.63 25.00 214382.0 5.336044e+08\n",
"2019-01-09 000002 25.40 25.88 25.11 25.33 340140.0 8.670814e+08\n",
"2019-01-10 000002 25.22 25.56 25.03 25.11 224649.0 5.689526e+08\n",
"2019-01-11 000002 25.10 25.54 25.01 25.30 240694.0 6.069947e+08\n",
"000002\n",
"---------------under is 账户情况和持仓情况 -------------------\n",
"{'code': '000002', 'instrument_id': '000002', 'user_id': 'x', 'portfolio_cookie': 'default', 'username': 'quantaxis', 'position_id': '5aa694d0-3861-43a8-9efc-84f380138bea', 'account_cookie': 'x', 'frozen': {}, 'name': None, 'spms_id': None, 'oms_id': None, 'market_type': 'stock_cn', 'exchange_id': None, 'moneypreset': 100000, 'moneypresetLeft': 100000, 'lastupdatetime': '', 'volume_long_today': 4000, 'volume_long_his': 0, 'volume_long': 4000, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'margin_long': 99270.0, 'margin_short': 0, 'margin': 99270.0, 'position_price_long': 24.8175, 'position_cost_long': 99270.0, 'position_price_short': 0, 'position_cost_short': 0, 'open_price_long': 24.8175, 'open_cost_long': 99270.0, 'open_price_short': 0, 'open_cost_short': 0, 'trades': [], 'orders': {}, 'last_price': 25.3, 'float_profit_long': 1930.0, 'float_profit_short': 0.0, 'float_profit': 1930.0, 'position_profit_long': 1930.0, 'position_profit_short': 0.0, 'position_profit': 1930.0}\n",
" datetime code price amount cash \\\n",
"0 2019-01-02 00:00:00 000001 9.19 1000 9.908050e+05 \n",
"1 2019-01-02 00:00:00 000002 23.90 1000 9.668990e+05 \n",
"2 2019-01-03 00:00:00 000001 9.28 1000 9.576140e+05 \n",
"3 2019-01-03 00:00:00 000002 24.07 -1000 9.816539e+05 \n",
"4 2019-01-04 00:00:00 000001 9.75 -2000 1.001129e+06 \n",
"5 2019-01-04 00:00:00 000002 24.93 1000 9.761932e+05 \n",
"6 2019-01-07 00:00:00 000001 9.74 1000 9.664482e+05 \n",
"7 2019-01-07 00:00:00 000002 25.05 -2000 1.016486e+06 \n",
"8 2019-01-08 00:00:00 000001 9.66 -3000 1.045429e+06 \n",
"9 2019-01-08 00:00:00 000002 25.00 -2000 1.095367e+06 \n",
"10 2019-01-09 00:00:00 000001 9.94 1000 1.085422e+06 \n",
"11 2019-01-09 00:00:00 000002 25.33 1000 1.060086e+06 \n",
"12 2019-01-10 00:00:00 000001 10.10 1000 1.049981e+06 \n",
"13 2019-01-10 00:00:00 000002 25.11 1000 1.024864e+06 \n",
"14 2019-01-11 00:00:00 000001 10.20 1000 1.014659e+06 \n",
"15 2019-01-11 00:00:00 000002 25.30 -4000 1.115733e+06 \n",
"\n",
" order_id realorder_id trade_id account_cookie \\\n",
"0 e23f9e01-e8d2-4a05-93ef-9163ce7a83ee None None x \n",
"1 1f430faa-86d1-440b-abf7-a7feddc17954 None None x \n",
"2 0230d608-91cc-422e-8deb-218f4faef3d7 None None x \n",
"3 427f1eed-b3bd-4078-94e3-156bf3ae21a6 None None x \n",
"4 48fd88b8-e3c0-4df5-94ef-62b936345bd9 None None x \n",
"5 d9aff179-9bc3-4268-b2d5-37eee8de309f None None x \n",
"6 41f23955-b920-4f04-bcb7-ca1cd960aa45 None None x \n",
"7 cb2fdd74-7326-41d9-812f-9d88da447741 None None x \n",
"8 8ef82ee7-87b8-4f7d-8a01-374f52b60cbb None None x \n",
"9 1f63fa52-f56b-4814-8eb3-5e4de849f3cb None None x \n",
"10 13e77d45-9e2c-4ef3-89f5-7fa63cc3b808 None None x \n",
"11 7e714c35-83a4-4cb4-8ab5-d4fb2b31ccb7 None None x \n",
"12 380f932e-7871-4c72-94d3-5077861c9f53 None None x \n",
"13 3966e418-9017-4565-b24f-ed9455ef5593 None None x \n",
"14 99048106-f032-45a2-92c6-5a076f899a8a None None x \n",
"15 3529f52a-3c09-46fc-944d-b3c619af7cd7 None None x \n",
"\n",
" commission tax message frozen direction total_frozen \n",
"0 5.0000 0.00 None 0 1 0 \n",
"1 5.9750 0.00 None 0 1 0 \n",
"2 5.0000 0.00 Non
gitextract_l2j75egg/ ├── .github/ │ └── workflows/ │ └── pythonpackage.yml ├── .gitignore ├── LICENSE ├── QAStrategy/ │ ├── __init__.py │ ├── qactabase.py │ ├── qahedgebase.py │ ├── qastockbase.py │ ├── qastrategybase.py │ ├── strategywithreal.py │ └── util.py ├── README.md ├── doc/ │ ├── Account.md │ ├── MarketData.md │ ├── Order.md │ ├── Position.md │ └── QAStrategyCTA.md ├── example/ │ ├── CCI_EXample.py │ ├── DoubleMA_Example.py │ ├── MACD_Example.py │ ├── Stock_Example.py │ ├── realtime_hedge.py │ └── realtime_hedge_tick.py ├── jupytertest/ │ ├── debug_for_sendorder.ipynb │ └── test_stock.ipynb └── setup.py
SYMBOL INDEX (143 symbols across 12 files)
FILE: QAStrategy/qactabase.py
class QAStrategyCTABase (line 27) | class QAStrategyCTABase():
method __init__ (line 28) | def __init__(self, code='rb2005', frequence='1min', strategy_id='QA_ST...
method bar_id (line 104) | def bar_id(self):
method BarsSinceEntryLong (line 109) | def BarsSinceEntryLong(self):
method BarsSinceEntryShort (line 113) | def BarsSinceEntryShort(self):
method EntryPriceLong (line 118) | def EntryPriceLong(self):
method EntryPriceShort (line 122) | def EntryPriceShort(self):
method on_sync (line 127) | def on_sync(self):
method _debug_sim (line 132) | def _debug_sim(self):
method debug_sim (line 179) | def debug_sim(self):
method run_sim (line 183) | def run_sim(self):
method run_backtest (line 188) | def run_backtest(self):
method user_init (line 205) | def user_init(self):
method debug (line 211) | def debug(self):
method x1 (line 227) | def x1(self, item):
method debug_t0 (line 240) | def debug_t0(self):
method debug_currenttick (line 271) | def debug_currenttick(self, freq):
method debug_histick (line 300) | def debug_histick(self, freq):
method subscribe_data (line 329) | def subscribe_data(self, code, frequence, data_host, data_port, data_u...
method subscribe_multi (line 358) | def subscribe_multi(self, codelist, frequence, data_host, data_port, d...
method old_data (line 384) | def old_data(self):
method update (line 387) | def update(self):
method market_datetime (line 395) | def market_datetime(self):
method market_data (line 404) | def market_data(self):
method force_close (line 411) | def force_close(self):
method upcoming_data (line 420) | def upcoming_data(self, new_bar):
method ind2str (line 457) | def ind2str(self, ind, ind_type):
method second_callback (line 461) | def second_callback(self, a, b, c, body):
method tick_callback (line 534) | def tick_callback(self, a, b, c, body):
method get_code_marketdata (line 541) | def get_code_marketdata(self, code):
method get_current_marketdata (line 544) | def get_current_marketdata(self):
method callback (line 547) | def callback(self, a, b, c, body):
method control_status (line 586) | def control_status(self, res):
method add_subscriber (line 589) | def add_subscriber(self, qaproid):
method subscriber_list (line 598) | def subscriber_list(self):
method load_strategy (line 607) | def load_strategy(self):
method on_dailyopen (line 610) | def on_dailyopen(self):
method on_dailyclose (line 613) | def on_dailyclose(self):
method on_bar (line 616) | def on_bar(self, bar):
method on_tick (line 619) | def on_tick(self, tick):
method _on_1min_bar (line 622) | def _on_1min_bar(self):
method on_deal (line 631) | def on_deal(self, order):
method on_1min_bar (line 639) | def on_1min_bar(self):
method on_5min_bar (line 642) | def on_5min_bar(self):
method on_15min_bar (line 645) | def on_15min_bar(self):
method on_30min_bar (line 648) | def on_30min_bar(self):
method order_handler (line 651) | def order_handler(self):
method daily_func (line 654) | def daily_func(self):
method risk_check (line 657) | def risk_check(self):
method plot (line 660) | def plot(self, name, data, format):
method get_code (line 673) | def get_code(self):
method check_order (line 679) | def check_order(self, direction, offset, code=None):
method on_ordererror (line 698) | def on_ordererror(self, direction, offset, price, volume):
method receive_simpledeal (line 701) | def receive_simpledeal(self,
method send_order (line 712) | def send_order(self, direction='BUY', offset='OPEN', price=3925, volu...
method update_account (line 787) | def update_account(self):
method get_exchange (line 808) | def get_exchange(self, code):
method get_positions (line 811) | def get_positions(self, code):
method get_cash (line 818) | def get_cash(self):
method run (line 825) | def run(self):
FILE: QAStrategy/qastockbase.py
class QAStrategyStockBase (line 28) | class QAStrategyStockBase(QAStrategyCTABase):
method __init__ (line 30) | def __init__(self, code=['000001'], frequence='1min', strategy_id='QA_...
method subscribe_data (line 44) | def subscribe_data(self, code, frequence, data_host, data_port, data_u...
method upcoming_data (line 59) | def upcoming_data(self, new_bar):
method ind2str (line 76) | def ind2str(self, ind, ind_type):
method callback (line 80) | def callback(self, a, b, c, body):
method _debug_sim (line 112) | def _debug_sim(self):
method run (line 144) | def run(self):
method debug (line 149) | def debug(self):
method update_account (line 166) | def update_account(self):
method send_order (line 181) | def send_order(self, direction='BUY', offset='OPEN', code=None, price...
FILE: QAStrategy/qastrategybase.py
class QAStrategyCTABase (line 27) | class QAStrategyCTABase():
method __init__ (line 28) | def __init__(self, code='rb1905', frequence='1min', strategy_id='QA_ST...
method bar_id (line 80) | def bar_id(self):
method _debug_sim (line 83) | def _debug_sim(self):
method debug_sim (line 117) | def debug_sim(self):
method run_sim (line 121) | def run_sim(self):
method run_backtest (line 126) | def run_backtest(self):
method on_sync (line 143) | def on_sync(self):
method debug (line 148) | def debug(self):
method subscribe_data (line 179) | def subscribe_data(self, code, frequence, data_host, data_port, data_u...
method subscribe_multi (line 191) | def subscribe_multi(self, codelist, frequence, data_host, data_port, d...
method old_data (line 201) | def old_data(self):
method update (line 204) | def update(self):
method market_datetime (line 212) | def market_datetime(self):
method market_data (line 216) | def market_data(self):
method force_close (line 223) | def force_close(self):
method upcoming_data (line 232) | def upcoming_data(self, new_bar):
method ind2str (line 249) | def ind2str(self, ind, ind_type):
method callback (line 253) | def callback(self, a, b, c, body):
method control_status (line 289) | def control_status(self, res):
method add_subscriber (line 292) | def add_subscriber(self, qaproid):
method subscriber_list (line 301) | def subscriber_list(self):
method load_strategy (line 310) | def load_strategy(self):
method on_dailyopen (line 313) | def on_dailyopen(self):
method on_dailyclose (line 316) | def on_dailyclose(self):
method on_bar (line 319) | def on_bar(self, bar):
method _on_1min_bar (line 322) | def _on_1min_bar(self):
method on_1min_bar (line 327) | def on_1min_bar(self):
method on_5min_bar (line 330) | def on_5min_bar(self):
method on_15min_bar (line 333) | def on_15min_bar(self):
method on_30min_bar (line 336) | def on_30min_bar(self):
method order_handler (line 339) | def order_handler(self):
method daily_func (line 342) | def daily_func(self):
method risk_check (line 345) | def risk_check(self):
method plot (line 348) | def plot(self, name, data, format):
method check_order (line 361) | def check_order(self, direction, offset):
method receive_simpledeal (line 376) | def receive_simpledeal(self,
method send_order (line 387) | def send_order(self, direction='BUY', offset='OPEN', price=3925, volu...
method update_account (line 443) | def update_account(self):
method get_exchange (line 456) | def get_exchange(self, code):
method get_positions (line 459) | def get_positions(self, code):
method get_cash (line 466) | def get_cash(self):
method run (line 473) | def run(self):
FILE: QAStrategy/strategywithreal.py
class QAStrategySyncOrders (line 7) | class QAStrategySyncOrders():
method __init__ (line 23) | def __init__(self, simid, realid, realamount=1):
method add_subscriber (line 32) | def add_subscriber(self, simid):
method callback (line 35) | def callback(self, a, b, c, data):
method on_order (line 43) | def on_order(self, order):
method send_order (line 54) | def send_order(self, order):
method start (line 67) | def start(self):
FILE: QAStrategy/util.py
function QA_data_futuremin_resample (line 3) | def QA_data_futuremin_resample(min_data, type_='5min'):
FILE: example/CCI_EXample.py
class CCI (line 5) | class CCI(QAStrategyCTABase):
method on_bar (line 9) | def on_bar(self, bar):
method cci (line 32) | def cci(self,):
method risk_check (line 35) | def risk_check(self):
FILE: example/DoubleMA_Example.py
class DMA (line 6) | class DMA(QAStrategyCTABase):
method on_bar (line 8) | def on_bar(self, bar):
method ma (line 31) | def ma(self,):
method risk_check (line 34) | def risk_check(self):
FILE: example/MACD_Example.py
class MACD (line 7) | class MACD(QAStrategyCTABase):
method on_bar (line 9) | def on_bar(self, bar):
method macd (line 31) | def macd(self,):
method risk_check (line 34) | def risk_check(self):
FILE: example/Stock_Example.py
class strategy (line 6) | class strategy(QAStrategyStockBase):
method on_bar (line 7) | def on_bar(self, data):
FILE: example/realtime_hedge.py
class CCI (line 4) | class CCI(QAStrategyCTABase):
method on_bar (line 8) | def on_bar(self, bar):
method cci (line 27) | def cci(self, code):
FILE: example/realtime_hedge_tick.py
class CCI (line 4) | class CCI(QAStrategyCTABase):
method on_tick (line 8) | def on_tick(self, tick):
method cci (line 11) | def cci(self, code):
FILE: setup.py
function read (line 51) | def read(fname):
Condensed preview — 25 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (626K chars).
[
{
"path": ".github/workflows/pythonpackage.yml",
"chars": 973,
"preview": "name: Python package\n\non: [push]\n\njobs:\n build:\n\n runs-on: ubuntu-latest\n strategy:\n max-parallel: 4\n m"
},
{
"path": ".gitignore",
"chars": 1239,
"preview": "# Byte-compiled / optimized / DLL files\n__pycache__/\n*.py[cod]\n*$py.class\n\n# C extensions\n*.so\n.vscode/settings.json\n\n# "
},
{
"path": "LICENSE",
"chars": 1067,
"preview": "MIT License\n\nCopyright (c) 2019 Vincent yu\n\nPermission is hereby granted, free of charge, to any person obtaining a copy"
},
{
"path": "QAStrategy/__init__.py",
"chars": 156,
"preview": "__version__ = '0.0.25'\n__author__ = 'yutiansut'\n\n\nfrom QAStrategy.util import QA_data_futuremin_resample\nfrom QAStrategy"
},
{
"path": "QAStrategy/qactabase.py",
"chars": 31325,
"preview": "import copy\nimport datetime\nimport json\nimport os\nimport re\nimport sys\nimport threading\nimport time\nimport uuid\n\nimport "
},
{
"path": "QAStrategy/qahedgebase.py",
"chars": 1,
"preview": "\n"
},
{
"path": "QAStrategy/qastockbase.py",
"chars": 9159,
"preview": "#\n\n\n\"\"\"\nstock_base\n\"\"\"\nimport uuid\nimport datetime\nimport json\nimport os\nimport threading\nimport requests\nimport pandas "
},
{
"path": "QAStrategy/qastrategybase.py",
"chars": 16904,
"preview": "import datetime\nimport json\nimport os\nimport re\nimport sys\nimport threading\nimport time\nimport copy\nimport uuid\n\nimport "
},
{
"path": "QAStrategy/strategywithreal.py",
"chars": 1720,
"preview": "from QAPUBSUB.consumer import subscriber_routing\nfrom QAPUBSUB.producer import publisher_routing\nfrom qaenv import event"
},
{
"path": "QAStrategy/util.py",
"chars": 587,
"preview": "import pandas as pd\n\ndef QA_data_futuremin_resample(min_data, type_='5min'):\n \"\"\"期货分钟线采样成大周期\n\n\n 分钟线采样成子级别的分钟线\n\n "
},
{
"path": "README.md",
"chars": 4638,
"preview": "# QAStrategy\n策略基类/ 基于QAAccount/QACEPEnging/QASPMS/QAREALTIMECollector/QATRADER\n\n_QAStrategy支持[```QIFI```](http://github."
},
{
"path": "doc/Account.md",
"chars": 180,
"preview": "你需要注意的是, self.acc 在不同的模式下是不一样的\n\n在回测模式: self.acc是一个实例化的 QUANTAXIS.QAAccountPro 类\n\n在模拟模式: self.acc是一个实例化的 qifiaccount 账户\n\n"
},
{
"path": "doc/MarketData.md",
"chars": 0,
"preview": ""
},
{
"path": "doc/Order.md",
"chars": 0,
"preview": ""
},
{
"path": "doc/Position.md",
"chars": 1472,
"preview": "# Postions 关于你的持仓的一切\n\n当我们开始写策略的时候, 必不可少的, 我们会跟持仓打交道, \n\n- 当行情变化的时候, 持仓的盈亏的计算(成本的统计视角)\n- 当我们要平仓的时候, 持仓(今仓/昨仓)的判断\n- 我们预估浮盈"
},
{
"path": "doc/QAStrategyCTA.md",
"chars": 3754,
"preview": "## 1. QAStrategyCTABase\n\nQAStrategy是被设计成(起码我是这么想的)成 \"\"\"支持股票期货/ 支持一个函数切换回测/模拟/SIM/实盘\"\"\"的基类\n\nQAStrategyCTABase 是面向常见cta场景\n"
},
{
"path": "example/CCI_EXample.py",
"chars": 1737,
"preview": "from QAStrategy import QAStrategyCTABase\nimport QUANTAXIS as QA\nimport pprint\n\nclass CCI(QAStrategyCTABase):\n\n\n\n def "
},
{
"path": "example/DoubleMA_Example.py",
"chars": 1169,
"preview": "from QAStrategy import QAStrategyCTABase\nimport QUANTAXIS as QA\nimport pprint\n\n\nclass DMA(QAStrategyCTABase):\n\n def o"
},
{
"path": "example/MACD_Example.py",
"chars": 1284,
"preview": "import pprint\n\nimport QUANTAXIS as QA\nfrom QAStrategy import QAStrategyCTABase\n\n\nclass MACD(QAStrategyCTABase):\n\n def"
},
{
"path": "example/Stock_Example.py",
"chars": 25260,
"preview": "import QUANTAXIS as QA\nfrom QAStrategy.qastockbase import QAStrategyStockBase\n\n\n\nclass strategy(QAStrategyStockBase):\n "
},
{
"path": "example/realtime_hedge.py",
"chars": 1321,
"preview": "from QAStrategy import QAStrategyCTABase\nimport QUANTAXIS as QA\n\nclass CCI(QAStrategyCTABase):\n\n\n\n def on_bar(self, b"
},
{
"path": "example/realtime_hedge_tick.py",
"chars": 521,
"preview": "from QAStrategy import QAStrategyCTABase\nimport QUANTAXIS as QA\n\nclass CCI(QAStrategyCTABase):\n\n\n\n def on_tick(self, "
},
{
"path": "jupytertest/debug_for_sendorder.ipynb",
"chars": 13203,
"preview": "{\"cells\":[{\"cell_type\":\"code\",\"execution_count\":1,\"metadata\":{},\"outputs\":[],\"source\":\"import QAStrategy\"},{\"cell_type\":"
},
{
"path": "jupytertest/test_stock.ipynb",
"chars": 465221,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"metadata\": {},\n \"outputs\": [\n {\n \"name\":"
},
{
"path": "setup.py",
"chars": 2805,
"preview": "\n# coding=utf-8\n#\n# The MIT License (MIT)\n#\n# Copyright (c) 2016-2017 yutiansut/QUANTAXIS\n#\n# Permission is hereby grant"
}
]
About this extraction
This page contains the full source code of the yutiansut/QAStrategy GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 25 files (572.0 KB), approximately 240.0k tokens, and a symbol index with 143 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.