CyberPunkMetalHead / gateio-crypto-trading-bot-binance-announcements-new-coins

This is a crypto trading bot that scans the Binance Annoucements page for new coins, and places trades on Gateio
MIT License
1.21k stars 303 forks source link

Gate API returns incorrect filled price in order response / incorrect PNL / incorrect volume purchase #96

Closed busyuqboy closed 2 years ago

busyuqboy commented 2 years ago

The bot is using incorrect price values (possibly) from the response of Gate.io spot orders API payload.
Not sure what we can do about this. It's simply wrong info. The price returned doesn't even match what they show on their website for your trade order history.

Real Example: I had the bot purchase a new listing coin on gate.io called ZLK.
The purchase went through and I had an order closed (and filled 100%). The order id is 97094620091. It's real. it's in the books.
But... The bot recorded the response to the spot order with a price of 7.
The gateio website shows a filled price of 6.10. The bot determined it bought a volume of 49.9999998 (config set to 50) at an amount of 7.14285714 at a price of 7. The gateio website shows a volume of 43.571428554 at an amount of 7.14285714 at a price of 6.10. Interesting, huh? If I GET the order by id (GET /spot/orders/{order_id}), it shows an price of 7. Even a request by order id returns the wrong price amount. How can this be, Gateio? How can your website have a different price than your orders endpoint?

The outcome of the bot says I lost -12%. But it was using an incorrect price. I actually lost less than 1% (it was $0.90 USDT). 2021-11-25 11:00:21,708 INFO: Sold ZLK with -0.9 profit | -12.857% PNL

I'm not sure there is anything we can do about this. It's a gate.io issue really.

busyuqboy commented 2 years ago

Okay, I figured out how to get the REAL price on your order.

GET /spot/my_trades

image

0xfschott commented 2 years ago

The price from the /spot/orders api is the original limit order price. However, everything under this price is bought. In order to compute the "real" price you could do something like final_price = order['fill_price'] / order['amount']

motumboe commented 2 years ago

I think there's nothing wrong on gate.io side. Maybe the bot takes into account the limit order price instead of the actual fill price.

busyuqboy commented 2 years ago

The price from the /spot/orders api is the original limit order price. However, everything under this price is bought. In order to compute the "real" price you could do something like final_price = order['fill_price'] / order['amount']

I see what you're saying....that the /spot/orders api tells you what you submitted for the price. It doesn't mean that is the price you actually filled your buy order with. But it seems like you can fetch (to confirm) your price/trades with /spot/my_trades and get the price that was actually used with the fill order.

Linus045 commented 2 years ago

If there is still a problem that needs to be addressed, feel free to open the issue again.