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

Catch exception when attempting to cancel loan offer #107

Merged
merged 1 commit into from Sep 30, 2016
Merged

Catch exception when attempting to cancel loan offer #107

merged 1 commit into from Sep 30, 2016

Conversation

ghost
Copy link

@ghost ghost commented Sep 8, 2016

If a loan offer is taken some time in between the "returnOpenLoanOffers" and "cancelLoanOffer" calls, the attempt to cancel the order will raise an error since it's already taken.

When this happens, the uncaught exception propagates to the main loop and causes the bot to not lend out its funds for as long as sleepTime.

This issue will be more likely to occur the higher the "spreadLend" parameter is.

2016-09-08 15:56:21 Canceling all BTC orders... Loan offer canceled.
2016-09-08 15:56:22 Canceling all BTC orders... Loan offer canceled.
2016-09-08 15:56:22 Canceling all BTC orders... Loan offer canceled.
2016-09-08 15:56:22 Canceling all BTC orders... Loan offer canceled.
2016-09-08 15:56:23 ERROR: Error canceling loan order, or you are not the person who placed it.
Traceback (most recent call last):
  File "lendingbot.py", line 461, in 
    cancelAndLoanAll()
  File "lendingbot.py", line 290, in cancelAndLoanAll
    msg = bot.cancelLoanOffer(cur,offer['id'])
  File "/home/scrawl/Dev/poloniexlendingbot/poloniex.py", line 157, in cancelLoanOffer
    return self.api_query('cancelLoanOffer',{"currency":currency,"orderNumber":orderNumber})
  File "/home/scrawl/Dev/poloniexlendingbot/poloniex.py", line 68, in api_query
    jsonRet = _read_response(ret)
  File "/home/scrawl/Dev/poloniexlendingbot/poloniex.py", line 38, in _read_response
    raise PoloniexApiError(data['error'])
PoloniexApiError: Error canceling loan order, or you are not the person who placed it.

The fix is to catch exceptions when attempting to cancel orders, and assume the order is already filled if the cancellation fails.

2016-09-08 16:01:38 Canceling all BTC orders... Loan offer canceled.
2016-09-08 16:01:38 Canceling all BTC orders... Loan offer canceled.
2016-09-08 16:01:39 Canceling all BTC orders... Loan offer canceled.
2016-09-08 16:01:39 Canceling all BTC orders... Loan offer canceled.
2016-09-08 16:01:40 Error canceling loan offer: Error canceling loan order, or you are not the person who placed it.
2016-09-08 16:01:41 Placing X BTC at Y% for 2 days... Loan order placed.
2016-09-08 16:01:44 Placing X BTC at Y% for 2 days... Loan order placed.
2016-09-08 16:01:44 Placing X BTC at Y% for 2 days... Loan order placed.
2016-09-08 16:01:45 Placing X BTC at Y% for 2 days... Loan order placed.

@ghost
Copy link
Author

ghost commented Sep 8, 2016

There is btw a similar issue with the following code (set the spreadlend & gaptop to high values to reproduce):

                    # increase limit for currency to get a more accurate response
                    loanOrdersRequestLimit[activeCur] += defaultLoanOrdersRequestLimit
                    log.log( activeCur + ': Not enough offers in response, adjusting request limit to ' + str(loanOrdersRequestLimit[activeCur]))

When the end of the loan book is reached, the bot increases the loan book size and effectively repeats the lending function, but ignores the fact that it may already have placed offers (e.g. the first two offers in the spreadLend were placed, then on the third offer we reached the end of the loan book). This causes the bot to attempt to lend out more funds that it has, and raises the API error + sleep timeout issue.

Copy link
Member

@Evanito Evanito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have personally seen this error in the past, and have not seen it at all since using this PR. Thats enough of a reason to merge it as any.

@Evanito Evanito merged commit ee41a6f into BitBotFactory:master Sep 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant