def execute(self): try: rst = c_query("当日成交") obj = {"deals": rst.items} self._handler.write(dumpUTF8Json(obj)) except Exception as e: err_str = dumpUTF8Json({"error": str(e)}) self._handler.write(err_str) finally: self.complete()
def execute(self): try: lv2 = MarketApi.Instance() rst = lv2.GetDetailTransactionData(self._stock, 30) data = {"transaction_detail": [i for i in rst]} ret_val = dumpUTF8Json(data) self._handler.write(ret_val) except QueryError as e: ret_val = dumpUTF8Json({"error": str(e)}) self._handler.write(ret_val) self.complete() except: self.complete() else: self.complete()
def execute(self): try: lv2 = MarketApi.Instance() rst = lv2.GetQuotes5(self._stocks) json_obj = {"quote5": []} for i in rst: i["名称"] = StockCode(i["代码"], i["市场"]).getStockName() json_obj["quote5"].append(i) json_str = dumpUTF8Json(json_obj) self._handler.write(json_str) except QueryError as e: err_str = dumpUTF8Json({"error": str(e)}) self._handler.write(err_str) self.complete() else: self.complete()
def execute(self): try: lv2 = MarketApi.Instance() rst = lv2.GetMinuteTimeData(self._stock) obj = {"minute": []} for i in rst: obj["minute"].append(i) json_str = dumpUTF8Json(obj) self._handler.write(json_str) except QueryError as e: err_str = dumpUTF8Json({"error": str(e)}) self._handler.write(err_str) _check_and_reconnect(e.feedback) self.complete() else: self.complete()
def execute(self): sp = StockPool.Instance() sp.sync() ss = sp.getStocks() obj = {"stockpool": ss} self._handler.write(dumpUTF8Json(obj)) self.complete()
def get(self): self.set_header("Access-Control-Allow-Origin", "*") # TODO: 不用线程异常栈不同,应该由Command自行处理异常 try: catalogues = self.get_argument('catalogues') if catalogues == u"quote10": stocks = self.get_argument('stocks').encode() stocks = stocks.split(',') cmd = QueryQuote10Cmd(stocks, self) self._quote_invoker.call(cmd) if catalogues == u"quote5": stocks = self.get_argument('stocks').encode() stocks = stocks.split(',') cmd = QueryQuote5Cmd(stocks, self) self._invoker.call(cmd) if catalogues == u"transaction_detail": stock = self.get_argument('stock').encode() cmd = QueryTransactionDetailCmd(stock, self) self._invoker.call(cmd) if catalogues == u"transaction": stock = self.get_argument('stock').encode() cmd = QueryTransactionCmd(stock, self) self._invoker.call(cmd) if catalogues == u"minute": stock = self.get_argument('stock').encode() cmd = QueryMinuteTimeDataCmd(stock, self) self._invoker.call(cmd) except Exception as e: self.write(dumpUTF8Json({'error': str(e)})) self.finish()
def execute(self): try: lv2 = MarketApi.Instance() rst = lv2.GetQuotes10(self._stocks) obj = {"quote10": []} for i in rst: i["名称"] = StockCode(i["代码"], i["市场"]).getStockName() obj["quote10"].append(i) json_str = dumpUTF8Json(obj) self._handler.write(json_str) except QueryError as e: err_str = dumpUTF8Json({"error": str(e)}) self._handler.write(err_str) _check_and_reconnect(e.feedback) self.complete() else: self.complete()
def execute(self): obj = { "request": { "cmd": "cancel", "orderId": self._orderId, "stock": self._stock, } } try: res = self._api.CancelOrder(self._marketId, self._orderId) obj["result"] = res[0] self._handler.write(dumpUTF8Json(obj)) except TradeError as e: obj['error'] = str(e) err_str = dumpUTF8Json(obj) self._handler.write(err_str) finally: self.complete()
def execute(self): obj = { "request": { "cmd": "buy", "stock": self._stock, "price": self._price, "share": self._share } } try: res = self._api.Buy(self._stock, self._price, self._share) obj["result"] = res[0] self._handler.write(dumpUTF8Json(obj)) except TradeError as e: obj['error'] = str(e) err_str = dumpUTF8Json(obj) self._handler.write(err_str) finally: self.complete()
def execute(self): obj = { "request": { "cmd": "short", "stock": self._stock, "price": self._price, "share": self._share } } try: res = self._sp.short_frompool(self._stock, self._price, self._share) obj["result"] = res[0] except CancelError as e: obj['error'] = str(e) except TradeError as e: obj['error'] = str(e) except AcquireError as e: obj['error'] = str(e) finally: self._handler.write(dumpUTF8Json(obj)) self.complete()