Skip to content

Commit

Permalink
pr update
Browse files Browse the repository at this point in the history
  • Loading branch information
Lin-Dongzhao committed Apr 3, 2024
1 parent 0e58a52 commit d62d74d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion rqalpha/apis/api_base.py
Expand Up @@ -171,7 +171,7 @@ def submit_order(id_or_ins, amount, side, price=None, position_effect=None):
market_price = env.get_last_price(order_book_id)
if not is_valid_price(market_price):
reason = _(u"Order Creation Failed: [{order_book_id}] No market data").format(order_book_id=order_book_id)
env.order_creation_faild(order_book_id, reason)
env.order_creation_failed(order_book_id, reason)
return

amount = int(amount)
Expand Down
8 changes: 4 additions & 4 deletions rqalpha/environment.py
Expand Up @@ -128,19 +128,19 @@ def can_cancel_order(self, order):
try:
reason = v.validate_cancellation(order, account)
if reason:
self.order_cancellation_faild(order_book_id=order.order_book_id, reason=reason)
self.order_cancellation_failed(order_book_id=order.order_book_id, reason=reason)
return False
except NotImplementedError:
# 避免由于某些 mod 版本未更新,Validator method 未修改
if not v.can_cancel_order(order, account):
return False
return True

def order_creation_faild(self, order_book_id, reason):
def order_creation_failed(self, order_book_id, reason):
user_system_log.warn(reason)
self.event_bus.publish_event(Event(EVENT.ORDER_CREATION_REJECT, order_book_id=order_book_id, reason=reason))

def order_cancellation_faild(self, order_book_id, reason):
def order_cancellation_failed(self, order_book_id, reason):
user_system_log.warn(reason)
self.event_bus.publish_event(Event(EVENT.ORDER_CANCELLATION_REJECT, order_book_id=order_book_id, reason=reason))

Expand Down Expand Up @@ -203,7 +203,7 @@ def can_submit_order(self, order: 'Order') -> bool:
try:
reason = v.validate_submission(order, account)
if reason:
self.order_creation_faild(order_book_id=order.order_book_id, reason=reason)
self.order_creation_failed(order_book_id=order.order_book_id, reason=reason)
return False
except NotImplementedError:
# 避免由于某些 mod 版本未更新,Validator method 未修改
Expand Down
8 changes: 4 additions & 4 deletions rqalpha/mod/rqalpha_mod_sys_accounts/api/api_future.py
Expand Up @@ -50,7 +50,7 @@ def _submit_order(id_or_ins, amount, side, position_effect, style):
reason = _(u"Order Creation Failed: 0 order quantity, order_book_id={order_book_id}").format(
order_book_id=order_book_id
)
env.order_creation_faild(order_book_id=order_book_id, reason=reason)
env.order_creation_failed(order_book_id=order_book_id, reason=reason)
return None
if isinstance(style, LimitOrder) and np.isnan(style.get_limit_price()):
raise RQInvalidArgument(_(u"Limit order price should not be nan."))
Expand All @@ -64,7 +64,7 @@ def _submit_order(id_or_ins, amount, side, position_effect, style):
price = env.get_last_price(order_book_id)
if not is_valid_price(price):
reason = _(u"Order Creation Failed: [{order_book_id}] No market data").format(order_book_id=order_book_id)
env.order_creation_faild(order_book_id=order_book_id, reason=reason)
env.order_creation_failed(order_book_id=order_book_id, reason=reason)
return

orders = []
Expand All @@ -77,7 +77,7 @@ def _submit_order(id_or_ins, amount, side, position_effect, style):
"Order Creation Failed: "
"close today amount {amount} is larger than today closable quantity {quantity}").format(
amount=amount, quantity=position.today_closable)
env.order_creation_faild(order_book_id=order_book_id, reason=reason)
env.order_creation_failed(order_book_id=order_book_id, reason=reason)
return []
orders.append(Order.__from_create__(
order_book_id, amount, side, style, POSITION_EFFECT.CLOSE_TODAY
Expand All @@ -87,7 +87,7 @@ def _submit_order(id_or_ins, amount, side, position_effect, style):
if amount > quantity:
reason = _(u"Order Creation Failed: close amount {amount} is larger than position quantity {quantity}").format(
amount=amount, quantity=quantity)
env.order_creation_faild(order_book_id=order_book_id, reason=reason)
env.order_creation_failed(order_book_id=order_book_id, reason=reason)
return []
if amount > old_quantity:
if old_quantity != 0:
Expand Down
12 changes: 6 additions & 6 deletions rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py
Expand Up @@ -101,7 +101,7 @@ def _submit_order(ins, amount, side, position_effect, style, current_quantity, a
price = env.data_proxy.get_last_price(ins.order_book_id)
if not is_valid_price(price):
reason = _(u"Order Creation Failed: [{order_book_id}] No market data").format(order_book_id=ins.order_book_id)
env.order_creation_faild(order_book_id=ins.order_book_id, reason=reason)
env.order_creation_failed(order_book_id=ins.order_book_id, reason=reason)
return

if (side == SIDE.BUY and current_quantity != -amount) or (side == SIDE.SELL and current_quantity != abs(amount)):
Expand All @@ -110,7 +110,7 @@ def _submit_order(ins, amount, side, position_effect, style, current_quantity, a

if amount == 0:
reason = _(u"Order Creation Failed: 0 order quantity, order_book_id={order_book_id}").format(order_book_id=ins.order_book_id)
env.order_creation_faild(order_book_id=ins.order_book_id, reason=reason)
env.order_creation_failed(order_book_id=ins.order_book_id, reason=reason)
return
order = Order.__from_create__(ins.order_book_id, abs(amount), side, style, position_effect)
if side == SIDE.BUY and auto_switch_order_value:
Expand Down Expand Up @@ -138,7 +138,7 @@ def _order_value(account, position, ins, cash_amount, style, zero_amount_as_exce
price = env.data_proxy.get_last_price(ins.order_book_id)
if not is_valid_price(price):
reason = _(u"Order Creation Failed: [{order_book_id}] No market data").format(order_book_id=ins.order_book_id)
env.order_creation_faild(order_book_id=ins.order_book_id, reason=reason)
env.order_creation_failed(order_book_id=ins.order_book_id, reason=reason)
return

amount = int(Decimal(cash_amount) / Decimal(price))
Expand All @@ -155,7 +155,7 @@ def _order_value(account, position, ins, cash_amount, style, zero_amount_as_exce
else:
if zero_amount_as_exception:
reason = _(u"Order Creation Failed: 0 order quantity, order_book_id={order_book_id}").format(order_book_id=ins.order_book_id)
env.order_creation_faild(order_book_id=ins.order_book_id, reason=reason)
env.order_creation_failed(order_book_id=ins.order_book_id, reason=reason)
return

if amount < 0:
Expand Down Expand Up @@ -341,7 +341,7 @@ def order_target_portfolio(
last_price = env.data_proxy.get_last_price(order_book_id)
if not is_valid_price(last_price):
reason = _(u"Order Creation Failed: [{order_book_id}] No market data").format(order_book_id=order_book_id)
env.order_creation_faild(order_book_id=order_book_id, reason=reason)
env.order_creation_failed(order_book_id=order_book_id, reason=reason)
continue

price_or_style = price_or_styles.get(ins.order_book_id)
Expand Down Expand Up @@ -380,7 +380,7 @@ def order_target_portfolio(
reason = _("Adjust position of {id_or_ins} Failed: Invalid close/open price {close_price}/{open_price}").format(
id_or_ins=order_book_id, close_price=close_price, open_price=open_price
)
env.order_creation_faild(order_book_id=order_book_id, reason=reason)
env.order_creation_failed(order_book_id=order_book_id, reason=reason)
continue

delta_quantity = (account_value * target_percent / close_price) - current_quantities.get(order_book_id, 0)
Expand Down

0 comments on commit d62d74d

Please sign in to comment.