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

Binance Futures Do Not Support LIMIT_MAKER #45

Open
4 tasks done
AlexCatarino opened this issue Jan 31, 2025 · 1 comment
Open
4 tasks done

Binance Futures Do Not Support LIMIT_MAKER #45

AlexCatarino opened this issue Jan 31, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@AlexCatarino
Copy link
Member

AlexCatarino commented Jan 31, 2025

Expected Behavior

Binance Futures do not support limit maker orders (limit order with post-only property)
https://developers.binance.com/docs/derivatives/

Actual Behavior

When we place a limit order with post-only property, we get {"code":-1116,"msg":"Invalid orderType."}

Code

# region imports
from AlgorithmImports import *
# endregion

class CrawlingOrangeCat(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2023, 7, 30)
        self.set_end_date(2023, 8, 30)
        self.timezone = TimeZones.UTC
        self.set_time_zone(self.timezone)
        self.set_start_date(2025, 1, 1)
        self.set_end_date(2025, 2, 1)
        self.set_account_currency("USDT")
        self.set_cash("USDT", 100000)
        interest_rate_model = BinanceFutureMarginInterestRateModel()
        self.SetBrokerageModel(BrokerageName.BinanceFutures, AccountType.Margin)

        self.default_order_properties = BinanceOrderProperties()
        self.default_order_properties.time_in_force = TimeInForce.GOOD_TIL_CANCELED
        self.default_order_properties.post_only = True

        sec = self.add_crypto_future(
                ticker='BTCUSDT', 
                resolution=Resolution.MINUTE, 
                fill_forward=False)
        sec.SetMarginInterestRateModel(interest_rate_model)

        self.symbol = sec.symbol
        self.traded_time = None


    def on_data(self, data: Slice):
        if not self.traded_time:
            
            if self.symbol in data.bars:
                p = data.bars[self.symbol].close

                self.limit_order(self.symbol, 0.03, 0.99*p, tag='test', order_properties=self.default_order_properties)
                self.traded_time = self.time
        else:
            if (self.time - self.traded_time).total_seconds() > 60 * 1:
                self.transactions.cancel_open_orders()

Potential Solution

BinanceBaseRestApiClient.cs#L272

if (Equals(body["type"], "LIMIT_MAKER") && order.SecurityType == SecurityType.CryptoFuture)
{
    throw new NotSupportedException($"{nameof(BinanceBaseRestApiClient)}.{nameof(CreateOrderBody)}: Unsupported order type: {order.Type} for {SecurityType.CryptoFuture}");
}

We need to update the brokerage model too.

Checklist

  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues
  • I have provided detailed steps to reproduce the issue
@AlexCatarino AlexCatarino added the bug Something isn't working label Jan 31, 2025
@tdrxy
Copy link

tdrxy commented Jan 31, 2025

Post-only on futures is possible if you pass timeInForce='GTX'.

Time in force enum definition for futures:
https://developers.binance.com/docs/derivatives/usds-margined-futures/common-definition#enum-definitions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants