ignaciop000 / binance-traderBot

Trading Bot for Binance
GNU General Public License v3.0
75 stars 28 forks source link

Error 400 #6

Closed charlyroot closed 6 years ago

charlyroot commented 6 years ago

when i open my browser on http://localhost:3001:

openOrders Exception: Error: Request failed with status code 400
[]

npm test:


> cross-env NODE_ENV=test ./node_modules/.bin/mocha

  Binance REST
    checkKey
      √ Call without param - should return null
      √ Call with wrong params - should throw an exception
      √ Call with good params - should be ok
    checkParams
      √ Call without param - should throw an exception
      √ Call with wrong type param - should throw an exception
      √ Call with good param but an required param is missing - should throw an exception
      √ Call with good param - should be ok
    Constructor
      √ Call without api key - no api and secret key, no default header
      √ Call api key - api and secret key, default header

 signedMethod
      √ Call method without secret key - should throw an exception

 makeQuery
      √ Call method without api key - should throw an exception
      √ Call method without secret key - should throw an exception
      √ Call method without url - should throw an exception
      √ Call method with bad type for data param - should throw an exception
      √ Call method with good param - should be ok

  Binance Websocket
    √ Call without param - should throw an exception
    √ Call without callback - should throw an exception
    √ Call with path and callback - should be ok

  Orders
    get_ticker
      √ get_ticker - should be ok
    get_order_book
      √ get_order_book - should be ok
    get_info
      √ get_info - should be ok

  binanceRequest
    √ Call without param - should be ok
    √ Call with api param - should be ok
    √ Call with api and timeout param - should be ok

  getSignature
    √ Call without param - should throw an exception
    √ Call with bad query format - should throw an exception
    √ Call without key param - should throw an exception
    √ Call with bad key format - should throw an exception
    √ Call with good params - should be ok

  trading
    action
BCNBTC : Buy order created id:5569742, quantity:958.00000000, buyPrice:0.00000105, Take profit aprox :0.00000105
Profit loss, called order, 5569742
Buy order fail (Not filled) Cancel order...
      √ BCNBTC - Real - Cancel Order (211ms)
BCNBTC : Buy order created id:5581947, quantity:967.00000000, buyPrice:0.00000104, Take profit aprox :0.00000104
Buy order filled... Try sell...
Sell order create id: 5581962
      √ BCNBTC - Real - Buy Order and wait (10035ms)

  utils
    checkEnum
      √ Call with wrong enum - should throw an exception
      √ Call with good enum - should return null

  33 passing (10s)
mistersms commented 6 years ago

hello charlyroot, i had the same issue. after i canceled my manual created Open Orders in binance with the symbols i had set in traderBot file coin.js the error disappeared. my output of "npm test" shows the same as yours.

charlyroot commented 6 years ago

Hi mistersms,

there is my coin.js :

const coins = [
{
    symbol:'ZECBTC',
    quantity:0,
    stop_loss:0,
    mode:'profit',
    profit:1.3,
    increasing:0.00000001,
    decreasing:0.00000001,
    loop:0,
    wait_time:0.7,
    prints: 1,
},
{
    symbol:'XRPBTC',
    quantity:0,
    stop_loss:0,
    mode:'profit',
    profit:1.3,
    increasing:0.00000001,
    decreasing:0.00000001,
    loop:0,
    wait_time:0.7,
    prints: 1,
},
{
    symbol:'XMRBTC',
    quantity:0,
    stop_loss:0,
    mode:'profit',
    profit:1.3,
    increasing:0.00000001,
    decreasing:0.00000001,
    loop:0,
    wait_time:0.7,
    prints: 1,
}
]

module.exports = coins;

after one night, the script doesn't make any order...

is working for u?

mistersms commented 6 years ago

Hi charlyroot, I've only been testing this bot for a few days and in this timeperiod this bot never sell or buy anything. previously i have tested a while with the bot yasinkuyu/binance-trader and had the same problem that the bot never sold or bought a coin in profit mode. in range mode the bot sold and bought coins, so it was not a problem with binance api or keys. my first test machine was a debian 9.4 with node 8.11.2 and npm 5.6.0 now i will test the bot on an older machine with debian 8.10 and same node and npm version, maby the results are better. i am not a programmer or linux guru, so i have to test around with my poor linux skills ;)

mistersms commented 6 years ago

this are my settings: { symbol:'ETHBTC', quantity:0.5, stop_loss:0, mode:'profit', profit:1.0, increasing:0.00000001, decreasing:0.00000001, loop:0, wait_time:1, prints: 1, }, { symbol:'EOSBTC', quantity:1, stop_loss:0, mode:'profit', profit:1.0, increasing:0.00000001, decreasing:0.00000001, loop:0, wait_time:1, prints: 1, }

mistersms commented 6 years ago

i have allways set quantity.

dreKion commented 6 years ago
05-25 09:32:19 PPT/ETH Limit Sell 0.023290 0.023290 0.47 0.47 0.010947 -- Filled
05-25 09:29:33 PPT/ETH Limit Buy 0.023177 0.023177 0.47 0.47 0.010894 -- Filled

Only 1 buy/sell this night

charlyroot commented 6 years ago

thx for ur coin.js mistersms, I do not think the quantity is blocking since it is automatically put.

But what is the "range" mode ?

dreKion is it in this mode that the trader has sold / bought this morning?

mistersms commented 6 years ago

it looks like that dreKion is using the range mode, where you can set static sell and buy limits. dreKion, can you post your coin.js?

mistersms commented 6 years ago

i found out that my installed file trader.js was an older one as the one who was fixed in issue #2 now i have changed trader.js to the fixed one and started a new run... maybe that was the problem i will keep you update...

Orbitalz-eth commented 6 years ago

was that the problem?

mistersms commented 6 years ago

hi BatmanPDX, the newest file trader.js did not resolve my issue, my bot doesnt sell or buy anything. but error code 400 disappeared. the second error i have is error message "Error action Error: Invalid get_ticker" in log, but therefore i opened issue #7 i have no idea, why my bot isnt selling or buying anything.

i am running pi-hole as internal dns server and in this log, i can only see dns requests to www.binance.com, no requests to stream.binance.com or api.binance.com. should the bot connect to stream.binance.com or api.binance.com for any buy or sell actions?

dreKion commented 6 years ago

const coins = [ { symbol:'BCNETH', quantity:1000, stop_loss:0, mode:'profit', profit:0.8, increasing:0.00000001, decreasing:0.00000001, loop:0, wait_time:0.7, prints: 1, }, { symbol:'XLMETH', quantity:1000, stop_loss:0, mode:'profit', profit:0.7, increasing:0.00000001, decreasing:0.00000001, loop:0, wait_time:0.7, prints: 1, }, { symbol:'ZECETH', quantity:0, stop_loss:0, mode:'profit', profit:0.8, increasing:0.00000001, decreasing:0.00000001, loop:0, wait_time:0.7, prints: 1, }, { symbol:'EOSETH', quantity:0, stop_loss:0, mode:'profit', profit:0.8, increasing:0.00000001, decreasing:0.00000001, loop:0, wait_time:0.7, prints: 1, }, { symbol:'XVGETH', quantity:0, stop_loss:0, mode:'profit', profit:1.0, increasing:0.00000001, decreasing:0.00000001, loop:0, wait_time:180.0, prints: 1, }, { symbol:'PPTETH', quantity:0, stop_loss:0, mode:'profit', profit:0.8, increasing:0.00000001, decreasing:0.00000001, loop:0, wait_time:0.7, prints: 1, } ]

module.exports = coins;

This is mi coins.js

borocode commented 6 years ago

having the same issue image

const coins = [
{
    symbol:'KMDBTC',
    quantity:0,
    stop_loss:0,
    mode:'profit',
    profit:1.0,
    increasing:0.00000001,
    decreasing:0.00000001,
    loop:0,
    wait_time:0.7,
    prints: 1,
},
{
    symbol:'BNBBTC',
    quantity:0,
    stop_loss:0,
    mode:'profit',
    profit:1.0,
    increasing:0.00000001,
    decreasing:0.00000001,
    loop:0,
    wait_time:0.7,
    prints: 1,
}
]

module.exports = coins;

#########################edit#############################

image

const coins = [
{
    symbol:'EOSBTC',
    amount:0.0012,
    stop_loss:0,
    mode:'profit',
    profit:0.7,
    increasing:0.00000001,
    decreasing:0.00000001,
    loop:0,
    wait_time:0.7,
    prints: 1,
},
{
    symbol:'KMDBTC',
    amount:0.0012,
    stop_loss:0,
    mode:'profit',
    profit:0.7,
    increasing:0.00000001,
    decreasing:0.00000001,
    loop:0,
    wait_time:0.7,
    prints: 1,
}
]

module.exports = coins;
tmalinao commented 6 years ago

anybody already solved this error?

Orbitalz-eth commented 6 years ago

Are you running your shell in admin mode?

tmalinao commented 6 years ago

yes i am.. but still the same error occurred..did you guys adjusted your "binance_rest.js"?

ignaciop000 commented 6 years ago

i add more logs, please execute and copy the result, thanks

mistersms commented 6 years ago

i have adjusted binance_rest.js and test/orders.test.js >>> question: is this logging know only active in test mode?

ignaciop000 commented 6 years ago

No, the logs are the same in test mode and production mode. New logs prints msg on 400 error

tmalinao commented 6 years ago

hi, i put logs upon calling the openorders and this is the result.... openorders

async openOrders(params = {}){ this.signedMethod() // secret and api key required for this method const url = "api/v3/openOrders" let query = this.makeQuery(url, params); print('URL LOG: %s',url); print('PARAMS LOG: %s',params); print('QUERY LOG: %s',query); const resp = await this.request.get(query);
return resp.data; } is the query variable correct?

openorders

charlyroot commented 6 years ago

still the same error 400 :

Buy error: Error: Request failed with status code 400

no additionnal log sorry

ignaciop000 commented 6 years ago

@tmalinao you have old version, In the latest version openorders is not available @charlyroot now i added logs to all calls, please check again.

thanks

tmalinao commented 6 years ago

@ignaciop000 Thank you bro.. last night i run the bot for the whole night the new version. there is a buy transaction in the dashboard but when i check itself from the binance history nothing is there.. i check my shell i found out that code 400 for the buy also. anyway i will get the updated one and let you know for the result again.

mistersms commented 6 years ago

hello, i have run the bot the whole night too. the bot is buying and is canceling the order at the same time: error2 in the binance app you can see the canceled orders, if filter is set to view the canceled orders: screenshot_20180529-081820 this is my coin.js at the moment:

const coins = [ { symbol:'ETHBTC', quantity:0, stop_loss:0, mode:'profit', profit:0.9, increasing:0.00000001, decreasing:0.00000001, loop:0, wait_time:0.7, prints: 1, }, { symbol:'EOSBTC', quantity:0, stop_loss:0, mode:'profit', profit:0.9, increasing:0.00000001, decreasing:0.00000001, loop:0, wait_time:0.7, prints: 1, }, { symbol:'XVGBTC', quantity:0, stop_loss:0, mode:'profit', profit:1.5, increasing:0.00000001, decreasing:0.00000001, loop:0, wait_time:180.0, prints: 1, }, { symbol:'PPTBTC', quantity:0, stop_loss:0, mode:'profit', profit:0.9, increasing:0.00000001, decreasing:0.00000001, loop:0, wait_time:0.7, prints: 1, } ]

module.exports = coins;

i will add know the debug string in my coin.js .....

mistersms commented 6 years ago

since the enabled debug in coin.js i had 3 failed buy orders:

Symbol: PPTBTC Profit: 0.22 Expected Profit: 0.90 ASK: 0.00176960 BID: 0.00176490 Commission: 0.00050000 profitSelling 0.00178167 Symbol: PPTBTC Profit: 1.05 Expected Profit: 0.90 ASK: 0.00178440 BID: 0.00176490 Commission: 0.00050000 profitSelling 0.00178167 PPTBTC : Buy order created id:19629477, quantity:0.67000000, buyPrice:0.00176500, Take profit aprox :0.00178167 Profit loss, called order, 19629477 Buy order fail (Not filled) Cancel order... Symbol: PPTBTC Profit: 0.74 Expected Profit: 0.90 ASK: 0.00178440 BID: 0.00177050 Commission: 0.00050000 profitSelling 0.00178732 Symbol: PPTBTC Profit: 0.66 Expected Profit: 0.90 ASK: 0.00178440 BID: 0.00177190 Commission: 0.00050000 profitSelling 0.00178873 -snip- Symbol: PPTBTC Profit: 0.28 Expected Profit: 0.90 ASK: 0.00176720 BID: 0.00176140 Commission: 0.00050000 profitSelling 0.00177813 Symbol: PPTBTC Profit: 0.95 Expected Profit: 0.90 ASK: 0.00180000 BID: 0.00178220 Commission: 0.00050000 profitSelling 0.00179913 PPTBTC : Buy order created id:19631323, quantity:0.67000000, buyPrice:0.00178230, Take profit aprox :0.00179913 Profit loss, called order, 19631323 Buy order fail (Not filled) Cancel order... Symbol: PPTBTC Profit: 0.56 Expected Profit: 0.90 ASK: 0.00179530 BID: 0.00178450 Commission: 0.00050000 profitSelling 0.00180145 Symbol: PPTBTC Profit: 0.25 Expected Profit: 0.90 ASK: 0.00179270 BID: 0.00178740 Commission: 0.00050000 profitSelling 0.00180438 -snip- Symbol: PPTBTC Profit: 0.22 Expected Profit: 0.90 ASK: 0.00177810 BID: 0.00177340 Commission: 0.00050000 profitSelling 0.00179025 Symbol: PPTBTC Profit: 1.17 Expected Profit: 0.90 ASK: 0.00179500 BID: 0.00177340 Commission: 0.00050000 profitSelling 0.00179025 PPTBTC : Buy order created id:19634517, quantity:0.67000000, buyPrice:0.00177350, Take profit aprox :0.00179025 Profit loss, called order, 19634517 Buy order fail (Not filled) Cancel order... Symbol: PPTBTC Profit: 0.24 Expected Profit: 0.90 ASK: 0.00178750 BID: 0.00178240 Commission: 0.00050000 profitSelling 0.00179933 Symbol: PPTBTC Profit: 0.41 Expected Profit: 0.90 ASK: 0.00178750 BID: 0.00177940 Commission: 0.00050000 profitSelling 0.00179630 -snip-

does anybody know the reasen for "buy order fail (Not filled)" ?

mistersms commented 6 years ago

now i tried to test with set a stop_loss of 10% for PPTBTC:

{ symbol:'PPTBTC', quantity:0, stop_loss:10, mode:'profit', profit:1.0, increasing:0.00000001, decreasing:0.00000001, loop:0, wait_time:0.7, prints: 1, debug: true, }

after starting the bot there is still a Stop-Loss Amount of 0 shown:

grafik

should not the 10% stop-loss be seen there?

in the webgui there is also no stop-loss of 10% visible:

grafik

any ideas?

charlyroot commented 6 years ago
data:
      { code: -2010,
        msg: 'Account has insufficient balance for requested action.' } } }
Error Message: Account has insufficient balance for requested action.
Buy error: Error: Request failed with status code 400

thx all is working on other order 👍

charlyroot commented 6 years ago

Just for information, if u trade BTC, the lowest order is 0.001. So if u trade on Ex: 3 crypto (BNBBTC, ETHBTC, ZECBTC) in ur coin.js, be sure to have 3x0.001= 0.003 BTC on ur wallet.

to avoid error 400 : 'Account has insufficient balance for requested action.' 🤣

tmalinao commented 6 years ago

you mean to say if i have only 0.001 then only i can put 1 pair in my coins.js to avoid status code400 in buying?

charlyroot commented 6 years ago

yes because if the bot create an order of 1150 BCN for 0.001 BTC for example, is possible the bot want to buy another crypto (ETH for example) before the BCN are received and re-sell.

so -> 'Account has insufficient balance for requested action.'

tmalinao commented 6 years ago

still i am getting status code 400

tmalinao commented 6 years ago

hello guys any update on this?

ignaciop000 commented 6 years ago

@tmalinao please, share the logs with the detail of 400 error

tmalinao commented 6 years ago

hi @ignaciop000 ,

This is the error i got. msg: 'Timestamp for this request is outside of the recvWindow.' } } } Error Message: Timestamp for this request is outside of the recvWindow. Buy error: Error: Request failed with status code 400 but my time and date is sync. i tried to search with the same case and follow the steps what they did but still i received the error. Thanks.

goodthebest commented 6 years ago

@mistersms did you manage to fix stop_loss issue? I'm also having same issue, looking for a fix.

mistersms commented 6 years ago

@goodthebest no, i did not manage to fix stop_loss issue. i am testing around with this bot about 3-4 weeks and i have the problem that the bot never bought a symbol correctly. sometimes i get error 400, but most of the time i get this error:

Symbol: PPTBTC Profit: 0.95 Expected Profit: 0.80 ASK: 0.00149990 BID: 0.00148500 Commission: 0.00050000 profitSelling 0.00149762 PPTBTC : Buy order created id:20520435, quantity:2.00000000, buyPrice:0.00148510, Take profit aprox :0.00149762 Profit loss, called order, 20520435 Buy order fail (Not filled) Cancel order... Symbol: PPTBTC Profit: 0.77 Expected Profit: 0.80 ASK: 0.00149990 BID: 0.00148770 Commission: 0.00050000 profitSelling 0.00150035

it looks like the bot is buying and selling at the same time, but stop_loss is set to 0.

do you have normal orders for buying and selling?

@ignaciop000 attached you can find my logs to status code 400 traderbot-error-statuscode400.txt