freqtrade / freqtrade

Free, open source crypto trading bot
https://www.freqtrade.io
GNU General Public License v3.0
28.45k stars 6.1k forks source link

ftx: Freqtrade is trying to close non existing trades #7165

Closed darioneto closed 2 years ago

darioneto commented 2 years ago

Describe your environment

Observed Results:

All trades have been closed on the exchange however the logs are populated with the below info for multiple pairs. Exchange is FTX.

 Marking Trade(id=2, pair=SOL/USDT, amount=38.94000000, is_short=False, leverage=1.0, open_rate=40.71750000, open_since=closed) as closed as the trade is fulfilled and found no open orders for it

 Marking Trade(id=1, pair=ETH/USDT, amount=0.77500000, is_short=False, leverage=1.0, open_rate=1636.29961290, open_since=closed) as closed as the trade is fulfilled and found no open orders for it.

I've deleted the previous orders from the dbtabase to fix this kind of log message, however, there are many trades that just keep on popping up in the logs, and not sure what is causing it. Technically not causing issues with further executions as far as I see but the log looks concerning.

xmatthias commented 2 years ago

first of all - latest develop is not a valid version - and is a changing target with every merge / commit. So what's "latest" for me tomorrow will be different from your "latest".

Freqtrade does not support closing trades "on exchange" - and will not detect changes in such positions (you could also be manually trading the same account - where you'd not want freqtrade to detect every order/change).

Deleting orders from the database won't help - you'll have to delete the whole trade - best via /delete <tradeid> from telegram or the UI. This is also documented in the cheatsheet

darioneto commented 2 years ago

the output of freqtrade -V: freqtrade docker-4c68bec1

Deleting from the database via telegram, that's how I've done it. That seems to remove all traces from history. But this is not a solution moving forward, or is it?

There was no manual deletion of trades. I don't even login to the bot accounts on the exchange.

This almost appears on all the bots. Initially, I thought it was once off but that seems to be affecting all bots.

xmatthias commented 2 years ago

All trades have been closed on the exchange

this implies to me that you closed them manually. If that's not the case - then i don't see what's wrong with that output - unless it's continuous - which the message doesn't really suggest.

darioneto commented 2 years ago

They were not closed manually and yes, the logs continues every few seconds for the same pair from different bots. The above was just an example.

stash86 commented 2 years ago

are you using 1 database for multiple bots?

darioneto commented 2 years ago

1 db per bot , and one pair per subaccount

xmatthias commented 2 years ago

then i missunderstood.

please provide with a "fuller" excerpt of the logs (no removed lines in between, ...). Isolated lines usually only tell part of the story - and will not explain the reason for something.

Also, please enable "exchange": {"log_responses" = True"} in the configuration so we can see the responses that cause the trade to not properly close.

darioneto commented 2 years ago

sure will do, this typically happens after when the trade is exited so may need a while for this to happen. As of now, I deleted all the problematic entries and the log is clean.

darioneto commented 2 years ago

here are the logs from the last trade. I checked the exchange, there is no pending order left out. As I mentioned every time the trade is closed (in this case stop loss on exchange) the info gets logged constantly which is cluttering the log buffer. I'm not aware if this may cause any further issues if I leave it like that as I've been deleting each trade due to this, to clean this up.

 2022-08-03 23:54:20,393 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': startup, 'status': "Searching for USDT pairs to buy and sell based on [{'StaticPairList': 'StaticPairList'}]"}
 2022-08-03 23:54:20,813 - freqtrade.rpc.discord - INFO - Sending discord message: {'type': startup, 'status': "Searching for USDT pairs to buy and sell based on [{'StaticPairList': 'StaticPairList'}]"}
 2022-08-03 23:54:20,832 - freqtrade.freqtradebot - INFO - Updating 0 open orders.
 2022-08-03 23:54:20,839 - freqtrade.freqtradebot - INFO - Updating sell-fee on trade Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed)for order 250531287.
 2022-08-03 23:54:20,839 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed)
 2022-08-03 23:54:21,113 - freqtrade.exchange.exchange - INFO - API fetch_stoploss_order: [{'info': {'id': '250531287', 'market': 'ETH/USDT', 'future': None, 'side': 'sell', 'type': 'stop', 'orderPrice': None, 'triggerPrice': '1617.2', 'size': '0.766', 'status': 'triggered', 'createdAt': '2022-08-03T11:08:46.829595+00:00', 'triggeredAt': '2022-08-03T22:44:05.051591+00:00', 'orderId': None, 'error': None, 'reduceOnly': False, 'trailValue': None, 'trailStart': None, 'cancelledAt': None, 'cancelReason': None, 'retryUntilFilled': True, 'orderType': 'market', 'filledSize': '0.766', 'avgFillPrice': '1617.3', 'orderStatus': 'closed'}, 'id': '250531287', 'clientOrderId': None, 'timestamp': 1659524926829, 'datetime': '2022-08-03T11:08:46.829Z', 'lastTradeTimestamp': 1659566645051, 'symbol': 'ETH/USDT', 'type': 'stop', 'timeInForce': None, 'postOnly': None, 'reduceOnly': False, 'side': 'sell', 'price': 1617.2, 'stopPrice': 1617.2, 'amount': 0.766, 'cost': 1238.8518, 'average': 1617.3, 'filled': 0.766, 'remaining': 0.0, 'status': 'closed', 'fee': None, 'trades': [], 'fees': []}]
 2022-08-03 23:54:21,385 - freqtrade.exchange.exchange - INFO - API get_trades_for_order: []
 2022-08-03 23:54:21,385 - freqtrade.freqtradebot - INFO - Applying fee on amount for Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed) failed: myTrade-Dict empty found
 2022-08-03 23:54:21,386 - freqtrade.persistence.trade_model - INFO - Updating trade (id=3) ...
 2022-08-03 23:54:21,386 - freqtrade.persistence.trade_model - INFO - Marking Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed) as closed as the trade is fulfilled and found no open orders for it.
 2022-08-03 23:54:21,683 - freqtrade.wallets - INFO - Wallets synced.
 2022-08-03 23:54:25,835 - freqtrade.worker - INFO - Bot heartbeat. PID=1, version='docker-4c68bec1', state='RUNNING'
 2022-08-03 23:54:25,842 - freqtrade.freqtradebot - INFO - Updating sell-fee on trade Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed)for order 250531287.
 2022-08-03 23:54:25,842 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed)
 2022-08-03 23:54:26,139 - freqtrade.exchange.exchange - INFO - API fetch_stoploss_order: [{'info': {'id': '250531287', 'market': 'ETH/USDT', 'future': None, 'side': 'sell', 'type': 'stop', 'orderPrice': None, 'triggerPrice': '1617.2', 'size': '0.766', 'status': 'triggered', 'createdAt': '2022-08-03T11:08:46.829595+00:00', 'triggeredAt': '2022-08-03T22:44:05.051591+00:00', 'orderId': None, 'error': None, 'reduceOnly': False, 'trailValue': None, 'trailStart': None, 'cancelledAt': None, 'cancelReason': None, 'retryUntilFilled': True, 'orderType': 'market', 'filledSize': '0.766', 'avgFillPrice': '1617.3', 'orderStatus': 'closed'}, 'id': '250531287', 'clientOrderId': None, 'timestamp': 1659524926829, 'datetime': '2022-08-03T11:08:46.829Z', 'lastTradeTimestamp': 1659566645051, 'symbol': 'ETH/USDT', 'type': 'stop', 'timeInForce': None, 'postOnly': None, 'reduceOnly': False, 'side': 'sell', 'price': 1617.2, 'stopPrice': 1617.2, 'amount': 0.766, 'cost': 1238.8518, 'average': 1617.3, 'filled': 0.766, 'remaining': 0.0, 'status': 'closed', 'fee': None, 'trades': [], 'fees': []}]
 2022-08-03 23:54:26,414 - freqtrade.exchange.exchange - INFO - API get_trades_for_order: []
 2022-08-03 23:54:26,414 - freqtrade.freqtradebot - INFO - Applying fee on amount for Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed) failed: myTrade-Dict empty found
 2022-08-03 23:54:26,414 - freqtrade.persistence.trade_model - INFO - Updating trade (id=3) ...
 2022-08-03 23:54:26,415 - freqtrade.persistence.trade_model - INFO - Marking Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed) as closed as the trade is fulfilled and found no open orders for it.
 2022-08-03 23:54:26,680 - freqtrade.wallets - INFO - Wallets synced.
 2022-08-03 23:54:30,846 - freqtrade.freqtradebot - INFO - Updating sell-fee on trade Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed)for order 250531287.
 2022-08-03 23:54:30,847 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed)
 2022-08-03 23:54:31,132 - freqtrade.exchange.exchange - INFO - API fetch_stoploss_order: [{'info': {'id': '250531287', 'market': 'ETH/USDT', 'future': None, 'side': 'sell', 'type': 'stop', 'orderPrice': None, 'triggerPrice': '1617.2', 'size': '0.766', 'status': 'triggered', 'createdAt': '2022-08-03T11:08:46.829595+00:00', 'triggeredAt': '2022-08-03T22:44:05.051591+00:00', 'orderId': None, 'error': None, 'reduceOnly': False, 'trailValue': None, 'trailStart': None, 'cancelledAt': None, 'cancelReason': None, 'retryUntilFilled': True, 'orderType': 'market', 'filledSize': '0.766', 'avgFillPrice': '1617.3', 'orderStatus': 'closed'}, 'id': '250531287', 'clientOrderId': None, 'timestamp': 1659524926829, 'datetime': '2022-08-03T11:08:46.829Z', 'lastTradeTimestamp': 1659566645051, 'symbol': 'ETH/USDT', 'type': 'stop', 'timeInForce': None, 'postOnly': None, 'reduceOnly': False, 'side': 'sell', 'price': 1617.2, 'stopPrice': 1617.2, 'amount': 0.766, 'cost': 1238.8518, 'average': 1617.3, 'filled': 0.766, 'remaining': 0.0, 'status': 'closed', 'fee': None, 'trades': [], 'fees': []}]
 2022-08-03 23:54:31,393 - freqtrade.exchange.exchange - INFO - API get_trades_for_order: []
 2022-08-03 23:54:31,394 - freqtrade.freqtradebot - INFO - Applying fee on amount for Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed) failed: myTrade-Dict empty found
 2022-08-03 23:54:31,394 - freqtrade.persistence.trade_model - INFO - Updating trade (id=3) ...
 2022-08-03 23:54:31,395 - freqtrade.persistence.trade_model - INFO - Marking Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed) as closed as the trade is fulfilled and found no open orders for it.
 2022-08-03 23:54:31,690 - freqtrade.wallets - INFO - Wallets synced.
 2022-08-03 23:54:35,850 - freqtrade.freqtradebot - INFO - Updating sell-fee on trade Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed)for order 250531287.
 2022-08-03 23:54:35,850 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed)
 2022-08-03 23:54:36,224 - freqtrade.exchange.exchange - INFO - API fetch_stoploss_order: [{'info': {'id': '250531287', 'market': 'ETH/USDT', 'future': None, 'side': 'sell', 'type': 'stop', 'orderPrice': None, 'triggerPrice': '1617.2', 'size': '0.766', 'status': 'triggered', 'createdAt': '2022-08-03T11:08:46.829595+00:00', 'triggeredAt': '2022-08-03T22:44:05.051591+00:00', 'orderId': None, 'error': None, 'reduceOnly': False, 'trailValue': None, 'trailStart': None, 'cancelledAt': None, 'cancelReason': None, 'retryUntilFilled': True, 'orderType': 'market', 'filledSize': '0.766', 'avgFillPrice': '1617.3', 'orderStatus': 'closed'}, 'id': '250531287', 'clientOrderId': None, 'timestamp': 1659524926829, 'datetime': '2022-08-03T11:08:46.829Z', 'lastTradeTimestamp': 1659566645051, 'symbol': 'ETH/USDT', 'type': 'stop', 'timeInForce': None, 'postOnly': None, 'reduceOnly': False, 'side': 'sell', 'price': 1617.2, 'stopPrice': 1617.2, 'amount': 0.766, 'cost': 1238.8518, 'average': 1617.3, 'filled': 0.766, 'remaining': 0.0, 'status': 'closed', 'fee': None, 'trades': [], 'fees': []}]
 2022-08-03 23:54:36,494 - freqtrade.exchange.exchange - INFO - API get_trades_for_order: []
 2022-08-03 23:54:36,495 - freqtrade.freqtradebot - INFO - Applying fee on amount for Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed) failed: myTrade-Dict empty found
 2022-08-03 23:54:36,495 - freqtrade.persistence.trade_model - INFO - Updating trade (id=3) ...
 2022-08-03 23:54:36,496 - freqtrade.persistence.trade_model - INFO - Marking Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed) as closed as the trade is fulfilled and found no open orders for it.
 2022-08-03 23:54:36,812 - freqtrade.wallets - INFO - Wallets synced.
 2022-08-03 23:54:40,850 - freqtrade.freqtradebot - INFO - Updating sell-fee on trade Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed)for order 250531287.
 2022-08-03 23:54:40,851 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed)
 2022-08-03 23:54:41,139 - freqtrade.exchange.exchange - INFO - API fetch_stoploss_order: [{'info': {'id': '250531287', 'market': 'ETH/USDT', 'future': None, 'side': 'sell', 'type': 'stop', 'orderPrice': None, 'triggerPrice': '1617.2', 'size': '0.766', 'status': 'triggered', 'createdAt': '2022-08-03T11:08:46.829595+00:00', 'triggeredAt': '2022-08-03T22:44:05.051591+00:00', 'orderId': None, 'error': None, 'reduceOnly': False, 'trailValue': None, 'trailStart': None, 'cancelledAt': None, 'cancelReason': None, 'retryUntilFilled': True, 'orderType': 'market', 'filledSize': '0.766', 'avgFillPrice': '1617.3', 'orderStatus': 'closed'}, 'id': '250531287', 'clientOrderId': None, 'timestamp': 1659524926829, 'datetime': '2022-08-03T11:08:46.829Z', 'lastTradeTimestamp': 1659566645051, 'symbol': 'ETH/USDT', 'type': 'stop', 'timeInForce': None, 'postOnly': None, 'reduceOnly': False, 'side': 'sell', 'price': 1617.2, 'stopPrice': 1617.2, 'amount': 0.766, 'cost': 1238.8518, 'average': 1617.3, 'filled': 0.766, 'remaining': 0.0, 'status': 'closed', 'fee': None, 'trades': [], 'fees': []}]
 2022-08-03 23:54:41,409 - freqtrade.exchange.exchange - INFO - API get_trades_for_order: []
 2022-08-03 23:54:41,409 - freqtrade.freqtradebot - INFO - Applying fee on amount for Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed) failed: myTrade-Dict empty found
 2022-08-03 23:54:41,410 - freqtrade.persistence.trade_model - INFO - Updating trade (id=3) ...
 2022-08-03 23:54:41,410 - freqtrade.persistence.trade_model - INFO - Marking Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed) as closed as the trade is fulfilled and found no open orders for it.
 2022-08-03 23:54:41,686 - freqtrade.wallets - INFO - Wallets synced.
 2022-08-03 23:54:45,855 - freqtrade.freqtradebot - INFO - Updating sell-fee on trade Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed)for order 250531287.
 2022-08-03 23:54:45,855 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed)
 2022-08-03 23:54:46,139 - freqtrade.exchange.exchange - INFO - API fetch_stoploss_order: [{'info': {'id': '250531287', 'market': 'ETH/USDT', 'future': None, 'side': 'sell', 'type': 'stop', 'orderPrice': None, 'triggerPrice': '1617.2', 'size': '0.766', 'status': 'triggered', 'createdAt': '2022-08-03T11:08:46.829595+00:00', 'triggeredAt': '2022-08-03T22:44:05.051591+00:00', 'orderId': None, 'error': None, 'reduceOnly': False, 'trailValue': None, 'trailStart': None, 'cancelledAt': None, 'cancelReason': None, 'retryUntilFilled': True, 'orderType': 'market', 'filledSize': '0.766', 'avgFillPrice': '1617.3', 'orderStatus': 'closed'}, 'id': '250531287', 'clientOrderId': None, 'timestamp': 1659524926829, 'datetime': '2022-08-03T11:08:46.829Z', 'lastTradeTimestamp': 1659566645051, 'symbol': 'ETH/USDT', 'type': 'stop', 'timeInForce': None, 'postOnly': None, 'reduceOnly': False, 'side': 'sell', 'price': 1617.2, 'stopPrice': 1617.2, 'amount': 0.766, 'cost': 1238.8518, 'average': 1617.3, 'filled': 0.766, 'remaining': 0.0, 'status': 'closed', 'fee': None, 'trades': [], 'fees': []}]
 2022-08-03 23:54:46,495 - freqtrade.exchange.exchange - INFO - API get_trades_for_order: []
 2022-08-03 23:54:46,496 - freqtrade.freqtradebot - INFO - Applying fee on amount for Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed) failed: myTrade-Dict empty found
 2022-08-03 23:54:46,496 - freqtrade.persistence.trade_model - INFO - Updating trade (id=3) ...
 2022-08-03 23:54:46,497 - freqtrade.persistence.trade_model - INFO - Marking Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed) as closed as the trade is fulfilled and found no open orders for it.
 2022-08-03 23:54:46,815 - freqtrade.wallets - INFO - Wallets synced.
 2022-08-03 23:54:50,859 - freqtrade.freqtradebot - INFO - Updating sell-fee on trade Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed)for order 250531287.
 2022-08-03 23:54:50,859 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed)
 2022-08-03 23:54:51,155 - freqtrade.exchange.exchange - INFO - API fetch_stoploss_order: [{'info': {'id': '250531287', 'market': 'ETH/USDT', 'future': None, 'side': 'sell', 'type': 'stop', 'orderPrice': None, 'triggerPrice': '1617.2', 'size': '0.766', 'status': 'triggered', 'createdAt': '2022-08-03T11:08:46.829595+00:00', 'triggeredAt': '2022-08-03T22:44:05.051591+00:00', 'orderId': None, 'error': None, 'reduceOnly': False, 'trailValue': None, 'trailStart': None, 'cancelledAt': None, 'cancelReason': None, 'retryUntilFilled': True, 'orderType': 'market', 'filledSize': '0.766', 'avgFillPrice': '1617.3', 'orderStatus': 'closed'}, 'id': '250531287', 'clientOrderId': None, 'timestamp': 1659524926829, 'datetime': '2022-08-03T11:08:46.829Z', 'lastTradeTimestamp': 1659566645051, 'symbol': 'ETH/USDT', 'type': 'stop', 'timeInForce': None, 'postOnly': None, 'reduceOnly': False, 'side': 'sell', 'price': 1617.2, 'stopPrice': 1617.2, 'amount': 0.766, 'cost': 1238.8518, 'average': 1617.3, 'filled': 0.766, 'remaining': 0.0, 'status': 'closed', 'fee': None, 'trades': [], 'fees': []}]
 2022-08-03 23:54:51,439 - freqtrade.exchange.exchange - INFO - API get_trades_for_order: []
 2022-08-03 23:54:51,440 - freqtrade.freqtradebot - INFO - Applying fee on amount for Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed) failed: myTrade-Dict empty found
 2022-08-03 23:54:51,440 - freqtrade.persistence.trade_model - INFO - Updating trade (id=3) ...
 2022-08-03 23:54:51,441 - freqtrade.persistence.trade_model - INFO - Marking Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed) as closed as the trade is fulfilled and found no open orders for it.
 2022-08-03 23:54:51,711 - freqtrade.wallets - INFO - Wallets synced.
 2022-08-03 23:54:55,863 - freqtrade.freqtradebot - INFO - Updating sell-fee on trade Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed)for order 250531287.
 2022-08-03 23:54:55,863 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed)
 2022-08-03 23:54:56,136 - freqtrade.exchange.exchange - INFO - API fetch_stoploss_order: [{'info': {'id': '250531287', 'market': 'ETH/USDT', 'future': None, 'side': 'sell', 'type': 'stop', 'orderPrice': None, 'triggerPrice': '1617.2', 'size': '0.766', 'status': 'triggered', 'createdAt': '2022-08-03T11:08:46.829595+00:00', 'triggeredAt': '2022-08-03T22:44:05.051591+00:00', 'orderId': None, 'error': None, 'reduceOnly': False, 'trailValue': None, 'trailStart': None, 'cancelledAt': None, 'cancelReason': None, 'retryUntilFilled': True, 'orderType': 'market', 'filledSize': '0.766', 'avgFillPrice': '1617.3', 'orderStatus': 'closed'}, 'id': '250531287', 'clientOrderId': None, 'timestamp': 1659524926829, 'datetime': '2022-08-03T11:08:46.829Z', 'lastTradeTimestamp': 1659566645051, 'symbol': 'ETH/USDT', 'type': 'stop', 'timeInForce': None, 'postOnly': None, 'reduceOnly': False, 'side': 'sell', 'price': 1617.2, 'stopPrice': 1617.2, 'amount': 0.766, 'cost': 1238.8518, 'average': 1617.3, 'filled': 0.766, 'remaining': 0.0, 'status': 'closed', 'fee': None, 'trades': [], 'fees': []}]
 2022-08-03 23:54:56,427 - freqtrade.exchange.exchange - INFO - API get_trades_for_order: []
 2022-08-03 23:54:56,427 - freqtrade.freqtradebot - INFO - Applying fee on amount for Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed) failed: myTrade-Dict empty found
 2022-08-03 23:54:56,428 - freqtrade.persistence.trade_model - INFO - Updating trade (id=3) ...
 2022-08-03 23:54:56,428 - freqtrade.persistence.trade_model - INFO - Marking Trade(id=3, pair=ETH/USDT, amount=0.76600000, is_short=False, leverage=1.0, open_rate=1599.20000000, open_since=closed) as closed as the trade is fulfilled and found no open orders for it.
 2022-08-03 23:54:56,699 - freqtrade.wallets - INFO - Wallets synced.

Orders table for trade ID 3:

"8" "3" "stoploss"  "ETH/USDT"  "false" "250415564" "cancelled" "ETH/USDT"  "stop"  "sell"  "1602.8"        "0.766" "0" "0.766" "0" "1602.8"    "2022-08-03 07:39:33.026"       "2022-08-03 11:08:46.642556"    
"5" "3" "buy"   "ETH/USDT"  "false" "168754831310"  "closed"    "ETH/USDT"  "market"    "buy"   "1599.2"    "1599.2"    "0.766" "0.766" "0" "1224.9872"     "2022-08-03 00:59:29.411"   "2022-08-03 00:59:33.50068" "2022-08-03 00:59:33.500685"    
"6" "3" "stoploss"  "ETH/USDT"  "false" "250206136" "cancelled" "ETH/USDT"  "stop"  "sell"  "1551.3"        "0.766" "0" "0.766" "0" "1551.3"    "2022-08-03 00:59:34.77"        "2022-08-03 06:03:48.952232"    
"9" "3" "stoploss"  "ETH/USDT"  "false" "250531287" "closed"    "ETH/USDT"  "stop"  "sell"  "1617.2"    "1617.3"    "0.766" "0.766" "0" "1238.8518" "1617.2"    "2022-08-03 11:08:46.829"   "2022-08-03 23:52:35.196222"    "2022-08-03 23:52:35.196232"    
"7" "3" "stoploss"  "ETH/USDT"  "false" "250368697" "cancelled" "ETH/USDT"  "stop"  "sell"  "1602.8"        "0.766" "0" "0.766" "0" "1602.8"    "2022-08-03 06:03:49.058"       "2022-08-03 07:39:32.924403"    

trades table for ID:3

"3" "ftx" "ETH/USDT" "ETH" "USDT" "false" "0.0006" "0.7349923199999999" "USDT" "0.0006" "1599.2" "1599.3" "1225.72219232" "1617.3" "1617.1314016886747" "0.01010531" "12.3862966" "1224.9872" "0.766" "0.766875956375014" "2022-08-03 00:59:29.493822" "2022-08-03 22:44:08.009487" "1617.1314016886747" "-0.03546975922183293" "1551.224" "-0.03" "2022-08-03 12:23:09.88636" "1683" "1591.3" "stoploss_on_exchange" "closed" "eth_long_red_strategy" "RED>5 & RED> 0.3" "1" "SPOT" "1" "false" "0" "0"

strategy stop loss config:

    use_custom_stoploss = True

    def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,
                        current_rate: float, current_profit: float, **kwargs) -> float:

        # evaluate highest to lowest, so that highest possible stop is used
        if current_profit > 0.09:
            return stoploss_from_open(0.05, current_profit, is_short=trade.is_short)
        elif current_profit > 0.04:
            return stoploss_from_open(0.01, current_profit, is_short=trade.is_short)
        elif current_profit > 0.02:
            return stoploss_from_open(0.001, current_profit, is_short=trade.is_short)

        # return maximum stoploss value, keeping current stoploss price unchanged
        return 1

    # Strategy interface version - allow new iterations of the strategy interface.
    # Check the documentation or the Sample strategy to get the latest version.
    INTERFACE_VERSION = 3

    # Optimal timeframe for the strategy.
    timeframe = '1m'

    # Can this strategy go short?
    can_short: bool = False

    # Minimal ROI designed for the strategy.
    # This attribute will be overridden if the config file contains "minimal_roi".
    minimal_roi = {
        "60": 0.50,
        "30": 0.40,
        "0": 0.30
    }

    # Optimal stoploss designed for the strategy.
    # This attribute will be overridden if the config file contains "stoploss".
    stoploss = -0.03 
...
    order_types = {
        'entry': 'market',
        'exit': 'market',
        'stoploss': 'market',
        'stoploss_on_exchange': True
    }
xmatthias commented 2 years ago

FTX's stop order handling is a bit strange in certain scenarios (and quite different between stop limit and stop market orders).

Can you run the following in an interactive shell?

import ccxt
exchange = ccxt.ftx({'apiKey': '<yourApiKey>', 'secret': '<yoursecret>' })
trades = exchange.fetch_my_trades('ETH/USDT', 1659524920000)
print(trades)
print([t for t in trades if t['order'] == '250531287'])

Ideally - this would print first a longer list of trades (Or just one trade - depending if you had other ETH trades since) - and then the filtered trades. i do however suspect that the 2nd print will print an empty list ... but we'll see about that :laughing:

darioneto commented 2 years ago

I changed that script slightly to work with subaccount. Nonetheless here is the output:

[{'info': {'id': '9401972852', 'market': 'ETH/USDT', 'future': None, 'baseCurrency': 'ETH', 'quoteCurrency': 'USDT', 'type': 'order', 'side': 'sell', 'price': '1617.3', 'size': '0.766', 'orderId': '169047223550', 'time': '2022-08-03T22:44:05.252399+00:00', 'tradeId': '4659134573', 'feeRate': '0.0006', 'fee': '0.74331108', 'feeCurrency': 'USDT', 'liquidity': 'taker'}, 'timestamp': 1659566645252, 'datetime': '2022-08-03T22:44:05.252Z', 'symbol': 'ETH/USDT', 'id': '9401972852', 'order': '169047223550', 'type': None, 'takerOrMaker': 'taker', 'side': 'sell', 'price': 1617.3, 'amount': 0.766, 'cost': 1238.8518, 'fee': {'cost': 0.74331108, 'currency': 'USDT', 'rate': 0.0006}, 'fees': [{'currency': 'USDT', 'cost': 0.74331108, 'rate': 0.0006}]}]
[]

I've got another trade going on Binance this time, so looking forward to seeing if this is only FTX or another exchange.

darioneto commented 2 years ago

The trade on Binance was closed and no logs in the buffer. So looks like FTX is the problem.

xmatthias commented 2 years ago

It's a FTX problem - and one that most likely will result in the removal of stop-market order support - unless i can find a way to match these two orders (on something other than time).

The problem on FTX stops is the following:

Your data above confirms this - Based on the dates, the trade is clearly the trade that got triggered - but there's no ID connecting the two (the trade-orderid is 169047223550 - which is not in the order response - which had an id of 250531287.

darioneto commented 2 years ago

Thanks for looking into it.

I only trade one pair per subaccount so the match should be easy to find based on the "ft_trade_id" alone, but I understand others may have different requirements.

Ok so in the conclusion we are not able to use the stop-market orders with FTX until a solution is found in future releases?

xmatthias commented 2 years ago

for the moment, that's correct (at least without manual intervention by setting the fee_close_currency (which is used to determine if the fee was updated). it also implicitly means that fees will not be 100% accurate - but an estimation based on the entry fees - at least when using stop-market orders.

darioneto commented 2 years ago

Not sure what you mean in reference to the fee_close_currency, If that approach can be somehow automated I'm ok with that. My accounts are separated one per Ticker. Manual intervention of deleting every single order is not the solution.

xmatthias commented 2 years ago

no it cannot. it'd involve changing the database table and adding a currency in one field. Same goes for deleting - it's clearly not a solution.

it's a workaround - but the best short-term solution is to switch to stop-limit orders.

darioneto commented 2 years ago

stop-limits orders are not an option in those markets. Probably better to move to another exchange that supports stop-markets. When do you think some sort of solution to this can be implemented on FTX?

xmatthias commented 2 years ago

Stop-limit vs. stop-market don't make much a difference if stoploss_on_exchange_limit_ratio is configured properly (which defines the gap between the stop and the limit order). Having a value > 1% (the default) here will make sure that the subsequent limit-order will be filled (it'll still fill at market terms - so the best price available at that point).


For the moment - I'm not aware of a solution (the order and trade id's don't allow a proper way to find each other).

The solution will therefore either take a longer time (in hopes ftx support will fix this in their API) - or by disabling stop-market orders for FTX (which is probably the short-term route).

darioneto commented 2 years ago

so the limit ratio margin is added on the top as a limit, Say if I need true 3% SL, then I need to set SL as 2% having stoploss_on_exchange_limit_ratio as default? If that order is filled in market terms then it should be fine. From what I understood limit-order will guarantee the required price, but never ensure to be filled if the price moves violently.

xmatthias commented 2 years ago

a stop-limit has 2 prices - the trigger price - and the limit price. Now assuming a long 1x position - your stoploss will be 3% below the entry (the stop price).

With a stop-market order, the order will trigger at 3% - and will fill based on the orderbook at that moment - which could mean a position loss of 3%, 3.1% - or 5% - or 10% (if the coin dropped quickly / has very low ordrebook volume).

with stoploss_on_exchange_limit_ratio - you define exactly this value - so it'll be stoploss_on_exchange_limit_ratio% below the stoploss. Your stoploss value will not change - but the limit order will be at -4% (assuming you set stoploss_on_exchange_limit_ratio=0.01).

If you set this to 10% (0.10) - you're effectively saying you're willing to accept a max. loss of 13% (if the order is not filled then, it'd be a "stuck" order until price returns to this value). Now in normal instances, it'll fill at around 3.1% (similar to a stop market order).

as the limit price is (in all normal instances) below the current ob prices - you'll get a so-called marketable order - so it'll fill as if it were a market order - at the limit price *or better.


Funnily, you mentioned binance before - where stop-market orders are not available - so most likely, you're using this concept already - it's just that ftx (currently) provides both stop-market and stop-limit - which makes a difference then.

darioneto commented 2 years ago

Ok, thanks for your time, I'd still prefer to set it as the market, but if that's not possible I will experiment with the limit and see how well it performs with larger amounts. As for the Binance config strategy, all orders are set as market and that seems to be working without issues somehow. I wasn't aware Binance is not supporting the market stop orders

xmatthias commented 2 years ago

on binance - if you're using stoploss on exchange - it'll be limit orders (no matter the configuration). The exchange notes do mention this about binance ;)

xmatthias commented 2 years ago

there's a fix after all - fixed in the latest develop.

darioneto commented 2 years ago

ok thanks for the update, I will test it out