freqtrade / freqtrade

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

Kraken balance incorrect for position #9880

Closed fritz-fritz closed 8 months ago

fritz-fritz commented 8 months ago

Describe your environment

Note: All issues other than enhancement requests will be closed without further comment if the above template is deleted or not filled out.

Describe the problem:

Bot is unable to place stop loss order as the exchange API is kicking back an error. It seems the balance of the position is out of whack with what is on the exchange.

Observed Results:

Relevant code exceptions or logs

Note: Please copy/paste text of the messages, no screenshots of logs please.

    "order_types": {
        "entry": "limit",
        "exit": "limit",
        "emergency_exit": "market",
        "force_entry": "market",
        "force_exit": "market",
        "stoploss": "market",
        "stoploss_on_exchange": true,
        "stoploss_on_exchange_interval": 60
    }
2024-02-27 09:03:42,006 - freqtrade.worker - INFO - Bot heartbeat. PID=1, version='2024.1', state='RUNNING'
2024-02-27 09:04:43,553 - freqtrade.worker - INFO - Bot heartbeat. PID=1, version='2024.1', state='RUNNING'
2024-02-27 09:05:54,540 - freqtrade.wallets - INFO - Wallets synced.
2024-02-27 09:05:54,541 - freqtrade.freqtradebot - INFO - Checking depth of market for STX/USD ...
2024-02-27 09:05:57,513 - freqtrade.freqtradebot - INFO - Bids: 39838.476, Asks: 34896.433, Delta: 1.1416202911053976, Direction: longBid Price: 3.1164, Ask Price: 3.1192, Immediate Bid Quantity: 8.045, Immediate Ask Quantity: 78.0.
2024-02-27 09:05:57,513 - freqtrade.freqtradebot - INFO - Bids to asks delta for STX/USD DOES satisfy condition.
2024-02-27 09:06:00,849 - freqtrade.freqtradebot - INFO - Long signal found: about create a new trade for STX/USD with stake_amount: 19.555767 ...
2024-02-27 09:06:01,095 - freqtrade.freqtradebot - INFO - Order O3SKMY-K5O4Q-TSVUJS was created for STX/USD and status is open.
2024-02-27 09:06:07,444 - freqtrade.wallets - INFO - Wallets synced.
2024-02-27 09:06:07,448 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'trade_id': 1, 'type': entry, 'buy_tag': 'enter1eworsi_', 'enter_tag': 'enter1eworsi_', 'exchange': 'Kraken', 'pair': 'STX/USD', 'leverage': 1.0, 'direction': 'Long', 'limit': 3.1165, 'open_rate': 3.1165, 'order_type': 'limit', 'stake_amount': 19.555767, 'stake_currency': 'USD', 'base_currency': 'STX', 'quote_currency': 'USD', 'fiat_currency': 'USD', 'amount': 6.2749132, 'open_date': datetime.datetime(2024, 2, 27, 14, 6, 1, 95344, tzinfo=datetime.timezone.utc), 'current_rate': 3.1165, 'sub_trade': False}
2024-02-27 09:06:07,453 - freqtrade.worker - INFO - Bot heartbeat. PID=1, version='2024.1', state='RUNNING'
2024-02-27 09:06:10,003 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=1, pair=STX/USD, amount=6.27491320, is_short=False, leverage=1.0, open_rate=3.11650000, open_since=2024-02-27 14:06:01)
2024-02-27 09:06:13,048 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=1, pair=STX/USD, amount=6.27491320, is_short=False, leverage=1.0, open_rate=3.11650000, open_since=2024-02-27 14:06:01)
2024-02-27 09:06:13,051 - freqtrade.freqtradebot - INFO - Fee for Trade Trade(id=1, pair=STX/USD, amount=6.27491320, is_short=False, leverage=1.0, open_rate=3.11650000, open_since=2024-02-27 14:06:01) [buy]: 0.03128923 USD - rate: 0.0016
2024-02-27 09:06:13,051 - freqtrade.persistence.trade_model - INFO - Updating trade (id=1) ...
2024-02-27 09:06:13,052 - freqtrade.persistence.trade_model - INFO - LIMIT_BUY has been fulfilled for Trade(id=1, pair=STX/USD, amount=6.27491320, is_short=False, leverage=1.0, open_rate=3.11650000, open_since=2024-02-27 14:06:01).
2024-02-27 09:06:22,086 - freqtrade.wallets - INFO - Wallets synced.
2024-02-27 09:06:22,088 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'trade_id': 1, 'type': entry_fill, 'buy_tag': 'enter1eworsi_', 'enter_tag': 'enter1eworsi_', 'exchange': 'Kraken', 'pair': 'STX/USD', 'leverage': 1.0, 'direction': 'Long', 'limit': 3.1165, 'open_rate': 3.1165, 'order_type': 'limit', 'stake_amount': 19.5557669878, 'stake_currency': 'USD', 'base_currency': 'STX', 'quote_currency': 'USD', 'fiat_currency': 'USD', 'amount': 6.2749132, 'open_date': datetime.datetime(2024, 2, 27, 14, 6, 1, 95344, tzinfo=datetime.timezone.utc), 'current_rate': 3.1165, 'sub_trade': False}
2024-02-27 09:06:22,576 - freqtrade.freqtradebot - WARNING - Unable to place stoploss order Insufficient funds to create market sell order on market STX/USD. Tried to sell amount 6.2749132 at rate None with stop-price 2.3811. Message: kraken {"error":["EOrder:Insufficient funds"]}.
2024-02-27 09:06:22,576 - freqtrade.freqtradebot - INFO - Trying to refind lost order for Trade(id=1, pair=STX/USD, amount=6.27491320, is_short=False, leverage=1.0, open_rate=3.11650000, open_since=2024-02-27 14:06:01)
2024-02-27 09:06:22,576 - freqtrade.freqtradebot - INFO - Trying to refind Order(id=1, trade=1, order_id=O3SKMY-K5O4Q-TSVUJS, side=buy, filled=6.2749132, price=3.1165, status=closed, date=2024-02-27 14:06:00)
2024-02-27 09:06:25,891 - freqtrade.freqtradebot - WARNING - Unable to place stoploss order Insufficient funds to create market sell order on market STX/USD. Tried to sell amount 6.2749132 at rate None with stop-price 2.5669. Message: kraken {"error":["EOrder:Insufficient funds"]}.
2024-02-27 09:06:25,891 - freqtrade.freqtradebot - INFO - Trying to refind lost order for Trade(id=1, pair=STX/USD, amount=6.27491320, is_short=False, leverage=1.0, open_rate=3.11650000, open_since=2024-02-27 14:06:01)
2024-02-27 09:06:25,891 - freqtrade.freqtradebot - INFO - Trying to refind Order(id=1, trade=1, order_id=O3SKMY-K5O4Q-TSVUJS, side=buy, filled=6.2749132, price=3.1165, status=closed, date=2024-02-27 14:06:00)
2024-02-27 09:06:30,704 - freqtrade.freqtradebot - WARNING - Unable to place stoploss order Insufficient funds to create market sell order on market STX/USD. Tried to sell amount 6.2749132 at rate None with stop-price 2.5669. Message: kraken {"error":["EOrder:Insufficient funds"]}.
2024-02-27 09:06:30,704 - freqtrade.freqtradebot - INFO - Trying to refind lost order for Trade(id=1, pair=STX/USD, amount=6.27491320, is_short=False, leverage=1.0, open_rate=3.11650000, open_since=2024-02-27 14:06:01)
2024-02-27 09:06:30,710 - freqtrade.freqtradebot - INFO - Trying to refind Order(id=1, trade=1, order_id=O3SKMY-K5O4Q-TSVUJS, side=buy, filled=6.2749132, price=3.1165, status=closed, date=2024-02-27 14:06:00)
2024-02-27 09:06:35,711 - freqtrade.freqtradebot - WARNING - Unable to place stoploss order Insufficient funds to create market sell order on market STX/USD. Tried to sell amount 6.2749132 at rate None with stop-price 2.5669. Message: kraken {"error":["EOrder:Insufficient funds"]}.

Purchase stx_purchase

Balance stx_balance

Manual recreate error stx_sell

Freqtrade Trade Details stx_freqtrade

fritz-fritz commented 8 months ago

Just an additional thought, perhaps it is an issue with dust. Perhaps the full amount is actually held on the exchange but that due to their precision rounding they won't allow trading it. I've ran into similar issues with Kraken before.

xmatthias commented 8 months ago

According to the limit provided by ccxt - the "amount" precision limit is 1e-08 - which is the precision limit we do place the order at (and afaik, also the limit that ccxt internally applies again) - and which will also be the precision stored in the database for this trade (field amount_precision).

From the ccxt markets output for this pair: image

If we assume that this precision limit is incorrect (it's not 1e-8, but 1e-5 - based on your screenshot) - then this is an error in the information provided by ccxt (which most likely, is sourcing this from the exchange). Having precision correct would mean that we'd round the price down to the appropriate level ... but that's not applied here - for (hopefully) obvious reasons.

Now it'd be strange (though not unheared of) to have the exchange report the amount at one precision - but then utilize it at another precision to place orders - but it'd be new to me that kraken is among these.

Looking at the https://api.kraken.com/0/public/AssetPairs endpoint - 1e-8 does seem correct though (lot-decimals = 8) - which would place such an error at the information the exchange provides - not with freqtrade or ccxt.

image

None of these infos is 5 (or 0.5) - which is the number of decimals you're seeing ... which points to this not being a rounding problem, really.

It could be fee dust - sure - but isn't - as your fees were paid in USD (see first screenshot). What does the freqtrade /balance report for this pair? (either freqUI or telegram) is it 6.2749132 - or 6.27491?

fritz-fritz commented 8 months ago

well, since this was posted, I left the bot running with the trade live and it appears to have exited the trade successfully due to ROI.

2024-02-28 02:24:52 WARNING freqtrade.freqtradebot - Unable to place stoploss order Insufficient funds to create market sell order on market STX/USD. Tried to sell amount 6.2749132 at rate None with stop-price 2.5702. Message: kraken {"error":["EOrder:Insufficient funds"]}.
2024-02-28 02:24:52 INFO    freqtrade.freqtradebot - Trying to refind lost order for Trade(id=1, pair=STX/USD, amount=6.27491320, is_short=False, leverage=1.0, open_rate=3.11650000, open_since=2024-02-27 14:06:01)
2024-02-28 02:24:52 INFO    freqtrade.freqtradebot - Trying to refind Order(id=1, trade=1, order_id=O3SKMY-K5O4Q-TSVUJS, side=buy, filled=6.2749132, price=3.1165, status=closed, date=2024-02-27 14:06:00)
2024-02-28 02:24:55 INFO    freqtrade.freqtradebot - Exit for STX/USD detected. Reason: roi
2024-02-28 02:25:01 INFO    freqtrade.wallets - Wallets synced.
2024-02-28 02:25:01 INFO    freqtrade.freqtradebot - STX/USD - Falling back to wallet-amount 6.27491 -> 6.2749132.
2024-02-28 02:25:02 INFO    freqtrade.rpc.rpc_manager - Sending rpc message: {'type': exit, 'trade_id': 1, 'exchange': 'Kraken', 'pair': 'STX/USD', 'leverage': 1.0, 'direction': 'Long', 'gain': 'profit', 'limit': 3.1399, 'order_rate': 3.1399, 'order_type': 'limit', 'amount': 6.27491, 'open_rate': 3.1165, 'close_rate': 3.1399, 'current_rate': 3.1399, 'profit_amount': 0.08400955, 'profit_ratio': 0.00428903, 'buy_tag': 'enter1eworsi_', 'enter_tag': 'enter1eworsi_', 'exit_reason': 'roi', 'open_date': datetime.datetime(2024, 2, 27, 14, 6, 1, 95344, tzinfo=datetime.timezone.utc), 'close_date': datetime.datetime(2024, 2, 28, 7, 25, 2, 298796, tzinfo=datetime.timezone.utc), 'stake_amount': 19.5557669878, 'stake_currency': 'USD', 'base_currency': 'STX', 'quote_currency': 'USD', 'fiat_currency': 'USD', 'sub_trade': False, 'cumulative_profit': 0.0, 'final_profit_ratio': None, 'is_final_exit': False}
2024-02-28 02:25:08 INFO    freqtrade.wallets - Wallets synced.
2024-02-28 02:25:08 INFO    freqtrade.worker - Bot heartbeat. PID=1, version='2024.1', state='RUNNING'
2024-02-28 02:25:58 INFO    freqtrade.freqtradebot - Found open order for Trade(id=1, pair=STX/USD, amount=6.27491000, is_short=False, leverage=1.0, open_rate=3.11650000, open_since=2024-02-27 14:06:01)
2024-02-28 02:25:58 INFO    freqtrade.freqtradebot - Fee for Trade Trade(id=1, pair=STX/USD, amount=6.27491000, is_short=False, leverage=1.0, open_rate=3.11650000, open_since=2024-02-27 14:06:01) [sell]: 0.03152414 USD - rate: 0.0016
2024-02-28 02:25:58 INFO    freqtrade.persistence.trade_model - Updating trade (id=1) ...
2024-02-28 02:25:58 INFO    freqtrade.persistence.trade_model - LIMIT_SELL has been fulfilled for Trade(id=1, pair=STX/USD, amount=6.27491000, is_short=False, leverage=1.0, open_rate=3.11650000, open_since=2024-02-27 14:06:01).
2024-02-28 02:25:58 INFO    freqtrade.persistence.trade_model - Marking Trade(id=1, pair=STX/USD, amount=0.00000320, is_short=False, leverage=1.0, open_rate=3.11650000, open_since=closed) as closed as the trade is fulfilled and found no open orders for it.
2024-02-28 02:26:04 INFO    freqtrade.wallets - Wallets synced.
2024-02-28 02:26:04 INFO    freqtrade.rpc.rpc_manager - Sending rpc message: {'type': exit_fill, 'trade_id': 1, 'exchange': 'Kraken', 'pair': 'STX/USD', 'leverage': 1.0, 'direction': 'Long', 'gain': 'profit', 'limit': 3.1399, 'order_rate': 3.1399, 'order_type': 'limit', 'amount': 3.2e-06, 'open_rate': 3.1165, 'close_rate': 3.1399, 'current_rate': None, 'profit_amount': 4e-08, 'profit_ratio': 0.00428955, 'buy_tag': 'enter1eworsi_', 'enter_tag': 'enter1eworsi_', 'exit_reason': 'roi', 'open_date': datetime.datetime(2024, 2, 27, 14, 6, 1, 95344, tzinfo=datetime.timezone.utc), 'close_date': datetime.datetime(2024, 2, 28, 7, 25, 58, 905000, tzinfo=datetime.timezone.utc), 'stake_amount': 9.9728e-06, 'stake_currency': 'USD', 'base_currency': 'STX', 'quote_currency': 'USD', 'fiat_currency': 'USD', 'sub_trade': False, 'cumulative_profit': 0.08401954, 'final_profit_ratio': 0.0042895440273327335, 'is_final_exit': True}
2024-02-28 02:26:04 INFO    cooldown_period - Cooldown for STX/USD for 5 candles.
2024-02-28 02:26:04 INFO    freqtrade.rpc.rpc_manager - Sending rpc message: {'type': protection_trigger, 'base_currency': 'STX', 'id': 2, 'pair': 'STX/USD', 'lock_time': '2024-02-28 07:26:04', 'lock_timestamp': 1709105164953, 'lock_end_time': '2024-02-28 07:55:00', 'lock_end_timestamp': 1709106900000, 'reason': 'Cooldown period for 5 candles.', 'side': '*', 'active': True}
2024-02-28 02:26:09 INFO    freqtrade.worker - Bot heartbeat. PID=1, version='2024.1', state='RUNNING'
2024-02-28 02:27:09 INFO    freqtrade.worker - Bot heartbeat. PID=1, version='2024.1', state='RUNNING'
2024-02-28 02:28:09 INFO    freqtrade.worker - Bot heartbeat. PID=1, version='2024.1', state='RUNNING'

Though fortunately it has re-entered and so I can get you the logs you requested.

2024-02-28 04:25:10 INFO    freqtrade.wallets - Adjusted stake amount for pair STX/USD is more than 30% bigger than the desired stake amount of (6.54630900 * 1.3 = 8.51020170) < 10.18017), ignoring trade.
2024-02-28 04:26:03 INFO    freqtrade.wallets - Wallets synced.
2024-02-28 04:26:03 INFO    freqtrade.freqtradebot - Checking depth of market for STX/USD ...
2024-02-28 04:26:06 INFO    freqtrade.freqtradebot - Bids: 41855.761999999995, Asks: 29753.92, Delta: 1.4067310122498144, Direction: longBid Price: 3.2394, Ask Price: 3.2401, Immediate Bid Quantity: 1807.905, Immediate Ask Quantity: 45.809.
2024-02-28 04:26:06 INFO    freqtrade.freqtradebot - Bids to asks delta for STX/USD DOES satisfy condition.
2024-02-28 04:26:09 INFO    freqtrade.freqtradebot - Long signal found: about create a new trade for STX/USD with stake_amount: 19.638927 ...
2024-02-28 04:26:09 INFO    freqtrade.freqtradebot - Order OMKHGS-37OIA-XSC5LU was created for STX/USD and status is open.
2024-02-28 04:26:15 INFO    freqtrade.wallets - Wallets synced.
2024-02-28 04:26:15 INFO    freqtrade.rpc.rpc_manager - Sending rpc message: {'trade_id': 2, 'type': entry, 'buy_tag': 'enter1eworsi_', 'enter_tag': 'enter1eworsi_', 'exchange': 'Kraken', 'pair': 'STX/USD', 'leverage': 1.0, 'direction': 'Long', 'limit': 3.2394, 'open_rate': 3.2394, 'order_type': 'limit', 'stake_amount': 19.638927, 'stake_currency': 'USD', 'base_currency': 'STX', 'quote_currency': 'USD', 'fiat_currency': 'USD', 'amount': 6.06251991, 'open_date': datetime.datetime(2024, 2, 28, 9, 26, 9, 718796, tzinfo=datetime.timezone.utc), 'current_rate': 3.2394, 'sub_trade': False}
2024-02-28 04:26:15 INFO    freqtrade.worker - Bot heartbeat. PID=1, version='2024.1', state='RUNNING'
2024-02-28 04:26:18 INFO    freqtrade.freqtradebot - Found open order for Trade(id=2, pair=STX/USD, amount=6.06251991, is_short=False, leverage=1.0, open_rate=3.23940000, open_since=2024-02-28 09:26:09)
2024-02-28 04:26:21 INFO    freqtrade.freqtradebot - Found open order for Trade(id=2, pair=STX/USD, amount=6.06251991, is_short=False, leverage=1.0, open_rate=3.23940000, open_since=2024-02-28 09:26:09)
2024-02-28 04:26:21 INFO    freqtrade.freqtradebot - Fee for Trade Trade(id=2, pair=STX/USD, amount=6.06251991, is_short=False, leverage=1.0, open_rate=3.23940000, open_since=2024-02-28 09:26:09) [buy]: 0.03142228 USD - rate: 0.0016
2024-02-28 04:26:21 INFO    freqtrade.persistence.trade_model - Updating trade (id=2) ...
2024-02-28 04:26:21 INFO    freqtrade.persistence.trade_model - LIMIT_BUY has been fulfilled for Trade(id=2, pair=STX/USD, amount=6.06251991, is_short=False, leverage=1.0, open_rate=3.23940000, open_since=2024-02-28 09:26:09).
2024-02-28 04:26:30 INFO    freqtrade.wallets - Wallets synced.
2024-02-28 04:26:30 INFO    freqtrade.rpc.rpc_manager - Sending rpc message: {'trade_id': 2, 'type': entry_fill, 'buy_tag': 'enter1eworsi_', 'enter_tag': 'enter1eworsi_', 'exchange': 'Kraken', 'pair': 'STX/USD', 'leverage': 1.0, 'direction': 'Long', 'limit': 3.2394, 'open_rate': 3.2394, 'order_type': 'limit', 'stake_amount': 19.638926996454, 'stake_currency': 'USD', 'base_currency': 'STX', 'quote_currency': 'USD', 'fiat_currency': 'USD', 'amount': 6.06251991, 'open_date': datetime.datetime(2024, 2, 28, 9, 26, 9, 718796, tzinfo=datetime.timezone.utc), 'current_rate': 3.2394, 'sub_trade': False}
2024-02-28 04:26:31 INFO    freqtrade.exchange.exchange - stoploss market order added for STX/USD. stop price: 2.475. limit: None
2024-02-28 04:27:32 INFO    VolatilityFilter - Removed EUR/USD from whitelist, because volatility over 10 days is: 0.011 which is not in the configured range of 0.05-9223372036854775807.
2024-02-28 04:27:32 INFO    freqtrade.plugins.pairlistmanager - Whitelist with 15 pairs: ['BTC/USD', 'ETH/USD', 'SOL/USD', 'DOGE/USD', 'XRP/USD', 'INJ/USD', 'FIL/USD', 'GALA/USD', 'MATIC/USD', 'DOT/USD', 'NEAR/USD', 'PEPE/USD', 'STX/USD', 'ADA/USD', 'SEI/USD']
2024-02-28 04:27:33 INFO    freqtrade.freqtradebot - Cancelling current stoploss on exchange for pair STX/USD (orderid:ONDHUR-6NURR-6RNYLB) in order to add another one ...
2024-02-28 04:27:33 INFO    freqtrade.freqtradebot - Cancelling stoploss on exchange for Trade(id=2, pair=STX/USD, amount=6.06251991, is_short=False, leverage=1.0, open_rate=3.23940000, open_since=2024-02-28 09:26:09)
2024-02-28 04:27:36 INFO    freqtrade.exchange.exchange - stoploss market order added for STX/USD. stop price: 2.6681. limit: None
2024-02-28 04:27:39 INFO    freqtrade.worker - Bot heartbeat. PID=1, version='2024.1', state='RUNNING'
2024-02-28 04:28:40 INFO    freqtrade.worker - Bot heartbeat. PID=1, version='2024.1', state='RUNNING'
2024-02-28 04:29:40 INFO    freqtrade.worker - Bot heartbeat. PID=1, version='2024.1', state='RUNNING'
$ docker exec -it freqtrade python3 scripts/rest_client.py --config user_data/config.json balance
{
    "currencies":
    [
        {
            "currency": "XMR",
            "free": 0.37523,
            "balance": 0.37523,
            "used": 0.0,
            "bot_owned": 0.0,
            "est_stake": 52.6147506,
            "est_stake_bot": 0.0,
            "stake": "USD",
            "side": "long",
            "leverage": 1.0,
            "is_position": false,
            "position": 0.0,
            "is_bot_managed": false
        },
        {
            "currency": "USD",
            "free": 0.167,
            "balance": 0.167,
            "used": 0.0,
            "bot_owned": -0.031059269964536895,
            "est_stake": 0.167,
            "est_stake_bot": -0.031059269964536895,
            "stake": "USD",
            "side": "long",
            "leverage": 1.0,
            "is_position": false,
            "position": 0.0,
            "is_bot_managed": true
        },
        {
            "currency": "STX",
            "free": 9.000000034120603E-8,
            "balance": 6.06252,
            "used": 6.06251991,
            "bot_owned": 6.06251991,
            "est_stake": 19.079962944000002,
            "est_stake_bot": 19.079962660752,
            "stake": "USD",
            "side": "long",
            "leverage": 1.0,
            "is_position": false,
            "position": 0.0,
            "is_bot_managed": true
        }
    ],
    "total": 71.861713544,
    "total_bot": 19.048903390787462,
    "symbol": "USD",
    "value": 71.861713544,
    "value_bot": 19.048903390787462,
    "stake": "USD",
    "note": "",
    "starting_capital": 19.721907456454,
    "starting_capital_ratio": -0.03412469443701294,
    "starting_capital_pct": -3.41,
    "starting_capital_fiat": 19.721907456454,
    "starting_capital_fiat_ratio": -0.03412469443701294,
    "starting_capital_fiat_pct": -3.41
}
$ docker exec -it freqtrade python3 scripts/rest_client.py --config user_data/config.json trades 
{
    "trades":
    [
        {
            "trade_id": 1,
            "pair": "STX/USD",
            "base_currency": "STX",
            "quote_currency": "USD",
            "is_open": false,
            "exchange": "kraken",
            "amount": 0.0000032,
            "amount_requested": 6.2749132,
            "stake_amount": 0.00000997,
            "max_stake_amount": 19.55576699,
            "strategy": "EI3v2_tag_cofi_green",
            "enter_tag": "enter1eworsi_",
            "timeframe": 5,
            "fee_open": 0.0016,
            "fee_open_cost": 1.595648E-8,
            "fee_open_currency": "USD",
            "fee_close": 0.0016,
            "fee_close_cost": 0.03152414,
            "fee_close_currency": "USD",
            "open_date": "2024-02-27 14:06:01",
            "open_timestamp": 1709042761095,
            "open_rate": 3.1165,
            "open_rate_requested": 3.1165,
            "open_trade_value": 0.00000999,
            "close_date": "2024-02-28 07:25:58",
            "close_timestamp": 1709105158905,
            "realized_profit": 0.08401954,
            "realized_profit_ratio": 0.0042895440273327335,
            "close_rate": 3.1399,
            "close_rate_requested": 3.1399,
            "close_profit": 0.0042895440273327335,
            "close_profit_pct": 0.43,
            "close_profit_abs": 0.08401954,
            "trade_duration_s": 62397,
            "trade_duration": 1039,
            "profit_ratio": 0.0042895440273327335,
            "profit_pct": 0.43,
            "profit_abs": 0.08401954,
            "exit_reason": "roi",
            "exit_order_status": "closed",
            "stop_loss_abs": 2.5702,
            "stop_loss_ratio": -0.17531010650332568,
            "stop_loss_pct": -17.53101065033257,
            "stoploss_order_id": null,
            "stoploss_last_update": null,
            "stoploss_last_update_timestamp": null,
            "initial_stop_loss_abs": 2.3811,
            "initial_stop_loss_ratio": -0.236,
            "initial_stop_loss_pct": -23.599999999999998,
            "min_rate": 2.8668,
            "max_rate": 3.1399,
            "leverage": 1.0,
            "interest_rate": 0.0,
            "liquidation_price": null,
            "is_short": false,
            "trading_mode": "spot",
            "funding_fees": 0.0,
            "amount_precision": 1E-8,
            "price_precision": 0.0001,
            "precision_mode": 4,
            "contract_size": 1.0,
            "has_open_orders": false,
            "orders":
            [
                {
                    "amount": 6.2749132,
                    "safe_price": 3.1165,
                    "ft_order_side": "buy",
                    "order_filled_timestamp": 1709042773048,
                    "ft_is_entry": true,
                    "pair": "STX/USD",
                    "order_id": "O3SKMY-K5O4Q-TSVUJS",
                    "status": "closed",
                    "average": 3.1165,
                    "cost": 19.5557669878,
                    "filled": 6.2749132,
                    "is_open": false,
                    "order_date": "2024-02-27 14:06:00",
                    "order_timestamp": 1709042760931,
                    "order_filled_date": "2024-02-27 14:06:13",
                    "order_type": "limit",
                    "price": 3.1165,
                    "remaining": 0.0,
                    "ft_fee_base": null,
                    "funding_fee": 0.0
                },
                {
                    "amount": 6.27491,
                    "safe_price": 3.1399,
                    "ft_order_side": "sell",
                    "order_filled_timestamp": 1709105158905,
                    "ft_is_entry": false,
                    "pair": "STX/USD",
                    "order_id": "OKDZ6I-E5AWI-LLIGE4",
                    "status": "closed",
                    "average": 3.1399,
                    "cost": 19.702589909,
                    "filled": 6.27491,
                    "is_open": false,
                    "order_date": "2024-02-28 07:25:01",
                    "order_timestamp": 1709105101950,
                    "order_filled_date": "2024-02-28 07:25:58",
                    "order_type": "limit",
                    "price": 3.1399,
                    "remaining": 0.0,
                    "ft_fee_base": null,
                    "funding_fee": 0.0
                }
            ]
        }
    ],
    "trades_count": 1,
    "offset": 0,
    "total_trades": 1
}

Curiously, the bot had no trouble here placing the stoploss this time. I'm not sure what to make of this. Clearly however, theres some logic "falling back to wallet-amount" that occurred before it placed the sell order.

xmatthias commented 8 months ago

well that 2nd trade is unfortunately no longer interesting - but kinda confirms what i said above.

6.06251991 is clearly at 8 decimals (aligned with the precision of the pair in the ccxt response). that also makes the /balance response pointless - as it's now for a "correct" trade.


STX/USD - Falling back to wallet-amount 6.27491 -> 6.2749132. is some fallback method if the amount in the wallet is below the actual amount. More telling is the line before that - "Trying to refind lost order" - which is the fallback method in case something goes wrong.

Now the exchange Orders did still report an amount of 6.2749132 for this order - with the fee having been paid in USD. That value also aligns with the result of cost / price (or 19.5557669878 / 3.1165) - so that IS the correct value.

Why you don't have that amount in your wallet is beyond me - but i don't think something freqtrade will be able to fix (this seems to be an exchange oddity if you ask me).

Can you provide me with the raw response for the initial buy order?

import ccxt
exchange = ccxt.kraken({
    'apiKey': '<yourApiKey>', 
    'secret': '<yoursecret>'
    })
res = exchange.fetch_order('O3SKMY-K5O4Q-TSVUJS', 'STX/USD')
print(res)

We'll see what this says ... but i fear it'll confirm what i'm saying / suspecting ...

fritz-fritz commented 8 months ago

Yup, I'm following ya.

$ docker exec -it freqtrade python3 user_data/debug.py
{
    "id": "O3SKMY-K5O4Q-TSVUJS",
    "clientOrderId": "0",
    "info":
    {
        "id": "O3SKMY-K5O4Q-TSVUJS",
        "refid": None,
        "userref": "0",
        "status": "closed",
        "opentm": "1709042760.9312103",
        "starttm": "0",
        "expiretm": "0",
        "descr":
        {
            "pair": "STXUSD",
            "type": "buy",
            "ordertype": "limit",
            "price": "3.1165",
            "price2": "0",
            "leverage": "none",
            "order": "buy 6.27491320 STXUSD @ limit 3.1165",
            "close": ""
        },
        "vol": "6.27491320",
        "vol_exec": "6.27491320",
        "cost": "19.55576699",
        "fee": "0.03128923",
        "price": "3.1165",
        "stopprice": "0.00000000",
        "limitprice": "0.00000000",
        "misc": "",
        "oflags": "post,fciq",
        "trades":
        [
            "TWVJCV-5K5WQ-BFET3N"
        ],
        "reason": None,
        "closetm": "1709042772.7537236"
    },
    "timestamp": 1709042760931,
    "datetime": "2024-02-27T14:06:00.931Z",
    "lastTradeTimestamp": None,
    "status": "closed",
    "symbol": "STX/USD",
    "type": "limit",
    "timeInForce": "PO",
    "postOnly": True,
    "side": "buy",
    "price": 3.1165,
    "stopPrice": None,
    "triggerPrice": None,
    "takeProfitPrice": None,
    "stopLossPrice": None,
    "cost": 19.5557669878,
    "amount": 6.2749132,
    "filled": 6.2749132,
    "average": 3.1165,
    "remaining": 0.0,
    "fee":
    {
        "cost": "0.03128923",
        "rate": None,
        "currency": "USD"
    },
    "trades":
    [
        {
            "id": "TWVJCV-5K5WQ-BFET3N",
            "orderId": "O3SKMY-K5O4Q-TSVUJS",
            "symbol": "STX/USD",
            "info":
            {},
            "fees":
            [],
            "amount": None,
            "price": None,
            "cost": None,
            "fee":
            {
                "cost": None
            }
        }
    ],
    "fees":
    [
        {
            "cost": 0.03128923,
            "rate": None,
            "currency": "USD"
        }
    ],
    "lastUpdateTimestamp": None,
    "reduceOnly": None
}

Clearly, the full amount was filled in the purchase and should have been found. Could it have been a timing issue? I feel like the logging for the placement of the stoploss leaves a little to be desired here.

I guess unless you have other thoughts this might have just been a temporary API issue with the exchange? If you concur feel free to close.

xmatthias commented 8 months ago

That's correct - 6.2749132 was filled - but your balance did truncate that to 6.27491 - aligned between exchange UI and bot / api responses (this disconnect causes the "Falling back to wallet-amount" message).

Timing has nothing to do with this, really - but rather inconsistent API responses.

If i were you, i'd take this up with kraken support - as it seems like they "bill" you for full amount - but then "take" .xx32 out of the wallet. this can be fees - but wasn't - as the UI is showing (Fees were paid in USD).

xmatthias commented 8 months ago

I'd be interested to hear what the kraken support said about this case though ... so maybe you can update me on that if you did open an issue and they did get back to you on it with anything useful ...

keithorange commented 8 months ago

That's correct - 6.2749132 was filled - but your balance did truncate that to 6.27491 - aligned between exchange UI and bot / api responses (this disconnect causes the "Falling back to wallet-amount" message).

Timing has nothing to do with this, really - but rather inconsistent API responses.

If i were you, i'd take this up with kraken support - as it seems like they "bill" you for full amount - but then "take" .xx32 out of the wallet. this can be fees - but wasn't - as the UI is showing (Fees were paid in USD).

WOW! @xmatthias this may be a big discovery! Is it similar to the siphon tool from "Office Space" that takes a ~0.00001 of a transaction and hopefully nobody notices? Can you elaborate on what you found? I think it's very important and may be a very powerful piece of information to trade on or create a short sell on.

keithorange commented 8 months ago

@xmatthias @fritz-fritz I also am having a similar issue.

Tried to sell amount 1385.1854417 at rate None with stop-price 0.29909. Message: kraken {"error":["EOrder:Insufficient funds"]}. and Unable to place stoploss order Insufficient funds to create market sell order on market

I am using Kraken and setting stop-loss orders via custom stoploss (its a custom Trailing Stop Loss). It works 95% of the time, but sometimes it doesn't, and this time, it didn't even move stoploss on exchange!

My question is, Are there settings or configurations for FreqTrade i can set to help me here? For making orders, and this particular case with Kraken?

Thanks!

keithorange commented 8 months ago

@xmatthias @fritz-fritz I also am having a similar issue.

Tried to sell amount 1385.1854417 at rate None with stop-price 0.29909. Message: kraken {"error":["EOrder:Insufficient funds"]}. and Unable to place stoploss order Insufficient funds to create market sell order on market

I am using Kraken and setting stop-loss orders via custom stoploss (its a custom Trailing Stop Loss). It works 95% of the time, but sometimes it doesn't, and this time, it didn't even move stoploss on exchange!

My question is, Are there settings or configurations for FreqTrade i can set to help me here? For making orders, and this particular case with Kraken?

Thanks!

I think you can set stoploss_on_exchange_limit to 0.99 or 0.9999 and it will maybe bring up fill rate from 95% to 99%. `stoploss_on_exchange and stoploss_on_exchange_limit_ratio

Enable or Disable stop loss on exchange. If the stoploss is on exchange it means a stoploss limit order is placed on the exchange immediately after buy order fills. This will protect you against sudden crashes in market, as the order execution happens purely within the exchange, and has no potential network overhead.

If stoploss_on_exchange uses limit orders, the exchange needs 2 prices, the stoploss_price and the Limit price. stoploss defines the stop-price where the limit order is placed - and limit should be slightly below this. If an exchange supports both limit and market stoploss orders, then the value of stoploss will be used to determine the stoploss type.

Calculation example: we bought the asset at 100$. Stop-price is 95$, then limit would be 95 * 0.99 = 94.05$ - so the limit order fill can happen between 95$ and 94.05$.

For example, assuming the stoploss is on exchange, and trailing stoploss is enabled, and the market is going up, then the bot automatically cancels the previous stoploss order and puts a new one with a stop value higher than the previous stoploss order.`

xmatthias commented 8 months ago

Please don't force-ping people at random (especially not 3 times in a row), with information that's irrelevant to the topic at hand. People involved in the discussion will be auto-subscribed - but please leave it up to them to receive notifications or not.

Can you elaborate on what you found? what is written above. It's also not a find - just something someone reported. confirmation (and on what support says to this behavior) is outstanding / wasn't provided. given that it didn't happen to my account - there's also nothing to talk to with support, either (i wasn't the one they potentially took fractions of a coin from).

I think it's very important and may be a very powerful piece of information to trade on or create a short sell on.

Not really - i'd not see how you can exploit the fact that you buy 1.2345 - and only get 1.23 coins.

I think you can set stoploss_on_exchange_limit to 0.99 or 0.9999 and it will maybe bring up fill rate from 95% to 99%. `stoploss_on_exchange and stoploss_on_exchange_limit_ratio

I'm not sure what you're trying to do here. This issue is neither about stop orders - nor is copy/pasting the information from the documentation going to be helpful.

This is setting about stop limit orders - defining the gap between the stop order - and the limit price (The worst price you're willing to accept). decreasing the gap from 1% to 0.01% will decrease your fill rate drastically (your stop triggers at 95$ - your worst sell order price is at 94.05$ - or at 94.99$ guess which one fills easier?).