remy 10 سال پیش
والد
کامیت
f2793e6319
14فایلهای تغییر یافته به همراه236 افزوده شده و 13 حذف شده
  1. 1 0
      Documents/.~lock.tableau.ods#
  2. BIN
      Documents/libelles.csv_1.ods
  3. 7 0
      Src/Partage.py
  4. 26 0
      Src/achatVente.py
  5. BIN
      Src/achatVente.pyc
  6. 10 6
      Src/recup.py
  7. BIN
      Src/recup.pyc
  8. 21 0
      Src/scanValeur.py
  9. BIN
      Src/scanValeur.pyc
  10. 88 3
      Src/test.py
  11. 22 0
      Src/timer.py
  12. BIN
      Src/timer.pyc
  13. 61 4
      Src/valeurs.py
  14. BIN
      Src/valeurs.pyc

+ 1 - 0
Documents/.~lock.tableau.ods#

@@ -0,0 +1 @@
+,rcluze,PC-ANGELIQUE1,12.07.2016 14:19,file:///home/rcluze/.config/libreoffice/4;

BIN
Documents/libelles.csv_1.ods


+ 7 - 0
Src/Partage.py

@@ -0,0 +1,7 @@
+from threading import RLock
+
+
+verrou = RLock()
+
+Vendre=[]
+Annulation=[]

+ 26 - 0
Src/achatVente.py

@@ -0,0 +1,26 @@
+from threading import Thread
+from valeurs import *
+
+
+class AchatVente(Thread):
+
+    def __init__(self, valeur,verrou):
+        Thread.__init__(self)
+        
+    def run(self):
+        i=0
+        gain =0.0 
+        while 1:
+			#~ with verrou:
+			if valeur[i].getAAnule == 1:
+				valeur[i].Anulation()
+			if valeur[i].getAVendre == 1:
+				gain=gain+valeur[i].Vente()
+			if getMise()==0:
+				valeur[i].Achat(25)
+			
+			print ("Gain : "+ str(gain))
+			time.sleep(0.4)
+			i=i+1
+			if i<39:
+				i=0

BIN
Src/achatVente.pyc


+ 10 - 6
Src/recup.py

@@ -1,12 +1,16 @@
 import urllib
 
 def recupfunc(add):
-	d = urllib.urlopen(add).read()
-	s= d.split("\n")
-	val = float(s[149].split('>')[1].split('<')[0])
-	var = float(s[152].split('>')[2].split('<')[0])
-	pou = float(s[153].split('(')[1].split('%')[0])
+	while 1:
+		try:
+			d = urllib.urlopen(add).read()
+			s= d.split("\n")
+			val = float(s[149].split('>')[1].split('<')[0])
+			var = float(s[152].split('>')[2].split('<')[0])
+			pou = float(s[153].split('(')[1].split('%')[0])
 
-	return [val,var,pou]
+			return [val,var,pou]
+		except:
+			print("erreur" +str(add))
 	
 #~ print (recup('https://www.google.com/finance?q=lhn&ei=DHF_V8GIEoi8UcP-nfgB'))

BIN
Src/recup.pyc


+ 21 - 0
Src/scanValeur.py

@@ -0,0 +1,21 @@
+from threading import Thread
+from valeurs import *
+
+
+class Scan(Thread):
+
+    def __init__(self, valeur,verrou):
+        Thread.__init__(self)
+        
+    def run(self):
+        i=0
+        while 1:
+		#~ with verrou:
+			tmp=valeur[i].getNewTaux()
+			if tmp-valeur[i].getTaux() > 0.5:
+				valeur[i].MiseEnVente()
+			time.sleep(0.4)
+			i=i+1
+			if i<39:
+				i=0
+			

BIN
Src/scanValeur.pyc


+ 88 - 3
Src/test.py

@@ -1,5 +1,9 @@
 from valeurs import *
+from scanValeur import *
+from timer import *
+from achatVente import *
 import time
+from threading import Thread, RLock
 
 f = open('cac.txt','r')
 
@@ -7,8 +11,89 @@ valeur=[]
 
 for i in f:
 	t = i.split(';')
-	url = t[0]
-	nom = t[1]
+	url = t[1]
+	nom = t[0]
 	valeur.append(Valeur(nom,url))
 
-print(valeur[1].nom)
+f.close()
+
+tempsdepart =time.time()
+
+class AchatVente(Thread):
+
+	
+    def __init__(self):
+        Thread.__init__(self)
+       
+        
+    def run(self):
+		i=0
+		gain =0.0
+		while 1:
+			with verrou:
+				if valeur[i].getAAnule() == 1:
+					valeur[i].Anulation()
+				if valeur[i].getAVendre() == 1:
+					gain=gain+valeur[i].Vente()
+					print ("Gain Total: "+ str(gain)+ " en " + str(time.time()-tempsdepart) + "s")
+				if valeur[i].getMise()==0:
+					valeur[i].Achat(25)
+			time.sleep(00.001)
+			i=i+1
+			if i>39:
+				i=0
+
+
+class Scan(Thread):
+
+    def __init__(self):
+        Thread.__init__(self)
+        
+    def run(self):
+        i=0
+        while 1:
+			with verrou:
+				tmp=valeur[i].getNewTaux()- valeur[i].getTaux()
+				
+				if tmp > 0.02:
+					valeur[i].MiseEnVente()
+			time.sleep(0.4)
+			i=i+1
+			if i>39:
+				i=0
+			
+class Timer(Thread):
+
+    def __init__(self):
+        Thread.__init__(self)
+        
+    def run(self):
+        i=0
+        while 1:
+			with verrou:
+				if valeur[i].tempsRestant() < 30:
+					if valeur[i].getNewTaux() > 0:
+						valeur[i].MiseEnVente()
+					else:
+						valeur[i].MiseEnAnnulation()
+			time.sleep(0.4)
+			i=i+1
+			if i>39:
+				i=0
+
+verrou = RLock()
+
+threadAchat = AchatVente()
+threadTimer = Timer()
+threadScan  = Scan() 
+
+threadAchat.start()
+threadTimer.start()
+threadScan.start()
+
+threadAchat.join()
+threadTimer.join()
+threadScan.join()
+
+#~ print(str(valeur[1].getTaux()))
+#~ print(str(valeur[1].getNewTaux()))

+ 22 - 0
Src/timer.py

@@ -0,0 +1,22 @@
+from threading import Thread
+from valeurs import *
+
+
+class Timer(Thread):
+
+    def __init__(self, valeur,verrou):
+        Thread.__init__(self)
+        
+    def run(self):
+        i=0
+        while 1:
+			#~ with verrou:
+			if valeur[i].tempsRestant() < 30:
+				if valeur[i].getNewTaux() > 0:
+					valeur[i].MiseEnVente()
+				else:
+					valeur[i].MiseEnAnnulation()
+			time.sleep(0.4)
+			i=i+1
+			if i<39:
+				i=0

BIN
Src/timer.pyc


+ 61 - 4
Src/valeurs.py

@@ -1,16 +1,73 @@
 import time
 from recup import recupfunc
 
-class Valeur:	
+class Valeur(object):	
 	def __init__(self,nom,url):
 		self.nom=nom
 		self.url=url
-		self.variation=recupfunc(self.url)
-		self.mise=25.0
+		self.taux=recupfunc(self.url)
+		self.mise=0.0
 		self.date=time.time()
 		self.validation=0
 		self.anulation=0
+		self.AVendre = 0
+		self.AAnule = 0
 	
-	def setMise(mise):
+	"""achat d'une actiont"""
+	def Achat(self,mise):
+		self.variationAchat=recupfunc(self.url)
+		self.date=time.time()
 		self.mise=mise
+		print ("achat de " + str(mise) + " de " + str(self.nom))
+	
+	"""vent une transaction si le taux est interesant sinon annulle"""
+	def Vente(self):
+		self.AVendre=0
+		tmp = recupfunc(self.url)[2]
+		taux=(tmp-self.taux[2])/100
+		if taux < 0:
+			Anulation()
+		else:
+			self.validation = self.validation + 1
+			tmpMise=self.mise
+			self.mise=0.0
+			gainpro = tmpMise*taux
+			print ("vente de " + str(tmpMise) + " de " + str(self.nom) + " pour un taux de " + str(taux) + ". Gain " + str(gainpro))
+			return gainpro
+		
+	""" anule une transaction """
+	def Anulation(self): # a voir si on regarde pas si on mettrais pas en vente 
+		self.AAnule = 0
+		self.anulation = self.annulation +1
+		print ("annulation de " + str(mise) + " de " + str(self.nom))
+		self.mise = 0.0
+		
+	"""retourne le temps restant en sec avant l'expiration du choix de l'option
+	"""
+	def tempsRestant(self):
+		return 600-(time.time()-self.date)
+	
+	def getNewTaux(self):
+		return recupfunc(self.url)[2]
+		
+	def MiseEnVente(self):
+		self.AVendre=1
+	
+	def MiseEnAnnulation(self):
+		self.AAnule=1
+		
+	def getAVendre(self):
+		return self.AVendre
+		
+	def getAAnule(self):
+		return self.AAnule
+	
+	def getTaux(self):
+		return self.taux[2]
+		
+	def getMise(self):
+		return self.mise
+		
+	def getNom(self):
+		return self.nom
 	

BIN
Src/valeurs.pyc