CoinRoster / slotmachine

fruitgame
0 stars 0 forks source link

Account page investment balance appears incorrect #37

Closed Patrick-Bay closed 6 years ago

Patrick-Bay commented 6 years ago

After a deposit or withdrawal the book and current values for the bankroll investment match (this is incorrect!)

In addition, the available balance field does not match the balance listed in the transaction history (note the difference in risk@riskingtime.com account). It seems that in this example the balance is not accounting for the system withdrawal.

Patrick-Bay commented 6 years ago

After some investigation I estimate that this task will take up to 3 hours to fix.

To begin with I will need to look at the rpc_getInvestorInfo in the investment plugin to see where the information is being retrieved from (or possibly calculated). Coordinated with this may be some changes to the `buildInvestmentsTable" function in the account page script.

Finally, the value being returned for the available balance will need to be confirmed with the one that's being returned by the rpc_getAccountTransactions function in the main game server code (and updated if necessary).

RiskingTime commented 6 years ago

ok please proceed

Patrick-Bay commented 6 years ago

Fix for these issues has been committed (https://github.com/CoinRoster/slotmachine/commit/33cf14690304a69fd145ee38bd64b5503b317fe6), pulled to the development server, and may be tested immediately.

As part of this update a new value is being stored with investment transactions (user_investment_exclude_btc), which tracks investment deposits or withdrawals that are excluded from the user's total (active) investment balance. The dividend payment functionality has been updated to reset this value when it is included in the user's total investment balance.

RiskingTime commented 6 years ago

ok I'll review

RiskingTime commented 6 years ago

investment_balance_20180410

RiskingTime commented 6 years ago

see image in the thread, book value is 0.1 but current value is 0, this should be impossible unless the bankroll looses so much it goes to zero (which in this case it has not)

RiskingTime commented 6 years ago

also the change column is wrong, showing -0.1

RiskingTime commented 6 years ago

image

RiskingTime commented 6 years ago

similar issues with my other account, I withdrew 0.25, in-game balance updated accurately, and the book value showing updating accurately, but the current value of the investment did not change, and the change column shows 0.25

Patrick-Bay commented 6 years ago

As a review from our phone convo:

A deposit is simply reflected in (added to) both the book value and current value.

A withdrawal is done on a proportional basis for the book value and directly subtracted from the current value. The proportion for the amount to subtract from the book value is:

*withdrawal_amount (book_value / current_value)**

For example, if our book value is 0.34 and our current value is 0.54 and we withdraw 0.26 (about 63% of the current value), we should subtract 0.26 * (0.34 / 0.54), or 0.16 from the book value.

I'll make the appropriate changes to the investment plugin to reflect this.

RiskingTime commented 6 years ago

yes, please proceed

RiskingTime commented 6 years ago

hi patrick, I think the formula is actually= amount of withdrawal / current value of investment ) * cost base = the amount to withdraw from the cost base

if a user withdrawals 0.2 btc from a market value of 1 with a cost base of 0.5, then the cost base goes down by 20% of 0.5 = 0.1 removed from the cost base. in this case, withdrawing 1 would result in a decrease of the entire amount of the market value and also the entire amount of the cost base.

RiskingTime commented 6 years ago

when investment withdrawals are made, the change in the cost base is proportional to the change in the market value. So if the amount withdrawn represented 20% of the market value, then the cost base should also decrease by this portion (20%) although the amounts will be different (if the bankroll is up, the amount from the cost base with be lower, and if down it will be higher i think).

Also, we are breaking new ground, nobody has ever done this before!!!

Patrick-Bay commented 6 years ago

Is it possible that our equations are identities (I believe this is the term)? I calculated the same withdrawal amount as you with my formula.

Nevertheless, the latest update (https://github.com/CoinRoster/slotmachine/commit/aba4ce31acd983a83c8e691e8e827d63d299db4d) reflects your most recent feedback and is now running live on the server, available for testing.

RiskingTime commented 6 years ago

let's review this on Wednesday when we meet to confirm this is complete