def update_close_position(self, order): executed_amount = abs(order.executed_amount) if self.episode_count != self.close_position.get_episode_count(): old_close_position = self.close_position self.close_position = Episode() self.close_position.episode_number = self.get_episode_number() + 'S' self.close_position.item_name = order.item_name self.close_position.order_price = order.order_price self.close_position.virtual_open_amount = old_close_position.virtual_open_amount self.orders[self.close_position.episode_number] = self.close_position self.close_position.executed_time = order.executed_time self.close_position.order_number = order.order_number self.close_position.order_position = order.order_position self.close_position.order_state = order.order_state self.close_position.executed_price_avg = order.executed_price_avg if order.order_state == RECEIPT: self.close_position.order_amount += order.order_amount self.close_position.open_amount += order.open_amount elif order.order_state == ORDER_EXECUTED: self.close_position.open_amount -= executed_amount self.close_position.virtual_open_amount -= executed_amount self.close_position.executed_amount_sum += executed_amount self.close_position.profit += order.profit self.close_position.net_profit += order.net_profit self.total_profit += order.profit self.total_fee += order.total_fee self.net_profit += order.net_profit if not self.close_position.open_amount: if self.trade_position == SELL: self.close_position_purchase_history[self.close_position.executed_time] = self.close_position.executed_price_avg else: self.close_position_sale_history[self.close_position.executed_time] = self.close_position.executed_price_avg if self.stop_loss_ordered and not order.open_amount: self.stop_loss_ordered = False
def update_open_position(self, order): executed_amount = abs(order.executed_amount) if self.episode_count != self.open_position.get_episode_count(): old_open_position = self.open_position self.open_position = Episode() self.open_position.episode_number = self.get_episode_number() + 'E' self.open_position.item_name = order.item_name self.open_position.virtual_open_amount = old_open_position.virtual_open_amount self.orders[self.open_position.episode_number] = self.open_position self.open_position.order_price = order.order_price self.open_position.executed_time = order.executed_time self.open_position.order_number = order.order_number self.open_position.order_position = order.order_position self.open_position.order_state = order.order_state self.open_position.executed_price_avg = order.executed_price_avg if order.order_state == RECEIPT: self.open_position.order_amount += order.order_amount self.open_position.open_amount += order.open_amount elif order.order_state == ORDER_EXECUTED: self.open_position.open_amount -= executed_amount self.open_position.virtual_open_amount -= executed_amount self.open_position.executed_amount_sum += executed_amount if not self.open_position.open_amount: if self.trade_position == PURCHASE: self.open_position_purchase_history[self.open_position.executed_time] = self.open_position.executed_price_avg else: self.open_position_sale_history[self.open_position.executed_time] = self.open_position.executed_price_avg
def stop(self): if not self.is_running: return self.post('STOPPED') # Open Orders cancellation self.clear_open_orders() # Init Fields self.broker = None self.is_running = False self.sell_off_ordered = False self.settle_up_in_progress = False self.finish_up_in_progress = False self.open_orders = 0 self.open_correct_orders = 0 self.open_cancel_orders = 0 self.open_purchase_correct_orders = 0 self.open_purchase_cancel_orders = 0 self.open_sale_correct_orders = 0 self.open_sale_cancel_orders = 0 self.previous_situation = '' self.previous_msg = () self.timer.stop() self.chart_locator = list() self.chart_formatter = list() self.interval_prices = list() self.loss_cut_prices = list() self.top_price = 0 self.bottom_price = 0 self.chart_scope = 60 self.orders.clear() self.purchase_episode_shifted = False self.sale_episode_shifted = False self.episode_purchase = Episode() self.episode_sale = Episode() self.episode_purchase_number = '' self.episode_sale_number = '' self.episode_count = 0 self.episode_amount = 0 self.capital = 0 self.interval = 0 self.loss_cut = 0 self.shift_interval = 0 self.reference_price = 0 self.buy_limit = 0 self.loss_limit = 0 self.minimum_transaction_amount = 0 self.start_time_text = '' self.start_time = 0 self.start_price = 0 self.total_profit = 0 self.total_fee = 0 self.net_profit = 0 self.fee = 0 self.fee_ratio = 0.0 self.tax_ratio = 0.0 # Continue Charting self.trader.go_chart()
def __init__(self, trader, log): WookLog.custom_init(self, log) self.trader = trader self.log = log self.broker = None self.is_running = False self.sell_off_ordered = False self.settle_up_in_progress = False self.finish_up_in_progress = False self.open_orders = 0 self.open_correct_orders = 0 self.open_cancel_orders = 0 self.open_purchase_correct_orders = 0 self.open_purchase_cancel_orders = 0 self.open_sale_correct_orders = 0 self.open_sale_cancel_orders = 0 self.previous_situation = '' self.previous_msg = () self.draw_chart = ChartDrawer(self.display_chart) self.timer = QTimer() self.timer.setInterval(60000) self.timer.timeout.connect(self.on_every_minute) self.chart_locator = list() self.chart_formatter = list() self.interval_prices = list() self.loss_cut_prices = list() self.top_price = 0 self.bottom_price = 0 self.chart_scope = 90 self.items = dict() self.orders = dict() self.episode_purchase = Episode() self.episode_sale = Episode() self.purchase_episode_shifted = False self.sale_episode_shifted = False self.episode_purchase_number = '' self.episode_sale_number = '' self.episode_count = 0 self.episode_amount = 0 self.capital = 0 self.interval = 0 self.loss_cut = 0 self.shift_interval = 0 self.reference_price = 0 self.buy_limit = 0 self.loss_limit = 0 self.minimum_transaction_amount = 0 self.start_time_text = '' self.start_comment = '' self.start_time = 0 self.start_price = 0 self.total_profit = 0 self.total_fee = 0 self.net_profit = 0 self.fee = 0 self.fee_ratio = 0.0 self.tax_ratio = 0.0