Skip to content
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

Order Failed,Code: 400, Msg:{"code":-4014,"msg":"Price not increased … #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion gridtrader/trader/strategies/future_grid_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from gridtrader.trader.object import OrderData, TickData, TradeData, ContractData
from .template import CtaTemplate
from gridtrader.trader.utility import GridPositionCalculator

from utils.contract_handler import ContractHandler

class FutureGridStrategy(CtaTemplate):
"""
Expand Down Expand Up @@ -148,6 +148,8 @@ def on_tick(self, tick: TickData):

for i in range(self.max_open_orders):
price = self.bottom_price + (mid_count - i - 1) * self.step_price
_ContractHandler = ContractHandler(self.contract_data.price_tick)
price = _ContractHandler.process_price(price)
if price < self.bottom_price:
return

Expand All @@ -158,6 +160,8 @@ def on_tick(self, tick: TickData):
if len(self.short_orders_dict.keys()) == 0:
for i in range(self.max_open_orders):
price = self.bottom_price + (mid_count + i + 1) * self.step_price
_ContractHandler = ContractHandler(self.contract_data.price_tick)
price = _ContractHandler.process_price(price)
if price > self.upper_price:
return

Expand Down
20 changes: 20 additions & 0 deletions utils/contract_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from decimal import Decimal, ROUND_DOWN


class ContractHandler:
def __init__(self, price_tick_str:str=None,price_tick:Decimal=None):
# 假设 price_tick 是 Decimal 类型
if price_tick_str is not None:
self.price_tick = Decimal(price_tick_str)
elif price_tick is not None:
self.price_tick = price_tick

def process_price(self, price):
# 确保 price 也转换为 Decimal 类型
price = Decimal(price)

# 将 price 按照 price_tick 进行舍入
processed_price = (price // self.price_tick) * self.price_tick

# 返回处理后的价格(保留原始精度)
return processed_price