Comments (1)
def QA_backtest_send_order(self, __code: str, __amount: int, __towards: int, __order: dict):
"""
2017/8/4
委托函数
在外部封装的一个报价接口,尽量满足和实盘一样的模式
输入
=============
买入/卖出
股票代码
买入/卖出数量
委托模式*
0 限价委托 LIMIT ORDER
1 市价委托 MARKET ORDER
2 严格模式(买入按最高价 卖出按最低价) STRICT ORDER
输出
=============
返回:
委托状态/委托id
成交状态/成交id/成交量/成交价
错误/错误id/
return bid_status,trade_status,error
"""
# 必须是100股的倍数
__amount = int(__amount / 100) * 100
# self.__QA_backtest_set_bid_model()
if __order['bid_model'] in ['limit', 'Limit', 'Limited', 'limited', 'l', 'L', 0, '0']:
# 限价委托模式
__bid_price = __order['price']
elif __order['bid_model'] in ['Market', 'market', 'MARKET', 'm', 'M', 1, '1']:
__bid_price = 'market_price'
elif __order['bid_model'] in ['strict', 'Strict', 's', 'S', '2', 2]:
__bid_price = 'strict'
__bid = self.bid.bid
__bid['order_id'] = str(random.random())
__bid['user'] = self.setting.QA_setting_user_name
__bid['strategy'] = self.strategy_name
__bid['code'] = __code
__bid['date'] = self.running_date
__bid['price'] = __bid_price
__bid['amount'] = __amount
if __towards == 1:
# 这是买入的情况 买入的时候主要考虑的是能不能/有没有足够的钱来买入
__bid['towards'] = 1
__message = self.market.receive_bid(
__bid, self.setting.client)
# 先扔进去买入,再通过返回的值来判定是否成功
if float(self.account.message['body']['account']['cash'][-1]) > \
float(__message['body']['bid']['price']) * \
float(__message['body']['bid']['amount']):
# 这里是买入资金充足的情况
# 不去考虑
pass
else:
# 如果买入资金不充足,则按照可用资金去买入
__message['body']['bid']['amount'] = int(float(
self.account.message['body']['account']['cash'][-1]) / float(
float(str(__message['body']['bid']['price'])[0:5]) * 100)) * 100
if __message['body']['bid']['amount'] > 0:
# 这个判断是为了 如果买入资金不充足,所以买入报了一个0量单的情况
#如果买入量>0, 才判断为成功交易
self.account.QA_account_receive_deal(__message)
# 下面是卖出操作,这里在卖出前需要考虑一个是否有仓位的问题:
# 因为在股票中是不允许卖空操作的,所以这里是股票的交易引擎和期货的交易引擎的不同所在
elif __towards == -1:
# 如果是卖出操作 检查是否有持仓
# 股票中不允许有卖空操作
# 检查持仓面板
__amount_hold = self.QA_backtest_hold_amount(self,__code)
if __amount_hold > 0:
__bid['towards'] = -1
if __amount_hold >= __amount:
pass
else:
__bid['amount'] = __amount_hold
__message = self.market.receive_bid(
__bid, self.setting.client)
self.account.QA_account_receive_deal(__message)
else:
err_info = 'Error: Not Enough amount for code %s in hold list' % str(
__code)
QA_util_log_expection(err_info)
return err_info
from quantaxis.
Related Issues (20)
- Rust编译失败处理
- 初始化数据报错 HOT 5
- QA_User和QA_Risk是不是被弃用了,但是在qactabase.py中还有在使用的地方
- Quantaxis 2.0.0.dev33版本的回测样例 HOT 3
- docker环境下的安装失败 HOT 1
- 无法获取通达信板块数据,Error save_tdx.QA_SU_save_stock_block exception HOT 1
- 使用docker pull 时报网络错误 HOT 3
- 回测示例求教:基于RSRS的ETF轮动策略(closed) HOT 1
- 大数据AI推荐
- 安装依赖时,报错metadata-generation-failed
- 有港股的财务数据吗 HOT 1
- 报jqdatasdk not installed HOT 2
- 请问下大盘指数日线图和分时图是如何save 的,存在哪个表里
- 关于自由现金流FINONE(322)和(321)的精确定义?
- Failed to init data in quantaxis cli HOT 2
- qatrader运行异常 HOT 2
- qa沟通渠道问题 HOT 2
- QUANTAXIS 的一般/高级财务方法 报错 KeyError: '581'
- save all: xdxr 不会增量更新。
- QATdx 期货数据 get_history_transaction_data 分时或者分笔数据没有夜盘数据
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quantaxis.