Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

returnOrderTrades() maybe bug #151

Open
ghost opened this issue Aug 3, 2017 · 12 comments
Open

returnOrderTrades() maybe bug #151

ghost opened this issue Aug 3, 2017 · 12 comments
Labels
bug Something is not behaving as it should in the code serverside Stems from a poloniex server issue

Comments

@ghost
Copy link

ghost commented Aug 3, 2017

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
Copy link
Author

ghost commented Aug 4, 2017

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

@Mantas779
Copy link

Mantas779 commented Aug 4, 2017 via email

@ghost
Copy link
Author

ghost commented Aug 5, 2017

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
Copy link
Owner

s4w3d0ff commented Aug 7, 2017

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).
#109 (comment)

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
Copy link
Author

ghost commented Aug 7, 2017

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
Copy link
Owner

s4w3d0ff commented Aug 7, 2017

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
Copy link
Author

ghost commented Aug 7, 2017

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

@s4w3d0ff
Copy link
Owner

s4w3d0ff commented Aug 7, 2017

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

@ghost
Copy link
Author

ghost commented Aug 7, 2017

and between a buy and a cancel ?

@s4w3d0ff
Copy link
Owner

s4w3d0ff commented Aug 7, 2017

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

@ghost
Copy link
Author

ghost commented Aug 7, 2017

ok thanks

@mellertson
Copy link

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.

@s4w3d0ff s4w3d0ff added the bug Something is not behaving as it should in the code label Sep 17, 2017
@s4w3d0ff s4w3d0ff added the serverside Stems from a poloniex server issue label May 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not behaving as it should in the code serverside Stems from a poloniex server issue
Projects
None yet
Development

No branches or pull requests

3 participants