def __init__(self, log): super().__init__(log) self.log = log self.reference_price = 0 self.buy_limit = 0 self.loss_limit = 0 self.situation_processing = False self.inverse = None self.purchase = Order() self.sale = Order()
def update_episode_sale(self, order): executed_amount = abs(order.executed_amount) if self.sale_episode_shifted: self.sale_episode_shifted = False old_sale = self.episode_sale self.episode_sale = Order() self.episode_sale_number = self.get_episode_sale_number() self.episode_sale.episode_number = self.episode_sale_number self.episode_sale.item_name = order.item_name self.episode_sale.order_price = order.order_price self.episode_sale.virtual_open_amount = old_sale.virtual_open_amount self.episode_sale.executed_time = order.executed_time self.episode_sale.order_number = order.order_number self.episode_sale.order_position = order.order_position self.episode_sale.order_state = order.order_state self.episode_sale.executed_price_avg = order.executed_price_avg if order.order_state == RECEIPT: self.episode_sale.order_amount += order.order_amount self.episode_sale.open_amount += order.open_amount elif order.order_state == ORDER_EXECUTED: self.episode_sale.open_amount -= executed_amount self.episode_sale.virtual_open_amount -= executed_amount self.episode_sale.executed_amount_sum += executed_amount self.episode_sale.profit += order.profit self.episode_sale.net_profit += order.net_profit self.orders[self.episode_sale_number] = self.episode_sale if self.sell_off_ordered and not order.open_amount: self.sell_off_ordered = False
def update_episode_purchase(self, order): executed_amount = abs(order.executed_amount) if self.purchase_episode_shifted: old_purchase = self.episode_purchase self.purchase_episode_shifted = False self.episode_purchase = Order() self.episode_purchase_number = self.get_episode_purchase_number() self.episode_purchase.episode_number = self.episode_purchase_number self.episode_purchase.item_name = order.item_name self.episode_purchase.order_price = order.order_price self.episode_purchase.virtual_open_amount = old_purchase.virtual_open_amount self.episode_purchase.order_amount += order.order_amount self.episode_purchase.open_amount += order.open_amount self.episode_purchase.executed_time = order.executed_time self.episode_purchase.order_number = order.order_number self.episode_purchase.order_position = order.order_position self.episode_purchase.order_state = order.order_state self.episode_purchase.executed_price_avg = order.executed_price_avg if order.order_state == RECEIPT: pass elif order.order_state == ORDER_EXECUTED: self.episode_purchase.open_amount -= executed_amount self.episode_purchase.virtual_open_amount -= executed_amount self.episode_purchase.executed_amount_sum += executed_amount self.orders[self.episode_purchase_number] = self.episode_purchase
def __init__(self, trader, log, key): super().__init__('KHOPENAPI.KHOpenAPICtrl.1') WookLog.custom_init(self, log) WookUtil.__init__(self) # For Signal self.trader = trader # Password wc = WookCipher(key) wc.decrypt_data() self.login_id = wc.login_id self.login_password = wc.login_password self.account_password = wc.account_password self.certificate_password = wc.certificate_password # Eventloop self.login_event_loop = QEventLoop() self.event_loop = QEventLoop() self.timer_event_loop = QEventLoop() self.wook_timer = WookTimer(self.timer_event_loop) # Chart self.chart_prices = list() self.chart_item_code = '' self.is_running_chart = False # Deposit self.account_list = None self.account_number = 0 self.deposit = 0 self.withdrawable_money = 0 self.orderable_money = 0 # Items and Orders self.portfolio = dict() self.monitoring_items = dict() self.balance = dict() self.open_orders = dict() self.order_history = dict() self.previous_order = Order() # Pending order self.pending_order = None self.cancel_confirmed = False self.cancel_order_number = 0 # For debug self.order_position = '' self.order_variables = None # Request limit self.inquiry_count = 0 self.previous_time = 0.0 self.reference_time = Queue() self.reference_time_interval_limit = 20 self.consecutive_interval_limit = 0.25 self.request_time = 0 self.request_interval_limit = 0.5 self.request_block_time_limit = 5 self.request_block_size = 10 self.request_count = 0 self.request_count_threshold = 90 self.request_count_interval = 60 self.request_count_waiting = 30 # Fee and Tax # self.fee_ratio = 0.0035 self.fee_ratio = 0.00015 self.tax_ratio = 0.0023 self.futures_fee_ratio = 0.00003 self.futures_tax_ratio = 0.0 # Screen numbers self.screen_account = '0010' self.screen_open_order = '0020' self.screen_operation_state = '0040' self.screen_portfolio = '0060' self.screen_send_order = '0080' self.screen_stock_price = '0120' self.screen_futures_stock_price = '0140' self.screen_test = '9999'
def obtain_executed_order_info(self): order = Order() order.item_code = self.get_chejan_data(FID.ITEM_CODE) if order.item_code[0] == 'A': order.item_code = order.item_code[1:] order.item_name = self.get_item_name(order.item_code) order.executed_time = self.get_chejan_data(FID.ORDER_EXECUTED_TIME) order.order_amount = self.get_chejan_data(FID.ORDER_AMOUNT, number=True) order.executed_amount = self.get_chejan_data(FID.UNIT_EXECUTED_AMOUNT, number=True) order.executed_amount_sum = self.get_chejan_data(FID.EXECUTED_AMOUNT, number=True) order.open_amount = self.get_chejan_data(FID.OPEN_AMOUNT, number=True) order.order_number = self.get_chejan_data(FID.ORDER_NUMBER) order.original_order_number = self.get_chejan_data(FID.ORIGINAL_ORDER_NUMBER) order.executed_order_number = self.get_chejan_data(FID.EXECUTED_ORDER_NUMBER) order.order_price = self.get_chejan_data(FID.ORDER_PRICE, number=True) order.executed_price = self.get_chejan_data(FID.UNIT_EXECUTED_PRICE, number=True) order.executed_price_avg = self.get_chejan_data(FID.EXECUTED_PRICE, number=True) order.order_position = self.get_chejan_data(FID.ORDER_POSITION) order.current_price = abs(self.get_chejan_data(FID.CURRENT_PRICE, number=True)) order.order_state = self.get_chejan_data(FID.ORDER_STATE) order.order_type = self.get_chejan_data(FID.ORDER_POSITION) order.transaction_type = self.get_chejan_data(FID.TRANSACTION_TYPE) order.transaction_price = self.get_chejan_data(FID.EXECUTED_PRICE, number=True) # order.volume = self.get_chejan_data(FID.VOLUME, number=True) # order.transaction_fee = self.get_chejan_data(FID.TRANSACTION_FEE, number=True) # order.tax = self.get_chejan_data(FID.TRANSACTION_TAX, number=True) if order.order_position in (SELL, CORRECT_SELL): order.executed_amount = -abs(order.executed_amount) self.update_execution_info(order)
def get_order_history(self, sTrCode, sRecordName, sScrNo, sPrevNext): number_of_order = self.get_repeat_count(sTrCode, sRecordName) if sPrevNext == '0': self.order_history.clear() for count in range(number_of_order): get_comm_data = self.new_get_comm_data(sTrCode, sRecordName, count) order = Order() order.item_code = str(get_comm_data(ITEM_CODE)) order.item_name = get_comm_data(ITEM_NAME) order.executed_time = get_comm_data(TIME) order.order_amount = get_comm_data(ORDER_AMOUNT) order.executed_amount_sum = get_comm_data(EXECUTED_ORDER_AMOUNT) order.open_amount = get_comm_data(OPEN_AMOUNT) order.order_number = get_comm_data(ORDER_NUMBER) order.original_order_number = get_comm_data(ORIGINAL_ORDER_NUMBER) order.order_price = get_comm_data(ORDER_PRICE) order.executed_price_avg = get_comm_data(EXECUTED_ORDER_PRICE) order.order_position = get_comm_data(ORDER_POSITION) order.order_state = get_comm_data(ORDER_STATE) self.order_history[order.order_number] = order if order.open_amount != 0: self.open_orders[order.order_number] = order if sPrevNext == '2': self.request_order_history('', sPrevNext) else: self.trader.display_order_history() self.trader.display_open_orders() self.info('Order history information') self.init_screen(sScrNo)