Added companies and shareholders main loop

This commit is contained in:
Lukian 2024-12-29 14:52:50 +01:00
parent 8f11c56d1a
commit b002d0d730
4 changed files with 32 additions and 22 deletions

View file

@ -1,15 +1,17 @@
import requests
from time import sleep
from random import randint
HOST = "http://localhost:3000/"
HOST = "http://192.168.200.15/"
"""Achat d'une action par un actionnaire à une entreprise
input :
- idBuyer : identifiant de l'actionnaire
- idShare : identifiant de l'action
"""
def buyShare(idBuyer, idShare):
def buyShare(idBuyer, idShare, price):
url = HOST + 'api/shares/buy'
obj={'id':idBuyer,'share_id':idShare}
obj={'id':idBuyer,'share_id':idShare, 'price': price}
r = requests.post(url, json=obj)
return r.json()
@ -53,5 +55,13 @@ def getAllBuyers():
return r.json()
if __name__ == "__main__":
pass
while True:
shareholders = getAllBuyers()
shares = getAllShares()
for shareholder in shareholders:
shareId = randint(0, len(shares) - 1)
buyShare(shareholder["id"], shareId, shares[shareId][price] + randint(-20, 20))
sleep(30)