s4w3d0ff / python-poloniex

Poloniex API wrapper for Python 2.7 & 3
https://poloniex.com/support/api
GNU General Public License v2.0
568 stars 164 forks source link

returnOrderTrades() maybe bug #151

Open ghost opened 7 years ago

ghost commented 7 years ago

Hello, I am using the v0.4.6 and there are a strange bug in my code or in poloniex api or in the module ... I have put an amount to buy then sell it I check when the amount is buy before sell it My bot is working well a lot of time but when i was wake up this morning i have had the amount buy and no sell order set. So i think maybe there are a bug in returnOrderTrades(). I use in a function returnOrderTrades to get the amount to sell but it seems sometime it's not working. Here my func:

def check(order_id): global polo global timeout polo.timeout = (timeout, timeout) while True: try: result = polo.returnOrderTrades(order_id) total_end = Decimal("0") amount_end = Decimal("0") for item in result: fee = Decimal(str(item["fee"])) total_end += Decimal(str(item["total"])) amount = Decimal(str(item["amount"])) amount = amount * (Decimal("1") - fee) amount = amount.quantize(Decimal('.00000001'), rounding=ROUND_FLOOR) amount_end += amount else: return(1, amount_end, total_end) except Exception as exc: if str(exc) == "Order not found, or you are not the person who placed it."): return(0, Decimal("0"), Decimal("0")

Note i cancel the order before the check so if i have buy something check return me (1, amount_end, total_end) if not (0, Decimal("0"), Decimal("0")

I have read all my code a lot of time and i found nothing wrong in it.

So i think there are a bug in the poloniex module for returnOrderTrades() or in poloniex which return not the good value.

And other question does i need to use the v0.4.6 or the last one from github ?

Thanks for your help.

ghost commented 7 years ago

I think i have trouble in my code i have modified something i tell you now if it s work keep in touch.

Mantas779 commented 7 years ago

polo also has some connection error and freezes. maybe your app doesnt like it.

Op 3 aug. 2017 21:37 schreef "yepla" notifications@github.com:

Hello, I am using the v0.4.6 and there are a strange bug in my code or in poloniex api or in the module ... I have put an amount to buy then sell it I check when the amount is buy before sell it My bot is working well a lot of time but when i was wake up this morning i have had the amount buy and no sell order set. So i think maybe there are a bug in returnOrderTrades(). I use in a function returnOrderTrades to get the amount to sell but it seems sometime it's not working. Here my func:

def check(order_id): global polo global timeout polo.timeout = (timeout, timeout) while True: try: result = polo.returnOrderTrades(order_id) total_end = Decimal("0") amount_end = Decimal("0") for item in result: fee = Decimal(str(item["fee"])) total_end += Decimal(str(item["total"])) amount = Decimal(str(item["amount"])) amount = amount * (Decimal("1") - fee) amount = amount.quantize(Decimal('.00000001'), rounding=ROUND_FLOOR) amount_end += amount else: return(1, amount_end, total_end) except Exception as exc: if str(exc) == "Order not found, or you are not the person who placed it."): return(0, Decimal("0"), Decimal("0")

Note i cancel the order before the check so if i have buy something check return me (1, amount_end, total_end) if not (0, Decimal("0"), Decimal("0")

I have read all my code a lot of time and i found nothing wrong in it.

So i think there are a bug in the poloniex module for returnOrderTrades() or in poloniex which return not the good value.

Thanks for your help.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/s4w3d0ff/python-poloniex/issues/151, or mute the thread https://github.com/notifications/unsubscribe-auth/AQ4TJswCBt2UdvIuLgz0w0-b9u7ZRcgqks5sUiGVgaJpZM4Os5Wb .

ghost commented 7 years ago

I don't think it was the problem all my api request are in a while True, so it s not stop the while until it get the result !

s4w3d0ff commented 7 years ago

Personally, I have had issues with the returnOrderTrades command.

First, I have found that calling returnOrderTrades on an open order (that you own), poloniex will return an error if that order has not made any trades yet (like a postOnly order).

If no trades for the order have occurred or you specify an order that does not belong to you, you will receive an error.

Second, returnOrderTrades sometimes seems to return an error when you make a trade and immediately call returnOrderTrades after. Example:

orderNumber = polo.buy(market, rate, amount, orderType='fillOrKill')['orderNumber']
trades = polo.returnOrderTrades(orderNumber)

You would need to wait a bit:

orderNumber = polo.buy(market, rate, amount, orderType='fillOrKill')['orderNumber']
time.sleep(2)
trades = polo.returnOrderTrades(orderNumber)

This is probably an internal lag issue with poloniex and not much can be done but add a pause in the script.

Third, poloniex now has a ban policy in which if a user makes too many api calls which returns an error in a short time, they will ban that users ip temporarily, resulting in cloudflare messages (invalid JSON). https://github.com/s4w3d0ff/python-poloniex/issues/109#issuecomment-302804256

You may be temporarily blocked by Cloudflare if your API calls create many client errors (any HTTP 4xx code such as invalid nonce, insufficient balance, etc).

Since returnOrderTrades is prone to return errors, it is probably not a good idea to put it in a while loop. Doing so might cause it to just keep throwing errors and then eventually ban just because your open order never filled.

ghost commented 7 years ago

I use returnOrderTrades dirrectly after cancel the order so does i need put a sleep between the cancel and returnOrderTrades ? Does i need to to put a sleep between a buy order and a cancel too ? Does i need to put a sleep of 2secs between each api call to prevent error ? Does 2 secs is enought what is the minimum sleep i must put to prevent error ? Thanks.

s4w3d0ff commented 7 years ago

I would hope 2 sec is enough time, but only poloniex knows.

You shouldn't need to wait between every api call, just the ones that have data that needs to be processed by the poloniex servers.

Like placing an order then checking for trades. Poloniex might be under heavy load and the market is moving quickly. If you send an api request to poloniex asking to place an order, it takes some time for poloniex to process the request. You are going to want to wait a bit before you ask for information on that order.

How long? I have no idea, it probably changes when there are a lot of users online. 1-2 sec is probably safe but probably not needed between every api call.

ghost commented 7 years ago

ok but does i need to put a sleep between a cancel order and a returnOrderTrades ?

s4w3d0ff commented 7 years ago

If it is on the same 'orderNumber', I probably would.

ghost commented 7 years ago

and between a buy and a cancel ?

s4w3d0ff commented 7 years ago

again, if the same orderNumber, yes your going to want a slight pause.

ghost commented 7 years ago

ok thanks

mellertson commented 7 years ago

I have also received the message you describe after placing an order. However, I just pause and then check again a moment later and it works for me. It seems to be as s4w3d0ff said, where Poloniex doesn't place the order immediately.