3commas-io / 3commas-official-api-docs

Official Documentation for the 3commas APIs
https://3commas.io
251 stars 87 forks source link

Error take_profit[steps][price][type] missing #31

Closed spiritix closed 3 years ago

spiritix commented 3 years ago

I'm trying to place an order using the /public/api/v2/smart_trades endpoint with the following parameters:

Array
(
    [account_id] => 99999
    [pair] => USDT_ADADOWN
    [position] => Array
        (
            [type] => buy
            [order_type] => market
            [units] => Array
                (
                    [value] => 50
                )

        )

    [take_profit] => Array
        (
            [enabled] => 1
            [steps] => Array
                (
                    [0] => Array
                        (
                            [order_type] => market
                            [price] => Array
                                (
                                    [value] => 0.477
                                    [type] => last
                                )

                            [volume] => 50
                        )

                    [1] => Array
                        (
                            [order_type] => market
                            [price] => Array
                                (
                                    [value] => 0.485
                                    [type] => last
                                )

                            [volume] => 50
                        )

                )

        )

)

The request results in the following error response:

{"error":"record_invalid","error_description":"Invalid parameters","error_attributes":{"take_profit[steps]":["is invalid"],"take_profit[steps][price][type]":["is missing"],"value,percent":["are missing, exactly one parameter must be provided"]}}

However, as you can see above, take_profit[steps][price][type] is actually set. When I set take_profit[enabled] to false it works but of course the take profit isn't being applied. Is this a bug or am I doing something wrong?

Asafffff commented 3 years ago

I have the same problem

aschitz commented 3 years ago

I get the same Error with creating new Smart Trades or Updating Smart Trades

spiritix commented 3 years ago

I managed to solve the problem by using POST body (JSON) instead of GET parameters. Seems like the 3commas API isn't able to properly parse GET parameters, even though stated so in the docs.

3commas-io commented 3 years ago

arrays in get requests is a very tricky part, better to use JSON body always

ganya-qwe commented 3 years ago

having same problem when tring to send api call through node js, cant find how to solve. But iam using POST image "take_profit": { "enabled": "true", "steps": [ { "order_type": "limit", "price": { "value": takeProfit, "type": "last", "percent": "0.1" }, "volume": "100", "trailing": { "enabled": "true", "percent": "0.1" } } ] },

ordinz commented 2 years ago

I am also experiencing this, using https://github.com/kirosc/3commas-typescript/blob/master/src/index.ts. It is using a POST.

Anyone solved this?

mattguetta commented 2 years ago

Anyone solve this ? Trying to take_profit with 3commas-api-node. Thanks

spiritix commented 2 years ago

Yeah, don't use arrays guys, use JSON instead.

mattguetta commented 2 years ago

Yeah, don't use arrays guys, use JSON instead.

Actually I'm not using array, I'm doing it the same way @dmitriy-ganin is doing

mattguetta commented 2 years ago

And the most weird is I get differents results with the same code (template from official doc)

error: 'record_invalid', error_description: 'Invalid parameters', error_attributes: { 'take_profit[steps]': [ 'is invalid' ], 'take_profit[steps][price][type]': [ 'is missing' ], 'take_profit[steps][price][value],take_profit[steps][price][percent]': [ 'are missing, exactly one parameter must be provided' ] } } [nodemon] restarting due to changes... [nodemon] startingnode serve app.js { error: 'record_invalid', error_description: 'Invalid parameters', error_attributes: { 'take_profit[steps]': [ 'is invalid' ], 'take_profit[steps][2][price][type]': [ 'is missing' ], 'take_profit[steps][2][price][value],take_profit[steps][2][price][percent]': [ 'are missing, exactly one parameter must be provided' ]

ordinz commented 2 years ago

@mattguetta I had the same problem. I ended up bashing my head for awhile and somehow copying and pasting directly from https://github.com/3commas-io/3commas-official-api-docs/blob/master/smart_trades_v2_api.md and then modifying worked. It was a lot of trial and error, and I still don't know why it ended up working.

Good luck

mattguetta commented 2 years ago

@lukelove Thanks for help, yeah that's what I'm trying, but still get those errors, drives me crazy ^^ This output looks the same on your side ?

account_id=XXX&pair=USDT_BTC&position[type]=buy&position[units][value]=0.01&position[order_type]=market&take_profit[enabled]=true&take_profit[steps][0][order_type]=limit&take_profit[steps][0][price][value]=10000&take_profit[steps][0][price][type]=bid&take_profit[steps][0][volume]=10&take_profit[steps][1][order_type]=limit&take_profit[steps][1][price][value]=10500&take_profit[steps][1][price][type]=bid&take_profit[steps][1][volume]=20&take_profit[steps][2][order_type]=limit&take_profit[steps][2][price][value]=11000&take_profit[steps][2][price][type]=bid&take_profit[steps][2][volume]=30&take_profit[steps][3][order_type]=market&take_profit[steps][3][price][value]=11500&take_profit[steps][3][price][type]=bid&take_profit[steps][3][volume]=40&take_profit[steps][3][trailing][enabled]=true&take_profit[steps][3][trailing][percent]=10.5&stop_loss[enabled]=false

ordinz commented 2 years ago

ya that's what I remember seeing @mattguetta

Have you seen https://github.com/sgerodes/3commas-postman, this might help test

swizzmagik commented 2 years ago

Did anyone ever find a solution for this issue?

mattguetta commented 2 years ago

Yep got one, I’ll do my best to post it tomorrow

www.mattguetta.com // @mattguetta

Le 23 mai 2022 à 21:41, J. Brandon Johnson @.***> a écrit :

 Did anyone ever find a solution for this issue?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

swizzmagik commented 2 years ago

@mattguetta any luck on finding a solution?

Yep got one, I’ll do my best to post it tomorrow www.mattguetta.com // @mattguetta Le 23 mai 2022 à 21:41, J. Brandon Johnson @.***> a écrit :  Did anyone ever find a solution for this issue? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

mattguetta commented 2 years ago

Hi, sorry for delay, holydays there ^^ Can't push it on github, please update package with this file: https://www.dropbox.com/t/myGD1DytlXwt2PKR

MentalFish commented 2 years ago

Your Dropbox upload has expired, what was the solution to this issue @mattguetta?

swizzmagik commented 2 years ago

Hi guys, here is the link to the patched index.js that includes the fix provided by Matt: https://gist.github.com/swizzmagik/44e76af6e006a3b3d8e0864a9ebf197e