Wie findet ihr mein OOP?

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
qweet
User
Beiträge: 119
Registriert: Freitag 2. September 2005, 21:26

Montag 23. Januar 2006, 11:03

Ich bewege mich ja nun auf diesem Feld schon seit einiger Zeit und ich schätze mich als eher mäßigen OOP'ler ein. :) Es passt halt so.


folgendes Programm:
Bild

http://qweet.piranho.com/pictures.htm

Code: Alles auswählen


import wx
import time
import threading
import randomclient
from pprint import pprint




class row_of_profit_or_loss:
	def __init__(self):
		#INPUT
		self.last_trade_balance = 0
		
		#OUTPUT
		self.row_length = 0
		self.row = [0]
	def sort_row_by_profit_or_loss(self):
		self.row.insert(0, self.last_trade_balance)
		
		if (self.row[0] > 0) & (self.row[1] <= 0):
			self.row = [self.row[0]]
		elif (self.row[0] < 0) & (self.row[1] >= 0):
			self.row = [self.row[0]]
		elif (self.row[0] == 0):
			self.row = [self.row[0]]
	def tell_row_length(self):
		self.row_length = 0
		for i in range(len(self.row)):
			if self.row[0] > 0:
				self.row_length += 1
			elif self.row[0] < 0:
				self.row_length -= 1
			elif self.row[0] == 0:
				self.row_length = 0
	def do_action(self):
		self.sort_row_by_profit_or_loss()
		self.tell_row_length()
		
row_p_o_l = row_of_profit_or_loss()










class get_random_numbers:
	def __init__(self):
		# INPUT
		self.how_many_numbers = 0
		
		# OUTPUT
		self.raw_random_numbers = []
		self.new_random_numbers = []

		"""
		# FOR TESTING
		self.new_random_numbers = []
		for i in range(100):
			self.new_random_numbers.append('1')
		for i in range(100):
			self.new_random_numbers.append('0')
		"""
		
		"""
		# FOR TESTING
		self.new_random_numbers = 	[	
								1,
								-1, -1, -1, -1, -1, -1,
								1,
								-1, -1, -1, -1, -1, -1,
								1,
								-1, -1, -1, -1, -1, -1,
								1, 
								-1, -1, -1, -1, -1, -1,
								1, 
								-1, -1, -1, -1, -1,
								1,
								-1, -1, -1, -1, -1,
								1,
								-1, -1, -1, -1, -1,
								1,
								-1, -1, -1, -1, -1,
								1,
								-1, -1, -1, -1, -1,
								1,
								-1, -1, -1, -1, -1,
								1,
								-1, -1, -1, -1, -1,
								1,
								-1, -1, -1, -1, -1,
								1
								]	
		"""
		
	def get_numbers_from_client(self):
		self.raw_random_numbers = randomclient.truerand(self.how_many_numbers/8, 'b')

	def make_raw_to_new_numbers(self):
		for i in range(self.how_many_numbers/8):
			for j in range(8):
				self.new_random_numbers.append( self.raw_random_numbers[i][j] )
				
	def make_string_to_integer(self):
		for i in range(len(self.new_random_numbers)):
			if self.new_random_numbers[i] == '0':
				self.new_random_numbers[i] = '-1'
			self.new_random_numbers[i] = int(self.new_random_numbers[i])
			
	def do_action(self):
		self.get_numbers_from_client()
		self.make_raw_to_new_numbers()
		self.make_string_to_integer()
		
		
		

g_r_n = get_random_numbers()







class command_line:
	def __init__(self):
		self.how_many = input("Number of random-numbers? (only multiples of 8! max.80000): ")
		
		
		g_r_n.how_many_numbers = self.how_many
		g_r_n.do_action()
		
		
		
		
		print "You're trading EUR/USD. You goal is to maximize your profit"
		print "USAGE"
		print "Click on the 'Keep-Focus' window to let the program receive the keystrokes"
		print "The following keys take action in the program:"
		
		print "<up-arrow>: buy order"
		print "<down-arrow>: sell order"
		print "If you bought and now you press 'down' you close your position"
		
		print "Speed-Keys:"
		print "<t> and <g>: 1"
		print "<z> and <h>: 0.1"
		print "<u> and <j>: 0.01"
		print "<i> and <k>: 0.001"
		
		print "<Plus> on num-block: Increase your Stop Loss"
		print "<Minus> on num-block: Decrease your Stop Loss"
		
		print "<enter> to stop the process"
		print "<back-shift> to stop the process (should be the one over <enter>)"
		
		print "<Key-a>: if your Stop Loss gets hitted you need to press this key to continue"
		
		print "TO START PRESS <back-shift> (over <enter>)"
		
		print "Good luck!"
		

c_l = command_line()







class make_calculations:
	def __init__(self, new_random_numbers, start_price):
		self.new_random_numbers = new_random_numbers
		self.start_price = start_price
		
		self.price_list = [self.start_price]
		self.trend_list = []
		self.up_trend_length = 0
		self.down_trend_length = 0
		self.trend_direction = ''
		
	def calculate_all_prices(self):
		for i in range(len(self.new_random_numbers)):
			self.price_list.append	(self.price_list[i]+self.new_random_numbers[i])
		
	def calculate_current_trend(self):
		
		for i in range(len(self.new_random_numbers)):
			
			if (self.trend_direction != 'DOWN'):
				if (self.new_random_numbers[i] == 1):
					self.up_trend_length += 1
					self.trend_direction = 'UP'
				elif (self.trend_direction == 'UP'):
					self.trend_list.append(self.up_trend_length)
					self.up_trend_length = 0
					self.trend_direction = 'DOWN'
				
				if (self.new_random_numbers[i] == -1):
					self.down_trend_length -= 1
					self.trend_direction = 'DOWN'
				elif (self.trend_direction == 'DOWN'):
					self.trend_list.append(self.down_trend_length)
					self.down_trend_length = 0
					self.trend_direction = 'UP'
				
				
			elif (self.trend_direction != 'UP'):
				if (self.new_random_numbers[i] == -1):
					self.down_trend_length -= 1
					self.trend_direction = 'DOWN'
				elif (self.trend_direction == 'DOWN'):
					self.trend_list.append(self.down_trend_length)
					self.down_trend_length = 0
					self.trend_direction = 'UP'
				
				if (self.new_random_numbers[i] == 1):
					self.up_trend_length += 1
					self.trend_direction = 'UP'
				elif (self.trend_direction == 'UP'):
					self.trend_list.append(self.up_trend_length)
					self.up_trend_length = 0
					self.trend_direction = 'DOWN'
				
		if self.trend_direction == 'UP':
			self.trend_list.append(self.up_trend_length)
		elif self.trend_direction == 'DOWN':
			self.trend_list.append(self.down_trend_length)

	def do_action(self):
		self.calculate_all_prices()
		self.calculate_current_trend()

m_c = make_calculations(g_r_n.new_random_numbers, 2000)
m_c.do_action()





class Output_Panel_frame1(wx.Panel):
	def __init__(self, parent):
		wx.Panel.__init__(self, parent, -1, style=0)
		self.SetBackgroundColour("WHITE")

		
		
		
		
		x0 = 22
		y0 = 40
		
		self.one = wx.StaticText(self, -1, 'x')
		self.one.SetFont(wx.Font(30, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.one.MoveXY(0*x0, 0*y0)
		
		self.ten = wx.StaticText(self, -1, 'x')
		self.ten.SetFont(wx.Font(30, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.ten.MoveXY(1*x0, 0*y0)
		
		self.hundred = wx.StaticText(self, -1, 'x')
		self.hundred.SetFont(wx.Font(30, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.hundred.MoveXY(2*x0, 0*y0)
		
		self.thousand = wx.StaticText(self, -1, 'x')
		self.thousand.SetFont(wx.Font(30, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.thousand.MoveXY(3*x0, 0*y0)
		
		self.the_dot = wx.StaticText(self, -1, '.')
		self.the_dot.SetFont(wx.Font(30, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.the_dot.MoveXY(4*x0, 0*y0)
		
		self.after_dot = wx.StaticText(self, -1, '1')
		self.after_dot.SetFont(wx.Font(30, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.after_dot.MoveXY(5*x0, 0*y0)
		
		
		self.balance_left_edge = wx.StaticText(self, -1, 'B')
		self.balance_left_edge.SetFont(wx.Font(30, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.balance_left_edge.MoveXY(0*x0, 1*y0)
		
		
		
		
		
		
		
		x1 = 150
		y1 = 40
		
		self.current_buy_price = wx.StaticText(self, -1, 'x.xxxx')
		self.current_buy_price.SetFont(wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.current_buy_price.MoveXY(x1, 0*y1)
		
		self.row_length = wx.StaticText(self, -1, 'row: x/x')
		self.row_length.SetFont(wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.row_length.MoveXY(x1+160, 0*y1)
		
		
		self.current_price = wx.StaticText(self, -1, 'x.xxxx')
		self.current_price.SetFont(wx.Font(30, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.current_price.MoveXY(x1, 1*y1)
		
		self.current_sell_price = wx.StaticText(self, -1, 'x.xxxx')
		self.current_sell_price.SetFont(wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.current_sell_price.MoveXY(x1, 3*y1)
		
		
		self.balance = wx.StaticText(self, -1, 'B')
		self.balance.SetFont(wx.Font(30, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.balance.MoveXY(x1+160, 1*y1)
		
		
		
		
		
		
		self.current_moment = wx.StaticText(self, -1, 'x/'+str(g_r_n.how_many_numbers))
		self.current_moment.MoveXY(x1+160, 2*y1+20)
		self.current_moment.SetFont(wx.Font(30, wx.MODERN, wx.NORMAL, wx.BOLD))
		
		
		
		
		
		
		
		
		
		
		
		x2 = 150
		y2 = 200
		
		self.current_Stop_Loss_Difference = wx.StaticText(self, -1, '<current_Stop_Loss_Difference>')
		self.current_Stop_Loss_Difference.MoveXY(x2, y2)
		self.current_Stop_Loss_Difference.SetFont(wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD))
		
		self.current_speed = wx.StaticText(self, -1, '<current_speed>')
		self.current_speed.MoveXY(x2, y2+30)
		self.current_speed.SetFont(wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD))
		
		
		
		
		
		
		
		
		 
class Output_Panel_frame2(wx.Panel):
	def __init__(self, parent):
		wx.Panel.__init__(self, parent, -1, style=0)
		self.SetBackgroundColour("WHITE")
			
			
			
		x1 = 0 
		y1 = 40

		self.long = wx.StaticText(self, -1, 'long at:')
		self.long.SetFont(wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.long.MoveXY(x1, 0*y1)
		
		self.upper_Stop_Loss = wx.StaticText(self, -1, 'SL: ')
		self.upper_Stop_Loss.SetFont(wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.upper_Stop_Loss.MoveXY(x1+150, 0*y1)
		
		self.current_moment_long = wx.StaticText(self, -1, 'x/'+str(g_r_n.how_many_numbers))
		self.current_moment_long.SetFont(wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.current_moment_long.MoveXY(x1+300, 0*y1)
		
		
		self.short = wx.StaticText(self, -1, 'short at:')
		self.short.SetFont(wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.short.MoveXY(x1, 1*y1)
		
		self.lower_Stop_Loss = wx.StaticText(self, -1, 'SL: ')
		self.lower_Stop_Loss.SetFont(wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.lower_Stop_Loss.MoveXY(x1+150, 1*y1)
		
		self.current_moment_short = wx.StaticText(self, -1, 'x/'+str(g_r_n.how_many_numbers))
		self.current_moment_short.SetFont(wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.current_moment_short.MoveXY(x1+300, 1*y1)




		self.last_trade_balance = wx.StaticText(self, -1, 'last_trade_balance: ')
		self.last_trade_balance.MoveXY(x1, 3*y1)
		self.last_trade_balance.SetFont(wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD))
		
		self.sessions_balance = wx.StaticText(self, -1, 'sessions_balance: ')
		self.sessions_balance.MoveXY(x1, 4*y1)
		self.sessions_balance.SetFont(wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD))









class Input_Panel_frame3(wx.Panel):
	def __init__(self, parent3):
		wx.Panel.__init__(self, parent3, -1, style=0)
		self.Bind(wx.EVT_CHAR, self.LogKeyEvent)
		self.SetFocus()
		
		
		self.text = wx.StaticText(self, -1, 'Keep Focus in this panel by clicking in it')
		self.text.MoveXY(0, 0)
		self.text.SetFont(wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD))
		
		
		self.Key_Enter 		= 13
		self.Key_back		= 8
		self.Key_up 		= 317
		self.Key_down		= 319
		self.Key_right		= 318
		self.Key_minus		= 45
		self.Key_plus		= 43
		self.Key_a			= 97
		
		self.Key_t			= 116
		self.Key_g			= 103
		self.Key_z			= 122
		self.Key_h			= 104
		self.Key_u			= 117
		self.Key_j			= 106
		self.Key_i			= 105
		self.Key_k			= 107
		
		self.PressedKeyCode = 0
		
		self.Stop = 'YES'
		self.buy_or_sell = ''
		self.Stop_Loss_Difference = 20
		self.visible_speed = ['2', '.', '0', '0', '0']
		self.visible_speed_as_string = (self.visible_speed[0] + self.visible_speed[1] + self.visible_speed[2] + 
							self.visible_speed[3] + self.visible_speed[4])
		
	
	def reset_all(self):
		self.PressedKeyCode = 0
		self.buy_or_sell = ''
	
	def do_action(self):
		if self.PressedKeyCode == self.Key_Enter:
			self.Stop = 'YES'
		elif self.PressedKeyCode == self.Key_back:
			self.Stop = 'NO'
			
			
		elif self.PressedKeyCode == self.Key_plus:
			self.Stop_Loss_Difference += 1
		elif (self.PressedKeyCode == self.Key_minus)  & (self.Stop_Loss_Difference > 3):
			self.Stop_Loss_Difference -= 1
			
		elif self.PressedKeyCode == self.Key_a:
			c.Stop_Loss_reached = 'FALSE'
			c.Core_stop = 'NO'
			
			
			
			
			
			
			
		# T AND G	
		elif (self.PressedKeyCode == self.Key_t):
			self.visible_speed[0] = str ( 	int(self.visible_speed[0]) + 1	 )
			
			self.visible_speed_as_string = (self.visible_speed[0] + self.visible_speed[1] + self.visible_speed[2] + 
							self.visible_speed[3] + self.visible_speed[4])
			
			c.Core_speed = float(self.visible_speed_as_string)
		elif (self.PressedKeyCode == self.Key_g) & (	int(self.visible_speed[0]) > 0	):
			self.visible_speed[0] = str ( 	int(self.visible_speed[0]) - 1	 )
			
			self.visible_speed_as_string = (self.visible_speed[0] + self.visible_speed[1] + self.visible_speed[2] + 
							self.visible_speed[3] + self.visible_speed[4])
			
			c.Core_speed = float(self.visible_speed_as_string)
			
		# Z AND H		
		elif (self.PressedKeyCode == self.Key_z) & (	int(self.visible_speed[2]) < 9	):
			self.visible_speed[2] = str ( 	int(self.visible_speed[2]) + 1	 )
			
			self.visible_speed_as_string = (self.visible_speed[0] + self.visible_speed[1] + self.visible_speed[2] + 
							self.visible_speed[3] + self.visible_speed[4])
			
			c.Core_speed = float(self.visible_speed_as_string)
		elif (self.PressedKeyCode == self.Key_h) & (	int(self.visible_speed[2]) > 0	):
			self.visible_speed[2] = str ( 	int(self.visible_speed[2]) - 1	 )
			
			self.visible_speed_as_string = (self.visible_speed[0] + self.visible_speed[1] + self.visible_speed[2] + 
							self.visible_speed[3] + self.visible_speed[4])
			
			c.Core_speed = float(self.visible_speed_as_string)
			
		# U AND J	
		elif (self.PressedKeyCode == self.Key_u) & (	int(self.visible_speed[3]) < 9	):
			self.visible_speed[3] = str ( 	int(self.visible_speed[3]) + 1	 )
			
			self.visible_speed_as_string = (self.visible_speed[0] + self.visible_speed[1] + self.visible_speed[2] + 
							self.visible_speed[3] + self.visible_speed[4])
			
			c.Core_speed = float(self.visible_speed_as_string)
		elif (self.PressedKeyCode == self.Key_j) & (	int(self.visible_speed[3]) > 0	):
			self.visible_speed[3] = str ( 	int(self.visible_speed[3]) - 1	 )
			
			self.visible_speed_as_string = (self.visible_speed[0] + self.visible_speed[1] + self.visible_speed[2] + 
							self.visible_speed[3] + self.visible_speed[4])
			
			c.Core_speed = float(self.visible_speed_as_string)
			
		# I AND K		
		elif (self.PressedKeyCode == self.Key_i) & (	int(self.visible_speed[4]) < 9	):
			self.visible_speed[4] = str ( 	int(self.visible_speed[4]) + 1	 )
			
			self.visible_speed_as_string = (self.visible_speed[0] + self.visible_speed[4] + self.visible_speed[2] + 
							self.visible_speed[3] + self.visible_speed[4])
			
			c.Core_speed = float(self.visible_speed_as_string)
		elif (self.PressedKeyCode == self.Key_k) & (	int(self.visible_speed[4]) > 0	):
			self.visible_speed[4] = str ( 	int(self.visible_speed[4]) - 1	 )
			
			self.visible_speed_as_string = (self.visible_speed[0] + self.visible_speed[1] + self.visible_speed[2] + 
							self.visible_speed[3] + self.visible_speed[4])
			
			c.Core_speed = float(self.visible_speed_as_string)
			
			
		O_P_f1.current_Stop_Loss_Difference.SetLabel(str(self.Stop_Loss_Difference))
		O_P_f1.current_speed.SetLabel('sleep('+self.visible_speed_as_string+')')
					
					
					
					
		if c.Stop_Loss_reached == 'FALSE':	
			if self.PressedKeyCode == self.Key_up:
					self.buy_or_sell = 'BUY'
			elif self.PressedKeyCode == self.Key_down:
					self.buy_or_sell = 'SELL'
			
			
			
			
			
			
		if not workerthread.isAlive():
			global workerthread
			workerthread = threading.Thread(target=c.run)
			workerthread.start()

	def LogKeyEvent(self, evt):
		self.PressedKeyCode = evt.GetKeyCode()
		self.do_action()









class Core:
	def __init__(self):
		
		self.Core_stop = 'NO'
		self.Core_speed = 2.000
		
		
		self.current_moment = 0
		
		self.current_buy_price = 2001
		self.current_price = 2000
		self.current_sell_price = 1999
		
		self.string_current_price = str(self.current_price)
		
		self.bought_or_sold = ''
		
		self.remember_price = 0
		
		self.Stop_Loss_absolute = 0
		
		
		
		self.current_balance = 0
		self.last_trade_balance = 0
		self.sessions_balance = 0
		
		
		
		self.Stop_Loss_reached = 'FALSE'
		
		
		self.row_of_profit_loss = []
		self.row_length = 0
		self.only_profit_only_loss = ''
		
	def run(self):
		while (I_P_f3.Stop == 'NO') & (self.Core_stop == 'NO'):
			
			
			
			
			
			
			if self.Core_stop == 'NO':
				O_P_f1.SetBackgroundColour("WHITE")
				O_P_f1.Refresh()
			
			
			
			
			
			
			
			
			
			
			self.current_price += m_c.trend_list[self.current_moment]
			self.current_buy_price = self.current_price + 1
			self.current_sell_price = self.current_price - 1
			
			self.string_current_price = str(self.current_price)
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			if (I_P_f3.buy_or_sell == 'BUY') & (self.bought_or_sold == ''):
				O_P_f2.short.SetLabel('')
				O_P_f2.long.SetLabel('')
				O_P_f2.upper_Stop_Loss.SetLabel('')
				O_P_f2.lower_Stop_Loss.SetLabel('')
				O_P_f2.current_moment_long.SetLabel('')
				O_P_f2.current_moment_short.SetLabel('')
				
				
				self.remember_price = self.current_buy_price
				self.bought_or_sold = 'BOUGHT'
				self.Stop_Loss_absolute = self.remember_price - I_P_f3.Stop_Loss_Difference
				self.Core_stop = 'YES'
			
			
				O_P_f2.long.SetLabel('at: '+'1.'+str(self.remember_price))
				O_P_f2.upper_Stop_Loss.SetLabel('SL: '+'1.'+str(self.Stop_Loss_absolute))
				O_P_f2.current_moment_long.SetLabel(str(self.current_moment)+'/'+str(len(m_c.trend_list)-1))
				
			elif (I_P_f3.buy_or_sell == 'SELL') & (self.bought_or_sold == ''):
				O_P_f2.short.SetLabel('')
				O_P_f2.long.SetLabel('')
				O_P_f2.upper_Stop_Loss.SetLabel('')
				O_P_f2.lower_Stop_Loss.SetLabel('')
				O_P_f2.current_moment_short.SetLabel('')
				O_P_f2.current_moment_long.SetLabel('')
				
				
				self.remember_price = self.current_sell_price
				self.bought_or_sold = 'SOLD'
				self.Stop_Loss_absolute = self.remember_price + I_P_f3.Stop_Loss_Difference
				self.Core_stop = 'YES'


				O_P_f2.short.SetLabel('at: '+'1.'+str(self.remember_price))
				O_P_f2.lower_Stop_Loss.SetLabel('SL: '+'1.'+str(self.Stop_Loss_absolute))
				O_P_f2.current_moment_short.SetLabel(str(self.current_moment)+'/'+str(len(m_c.trend_list)-1))
				
				
				
				
				
				
				
				
				
				
				
				
				
				
			if self.bought_or_sold == 'BOUGHT':
				self.current_balance = self.current_sell_price - self.remember_price
			elif self.bought_or_sold == 'SOLD':
				self.current_balance = self.remember_price - self.current_buy_price
				
				
				
				
				
				
				
				
				
				
				
				
				
				
			if (I_P_f3.buy_or_sell == 'SELL') & (self.bought_or_sold == 'BOUGHT'):
				self.bought_or_sold = ''
				self.last_trade_balance = self.current_balance
				self.sessions_balance += self.last_trade_balance
				
				print self.current_balance
				if self.current_balance > 0:
					O_P_f1.SetBackgroundColour("GREEN")
					O_P_f1.Refresh()
				elif self.current_balance < 0:
					O_P_f1.SetBackgroundColour("RED")
					O_P_f1.Refresh()
					
				self.current_balance = 0
				self.Core_stop = 'YES'
				
				
				row_p_o_l.last_trade_balance = self.last_trade_balance
				row_p_o_l.do_action()
				self.row_length = row_p_o_l.row_length
				
				
				
				O_P_f2.short.SetLabel('at: '+'1.'+str(self.current_sell_price))
				O_P_f2.last_trade_balance.SetLabel('last_trade_balance: '+str(self.last_trade_balance))
				O_P_f2.sessions_balance.SetLabel('sessions_balance: '+str(self.sessions_balance))
				O_P_f2.current_moment_short.SetLabel(str(self.current_moment)+'/'+str(len(m_c.trend_list)-1))
				
			elif (I_P_f3.buy_or_sell == 'BUY') & (self.bought_or_sold == 'SOLD'):
				self.bought_or_sold = ''
				self.last_trade_balance = self.current_balance
				self.sessions_balance += self.last_trade_balance
				
				print self.current_balance
				if self.current_balance > 0:
					O_P_f1.SetBackgroundColour("GREEN")
					O_P_f1.Refresh()
				elif self.current_balance < 0:
					O_P_f1.SetBackgroundColour("RED")
					O_P_f1.Refresh()
				
				self.current_balance = 0
				self.Core_stop = 'YES'
				
				
				row_p_o_l.last_trade_balance = self.last_trade_balance
				row_p_o_l.do_action()
				self.row_length = row_p_o_l.row_length
				
				
				
				O_P_f2.long.SetLabel('at: '+'1.'+str(self.current_buy_price))
				O_P_f2.last_trade_balance.SetLabel('last_trade_balance: '+str(self.last_trade_balance))
				O_P_f2.sessions_balance.SetLabel('sessions_balance: '+str(self.sessions_balance))
				O_P_f2.current_moment_long.SetLabel(str(self.current_moment)+'/'+str(len(m_c.trend_list)-1))
				
			
			
			
			
			
			
			
			
			
			if (self.bought_or_sold == 'BOUGHT'):
				if self.current_sell_price <= self.Stop_Loss_absolute:
					self.bought_or_sold = ''
					self.Stop_Loss_reached = 'TRUE'
					self.last_trade_balance = self.Stop_Loss_absolute - self.remember_price
					self.sessions_balance += self.last_trade_balance
					self.current_balance = 0
					
					row_p_o_l.last_trade_balance = self.last_trade_balance
					row_p_o_l.do_action()
					self.row_length = row_p_o_l.row_length
					
					
					O_P_f1.SetBackgroundColour("RED")
					O_P_f1.Refresh()
					
					O_P_f2.short.SetLabel('at: '+'1.'+str(self.Stop_Loss_absolute))
					O_P_f2.last_trade_balance.SetLabel('last_trade_balance: '+str(self.last_trade_balance))
					O_P_f2.sessions_balance.SetLabel('sessions_balance: '+str(self.sessions_balance))
					O_P_f2.current_moment_short.SetLabel(str(self.current_moment)+'/'+str(len(m_c.trend_list)-1))
					
			elif (self.bought_or_sold == 'SOLD'):
				if self.current_buy_price >= self.Stop_Loss_absolute:
					self.bought_or_sold = ''
					self.Stop_Loss_reached = 'TRUE'
					self.last_trade_balance = self.remember_price - self.Stop_Loss_absolute
					self.sessions_balance += self.last_trade_balance
					self.current_balance = 0
					
					row_p_o_l.last_trade_balance = self.last_trade_balance
					row_p_o_l.do_action()
					self.row_length = row_p_o_l.row_length
					
					
					O_P_f1.SetBackgroundColour("RED")
					O_P_f1.Refresh()
					
					O_P_f2.long.SetLabel('at: '+'1.'+str(self.Stop_Loss_absolute))
					O_P_f2.last_trade_balance.SetLabel('last_trade_balance: '+str(self.last_trade_balance))
					O_P_f2.sessions_balance.SetLabel('sessions_balance: '+str(self.sessions_balance))
					O_P_f2.current_moment_long.SetLabel(str(self.current_moment)+'/'+str(len(m_c.trend_list)-1))
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
	
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			O_P_f1.row_length.SetLabel		(str(self.row_length))
			
			O_P_f1.balance_left_edge.SetLabel	(str(self.current_balance))
			O_P_f1.balance.SetLabel			(str(self.current_balance))
			
			O_P_f1.one.SetLabel		(self.string_current_price[3])
			O_P_f1.ten.SetLabel		(self.string_current_price[2])
			O_P_f1.hundred.SetLabel	(self.string_current_price[1])
			O_P_f1.thousand.SetLabel	(self.string_current_price[0])
			
			O_P_f1.current_buy_price.SetLabel('1.'+str(self.current_buy_price))
			O_P_f1.current_price.SetLabel('1.'+str(self.current_price))
			O_P_f1.current_sell_price.SetLabel('1.'+str(self.current_sell_price))
			O_P_f1.current_moment.SetLabel(str(self.current_moment)+'/'+str(len(m_c.trend_list)-1))
			
			
			
			O_P_f4.row.SetLabel(str(row_p_o_l.row))
			
			
			
			
			
			O_P_f5.current_price = self.current_price
			O_P_f5.current_trend = m_c.trend_list[self.current_moment]
			O_P_f5.do_action()
			
			
			
			
			
			
			
			
			
			
			
			print I_P_f3.buy_or_sell
			
			
			
			
			
			
			
			
			I_P_f3.reset_all()
			
			
			
			
				











			if self.Stop_Loss_reached == 'TRUE':
				self.Core_stop = 'YES'


























			self.current_moment += 1
			
			time.sleep(	self.Core_speed		)




			if self.current_moment == len(m_c.trend_list):
				self.Core_stop = 'YES'
				
				
				
				
				if self.bought_or_sold == 'BOUGHT':
					self.bought_or_sold = ''
					self.last_trade_balance = self.current_balance
					self.sessions_balance += self.last_trade_balance
							
					row_p_o_l.last_trade_balance = self.last_trade_balance
					row_p_o_l.do_action()
					self.row_length = row_p_o_l.row_length
					
					
							
					O_P_f2.short.SetLabel('at: '+'1.'+str(self.current_sell_price))
					O_P_f2.last_trade_balance.SetLabel('last_trade_balance: '+str(self.last_trade_balance))
					O_P_f2.sessions_balance.SetLabel('sessions_balance: '+str(self.sessions_balance))
					O_P_f2.current_moment_short.SetLabel(str(self.current_moment)+'/'+str(len(m_c.trend_list)-1))
				
				elif self.bought_or_sold == 'SOLD':
					self.bought_or_sold = ''
					self.last_trade_balance = self.current_balance
					self.sessions_balance += self.last_trade_balance
					
					row_p_o_l.last_trade_balance = self.last_trade_balance
					row_p_o_l.do_action()
					self.row_length = row_p_o_l.row_length


					O_P_f2.long.SetLabel('at: '+'1.'+str(self.current_buy_price))
					O_P_f2.last_trade_balance.SetLabel('last_trade_balance: '+str(self.last_trade_balance))
					O_P_f2.sessions_balance.SetLabel('sessions_balance: '+str(self.sessions_balance))
					O_P_f2.current_moment_long.SetLabel(str(self.current_moment)+'/'+str(len(m_c.trend_list)-1))
					
					
					
					
					
					
					
				O_P_f1.row_length.SetLabel	(str(self.row_length))
				O_P_f4.row.SetLabel			(str(row_p_o_l.row))




Zuletzt geändert von qweet am Montag 23. Januar 2006, 12:36, insgesamt 1-mal geändert.
qweet
User
Beiträge: 119
Registriert: Freitag 2. September 2005, 21:26

Montag 23. Januar 2006, 11:03

Code: Alles auswählen




class Output_Panel_frame4(wx.Panel):
	def __init__(self, parent):
		wx.Panel.__init__(self, parent, -1, style=0)
		self.SetBackgroundColour("WHITE")
		
		self.row = wx.StaticText(self, -1, 'row')
		self.row.SetFont(wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.row.MoveXY(0, 0)
		
		







# 500 * 750 IS FRAME_SIZE
class calculate_grids:
	def __init__(self, x_width, y_height, n_rows, n_cols):
		self.x_width = x_width
		self.y_height = y_height
		self.n_rows = n_rows
		self.n_cols = n_cols
		
		
		
		self.x_coors = []
		self.y_coors = []
		# MAKE GRID TO DRAW ON
		for i in range(n_cols):
			self.x_coors.append(i*x_width)
		for i in range(n_rows):
			self.y_coors.append(i*y_height)
			
			
			
		self.cell_container = []
		self.cell_container = [['x']*n_cols for n in range(n_rows)]
			

c_g = calculate_grids(12, 12, 30, 30)



class Output_Panel_frame5(wx.Panel):
	def __init__(self, parent):
		wx.Panel.__init__(self, parent, -1, style=0)
		self.SetBackgroundColour("BLACK")

		# INPUT
		self.current_price = 0
		self.current_trend = 0
		# /INPUT
		self.string_current_price = ''
		self.string_current_trend = ''
		
		
		
		
		self.text_current_price = wx.StaticText(self, -1, '')
		self.text_current_price.SetFont(wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD))
		self.text_current_price.MoveXY(c_g.x_coors[0], c_g.y_coors[6])
		self.text_current_price.SetForegroundColour("WHITE")
		
		
		# CONDITIONS
		self.trend_start_cell = [6, c_g.n_cols-2]
		self.trend_end_cell = [6, c_g.n_cols-2]
		
		wx.EVT_PAINT(self, self.OnPaint)
		
	def OnPaint(self, event=None):
		self.dc = wx.PaintDC(self)
	
	
	
	def Draw_Green(self, x1, y1, x2, y2):
		self.dc.SetPen(wx.Pen("GREEN", 2))
		self.dc.DrawLine(x1, y1, x2, y2)

	def Draw_Red(self, x1, y1, x2, y2):
		self.dc.SetPen(wx.Pen("RED", 2))
		self.dc.DrawLine(x1, y1, x2, y2)
		
	def Draw_White(self, x1, y1, x2, y2):
		self.dc.SetPen(wx.Pen("White", 2))
		self.dc.DrawLine(x1, y1, x2, y2)




	def Draw_Plus(self, x_coor_cell, y_coor_cell):
		self.Draw_Green(	x_coor_cell+c_g.x_width/8,			y_coor_cell+c_g.y_height/2, 	
						x_coor_cell+c_g.x_width-c_g.x_width/8,	y_coor_cell+c_g.y_height/2 )
						
		self.Draw_Green(	x_coor_cell+c_g.x_width/2,			y_coor_cell+c_g.y_height/8, 	
						x_coor_cell+c_g.x_width/2,			y_coor_cell+c_g.y_height-c_g.y_height/8 )
		
	def Draw_Minus(self, x_coor_cell, y_coor_cell):
		self.Draw_Red(		x_coor_cell+c_g.x_width/8,			y_coor_cell+c_g.y_height/2, 	
						x_coor_cell+c_g.x_width-c_g.x_width/8,	y_coor_cell+c_g.y_height/2 )
	
	def Draw_Buy(self, x_coor_cell, y_coor_cell):
		self.Draw_White(	x_coor_cell, 						y_coor_cell+c_g.y_height,
						x_coor_cell+c_g.x_width/2,			y_coor_cell)
		
		self.Draw_White(	x_coor_cell, 						y_coor_cell+c_g.y_height,
						x_coor_cell+c_g.x_width,				y_coor_cell+c_g.y_height)
						
		self.Draw_White(	x_coor_cell+c_g.x_width/2, 			y_coor_cell,
						x_coor_cell+c_g.x_width,				y_coor_cell+c_g.y_height)
						
	def Draw_Sell(self, x_coor_cell, y_coor_cell):
		self.Draw_White(	x_coor_cell, 						y_coor_cell,
						x_coor_cell+c_g.x_width,				y_coor_cell)
		
		self.Draw_White(	x_coor_cell, 						y_coor_cell,
						x_coor_cell+c_g.x_width/2,			y_coor_cell+c_g.y_height)
						
		self.Draw_White(	x_coor_cell+c_g.x_width/2, 			y_coor_cell+c_g.y_height,
						x_coor_cell+c_g.x_width,				y_coor_cell)
	
	
	
	# TESTED - WORKS
	def move_cols_to_the_left(self):
		for row in range(len(c_g.cell_container)):
			for col in range(len(c_g.cell_container[row])-1):
				c_g.cell_container[row][col] = c_g.cell_container[row][col+1]
			
	# TESTED - WORKS
	def move_rows_to_the_bottom(self):
		for i in range(1, c_g.n_rows-1):
			for j in range(c_g.n_cols-1):
				c_g.cell_container[(c_g.n_rows-1)-i][j] = c_g.cell_container[c_g.n_rows-2-i][j]
				
		for i in range(c_g.n_cols-1):
			c_g.cell_container[0][i] = 'x'
				
	# TESTED - WORKS			
	def move_rows_to_the_top(self):
		for i in range(1, c_g.n_rows-1):
			for j in range(c_g.n_cols-1):
				c_g.cell_container[i][j] = c_g.cell_container[i+1][j]
				
		for i in range(c_g.n_cols-1):
			c_g.cell_container[c_g.n_rows-1][i] = 'x'
	





	def evaluate_buy_or_sell(self):
		if I_P_f3.buy_or_sell == 'BUY':
			c_g.cell_container[self.trend_end_cell[0]+1][self.trend_end_cell[1]] = 'B'
		elif I_P_f3.buy_or_sell == 'SELL':
			c_g.cell_container[self.trend_end_cell[0]-1][self.trend_end_cell[1]] = 'S'

	
	def if_top_gets_hitted(self, i):
		while self.trend_start_cell[0]-i < 1:
			self.move_rows_to_the_bottom()
				
			self.trend_end_cell[0] += 1
			self.trend_start_cell[0] += 1
		
		c_g.cell_container[self.trend_start_cell[0]-i][self.trend_start_cell[1]] = '+'
		
	def if_bottom_gets_hitted(self, i):
		while self.trend_start_cell[0]+i > c_g.n_rows-2:
			self.move_rows_to_the_top()
				
			self.trend_end_cell[0] -= 1
			self.trend_start_cell[0] -= 1
		
		c_g.cell_container[self.trend_start_cell[0]+i][self.trend_start_cell[1]] = '-'


	def calculate_trend_cells(self):
		# CLEAR COLUMN
		for i in range(c_g.n_rows):
			c_g.cell_container[i][c_g.n_cols-2] = 'x'
		
		if self.current_trend > 0:
			self.trend_start_cell[0] = self.trend_end_cell[0]
			self.trend_end_cell[0] -= self.current_trend-1
			
			for i in range(self.current_trend):
				if self.trend_start_cell[0]-i > 0:
					c_g.cell_container[self.trend_start_cell[0]-i][self.trend_start_cell[1]] = '+'
				else:
					self.if_top_gets_hitted(i)
					
				
		elif self.current_trend < 0:
			self.trend_start_cell[0] = self.trend_end_cell[0]
			self.trend_end_cell[0] -= self.current_trend+1
			
			for i in range(-self.current_trend):
				if self.trend_start_cell[0]+i < c_g.n_rows-1:
					c_g.cell_container[self.trend_start_cell[0]+i][self.trend_start_cell[1]] = '-'
				else:
					self.if_bottom_gets_hitted(i)
				
		
	def evaluate_cell_container(self):
		for row in range(len(c_g.cell_container)):
			for col in range(len(c_g.cell_container[row])):
				if c_g.cell_container[row][col] == '+':
					self.Draw_Plus(c_g.x_coors[col], c_g.y_coors[row])
				elif c_g.cell_container[row][col] == '-':
					self.Draw_Minus(c_g.x_coors[col], c_g.y_coors[row])
					
				elif c_g.cell_container[row][col] == 'B':
					self.Draw_Buy(c_g.x_coors[col], c_g.y_coors[row])
				elif c_g.cell_container[row][col] == 'S':
					self.Draw_Sell(c_g.x_coors[col], c_g.y_coors[row])
					
	def set_current_price(self):
		self.text_current_price.MoveXY(	c_g.x_coors[ c_g.n_cols-1 ], 
								c_g.y_coors[ self.trend_end_cell[0] ] )
		self.text_current_price.SetLabel('1.'+str(self.current_price))
		
	
		
	def do_action(self):
		self.move_cols_to_the_left()
		self.calculate_trend_cells()
		self.evaluate_buy_or_sell()
	
		self.dc.Clear()
		self.set_current_price()
		self.evaluate_cell_container()
		





class MyApp(wx.App):
	def OnInit(self):
		x0 = 500
		y0 = 200
		x1 = 550
		y1 = 300
		frame1 = wx.Frame(None, -1, "Tape Reading", pos=(x0, y0), 				size=(x1, y1))
		frame2 = wx.Frame(None, -1, "Last_Trade", pos=(x0, y0+y1), 			size=(550, 250))
		frame3 = wx.Frame(None, -1, "Keep Focus", pos=(x0, y0-200), 			size=(550, 100))
		frame4 = wx.Frame(None, -1, "row_of_profit_or_loss", pos=(x0, y0-100), 	size=(550, 100))
		frame5 = wx.Frame(None, -1, "ASSOCIATE!", pos=(x0-500, y0-200),			size=(500, 750))
		
		
		
		global O_P_f1
		global O_P_f2
		global O_P_f3
		global O_P_f4
		global O_P_f5
		global I_P_f3
		
		
		O_P_f1 	= Output_Panel_frame1(frame1)
		O_P_f2 	= Output_Panel_frame2(frame2)
		O_P_f4 	= Output_Panel_frame4(frame4)
		O_P_f5	= Output_Panel_frame5(frame5)
		
		I_P_f3 	= Input_Panel_frame3(frame3)
		
		global c
		c = Core()
		
		
		
		
		
		
		
		
		
		frame1.Show(True)
		frame2.Show(True)
		frame3.Show(True)
		frame4.Show(True)
		frame5.Show(True)
		
		
		
		
		
		global workerthread;
		workerthread = threading.Thread(target=c.run)
		workerthread.start()
		
		
		
		return True
		
		
		
		




app = MyApp(0)
app.MainLoop()


modelnine
User
Beiträge: 670
Registriert: Sonntag 15. Januar 2006, 18:42
Wohnort: Celle
Kontaktdaten:

Montag 23. Januar 2006, 11:21

Wenn Du das ganze noch in Module aufteilst und es komprimierst (warum so viele Leerzeilen??), dann sieht das doch schon ganz manierlich aus.

--- Heiko.
qweet
User
Beiträge: 119
Registriert: Freitag 2. September 2005, 21:26

Montag 23. Januar 2006, 12:36

Die Leerzeilen, weil ich da noch in einer Phase war wo ich alles einfach unter einander geschrieben habe. Ich musste erstmal anfangen, langsam, objekt-orientiert zu denken. Deswegen die großen Leerzeilen dazwischen. Das sind meine anfänglichen, jungfräulichen "Objekte" mit klaren Aufgaben. :)

Bild: http://qweet.piranho.com/pictures.htm
BlackJack

Montag 23. Januar 2006, 22:20

Dir ist klar das ``&`` und ``and`` zwei verschiedene Sachen sind? Vom Gefühl her würde ich bei Deinen ``if``-Abfragen wo Du ``&`` benutzt jedenfalls ``and`` schreiben.

Dann benutzt Du in `tell_row_length()` den Index `i` gar nicht. Ich vermute die Methode macht nicht das was Du beabsichtigt hast!?

Ausserdem benutzt Du an einigen Stellen ``for i in range(len(iterable))`` wo es ein ``for item in iterable`` auch getan hätte.

Es fällt auch auf, das, wenn ich mich jetzt nicht verguckt habe, kein einziges ``return`` in dem Quelltext vorkommt. Das "riecht komisch". OOP heisst in Python nicht das man einfach alles in irgendeine Klasse packt. Es ist völlig okay ganz normale Funktionen mit Rückgabewerten zu schreiben.
qweet
User
Beiträge: 119
Registriert: Freitag 2. September 2005, 21:26

Dienstag 24. Januar 2006, 10:52

Also das mit dem ´´&´´ und ´´and´´ kannte ich noch nicht...
Auch danke für die anderen 2 Dinge, werds mir mal anschauen.

Das wegen dem return: Ich handhabe das meist so, dass ich eine Klasse mit definierten Variablen packe und alle Methoden dann halt an diesen Werten herumschrauben. Je nachdem wie ich das brauche nacheinander, einzeln oder oder oder...

´´self.do_action()´´ fasst halt alles erstmal so zusammen wie ich es zur Zeit brauche.
Antworten