-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
运行源代码中的test.py代码,策略里面的init,handle_bar方法没有调用 #70
Labels
Comments
@yushaorong 在策略文件中是直接定义 你在函数里面定义 |
通过 def test_buy_open():
from rqalpha.api import buy_open, subscribe, get_order, ORDER_STATUS, POSITION_EFFECT, SIDE
def init(context):
print("test_buy_open ladkfaldsfkjdsalfjldsajf1111111111111111")
context.f1 = 'P88'
context.amount = 1
# context.marin_rate = 10
subscribe(context.f1)
context.order_count = 0
context.order = None
def handle_bar(context, bar_dict):
order_id = buy_open(context.f1, 1)
order = get_order(order_id)
assert order.order_book_id == context.f1
assert order.quantity == 1
assert order.status == ORDER_STATUS.ACTIVE
assert order.unfilled_quantity == 1
assert order.unfilled_quantity + order.filled_quantity == order.quantity
assert order.side == SIDE.BUY
assert order.position_effect == POSITION_EFFECT.OPEN 而 RQAlpha 需要的是如下代码: from rqalpha.api import buy_open, subscribe, get_order, ORDER_STATUS, POSITION_EFFECT, SIDE
def init(context):
print("test_buy_open ladkfaldsfkjdsalfjldsajf1111111111111111")
context.f1 = 'P88'
context.amount = 1
# context.marin_rate = 10
subscribe(context.f1)
context.order_count = 0
context.order = None
def handle_bar(context, bar_dict):
order_id = buy_open(context.f1, 1)
order = get_order(order_id)
assert order.order_book_id == context.f1
assert order.quantity == 1
assert order.status == ORDER_STATUS.ACTIVE
assert order.unfilled_quantity == 1
assert order.unfilled_quantity + order.filled_quantity == order.quantity
assert order.side == SIDE.BUY
assert order.position_effect == POSITION_EFFECT.OPEN |
Open
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
在test_api()方法里单独调用一行代码
运行到main.py文件中
run()
方法里面这条语句运行完成后,策略代码没有加载到scope里面,导致
user_strategy = Strategy(env.event_bus, scope, ucontext)
初始化的时候找不到init
,handle_bar
方法。具体策略:补充:感觉是strategy_loader_help.py中
.
.
.
exec_(code, scope)这个执行的时候没有加载成功。
补充说明:
在这里面加上"strategy_file": 'rqalpha/examples/buy_and_hold.py'这种形式,不传代码块是可以运行init,handle_bar方法的
The text was updated successfully, but these errors were encountered: