1

我打开了我的保证金钱包并将一些 USDT 转入了那个钱包。我可以在我的代码中使用“create_margin_order”函数下多单,但在开空头头寸之前,我不能使用“create_margin_loan”函数借入 BTC。

这是我的代码:

    def btn_test_Clicked(self):
        current_time = datetime.now().strftime("%Y%m%d%H%M%S.%f")
        # check the amount which I can borrow
        order_result = self.binance_client.get_max_margin_loan(asset="BTC")
        print("Binance Max Loan = " + str(order_result))
        # borrowing the BTC
        order_result = self.binance_client.create_margin_loan(asset="BTC", amount=1.5)
        print("Binance Loan Result = " + str(order_result))
        # Place an order
        self.order_result = self.binance_client.create_margin_order(symbol="BTCUSDT", side=SIDE_SELL,type=ORDER_TYPE_LIMIT, timeInForce=TIME_IN_FORCE_GTC, quantity=1.5, price="8000")
        print("Binance Margin Order Result = " + str(order_result))

我使用 Python,IDE 是 PyCharm。点击按钮后,我可以看到关于最大借款金额的回复。之后,我的程序被终止,消息是:

进程以退出代码 -1073740791 (0xC0000409) 结束

很明显,我的代码关于借用部分是错误的。在 Binance 中使用 API 借用的正确方法是什么?谢谢你。

4

1 回答 1

4

无需先借贷,币安支持自动借贷功能。

这是代码:

order_result = client.create_margin_order(symbol="BTCUSDT", side=SIDE_BUY, type=ORDER_TYPE_LIMIT, timeInForce=TIME_IN_FORCE_GTC, sideEffectType="MARGIN_BUY", quantity=0.5, price=3000)

The important part is the "sideEffectType" parameter option. Borrow buy and borrow sell to open the position are all set to "MARGIN_BUY". And set to "AUTO_REPAY" to close the position. It can square the position and repay the debt at the same time.

于 2020-03-19T06:18:59.810 回答