def dispatchFromFile(market, dir): # 请求交易日 fileName = "%s/%s_tradeDate" % (dir, market) response = loadFromFile(fileName) # 写入交易日信息 address = WriterAddress.split(":") client = RPCClient(address[0], int(address[1]), 100) for x in response["C"]: param = {"F": {"M": market, "S": "FFFFFF"}, "C": [{"C": x}]} r = client.request("writeData", param) # print "write data ", param # 更新市场状态 if len(response["C"]) > 1: r = client.request( "update", {u"path": "marketStatus/%s" % market, u"data": {u"date": response["C"][-1]["G"], u"status": 2}} ) print "update market status", param # 写入日数据信息 if len(response["C"]) > 1: lastDate = response["C"][-1]["G"] print lastDate fileName = "%s/%s_stockList" % (dir, market) response = loadFromFile(fileName) print "request by daily ", len(response) param = {"M": market, "G": lastDate, "C": response} response = request(WriterAddress, "writeDaily", param) print "write daily ", response
def gdbm_view(request): if request.method == "GET": search_key = request.GET.get("search_key", None) host = request.GET.get("host", None) port = request.GET.get("port", None) strDb = "XtTradeData" param_key = {"strDb": strDb} param_value = {} if host and port: r = RPCClient(host=host, port=int(port)) keys = r.request("getAllKeys", param_key).values()[0] results = [] for item in keys: if re.search(search_key, item): param_value = {"strDb": strDb, "strKey": item} ret = r.request("readData", param_value).values()[0] results.append([item, json.dumps(ret)]) return render_to_response("demo/gdbm_view.html", locals(), context_instance=RequestContext(request)) elif request.method == "POST": response = {"success": False, "error": "", "id": None} try: response["success"] = True response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def gdbm_view(request): if request.method == "GET": search_key = request.GET.get('search_key', None) host = request.GET.get('host', None) port = request.GET.get('port', None) strDb = 'XtTradeData' param_key = {'strDb': strDb} param_value = {} if host and port: r = RPCClient(host=host, port=int(port)) keys = r.request('getAllKeys', param_key).values()[0] results = [] for item in keys: if re.search(search_key, item): param_value = {'strDb': strDb, 'strKey': item} ret = r.request('readData', param_value).values()[0] results.append([item, json.dumps(ret)]) return render_to_response("demo/gdbm_view.html", locals(), context_instance=RequestContext(request)) elif request.method == 'POST': response = {"success": False, "error": "", "id": None} try: response["success"] = True response["error"] = "执行成功!" return HttpResponse(json.dumps(response), mimetype="application/json") except Exception, e: response["error"] = "系统异常![%s]" % str(e) logger.error(response["error"] + getTraceBack()) return HttpResponse(json.dumps(response), mimetype="application/json")
def dispatchFromFile(market, dir): # 请求交易日 fileName = "%s/%s_tradeDate" % (dir, market) response = loadFromFile(fileName) # 写入交易日信息 address = WriterAddress.split(":") client = RPCClient(address[0], int(address[1]), 100) for x in response["C"]: param = {"F": {"M": market, "S": "FFFFFF"}, "C": [{"C": x}]} r = client.request("writeData", param) #print "write data ", param # 更新市场状态 if len(response["C"]) > 1: r = client.request( "update", { u"path": "marketStatus/%s" % market, u"data": { u"date": response["C"][-1]["G"], u"status": 2 } }) print "update market status", param # 写入日数据信息 if len(response["C"]) > 1: lastDate = response["C"][-1]["G"] print lastDate fileName = "%s/%s_stockList" % (dir, market) response = loadFromFile(fileName) print "request by daily ", len(response) param = {"M": market, "G": lastDate, "C": response} response = request(WriterAddress, "writeDaily", param) print "write daily ", response
def sync_request(func_name, params, gateway=TT_GATEWAY): """ 基础RPC请求方法 :param func_name: :param params: :param gateway: :return: """ s_client = RPCClient(TT_IP, TT_PORT, 10) return s_client.request(gateway, {"function": func_name, "param": params, "session": TT_SESSION_KEY})
def call(rpcname, rpcparams): try: #client = RPCClient(rpcparams["ip"],rpcparams["port"],"json", 60) client = RPCClient("192.168.1.111", 64350, "json", 60) except: rpcResult = { "content": [], "error": { "ErrorID": -101, "ErrorMsg": u'与mobileService连接超时' } } logger.error(traceback.format_exc()) return rpcResult if rpcparams.has_key("ip"): del rpcparams["ip"] if rpcparams.has_key("port"): del rpcparams["port"] #登录时对参数的处理 if rpcname == "login": rpcparams["strIPAddress"] = rpcparams["request_IP"] del rpcparams["request_IP"] #调用接口的容错处理 try: rpcparams["strPassword"] = generate_password( rpcparams["strPassword"]) rpcResult = client.request("login", rpcparams) except: rpcResult = { "content": [], "error": { "ErrorID": -102, "ErrorMsg": u'与mobileService连接超时' } } logger.error(traceback.format_exc()) #调用其它接口 else: try: rpcResult = client.request(rpcname, rpcparams) except: rpcResult = { "content": [], "error": { "ErrorID": -103, "ErrorMsg": u'与mobileService连接超时' } } logger.error(traceback.format_exc()) # time.sleep(2) #print traceback.format_exc() return rpcResult
def sync_request(func_name, params, gateway=TT_GATEWAY): """ 基础RPC请求方法 :param func_name: :param params: :param gateway: :return: """ s_client = RPCClient(TT_IP, TT_PORT, 10) return s_client.request(gateway, { "function": func_name, "param": params, "session": TT_SESSION_KEY })
def dispatchFromNet(market): # 请求交易日 param = { "market": market, "stock": "FFFFFF", "metaId": 2, "period": 86400000L, "timeTag": 0x1F3FFFFF830L, "compress": False } response = request(ReaderAddress, "requestByCount", param) # 写入交易日信息 address = WriterAddress.split(":") client = RPCClient(address[0], int(address[1]), 100) for x in response["C"]: param = {"F": {"M": market, "S": "FFFFFF"}, "C": [{"C": x}]} r = client.request("writeData", param) #print "write data ", param # 更新市场状态 if len(response["C"]) > 1: r = client.request( "update", { u"path": u"marketStatus/%s" % market, u"data": { u"date": response["C"][-1]["G"], u"status": 2 } }) print "update market status", param # 写入日数据信息 if len(response["C"]) > 1: lastDate = response["C"][-1]["G"] print lastDate param = { "market": "SF", "stock": "XXXXXX", "metaId": 2000, "period": 86400000L, "timeTag": lastDate, "seq": 0L, "compress": False } response = request(ReaderAddress, "requestByDaily", param) print "request by daily ", len(response) param = {"M": market, "G": lastDate, "C": response} response = request(WriterAddress, "writeDaily", param) print "write daily ", response
def dispatchFromNet(market): # 请求交易日 param = { "market": market, "stock": "FFFFFF", "metaId": 2, "period": 86400000L, "timeTag": 0x1F3FFFFF830L, "compress": False, } response = request(ReaderAddress, "requestByCount", param) # 写入交易日信息 address = WriterAddress.split(":") client = RPCClient(address[0], int(address[1]), 100) for x in response["C"]: param = {"F": {"M": market, "S": "FFFFFF"}, "C": [{"C": x}]} r = client.request("writeData", param) # print "write data ", param # 更新市场状态 if len(response["C"]) > 1: r = client.request( "update", {u"path": u"marketStatus/%s" % market, u"data": {u"date": response["C"][-1]["G"], u"status": 2}} ) print "update market status", param # 写入日数据信息 if len(response["C"]) > 1: lastDate = response["C"][-1]["G"] print lastDate
def __init__(self, host, port, handler=None): RPCClient.__init__(self, host, port, 0) self._cb = {}