dashed-slug.net › Forums › Exchange extension support › Negative available balance after trade
Tagged: available balance, execution, matching engine, orderbook
- This topic has 10 replies, 2 voices, and was last updated 1 year, 6 months ago by alexg.
March 23, 2021 at 4:32 pm #10273
Hi, we set a trading fee (maker / taker default) why goes this amount from the aviable balance, after a filled trade? it is hard to explain for the user.March 24, 2021 at 7:30 am #10275
Thank you for your feedback.
This is not enough information for me to understand the issue you are facing, but here’s a few facts about the matching engine (maybe relevant):
– All fees are charged on the base currency, same as on all exchanges. The maker fee is the fee paid by the participant who placed the first limit order on the order book. The user who placed the second matching limit order, or a market order, pays the taker fee. This is again subtracted from the base currency balance.
– In both cases, the balance, and thus the available balance, of both users, decreases by the fees paid. This is to be expected.
– The exchange will only allow users to place an order that leaves them with positive balance, assuming that the largest of the two fees is paid (maker or taker).
– As the matching engine is running, if the base balance or quote balance of the user who places the order goes negative, the trade is cancelled and any trade is reverted.
The thread is titled “negative available balance”. To be clear, are you saying that, after users trade on the exchange, and without other manipulation of the DB, the users get negative available balances? If so, was there a problem with the balance of the market maker, or with the balance of the market taker?
Could you give me a complete example that I can follow, to reproduce the problem? If possible, please send me the following information:
1. Initial example base and quote balances of two hypothetical users.
2. What orders were placed? Let’s agree on some example amounts, prices, and also whether these were both limit orders, or a limit and a market order.
3. Go to Wallets -> Transactions. After a successful match, there should be four trade transactions related to the trade. Can I see these four rows?
4. What are the base and quote balances of the two users after the trade?
5. Does this occur on the unmodified latest version of the exchange?
Please test with the unmodified exchange, and that includes the templates and all other code in the exchange, parent plugin, and coin adapters. Better to do this on an integration server, not a production server.
I ask for all these details, because the last time we discussed a similar issue, I could not find a problem with the matching engine. I was also unable to spot any errors in the code.
If there is such a serious error, I need some more information to find it. I also ran some additional tests before writing this reply, and could not reproduce such an issue, so I don’t know where to look. Looking forward to your reply with additional details.
with regardsMarch 26, 2021 at 12:27 pm #10287
curoius .. i wanted to make some screenshoots to explain what i mean but actuall it seeems to be goodApril 8, 2021 at 9:40 am #10346
So now i can show you.
User did a trade and sell or buy some coins. Now he have an negavite aviable amount. Iam not sure how to rebuild this. Other User trades a lot and goes not negative
Attachments:You must be logged in to view attached files.April 9, 2021 at 6:44 am #10351
Thank you for the screenshot. I believe you, but unless I know what the user did I cannot reproduce the issue. This is why I insist on more data (see my posts above).
If I cannot reproduce the issue, I cannot solve it. I have attempted to reproduce the issue multiple times.
If you can send me all the user’s data in the
wp_wallets_txs, wp_wallets_orders and wp_wallets_trades tables, then I will be able to reproduce it and possibly understand what happened.
Another possibility is that you could manually deposit 60 satoshi to the user, and see if this happens again. Since you say that other users do not face the same problem, it could be a one-time thing, possibly dependent on to the data in the database.
with regardsApril 24, 2021 at 11:11 am #10434
I have looked at this again and can describe the incident better.
there are coin a and b. With coin b there are sales offers and it was triggered with coin a. The seller of b has now a negative aviable balance and i see no paied fee in the adapter listApril 26, 2021 at 7:24 am #10441
In continuation to our previous discussion,
Unfortunately this is even less information than before.
If you want me to look at this issue again, please provide at least one of the following two things:
1. Clear instructions on how to reproduce the issue
Please see points 1 – 5 at https://www.dashed-slug.net/forums/topic/negative-aviable-balance-after-trade/#post-10275
I would need to see the base and quote balances of both users before and after the transaction, AND a screenshot of the trades under “Wallets” -> “Transactions” at a minimum.
2. An SQL dump of the transaction and trade data for the two users.
For example, if the trade was between users 123 and 321 and between coins with tickers ABC and XYZ, you could issue the following into the MySQL console:
select * from wp_wallets_txs where account in (123,321) and symbol in ('ABC','XYZ');
select * from wp_wallets_orders where account in (123,321) and ( base_symbol in ('ABC','XYZ') or quote_symbol in ('ABC','XYZ') );
Do not worry about sharing personal data – there are none. The users here are just integer numbers. This is not going to be a GDPR problem.
If you can provide either one of the above, then I can investigate the issue again.
with regardsApril 27, 2021 at 9:09 am #10444
is this in the attachment what you need?
Attachments:You must be logged in to view attached files.April 28, 2021 at 3:52 am #10448
Thank you. This is part of the information I requested. Please see again my previous posts.
with regardsNovember 22, 2021 at 6:19 pm #11218
im sorry, but i need to come back to this again.
after an daemon crash (and wallet.dat corrupt (i recoverd with pywallet the keys) i setup daemon new. wallet is correct now.. but i have rd 172% coins in coldwallet now and one user have a very high negative balance). is there a way to solve that? Deposti on new created walletadress (for this user) works.November 23, 2021 at 6:15 am #11219
Is it possible that, during the crash, the wallet was not the only thing damaged?
User balances have nothing to do with the hot wallet. User balances are the sum of transactions on the plugin’s ledger, and this is stored in the MySQL table
Before you edit the transactions or add/remove transactions, you must understand what happened:
I recommend that you review that user’s transactions, using the SQL query:
SELECT FROM wp_wallets_txs WHERE status = 'done' AND account = <USER_ID>;
<USER_ID>with the user’s actual numeric ID.)
This will give you all the user’s transactions that affect their balance.
Review the transactions and you will understand why the balance is what it is.
If you believe that the MySQL table was damaged, then I’m afraid you must restore it from backup.
In summary: there is nothing in the hot wallet that affects user balances directly. Hot wallets simply notify the plugin about incoming deposits, and tell the plugin whether withdrawals are successful or not. The plugin maintains its own ledger on MySQL. Therefore, if a user’s balance is negative, that means that the sum of that user’s balances on your MySQL table adds up to a negative number. Maybe a deposit was deleted, or part of an Exchange trade was corrupted/deleted, or your site was possibly hacked.
Hope this helps. Let me know if you have any more questions about this.
- You must be logged in to reply to this topic.