WISEPLAT / backtrader_binance

Binance API integration with Backtrader. Run strategies for Backtest and Live Trading. Get historical price data for Bitcoin, Ethereum and all coins from Binance. EASY create your strategies.
MIT License
150 stars 53 forks source link

binance.exceptions.BinanceAPIException: APIError(code=-1106): Parameter 'price' sent when not required. #11

Closed superdevel7 closed 1 month ago

superdevel7 commented 2 months ago

When I create the following order in my backtrader strategy, I got 1106 error. self.broker.buy(data=data, exectype=bt.Order.Stop, price=price, size=0.01, valid=expiration_time) I think it is because of using the parameter price rather than stopPrice for the ordery type STOP_LOSS.

WISEPLAT commented 2 months ago

Hi! Thanks for mention this. Your suggestions? Did you solve this?

superdevel7 commented 2 months ago

In backtrader_binance/binance_store.py I changed the create_order function.

@retry
def create_order(self, symbol, side, type, size, price):
    params = dict()
    if type in [ORDER_TYPE_LIMIT, ORDER_TYPE_STOP_LOSS_LIMIT]:
        params.update({
            'timeInForce': TIME_IN_FORCE_GTC
        })
    if type == ORDER_TYPE_STOP_LOSS:
        params.update({
            'stopPrice': self.format_price(symbol, price)
        })
    elif type != ORDER_TYPE_MARKET:
        params.update({
            'price': self.format_price(symbol, price)
        })
    return self.binance.create_order(
        symbol=symbol,
        side=side,
        type=type,
        quantity=self.format_quantity(symbol, size),
        newOrderRespType='RESULT',
        **params)

And it worked. You can review this.

WISEPLAT commented 2 months ago

cool, please create Pull Request for this, I will approve this change

WISEPLAT commented 1 month ago

Thanks for PR)