thibaultyou / tradingview-alerts-processor

Minimalist service designed to execute TradingView webhooks and process them to cryptocurrencies exchanges.
MIT License
79 stars 23 forks source link

Failed to open buy position on Binance Futures #10

Closed itsikg closed 3 years ago

itsikg commented 3 years ago

Running it using docker on Ubunto server. When launching command using CURL: curl -d '{"stub": "MAIN", "symbol": "ETH/USDT", "size": "20", "direction": "long" }' -X POST http://MYIPADDRESS/trades -H 'Content-Type: application/json; charset=utf-8'

Getting the following error on debug log: {"message":"exchanges|BinanceFutures - ETH/USDT ticker successfully fetched. -> {\"symbol\":\"ETH/USDT\",\"timestamp\":1627931284759,\"datetime\":\"2021-08-02T19:08:04.759Z\",\"high\":2699,\"low\":2506.11,\"vwap\":2602.7,\"open\":2592.1,\"close\":2662.24,\"last\":2662.24,\"change\":70.14,\"percentage\":2.706,\"baseVolume\":4477545.437,\"quoteVolume\":11653695521.96,\"info\":{\"symbol\":\"ETHUSDT\",\"priceChange\":\"70.14\",\"priceChangePercent\":\"2.706\",\"weightedAvgPrice\":\"2602.70\",\"lastPrice\":\"2662.24\",\"lastQty\":\"0.246\",\"openPrice\":\"2592.10\",\"highPrice\":\"2699.00\",\"lowPrice\":\"2506.11\",\"volume\":\"4477545.437\",\"quoteVolume\":\"11653695521.96\",\"openTime\":\"1627844880000\",\"closeTime\":\"1627931284759\",\"firstId\":\"899416357\",\"lastId\":\"903834469\",\"count\":\"4418010\"}}","level":"debug","timestamp":"2021-08-02T19:08:06.170Z"} {"message":"trading|Calculated 0.0075124707013642655 ETH/USDT equivalent for 20 $US.","level":"debug","timestamp":"2021-08-02T19:08:06.171Z"} {"details":{"name":"ExchangeError"},"level":"error","message":"trading|BinanceFutures/MAIN - Failed to open buy position on ETH/USDT.","timestamp":"2021-08-02T19:08:06.685Z"}

My guess is the trade value cannot contain more than 3 digits after the decimal point (for ETH). It has to be rounded according to the "step size" specific to the symbol.

thibaultyou commented 3 years ago

Thank you for opening this issue, I'll test on my side and keep you updated.

thibaultyou commented 3 years ago

I tried the same command and it seems to work fine on my side.

2021-08-03 11:01:32:debug:exchanges|BinanceFutures - ETH/USDT ticker successfully fetched. -> {"symbol":"ETH/USDT","timestamp":1627981291483,"datetime":"2021-08-03T09:01:31.483Z","high":2666.91,"low":2441,"vwap":2571.33,"open":2574.54,"close":2481,"last":2481,"change":-93.54,"percentage":-3.633,"baseVolume":4034721.247,"quoteVolume":10374617202.96,"info":{"symbol":"ETHUSDT","priceChange":"-93.54","priceChangePercent":"-3.633","weightedAvgPrice":"2571.33","lastPrice":"2481.00","lastQty":"3.000","openPrice":"2574.54","highPrice":"2666.91","lowPrice":"2441.00","volume":"4034721.247","quoteVolume":"10374617202.96","openTime":"1627894860000","closeTime":"1627981291483","firstId":"902161797","lastId":"906283309","count":"4121301"}} 2021-08-03 11:01:32:debug:trading|Calculated 0.008061265618702136 ETH/USDT equivalent for 20 $US. 2021-08-03 11:01:32:info:trading|BinanceFutures/BINAF - ^^^ Opening long position / buying ETH/USDT (~ 20.00 $US).

If you've just created your API key please ensure that you have checked the Enable Futures option under Binance > Dashboard > Settings > API Management.

artdanish commented 3 years ago

I tried the same command and it seems to work fine on my side.

2021-08-03 11:01:32:debug:exchanges|BinanceFutures - ETH/USDT ticker successfully fetched. -> {"symbol":"ETH/USDT","timestamp":1627981291483,"datetime":"2021-08-03T09:01:31.483Z","high":2666.91,"low":2441,"vwap":2571.33,"open":2574.54,"close":2481,"last":2481,"change":-93.54,"percentage":-3.633,"baseVolume":4034721.247,"quoteVolume":10374617202.96,"info":{"symbol":"ETHUSDT","priceChange":"-93.54","priceChangePercent":"-3.633","weightedAvgPrice":"2571.33","lastPrice":"2481.00","lastQty":"3.000","openPrice":"2574.54","highPrice":"2666.91","lowPrice":"2441.00","volume":"4034721.247","quoteVolume":"10374617202.96","openTime":"1627894860000","closeTime":"1627981291483","firstId":"902161797","lastId":"906283309","count":"4121301"}} 2021-08-03 11:01:32:debug:trading|Calculated 0.008061265618702136 ETH/USDT equivalent for 20 $US. 2021-08-03 11:01:32:info:trading|BinanceFutures/BINAF - ^^^ Opening long position / buying ETH/USDT (~ 20.00 $US).

If you've just created your API key please ensure that you have checked the Enable Futures option under Binance > Dashboard > Settings > API Management.

It's this only work with ETH? or All pairs in the exchange what do you mean only work work USD you mean in Uniated State binance?

thibaultyou commented 3 years ago

I provided this example with ETH because this is the pair @itsikg used in the command.

Trading works for all USD based markets, this means that you can trade as many pairs you want as long as the quote is USDT, BUSD or USD itself for both perpetuals / futures or spot trading.

For now I've just not implemented trading for Coin based markets yet like ETH/BTC, LINK/BTC and so on, price conversion is different for those since you're providing a size in dollars in your requests and the exchange need another format.

itsikg commented 3 years ago

I tried the same command and it seems to work fine on my side.

2021-08-03 11:01:32:debug:exchanges|BinanceFutures - ETH/USDT ticker successfully fetched. -> {"symbol":"ETH/USDT","timestamp":1627981291483,"datetime":"2021-08-03T09:01:31.483Z","high":2666.91,"low":2441,"vwap":2571.33,"open":2574.54,"close":2481,"last":2481,"change":-93.54,"percentage":-3.633,"baseVolume":4034721.247,"quoteVolume":10374617202.96,"info":{"symbol":"ETHUSDT","priceChange":"-93.54","priceChangePercent":"-3.633","weightedAvgPrice":"2571.33","lastPrice":"2481.00","lastQty":"3.000","openPrice":"2574.54","highPrice":"2666.91","lowPrice":"2441.00","volume":"4034721.247","quoteVolume":"10374617202.96","openTime":"1627894860000","closeTime":"1627981291483","firstId":"902161797","lastId":"906283309","count":"4121301"}} 2021-08-03 11:01:32:debug:trading|Calculated 0.008061265618702136 ETH/USDT equivalent for 20 $US. 2021-08-03 11:01:32:info:trading|BinanceFutures/BINAF - ^^^ Opening long position / buying ETH/USDT (~ 20.00 $US).

If you've just created your API key please ensure that you have checked the Enable Futures option under Binance > Dashboard > Settings > API Management.

Hey, thanks for checking this out. I re-checked my API settings and it is enabled for trading Futures (see screenshot). image If it's not a step-size issue than I'm puzzled what can cause this command to fail.

artdanish commented 3 years ago

Not works for me i try as per your documention but not working haveing faild error on CURL testing.

itsikg commented 3 years ago

Not works for me i try as per your documention but not working haveing faild error on CURL testing.

Screenshot_1

That's actually a simple one :) You created an account called MAIN, but the order was issued to account TEST which does not exist. Simply replace "stub":"TEST" with "stub":"MAIN" on your order command.

thibaultyou commented 3 years ago

Not works for me i try as per your documention but not working haveing faild error on CURL testing.

Screenshot_1

I see multiple issues here :

Try to avoid posting your keys or all sensitive informations like ip addresses.

thibaultyou commented 3 years ago

I tried the same command and it seems to work fine on my side.

2021-08-03 11:01:32:debug:exchanges|BinanceFutures - ETH/USDT ticker successfully fetched. -> {"symbol":"ETH/USDT","timestamp":1627981291483,"datetime":"2021-08-03T09:01:31.483Z","high":2666.91,"low":2441,"vwap":2571.33,"open":2574.54,"close":2481,"last":2481,"change":-93.54,"percentage":-3.633,"baseVolume":4034721.247,"quoteVolume":10374617202.96,"info":{"symbol":"ETHUSDT","priceChange":"-93.54","priceChangePercent":"-3.633","weightedAvgPrice":"2571.33","lastPrice":"2481.00","lastQty":"3.000","openPrice":"2574.54","highPrice":"2666.91","lowPrice":"2441.00","volume":"4034721.247","quoteVolume":"10374617202.96","openTime":"1627894860000","closeTime":"1627981291483","firstId":"902161797","lastId":"906283309","count":"4121301"}} 2021-08-03 11:01:32:debug:trading|Calculated 0.008061265618702136 ETH/USDT equivalent for 20 $US. 2021-08-03 11:01:32:info:trading|BinanceFutures/BINAF - ^^^ Opening long position / buying ETH/USDT (~ 20.00 $US).

If you've just created your API key please ensure that you have checked the Enable Futures option under Binance > Dashboard > Settings > API Management.

Hey, thanks for checking this out. I re-checked my API settings and it is enabled for trading Futures (see screenshot). image If it's not a step-size issue than I'm puzzled what can cause this command to fail.

You can check your debugging logs while you're logged into your instance with this command : cat ./docker/logs/debug.log

Have you tried trading other pairs ? Removing and adding back the account ? Do you have any limitation in your configuration ? (balance, leverage, margin)

If you really want to use this tool I can give you faster support on Discord, you can reach me here : thibaultyou#0885 and also on the Jackrabbit Discord server where there's a lot of strategies to mix with this tool.

thibaultyou commented 3 years ago

Should be fixed here, this was probably due to the position structure update made by Binance on Futures.

Please update you tool with the following command : sudo docker-compose stop && sudo docker-compose pull && sudo docker-compose up -d