QA_Account() 是quantaxis的核心类, 其作用是一个可以使用规则兼容各种市场的账户类
1.3.0以后, QA_Account需要由组合来进行创建(推荐)
user = QA.QA_user(username ='quantaxis', password = 'quantaxis')
portfotlio=user.new_portfolio('x1')
account = portfolio.new_account(args)
In [1]:
import QUANTAXIS as QA
import uuid
user = QA.QA_User(username ='quantaxis', password = 'quantaxis')
portfolio=user.new_portfolio('x1')
account = portfolio.new_account(account_cookie='test')
In [2]:
# strategy_name=None,
# user_cookie=None,
# portfolio_cookie=None,
# account_cookie=None,
# market_type=MARKET_TYPE.STOCK_CN,
# frequence=FREQUENCE.DAY,
# broker=BROKER_TYPE.BACKETEST,
# init_hold={},
# init_cash=1000000,
# commission_coeff=0.00025,
# tax_coeff=0.001,
# margin_level={},
# allow_t0=False,
# allow_sellopen=False,
# allow_margin=False,
# running_environment=RUNNING_ENVIRONMENT.BACKETEST
In [3]:
stock_account= portfolio.new_account(account_cookie =str(uuid.uuid4()),allow_t0=False,allow_margin=False,allow_sellopen=False,market_type=QA.MARKET_TYPE.STOCK_CN)
In [4]:
stockt0_account =portfolio.new_account(account_cookie =str(uuid.uuid4()),allow_t0=False,allow_margin=False,allow_sellopen=False,market_type=QA.MARKET_TYPE.STOCK_CN,init_hold={'000002':500}, running_environment=QA.RUNNING_ENVIRONMENT.TZERO)
In [5]:
rzrq_account = portfolio.new_account(account_cookie =str(uuid.uuid4()),allow_t0=False,allow_margin=True,allow_sellopen=True,market_type=QA.MARKET_TYPE.STOCK_CN)
In [6]:
future_account = portfolio.new_account(account_cookie =str(uuid.uuid4()),allow_t0=True,allow_margin=True,allow_sellopen=True, market_type=QA.MARKET_TYPE.FUTURE_CN)
In [7]:
option_account = portfolio.new_account(account_cookie =str(uuid.uuid4()),allow_t0=True,allow_margin=True,allow_sellopen=True, market_type=QA.MARKET_TYPE.OPTION_CN)
In [8]:
xxx = portfolio.new_account(account_cookie =str(uuid.uuid4()),allow_t0=True,allow_margin=True,allow_sellopen=True, market_type=QA.MARKET_TYPE.CRYPTOCURRENCY)
In [9]:
stock_account.init_assets
Out[9]:
In [10]:
stock_account.init_cash
Out[10]:
In [11]:
stock_account.init_hold
Out[11]:
In [12]:
stock_account= portfolio.new_account(account_cookie =str(uuid.uuid4()),init_hold={'000001':500}, allow_t0=False,allow_margin=False,allow_sellopen=False,running_environment=QA.MARKET_TYPE.STOCK_CN)
In [13]:
stock_account.init_assets
Out[13]:
In [14]:
stock_account.hold
Out[14]:
In [15]:
stock_account.sell_available
Out[15]:
In [16]:
stock_account= portfolio.new_account(account_cookie =str(uuid.uuid4()),init_cash= 200000,init_hold={'000002':500}, allow_t0=False,allow_margin=False,allow_sellopen=False,running_environment=QA.MARKET_TYPE.STOCK_CN)
In [17]:
stock_account.init_assets
Out[17]:
In [18]:
stock_account.init_cash
Out[18]:
In [19]:
stock_account.cash
Out[19]:
In [20]:
stock_account.cash_available
Out[20]:
In [ ]:
In [21]:
stock_account.reset_assets(init_cash=50000)
In [22]:
stock_account.init_assets
Out[22]:
In [23]:
stock_account.cash
Out[23]:
In [24]:
stock_account.cash_available
Out[24]:
In [25]:
order=stock_account.send_order(code='000001',amount=100,time='2019-01-19',
amount_model=QA.AMOUNT_MODEL.BY_AMOUNT,order_model=QA.ORDER_MODEL.CLOSE,
price=10,towards=QA.ORDER_DIRECTION.BUY)
In [26]:
future_order=future_account.send_order(code='RB1905',amount=100,time='2019-01-19',
amount_model=QA.AMOUNT_MODEL.BY_AMOUNT,order_model=QA.ORDER_MODEL.CLOSE,
price=3500,towards=QA.ORDER_DIRECTION.BUY_OPEN)
In [27]:
future_account
Out[27]:
In [28]:
order
Out[28]:
In [29]:
future_order
Out[29]:
In [30]:
order.trade(trade_price=10.1,trade_amount=100,trade_id='example_trade1',trade_time='2019-01-19 15:00:00')
In [31]:
future_order.trade(trade_price=3600,trade_amount=100,trade_id='example_trade2',trade_time='2019-01-19 21:00:00')
In [32]:
stock_account.history_table
Out[32]:
In [33]:
future_account.history_table
Out[33]:
In [34]:
stock_account.cash
Out[34]:
In [35]:
future_account.cash
Out[35]:
In [36]:
future_account.frozen
Out[36]:
In [37]:
stock_account.cash_available
Out[37]:
In [38]:
future_account.cash_available
Out[38]:
In [39]:
stock_account.hold
Out[39]:
In [40]:
future_account.hold
Out[40]:
In [41]:
stock_account.sell_available
Out[41]:
In [42]:
future_account.sell_available
Out[42]:
In [43]:
stock_account.receive_simpledeal(code='000004',order_id='model2',realorder_id='model2_real',trade_id='trade2',trade_amount=1000,trade_price=16,trade_time='2019-01-21',trade_towards=QA.ORDER_DIRECTION.BUY,message='model2')
In [44]:
stock_account.history_table
Out[44]:
In [45]:
stock_account.cash
Out[45]:
In [46]:
stock_account.cash_available
Out[46]:
In [47]:
stock_account.hold
Out[47]:
In [48]:
stock_account.sell_available
Out[48]:
In [49]:
stock_account.settle()
In [50]:
stock_account.sell_available
Out[50]:
In [51]:
future_account.settle()
In [52]:
## 关于账户存储和恢复
In [ ]:
In [ ]:
In [53]:
future_account
Out[53]:
In [54]:
future_account.history_table
Out[54]:
In [55]:
future_account.frozen
Out[55]:
In [56]:
future_account.cash_available
Out[56]:
In [57]:
future_account.sell_available
Out[57]:
In [58]:
future_account.hold_available
Out[58]:
In [59]:
stock_account
Out[59]:
In [60]:
stockt0_account.hold_available
Out[60]:
In [61]:
stockt0_account.sell_available
Out[61]:
In [62]:
stockt0_account.buy_available
Out[62]:
In [63]:
ordert0=stockt0_account.send_order(code='000002',amount=100,time='2019-01-19',
amount_model=QA.AMOUNT_MODEL.BY_AMOUNT,order_model=QA.ORDER_MODEL.CLOSE,
price=10,towards=QA.ORDER_DIRECTION.BUY)
In [64]:
stockt0_account.sell_available
Out[64]:
In [65]:
stockt0_account.buy_available
Out[65]:
In [66]:
stockt0_account.hold_available
Out[66]:
In [67]:
ordert0.trade(trade_price=10.1,trade_amount=100,trade_id='example_trade1',trade_time='2019-01-19 15:00:00')
In [68]:
stockt0_account.hold_available
Out[68]:
In [69]:
stockt0_account.sell_available
Out[69]:
In [70]:
stockt0_account.buy_available
Out[70]:
In [ ]:
In [ ]: