I'm absolutely stumped on the right way to do this (let alone the best way).
I have a group of users with shared quantities of bitcoins. We collectively trade and share the profits each day (minus a small percentage which goes to me for the management).
I'm trying to build a system to accurately calculate profits and fees but I just can't figure out the way to do it.
These are the tables I've created in the mysql db:
tansactions: (this information is pulled from the exchange api)
users:
accounting:
In my mind, I was thinking I would run a nightly script that would calculate the percentage of each person's profits and record it to the accounting table for that day.
I was thinking the accounting table could look something like this with the nightly script:
Date Transaction Amount Person / System
1/02/2021 Deposit 0.10000000 Person 1
2/02/2021 Profit 0.00041235 System
3/02/2021 Profit 0.00032456 System
4/02/2021 Profit 0.00021435 System
5/02/2021 Deposit 0.13234000 Person 2
6/02/2021 Profit 0.00152390 System
7/02/2021 Profit 0.00143540 System
8/02/2021 Profit 0.00325476 System
9/02/2021 Profit 0.00462534 System
10/02/2021 Deposit 0.00432100 Person 2
11/02/2021 Deposit 0.00625300 Person 3
12/02/2021 Profit 0.00876000 System
13/02/2021 Profit 0.00453720 System
14/02/2021 Profit 0.00642620 System
15/02/2021 Profit 0.00754000 System
16/02/2021 Withdraw 0.00087640 Person 1
17/02/2021 Profit 0.00245300 System
18/02/2021 Withdraw 0.00032625 Person 2
19/02/2021 Profit 0.00134432 System
20/02/2021 Deposit 0.01234500 Person 3
I can't think of an easy way to calculate the profit daily...
Any guidance / advice / help would be greatly appreciated!
Figured this out..
In short, here are the loops (not the most efficient way but, it works)
foreach(user)
{
check initial deposit amount and date
make an array of every date since
foreach(date since)
{
check what the whole account did on that day
calculate this user's percentage on that day
if there is a withdraw / deposit, handle that too
}
}
vague but hopefully explains the logic.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.