我的代码借用二进制API的加密货币有什么问题?

2024-05-17 06:31:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我打开保证金钱包,把一些美元转入了那个钱包。 我可以在代码中使用“创建保证金订单”功能下长订单,但在我打开空头头寸之前,我不能使用“创建保证金贷款”功能借用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的正确方法是什么?多谢各位


Tags: 代码margin订单保证金self功能clientbinance
1条回答
网友
1楼 · 发布于 2024-05-17 06:31:39

无需先借用,Binance支持自动借用和出售功能

代码如下:

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)

重要的部分是“sideEffectType”参数选项。 借入买入和借入卖出以打开头寸均设置为“保证金买入”。 并设置为“自动还款”关闭该位置。 它可以在平仓的同时偿还债务

相关问题 更多 >