• 递归拉取订单列表的方法


    拉取交易所订单列表时,常常需要分页拉取,但调用的时候希望一次获得完整的数据,这时采用递归的方式

    订单json如下所示

    {
        "datas":{
            "totalRow":625,
            "entrustList":[
                {
                    "entrustId":"E6615806999819034624",
                    "type":1,
                    "completeAmount":"0",
                    "price":"0.001874",
                    "availabelAmount":"1047",
                    "sequeueId":6615806999819034624,
                    "completeTotalMoney":"0",
                    "amount":"1047",
                    "createTime":1577331304507,
                    "status":0
                },
                {
                    "entrustId":"E6615806999282163712",
                    "type":1,
                    "completeAmount":"0",
                    "price":"0.001883",
                    "availabelAmount":"1047",
                    "sequeueId":6615806999282163712,
                    "amount":"1047",
                    "createTime":1577331304379,
                    "status":0
                }
            ],
            "totalPage":63,
            "pageSize":10,
            "pageNum":2
        },
        "resMsg":{
            "code":"1",
            "message":"success !",
            "enMessage":"None"
        }
    }

    python3代码如下

        #获取未成交订单
        def order_open(self, symbol, **kwargs):
            body = {
                'marketId'  : self.market2id[symbol],
                'pageIndex' : 1,
                'pageSize'  : 100,
            }
    
            for key, value in kwargs.items():
                body[key] = value
    
            params = {
                'body'      :body,
                'timestamp' :str(int(time.time() * 1000))
            }
            params['sign'] = self.signature("GET", params)
            url = self._web_url + '/oder_open'
            result = self.http_request(url, method = "GET", params = params)
    
            dict = {}
            for item in result["datas"]["entrustList"]:
                filter_dict = {}
                filter_dict['price'] = float(item["price"])
                filter_dict['quantity'] = float(item["amount"])
                filter_dict['direction'] = 'BUY' if item["type"] == 1 else "SELL"
                filter_dict['time'] = float(item["createTime"])
                dict[item["entrustId"]] = filter_dict
    
            if (body['pageIndex'] <= int(result["datas"]["totalRow"] / 100)):
                dict.update(self.order_open(symbol, pageIndex=body['pageIndex'] + 1))
                return dict
            else:
                return dict

    递归的核心在于这一段

            if (body['pageIndex'] <= int(result["datas"]["totalRow"] / 100)):
                dict.update(self.order_open(symbol, pageIndex=body['pageIndex'] + 1))
                return dict
            else:
                return dict
  • 相关阅读:
    删除svn版本信息
    ArcGIS Server中创建ao对象的CLSID如何获得
    操作系统引导
    有关IHttpModule与页面的执行顺序
    使用python查询中文汉字的Unicode
    VIM 入门(转载)
    Visual Studio 2010 添加vim支持
    win7 安装arcgis后出现问题解决方案
    C++中动态链接库的一些概念及入门(2)
    VS2010 MSDN
  • 原文地址:https://www.cnblogs.com/bitquant/p/recursion_order_list.html
Copyright © 2020-2023  润新知