def run_loop(self): mylog.debug(f'Model: {self.model.name()} ........') while True: msg = self.self_queue.get() # type: TradeMessage if isinstance(msg.operation, MsgBidOver): self.model.on_bid_over() elif isinstance(msg.operation, MsgPushRealTimePrice): self.model.handle_bar() elif isinstance(msg.operation, MsgQuitLoop): return else: message_box_error('Unknown message operation: ', msg.operation)
def _visit_client_server(url_args, headers, timeout=5): append_str = '' for i, k in enumerate(url_args): if not i: tmp = '?' else: tmp = '&' append_str += tmp + str(k) + '=' + str(url_args[k]) url = stock_server_operation_address + append_str mylog.info(url) while 1: try: resp = firefox_quick_get_url(url, headers, timeout=timeout) if resp.status_code == 200: return jsonpickle.loads(resp.text) message_box_error(f"Serve status_code:", resp.status_code, 'resp.text:', resp.text) except requests.exceptions.RequestException as e: mylog.error(f'Request Exception: {e}')
def from_string(cls, text): text_map = { '全部申报': EntrustStatus.no_commit, '未成交': EntrustStatus.no_commit, '成交': EntrustStatus.finished, '已成交': EntrustStatus.finished, '全部成交': EntrustStatus.finished, '部分成交': EntrustStatus.partial_finished, '部成': EntrustStatus.partial_finished, '撤单': EntrustStatus.cancelled, '已撤单': EntrustStatus.cancelled, '场内撤单': EntrustStatus.cancelled, '部分撤单': EntrustStatus.partial_cancelled, '部撤': EntrustStatus.partial_cancelled, '废单': EntrustStatus.invalid, '场内废单': EntrustStatus.invalid, '系统废单': EntrustStatus.invalid, '撤单已发': EntrustStatus.waiting_for_cancel } if text not in text_map: message_box_error(f'EntrustStatus: {text}') return text_map[text]
def fire_operation(oper): format_operation(oper) order_str = jsonpickle.dumps(oper) # mylog.warn(repr(oper)) order_str = order_str.strip() success_cnt = 0 fail_cnt = 0 for i in range(3): result = _visit_client_server( { 'operation': type(oper).__name__, **oper.__dict__ }, {'object': order_str}, timeout=10) if isinstance(result, ErrorResult): fail_cnt += 1 mylog.error( f'Client error: {result}, Retrying {i}, count: {fail_cnt}/{success_cnt}' ) else: success_cnt += 1 return result message_box_error(f'Failed eventually {result}')
def from_text(cls, text): if text == '买入' or text == '买': return EntrustWay.way_buy elif text == '卖出' or text == '卖': return EntrustWay.way_sell message_box_error(f'Not a valid entrust way {text}')