Implement code to make a price evolve based on the buy/ sell system

Hello community !

I have an issue to finalize my fantasy trading platform. I started few months ago on FlutterFlow and I'm stuck since few days.

So I created a free game where you can buy and sell shares of sportsmen. But I want to build a control market with rules (because it's just a game and I want to make it entertained).

For every 100 shares sell, I want the price to go down by 1% and for every 100 shares bought, I want the price to go down by 1%.

On my Firebase database, I have created a "transaction" table where you have the complete list of "buy" and "sell" shares by players. And on the "Player" table you have the "initial_price" (configure by myself", the "net_transaction_count" that counts the "buy-sell" on a player and the "current_price" that shows the price changed based on the number of buy and sell.

So I have 2 issues:

  • How I can count "buy - sell" on my player table for each player ? For example a user buy 250 shares then another user sell 50 shares. So I want my "net_transaction_count" = 200 (250 - 50). And to each "buy" or "sell" this amount evolve.

  • And then, How I can create the rules where to every 100 shares bought or sold the initial price evolve to +/- 1%. I think it's in custome code but I don't know how I can implement it and make it works.

Don't hesitate if you have a better idea or if you have any questions.

Thanks a lot in advance πŸ˜„

1
6 replies