coinbase / coinbase-pro-node

DEPRECATED — The official Node.js library for Coinbase Pro
Apache License 2.0
844 stars 316 forks source link

How to buy a maximum with a euro amount? #383

Closed F83D closed 5 years ago

F83D commented 5 years ago

Hi all,

Very good package for NodeJS, it's a pleasure to work with it.

It's not an issue, but a question. I'm looking for place a buy order for a maximum of BTC with a dedicated amount in euro. For instance, and as I do on the classic trade, I want to buy the maximum of BTC with 150€ at the market price. How can I do that with the API? It seems we need to indicate either the BTC price AND the size. I define the size using (amount / BTCPrice) but BTCPrice I got is the still the same according to the variation. That's why I would like to get the maximum of BTC with a dedicated amount of EUR. How can I do?

var order = {
    side: "buy",
    type: 'market',
    price: BTCPrice, // EUR
    size: (amount / BTCPrice).toFixed(8), // BTC
    product_id: "BTC-EUR"
};

Thank you for your help.

vansergen commented 5 years ago

@F83D This should do the job:

const buyParams = {
  type: 'market',
  funds: 150,
  product_id: 'BTC-EUR',
};
authedClient.buy(buyParams, callback);
F83D commented 5 years ago

Great, I've changed my params. Thanks for your quick reply and help.