generated from lucien/api-template
67 lines
1.8 KiB
Python
67 lines
1.8 KiB
Python
import requests
|
|
from time import sleep
|
|
from random import randint
|
|
|
|
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, price):
|
|
url = HOST + 'api/shares/buy'
|
|
obj={'id':idBuyer,'share_id':idShare, 'price': price}
|
|
r = requests.post(url, json=obj)
|
|
return r.json()
|
|
|
|
"""Affichage les actions possédées par un actionnaire
|
|
input :
|
|
- idBuyer : identifiant de l'actionnaire
|
|
"""
|
|
def getSharesOf(idBuyer):
|
|
url = HOST + 'api/shareholders/'+idBuyer+'/shares'
|
|
r = requests.get(url)
|
|
return r.json()
|
|
|
|
"""Affichage les informations d'une actions
|
|
input :
|
|
- idShare : identifiant de l'action
|
|
"""
|
|
def getShare(idShare):
|
|
url = HOST + 'api/shares/'+idShare
|
|
r = requests.get(url)
|
|
return r.json()
|
|
|
|
"""Affichage les actions en circulation sur le marché (possédées ou en vente) """
|
|
def getAllShares():
|
|
url = HOST + 'api/shares'
|
|
r = requests.get(url)
|
|
return r.json()
|
|
|
|
"""Affichage les informations sur un actionnaire
|
|
input :
|
|
- idBuyer : identifiant de l'actionnaire
|
|
"""
|
|
def getInfoBuyer(idBuyer):
|
|
url = HOST + 'api/shareholders/'+idBuyer
|
|
r=requests.get(url)
|
|
return r.json()
|
|
|
|
"""Affichage tous les actionnaires """
|
|
def getAllBuyers():
|
|
url = HOST + 'api/shareholders/'
|
|
r=requests.get(url)
|
|
return r.json()
|
|
|
|
if __name__ == "__main__":
|
|
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)
|
|
|