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,6 +1,8 @@
import requests
from time import sleep
from random import randint
HOST = "http://localhost:3000/"
HOST = "http://192.168.200.15/"
"""Affichage des actions mises en vente par une entreprise
input :
@ -38,5 +40,13 @@ def getCompanies():
return r.json()
if __name__ == "__main__":
pass
while True:
companies = getCompanies()
for company in companies:
price = randint(20, 2000)
for i in range(randint(0, 10)):
emmitShare(company["id"], price)
sleep(30)

View file

@ -6,23 +6,9 @@ services:
networks:
- bourse
shareholder1:
shareholders:
build: ./shareholder
container_name: shareholder1
restart: always
networks:
- bourse
shareholder2:
build: ./shareholder
container_name: shareholder2
restart: always
networks:
- bourse
shareholder3:
build: ./shareholder
container_name: shareholder3
container_name: shareholders
restart: always
networks:
- bourse

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)