def send_and_recieve(self): ##### # 64bit를 위한 데이터 제공 처리 부분 ##### print('bit32_client s&r proceed...') self.do_job() if Stg.get_stage32('B32_3_data_ready_for_64'): try: # 안보내지면 다음 스테이지로 안넘어가기는 하는데.. connection없어도 안보내지는게 # 맞는지 아직 모름 self.socket64.send(Msg.enc('message_for_64:B32_3'), zmq.NOBLOCK) Stg.proceed_32( ) # Trusted that message is in the QUEUE and sent -> 에러나면 이 자체 exception으로 빠져서 실행 안된다. # 'B32_4_wait_for_64_reply' except Exception as e: print('error in bit32 client send and recieve - 1st :: ', e) # confirm the message elif Stg.get_stage32('B32_6_reply_to_confirm_64'): try: #self.socket64.send(Msg.enc(Msg.tbl_64.get(self.message64))) #self.socket64.send(Msg.enc('message_for_64:B32_6'), zmq.NOBLOCK) self.socket64.send(Msg.enc('message_for_64:B32_6')) Stg.proceed_32() # Trusted that message is in the QUEUE except Exception as e: print('error in bit32 client send and recieve - 2nd :: ', e) else: print('bit32 client waiting for reading of data by 64bit')
def quit(self): print('bit32_client quit proceed...') # if Stg.get_stage32('B32_4_wait_for_64_reply'): # try: # #self.socket64.close() # self.socket64.disconnect() # print('remove bit32_client connection') # Stg.proceed_32() # except Exception as e: # print('error in bit32_client - closing socket') try: # B32_5_request_from_64 if Stg.get_stage32('B32_5_request_from_64') or Stg.get_stage32( 'B32_7_request_api_new_BSH_32'): # 메세지 보낸것을 confirm 되었으면! # self.socket64.close() # print('remove bit32_client connection') # self.socket64.send(Msg.enc('DUMMY_MESSAGE'), zmq.NOBLOCK) # print('sent dummy message by 32bit') self.socket64.disconnect() print('32bit client disconnect') #Stg.proceed_32() except Exception as e: print('error in bit32_client - closing socket')
def recieve_and_send(self): # iniitialzie self.message32 = None if Stg.get_stage32('B32_5_request_from_64'): #64bit가 제작이 끝났으니..! try: #if not( self.message32 in list(Msg.tbl_64)): self.message32 = Msg.dec(self.socket32.recv( zmq.NOBLOCK)) # no waiting... print(' @@@@', self.message32, '@@@@ ') if not (self.message32 == 'message_for_32:B64_6'): #raise ValueError('Wrong bi32.py fail-1') # 'message_for_32:S' self.message32 = None Stg.backward_32() else: Stg.proceed_32() pass ##### # 64bit의 데이터 읽어가는 부분 self.do_job() ##### except Exception as e: print('error in bit32 server recieve and send - 1st :: ', e) elif Stg.get_stage32('B32_4_wait_for_64_reply'): try: #self.message32 = Msg.dec(self.socket32.recv(zmq.NOBLOCK)) #if not Msg.tbl_32.get('data_ready_for_64:S') == self.message32: #confirm the reply self.message32 = Msg.dec(self.socket32.recv( zmq.NOBLOCK)) # no waiting... print(' @@@@', self.message32, '@@@@ ') if not (self.message32 == 'message_for_32:B64_1'): self.message32 = None Stg.err_counter_stage32() Stg.backward_32() else: Stg.proceed_32() # 'B32_5_request_from_64' except Exception as e: print('error in bit32 server recieve and send - 2nd :: ', e) #Stg.backward_32() # @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ # try: # Stg.proceed_32() # except Exception as e: # print('error in bit32 client send and recieve - 2nd :: ', e) else: print('bit32 server waiting for request of data by 64bit')
async def set_api_data(self): delay = 0.1 # get api, send mesg to 64, retrieve, then set api while True: await asyncio.sleep(delay) if Stg.get_stage32('B32_7_request_api_new_BSH_32'): ################################### # queue 써서 전달하는 방식이 나을 듯? -> global 변수를 큐로 설정해서..! # 여러개에 대한 작업이 진행되어야 하니깐... ################################### """ if self.message32 == 'sell:S' : ki.request_sell() ## ^ confirmation of new requests must be done in api.py elif self.message32 == 'buy:S': ki.request_buy() ## ^ confirmation of new requests must be done in api.py elif self.message32 == 'hold:S': pass elif self.message32 == 'sell_panic:S': # 나중에 하드 코딩으로 구현 ki.request_sell_panic() elif self.message32 == 'sell_all:S': ki.request_sell_all() #^^ ################# # confirmations MUST EXIST!!!!!!! -> ##################### """ print('send action to kiwoom-api') Stg.proceed_32()
async def get_api_data_loop(self): #^ 계속적으로 api에서 32bit으로 data를 가져오는 while문 # pyqt5 login # self.execute_pyq('login_instance') # self.execute_pyq('get_all_code_instance') ###### # Queue 에서 값을 읽어온다!!!!!!! # Queue 에서 값을 읽어온다!!!!!!! # Queue 에서 값을 읽어온다!!!!!!! ###### tmp_val = None delay = 0.2 while True: await asyncio.sleep( delay) # 아니면 function 자체를 await하게 __await__()변환을 하는게.. #tmp_val = copy.deepcopy(ki.request_data()) # 무조건... 돌린다 #^^ ################# # confirmation MUST EXIST!!!!!!! ##################### if Stg.get_stage32('B32_0_get_api_variables_to_32'): self.data_transfer_32bit_variables = None # for safety, reset the variable # 32bit 내부로 가져올 필요가 있을 때 self.data_transfer_32bit_variables = copy.deepcopy(tmp_val) Stg.proceed_32()
def quit(self): # 소켓 close하는 부분 if Stg.get_stage32('B32_6_reply_to_confirm_64'): try: #self.socket32.close() #self.socket32.disconnect() #Stg.proceed_32() pass # stage proceed done in recieve!! except Exception as e: print('error in bit32_server - closing socket')
async def data_creation_32(self): # 데이터가 32bit 글로벌로 받아왔다면, 내부 로직 돌리는 부분 delay = 0.1 while True: await asyncio.sleep(delay) if Stg.get_stage32('B32_2_clear_write_confirm_data_32' ): # pickle data로 만들어 주는 부분 bit_32_data_create.write_to_file(self.data_transfer_32bit_data) self.data_transfer_32bit_data = None Stg.proceed_32() #################### # clear file, write to file + inner-logics, confirm it is complete, # set flag lv_Data_ready_to_64bit = 1, # #################### await asyncio.sleep(delay)
async def api_data_inner_logic(self): #^ 데이터가 32bit 글로벌로 받아오고 interface 해주는 부분 delay = 0.1 while True: await asyncio.sleep(delay) self.data_transfer_32bit_data = None # for safety, reset the variable if Stg.get_stage32('B32_1_logics_for_32'): #await asyncio.sleep(delay) self.data_transfer_32bit_data = bit_32_data_create.inner_logic( self.data_transfer_32bit_variables ) #로직 돌려서 필요한 보조 지표 등등 생성... # 아니면 키움증권에서 받아올수는 있을 것 같음 ##^ maybe a class variable self.data_transfer_32bit_variables = None # for safety, reset the variable Stg.proceed_32()