Пример #1
0
def create_order():
    """
    单个下单
    :return:
    """
    api_key = Con().environment(wbf_config.env_name)[0]
    secret_key = Con().environment(wbf_config.env_name)[1]
    request_path = '/open/api/create_order'
    host = Con().environment(wbf_config.env_name)[-2]
    side = ['BUY', 'SELL']
    tye = [1, 2, 3]
    symbol = wbf_config.symbols
    for sym in range(0, len(symbol)):
        print(type(random.random()))
        price = abs(round(Order().lastprice(symbol[sym]) - random.random(), 2))
        print(price)
        params = {
            'side': side[0],
            "type": tye[0],
            "volume": round(random.random() + 5, 2),
            "symbol": symbol[sym],
            "api_key": api_key,
            "time": Con().now_time(),
            "price": price
        }
        res = Signature(secret_key).post_sign(wbf_config.typ, params,
                                              request_path, host)
        print('下单响应:{}'.format(res))
Пример #2
0
 def market_depth(self, sym, typ):
     """
     获取市场买卖盘
     :return:
     """
     request_path = '/open/api/market_dept'
     url = Con().environment(wbf_config.env_name)[-2] + request_path
     params = {"symbol": sym, "type": typ}
     try:
         res = requests.get(url=url, params=params)
         if res.status_code == 200:
             r = res.json()
             # print(r)
             return r
     except Exception as e:
         # print('error:{}'.format(e))
         Con().return_log(params, url, e)
Пример #3
0
 def order_cancel(self, types, p, secret_key):
     """
     撤销订单
     :param p:
     :return:
     """
     request_path = '/open/api/cancel_order'
     result = wbf_signature.Signature(secret_key).post_sign(
         types, p, request_path,
         Con().environment(wbf_config.env_name)[-2])
     print('撤销订单:{}'.format(result))
Пример #4
0
 def lastprice(self, symbol):
     """
     获取最新成交价
     :param symbol:
     :return:
     """
     url = Con().environment(wbf_config.env_name)[-2] + '/open/api/market'
     params = {"symbol": symbol}
     try:
         result = requests.get(url, params=params)
         # print(result.json())
         if result.status_code == 200:
             last_price = float(result.json()['data'][symbol])
             if last_price is None:
                 return 0
             else:
                 print(type(last_price))
                 return last_price
     except Exception as e:
         print("error:{}".format(e))
         Con().return_log(params, url, e)
Пример #5
0
    def get_sign(self, types, p, request_path, host):
        if types == 'old':
            si = self.sign(p)
            print('请求老的验签方式:{}'.format(si))
        else:
            si = self.share_sign(p, 'GET', host, request_path)
            print('请求新的验签方式:{}'.format(si))

        url = host + request_path
        print("请求域名:{}".format(url))
        p['sign'] = si
        print("请求参数:{}".format(p))
        try:
            res = requests.get(url=url, params=p)
            if res.status_code == 200:
                r = res.json()
                return r
        except Exception as e:
            Con().return_log(p, url, e)
Пример #6
0
    def post_sign(self, types, p, request_path, host):
        if types == 'old':
            si = self.sign(p)
            print('请求老的验签方式:{}'.format(si))
        else:
            si = self.share_sign(p, 'POST', host, request_path)
            print('请求新的验签方式:{}'.format(si))
        url = host + request_path
        print("请求域名:{}".format(url))
        p['sign'] = si
        print("请求参数:{}".format(p))
        try:
            headers = {
                'content-type': "application/x-www-form-urlencoded",
                'cache-control': "no-cache"
            }
            res = requests.post(url=url, data=p, headers=headers)
            print('response-code:{}'.format(res))
            if res.status_code == 200:
                r = res.json()
                return r

        except Exception as e:
            Con().return_log(p, url, e)