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

Orders not closing in huobi #2116

Closed
Ish2k2 opened this issue Aug 9, 2019 · 8 comments
Closed

Orders not closing in huobi #2116

Ish2k2 opened this issue Aug 9, 2019 · 8 comments
Assignees
Labels

Comments

@Ish2k2
Copy link

Ish2k2 commented Aug 9, 2019

Step 1: Have you search for this issue before posting it?

i saw previous huobi issues but none related to this.

Step 2: Describe your environment

  • Operating system: docker / ubuntu
  • Python Version: see below (python -V)
  • CCXT version: 1.18.1008 (pip freeze | grep ccxt)
  • Branch: Develop
  • Last Commit ID: 6c0c77b (git log --format="%H" -n 1)

Step 3: Describe the problem:

Running bot on huobi but when the sell occurs the bot keeps the orders open. The sell takes place on the exchange. Not sure why the bot isn't updating the orders appropriately. I've tried restarting the bot but it keeps the order "open" when they truly have been closed.

edit: forgot to add in my order types:

2019-08-09 22:56:46,450 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using order_types: {'buy': 'limit
', 'sell': 'limit', 'stoploss': 'market', 'stoploss_on_exchange': False}
2019-08-09 22:56:46,451 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using order_time_in_force: {'buy'
: 'gtc', 'sell': 'gtc'}

Steps to reproduce:

running on huobi

Observed Results:

  • What happened? order stays open
  • What did you expect to happen? bot to log the trade as closed

Relevant code exceptions or logs:

2019-08-09 11:57:59,348 - freqtrade.freqtradebot - INFO - Found no buy signals for whitelisted currencies. Trying again..
2019-08-09 11:58:02,852 - freqtrade.wallets - INFO - Wallets synced.
2019-08-09 11:58:02,857 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=1, pair=NEW/USDT, amount=xxxx, open_rate=0.00264100, open_since=4 hours ago)
2019-08-09 11:58:08,956 - freqtrade.exchange.exchange - INFO - returning cached ticker-data for XRP/USDT
2019-08-09 11:58:08,957 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': sell, 'exchange': 'Huobipro', 'pair': 'XRP/USDT', 'gain': 'profit', 'limit': xxxx, 'order_type': 'limit', 'amount': xxx, 'open_rate': xxx, 'current_rate':xxxx, 'profit_amount':xxx, 'profit_percent': xxx, 'sell_reason': 'trailing_stop_loss', 'stake_currency': 'USDT', 'fiat_currency': 'USD'}
2019-08-09 11:58:09,437 - freqtrade.freqtradebot - INFO - executed sell, reason:SellType.TRAILING_STOP_LOSS
2019-08-09 11:58:10,882 - freqtrade.wallets - INFO - Wallets synced.
2019-08-09 11:58:11,323 - freqtrade.freqtradebot - INFO - Found no buy signals for whitelisted currencies. Trying again..
2019-08-09 11:58:14,869 - freqtrade.wallets - INFO - Wallets synced.
2019-08-09 11:58:18,873 - freqtrade.wallets - INFO - Wallets synced.
2019-08-09 11:58:18,878 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=1, pair=NEW/USDT, amount=xx, open_rate=0.00264100, open_since=4 hours ago)
2019-08-09 11:58:20,871 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=2, pair=XRP/USDT, amount=xxx, open_rate=0.29680000, open_since=an hour ago)

also periodically getting this error but could just be a deprecation warning:
/usr/local/lib/python3.7/site-packages/arrow/factory.py:202: ArrowParseWarning: The .get() parsing method without a
format string will parse more strictly in version 0.15.0.See arrow-py/arrow#612 for more details.

@xmatthias
Copy link
Member

Please use tripple ` to wrap log segments, so they are easier to read.

the "arrowParseWarning" is nothing to worry about for now it's a deprecation warning, not an error.

Restarting the bot won't help in this case - you could close / delete the order from the database to fix this.

I think we'll need more logs for this case (earlier logs i guess, but maybe also from later ).

the 3rd line in the log already detects the open order for tradeid=1 - we'll need to see the log at least from when that sell-order was opened.

Also, line 5 opens a new sell-order for id=2 - the last line in the log shows it's still open, which can be valid and depends on what the exchange shows you (when it was filled, ...).

How does your exchange information look like? when were the orders placed, and when filled?

@xmatthias xmatthias added the Triage Needed Issues yet to verify label Aug 10, 2019
@Ish2k2
Copy link
Author

Ish2k2 commented Aug 10, 2019

Sorry for the format - was in a rush and I'm very new to GitHub.

pasting the buy logs below

2019-08-09 07:00:25,793 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=1, pair=NEW/USDT, amount=xxx, open_rate=0.00264100, open_since=just now)
2019-08-09 07:00:27,786 - freqtrade.freqtradebot - INFO - Applying fee on amount for Trade(id=1, pair=NEW/USDT, amount=xxx, open_rate=0.00264100, open_since=just now) (from xxx to xxx) from Order
2019-08-09 07:00:27,786 - freqtrade.persistence - INFO - Updating trade (id=1) ...
2019-08-09 07:00:27,786 - freqtrade.persistence - INFO - LIMIT_BUY has been fulfilled for Trade(id=1, pair=NEW/USDT, amount=xxx, open_rate=0.00264100, open_since=just now).
2019-08-09 07:00:30,322 - freqtrade.freqtradebot - INFO - Found no buy signals for whitelisted currencies. Trying again..

pasting the sell logs below

2019-08-09 07:02:13,161 - freqtrade.exchange.exchange - INFO - returning cached ticker-data for NEW/USDT
2019-08-09 07:02:13,161 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': sell, 'exchange': 'Huobipro', 'pair': 'NEW/USDT', 'gain': 'profit', 'limit': 0.002678, 'order_type': 'limit', 'amount': xxx, 'open_rate': 0.002641, 'current_rate': 0.002678, 'profit_amount': xxx, 'profit_percent': xxx, 'sell_reason': 'trailing_stop_loss', 'stake_currency': 'USDT', 'fiat_currency': 'USD'}
2019-08-09 07:02:13,374 - freqtrade.freqtradebot - INFO - executed sell, reason: SellType.TRAILING_STOP_LOSS
2019-08-09 07:02:15,092 - freqtrade.wallets - INFO - Wallets synced.
2019-08-09 07:02:15,587 - freqtrade.freqtradebot - INFO - Found no buy signals for whitelisted currencies. Trying again..
2019-08-09 07:02:19,095 - freqtrade.wallets - INFO - Wallets synced.
2019-08-09 07:02:19,099 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=1, pair=NEW/USDT, amount=xxx, open_rate=0.00264100, open_since=2 minutes ago)

Looking closer at huobi for the NEW/USDT sell that occurred at 2019-08-09 07:02:13 which is pretty close to real time once the order was placed by the bot. Looking at the sell details they filled immediately. Another note is that the buy by the bot is limit and the sells are market orders which are taken place successfully on the exchange.

I'm using HT to pay for the fees so i wonder if the residual amounts are what's keeping the orders open? I can try manually closing the orders and turning off the HT fees option. I appreciate your help with all this! :)

@xmatthias
Copy link
Member

I don't think you have a choice now other than closing them in the database as shown in the sql cheatcheet.

sell-orders are market because you define stoploss as market orders - (trailing-stoploss is a market-order too).

Your database should have the column open_order_id populated for the orders that are stuck open.
Please use the value in there for the following validation:

import ccxt
ct = ccxt.huobipro({'apiKey': '<yourApiKey>', 'secret': '<yoursecret>'})  # I think it's huobipro ...)

orderid = '' # <- order ID from database
pair = '' # <- Pair from database - so XRP/USDT and NEW/USDT (needs to match order_id)
print(ct.fetch_order(order_id, pair))

Note: you need to provide your apikey/secret and the orderid / pair to the script.
Don't paste that here - but we'll need the output (should be a dictionary ...) - feel free to obfuscate fields you don't like to share).

we'll need that to see why the bot isn't detecting the closed order, which the output from ccxt will help us with.

I'm not a huobi user so i hope this will help us determine why it's not working correctly for you.

Thanks in advance

@Ish2k2
Copy link
Author

Ish2k2 commented Aug 10, 2019

Thanks for the script

Here is the code below I used - ran twice for NEW/USDT and XRP/USDT (I updated the order_id and pair respectively)

import ccxt
ct = ccxt.huobipro({'apiKey': 'xxx', 'secret': 'xxx'})

order_id = '43846351641' 
pair = 'XRP/USDT' 
print(ct.fetch_order(order_id, pair))

resulting in below - NEW/USDT

{'info': {'id': 43820933312, 'symbol': 'newusdt', 'account-id': xxx, 'amount': xxx, 'price': '0.0', 'created-at': 1565334133023, 'type': 'sell-market', 'field-amount': xxx, 'field-cash-amount': xxx, 'field-fees': 0.496584267773400000, 'finished-at': 1565334133101, 'source': 'spot-api', 'state': 'filled', 'canceled-at': 0}, 'id': '43820933312', 'timestamp': 1565334133023, 'datetime': '2019-08-09T07:02:13.023Z', 'lastTradeTimestamp': None, 'symbol': 'NEW/USDT', 'type': 'market', 'side': 'sell', 'price': None, 'average': 0.0026282145338974404, 'cost':xxx, 'amount': xxx, 'filled': xxx, 'remaining': 0.0, 'status': 'closed', 'fee': {'cost': 0.4965842677734, 'currency': 'USDT'}}

and for XRP/USDT:

{'info': {'id': 43846351641, 'symbol': 'xrpusdt', 'account-id': xxx, 'amount': xxx, 'price': '0.0', 'created-at': 1565351888790, 'type': 'sell-market', 'field-amount': xxx, 'field-cash-amount': xxx, 'field-fees': '0.500505148000000000', 'finished-at': 1565351888929, 'source': 'spot-api', 'state': 'filled', 'canceled-at': 0}, 'id': '43846351641', 'timestamp': 1565351888790, 'datetime': '2019-08-09T11:58:08.790Z', 'lastTradeTimestamp': None, 'symbol': 'XRP/USDT', 'type': 'market', 'side': 'sell', 'price': None, 'average': 0.2977, 'cost': xxx, 'amount': xxx, 'filled': xxx, 'remaining': 0.0, 'status': 'closed', 'fee': {'cost': 0.500505148, 'currency': 'USDT'}}

let me know if you need any additional information/ if I deleted too much. It also looks like the information is being updated properly in the database as well but the bot is keeping the order open.

@xmatthias
Copy link
Member

It also looks like the information is being updated properly in the database as well but the bot is keeping the order open.

what makes you think that?
is close_rate and close_date set for these trades??

maybe get an extract from the database for these trades - obfuscated at will obviously?

@hroff-1902
Copy link
Member

...or attach the file in a personal message to @xmatthias at Slack in order to prevent disclosing publicly some sensitive info, if this may have sence

@Ish2k2
Copy link
Author

Ish2k2 commented Aug 10, 2019

Yes you are correct there is no close_rate or close_date populating. I saw the sell reason and made that assumption. My apologies. Here is the extract of the database:

1|huobipro|NEW/USDT|1|0.0|0.002|open_rate|open_rate_requested||close_rate_requested||xxx|xxx|2019-08-09 07:00:20.543674||43820933312|stop_loss|stop_loss_pct|intial_stop_loss|initial_stop_loss_pct||2019-08-09 07:02:06.093229|max_rate|min_rate|trailing_stop_loss|tunex|30
2|huobipro|XRP/USDT|1|0.0|0.002|open_rate|open_rate_requested||close_rate_requested||xxx|xxx|2019-08-09 11:00:21.077830||43846351641|stop_loss|stop_loss_pct|initial_stop_loss|initial_stop_loss_pct||2019-08-09 11:26:26.206113|max_rate|min_rate|trailing_stop_loss|tunex|30

@xmatthias xmatthias added Bug and removed Triage Needed Issues yet to verify labels Aug 11, 2019
@xmatthias xmatthias self-assigned this Aug 12, 2019
@xmatthias
Copy link
Member

xmatthias commented Aug 15, 2019

closed in #2124 (merge did fail - but it's merged (3af5691).

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 a pull request may close this issue.

3 participants