【问题标题】:Binance Api - buying and selling functions - pythonBinance Api - 买卖功能 - python
【发布时间】:2021-06-08 21:31:27
【问题描述】:

是否有人为买卖“DOGEUSDT”之类的货币对或任何其他货币对(保证金交易)制定了适当的工作功能, 我已经尽了最大努力,但最终出现了不同的错误,例如 - 手数失败、资金不足或此 API 最常见的价格过滤器错误

我想出的功能如下,谁能告诉我我错过了什么

  1. 这个功能是想出买/空的数量,效果还不错

     def buy_quantity(symbol,asset):
         a = 0
         while a < 3:
             try:
                 bal = pd.DataFrame(client.get_margin_account()['userAssets'])
                 bal = bal[bal['asset']==asset]
                 bal = float(bal['free']) * 0.90
                 break
            except:
                 print("can't extract asset value..retrying")
                 a+=1
         price = float(client.get_recent_trades(symbol=symbol)[0]['price'])    
         stepSize = float(client.get_symbol_info(symbol)['filters'][2]['stepSize'])
         precision = int(round(-math.log(stepSize, 10), 0)) 
         quantity = (bal / price)*0.9995 # Trading fee taken in consideration 
         quantity = round(quantity,precision)
         return quantity
    
  2. 这个功能是补空的,基本上是想给你借的数量

    def sell_quantity1(asset):
         a = 0
         while a < 3:
             try:
                 order = pd.DataFrame(client.get_margin_account()['userAssets'])
                 order = order[order['asset']==asset]
                 order = float(order['borrowed'])
                 break
             except:
                 print("can't extract borrowed order book...retrying")
                 a+=1
         order = round(order,5)
         return order
    
  3. 这个功能是卖出多头头寸

     def sell_quantity2(asset):
         a = 0
         while a < 3:
             try:
                 order = pd.DataFrame(client.get_margin_account()['userAssets'])
                 order = order[order['asset']==asset]
                 order = float(order['free'])
                 break
             except:
                 print("can't extract order book...retrying")
                 a+=1
         order = round(order,5)
         return order
    

我认为函数 2 和 3 应该像函数 1 一样正常工作,但它们没有,会弹出一些或其他错误 批量失败,资金不足或其他问题,我在这里缺少什么可以请有人帮助我我正在挣扎几天

提前致谢

【问题讨论】:

    标签: binance binance-api-client


    【解决方案1】:
    def order(side, quoteOrderQty, symbol, order_type=ORDER_TYPE_MARKET):
        try:
            order = client.create_order(symbol=symbol, side=side, type=order_type, quoteOrderQty=quoteOrderQty)
            print(order)
        except Exception as e:
            print("exception - {}".format(e))
    

    【讨论】:

      猜你喜欢
      • 2022-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-15
      相关资源
      最近更新 更多