generated from lucien/api-template
Added companies and shareholders main loop
This commit is contained in:
parent
8f11c56d1a
commit
b002d0d730
4 changed files with 32 additions and 22 deletions
|
@ -45,6 +45,10 @@ router.post('/buy', async (req, res) => {
|
||||||
return res.status(500).send({message: "This shareholder already owns that share."})
|
return res.status(500).send({message: "This shareholder already owns that share."})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shareholder[0].capital < price) {
|
||||||
|
return res.status(500).send({message: "Insufficient founds."})
|
||||||
|
}
|
||||||
|
|
||||||
await addTransaction(connection, price, share[0].owner_id, buyer_id, share_id)
|
await addTransaction(connection, price, share[0].owner_id, buyer_id, share_id)
|
||||||
await setShareOwner(connection, share_id, buyer_id)
|
await setShareOwner(connection, share_id, buyer_id)
|
||||||
if (share[0].owner != -1) {
|
if (share[0].owner != -1) {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import requests
|
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
|
"""Affichage des actions mises en vente par une entreprise
|
||||||
input :
|
input :
|
||||||
|
@ -38,5 +40,13 @@ def getCompanies():
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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)
|
||||||
|
|
||||||
|
|
|
@ -6,23 +6,9 @@ services:
|
||||||
networks:
|
networks:
|
||||||
- bourse
|
- bourse
|
||||||
|
|
||||||
shareholder1:
|
shareholders:
|
||||||
build: ./shareholder
|
build: ./shareholder
|
||||||
container_name: shareholder1
|
container_name: shareholders
|
||||||
restart: always
|
|
||||||
networks:
|
|
||||||
- bourse
|
|
||||||
|
|
||||||
shareholder2:
|
|
||||||
build: ./shareholder
|
|
||||||
container_name: shareholder2
|
|
||||||
restart: always
|
|
||||||
networks:
|
|
||||||
- bourse
|
|
||||||
|
|
||||||
shareholder3:
|
|
||||||
build: ./shareholder
|
|
||||||
container_name: shareholder3
|
|
||||||
restart: always
|
restart: always
|
||||||
networks:
|
networks:
|
||||||
- bourse
|
- bourse
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
import requests
|
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
|
"""Achat d'une action par un actionnaire à une entreprise
|
||||||
input :
|
input :
|
||||||
- idBuyer : identifiant de l'actionnaire
|
- idBuyer : identifiant de l'actionnaire
|
||||||
- idShare : identifiant de l'action
|
- idShare : identifiant de l'action
|
||||||
"""
|
"""
|
||||||
def buyShare(idBuyer, idShare):
|
def buyShare(idBuyer, idShare, price):
|
||||||
url = HOST + 'api/shares/buy'
|
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)
|
r = requests.post(url, json=obj)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
@ -53,5 +55,13 @@ def getAllBuyers():
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue