Search code examples
pythoncoinbase-api

Coinbase Pro python API - place_market_order() uses wrong amount


For reference, this is the GitHub for the python version: https://github.com/danpaquin/coinbasepro-python

My code is meant to distribute my USD balance evenly to max 3 accounts. Below is the LOG created for my code, proving it's values to be accurate

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

Originally, the USD Balance held 18.25, after the code determines the amount, 6.08 is the value of USD. Unfortunately, in my Coinbase Order history, it is shown that the full amount of the balance was used instead, leaving 0 balance in USD and none left to offer for other accounts. I've attempted keeping the value as a float in $X.XX format or change USD to string value instead, none shown any difference.

Question: Why? Am I missing something? LOG shows USD has the right value, so the call to function should be

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

but instead it's using all as if it was

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

Solution

  • After checking the code, I have seen that place_market_order[1] requires either "size" or "funds" to place the order [2].

    Based on your example, you are passing "6.08" positionally. This means that you are filling the "size" parameter, which is defined as the base currency, in your case "FORTH". Given the fact that FORTH is above 19$ (as per time of writing), this means that you are trying to use 115.52$, instead of 6.08, thus using the full amount.

    If you want to use USD (which is the Quote asset for the FORTHUSD symbol, you should use 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