【问题标题】:Coinbase Pro python API - place_market_order() uses wrong amountCoinbase Pro python API - place_market_order() 使用了错误的金额
【发布时间】:2021-06-28 14:26:38
【问题描述】:

供参考,这是python版本的GitHub:https://github.com/danpaquin/coinbasepro-python

我的代码旨在将我的美元余额平均分配给最多 3 个帐户。下面是为我的代码创建的 LOG,证明它的值是准确的

Choosing out of random, we'll be purchasing these: 
['SUSHIBUSD', 'NMRBUSD', 'FORTHBUSD']
Placing order for FORTH-USD for the amount of: 6.08
Placing order for NMR-USD for the amount of: 6.08
Placing order for SUSHI-USD for the amount of: 6.08
for b in buy:
    coin = Coins.Coinbase[index[temp]]
    LOG.write("Placing order for " + coin + " for the amount of: ")
    LOG.write(USD)
    LOG.write("\n")
    Bot.place_market_order(str(coin), 'buy', USD)
    temp += 1

原来USD Balance持有18.25,代码确定金额后,6.08就是USD的价值。不幸的是,在我的 Coinbase 订单历史记录中,显示使用了全部余额,剩下 0 美元余额,没有任何余额可供其他账户使用。我尝试将值保留为 $X.XX 格式的浮点数,或者将 USD 更改为字符串值,但没有显示任何差异。

问题:为什么?我错过了什么吗? LOG 显示 USD 具有正确的值,因此对函数的调用应该是

Bot.place_market_order('FORTH-USD', 'buy', '6.08')

但它使用 all 就好像它是

Bot.place_market_order('FORTH-USD', 'buy', '18.25')
or
Bot.place_market_order('FORTH-USD', 'buy', 'all')

【问题讨论】:

    标签: python coinbase-api


    【解决方案1】:

    检查代码后,我发现place_market_order[1] 需要“大小”或“资金”才能下订单[2]。

    根据您的示例,您在位置上传递了“6.08”。这意味着您正在填写“size”参数,该参数被定义为基础货币,在您的情况下为“FORTH”。鉴于 FORTH 高于 19 美元(截至撰写本文时),这意味着您尝试使用 115.52 美元,而不是 6.08 美元,因此使用了全部金额。

    如果您想使用美元(这是 FORTHUSD 代码的报价资产,您应该使用Bot.place_market_order('FORTH-USD', 'buy', funds='6.08')


    [1]https://github.com/danpaquin/coinbasepro-python/blob/5658b2212b0fe39dde18b792f34aeaf81dda6640/cbpro/authenticated_client.py#L381

    [2]https://docs.pro.coinbase.com/#place-a-new-order

    【讨论】:

    • 很公平,未来参考:``` def place_market_order(self, product_id, side, size=None, fund=None, client_oid=None, stp=None, overdraft_enabled=None,funding_amount=None) :```我明白你的意思了。如果可行,我将在今天晚些时候调整代码并将其标记为答案,谢谢:)
    • 添加20美元资金并运行代码,成功处理订单,谢谢!
    猜你喜欢
    • 2021-02-10
    • 1970-01-01
    • 1970-01-01
    • 2018-04-22
    • 2021-03-17
    • 1970-01-01
    • 2020-09-05
    • 2020-07-31
    • 1970-01-01
    相关资源
    最近更新 更多