Closed LawrentChen closed 2 years ago
4.5.1
3.9
MacOS
# !usr/bin/env python3 # -*- coding: utf-8 -*- from rqalpha.apis import * __config__ = { "base": { "start_date": "2021-01-04", "end_date": "2021-01-04", "frequency": "1d", "accounts": { "stock": 10000000 }, } } def init(context): """ 策略初始化 """ pass def handle_bar(context, bar_dict): """ K线数据更新 """ order_target_percent('000001.XSHE', 0.5) logger.info('---long_positions---') logger.info(get_position('000001.XSHE', 'long_positions')) logger.info('---POSITION_DIRECTION.LONG---') logger.info(get_position('000001.XSHE', POSITION_DIRECTION.LONG))
# output [2021-01-04 15:00:00.000000] INFO: user_log: ---long_positions--- [2021-01-04 15:00:00.000000] INFO: user_log: StockPosition(order_book_id=000001.XSHE, direction=long_positions, quantity=0, market_value=0, trading_pnl=0, position_pnl=0) [2021-01-04 15:00:00.000000] INFO: user_log: ---POSITION_DIRECTION.LONG--- [2021-01-04 15:00:00.000000] INFO: user_log: StockPosition(order_book_id=000001.XSHE, direction=LONG, quantity=268600, market_value=4995960.0, trading_pnl=0.0, position_pnl=0)
https://rqalpha.readthedocs.io/zh_CN/latest/api/base_api.html#get-position 这里的一个文档小 bug,get_position 方法里对于 direction 的参数类型写的是对的 (Optional[POSITION_DIRECTION]) ,但紧接着下面的 example 错了。
[In] get_position('000014.XSHE','long_positions") [Out] [BookingPosition({'order_book_id': '000014.XSHE', 'quantity': 100, 'direction': POSITION_DIRECTION.LONG, 'old_quantity': 0, 'trading_pnl': 1.0, 'avg_price': 9.56, 'last_price': 0, 'position_pnl': 0.0})]
如果传入 str 类型的话不会抛出异常,而是会像上面我的结果那样返回全 0 的Position
develop 分支已修复:https://rqalpha.readthedocs.io/zh_CN/develop/api/base_api.html#get-position
thx! close 掉吧
1. RQAlpha的版本
4.5.1
2. Python的版本
3.9
3. 是Windows/Linux/MacOS or others?
MacOS
4. 您出现问题对应的源码/或者能复现问题的简易代码 以及对应的配置
5. 您出现的错误堆栈日志信息
https://rqalpha.readthedocs.io/zh_CN/latest/api/base_api.html#get-position 这里的一个文档小 bug,get_position 方法里对于 direction 的参数类型写的是对的 (Optional[POSITION_DIRECTION]) ,但紧接着下面的 example 错了。
如果传入 str 类型的话不会抛出异常,而是会像上面我的结果那样返回全 0 的Position