import requests
def get_price(tick, level='1', op="buy"):
    level = int(level)
    str_ticker = tick.lower()

    rep_data = requests.get("http://qt.gtimg.cn/q=" + str_ticker).text
    print(rep_data)
    stocks_detail = "".join(rep_data)
    stock_detail = stocks_detail.split(";")[0]
    if len(stock_detail) < 49:
        return
    stock = stock_detail.split("~")

    buy1 = float(stock[9])
    buy2 = float(stock[11])
    buy3 = float(stock[13])
    buy4 = float(stock[15])
    buy5 = float(stock[17])

    sell1 = float(stock[19])
    sell2 = float(stock[21])
    sell3 = float(stock[23])
    sell4 = float(stock[25])
    sell5 = float(stock[27])

    if op == "buy" and level == 1:
        return buy1
    elif op == "buy" and level == 2:
        return buy2
    elif op == "buy" and level == 3:
        return buy3
    elif op == "buy" and level == 4:
        return buy4
    elif op == "buy" and level == 5:
        return buy5

    elif op == "sell" and level == 1:
        return sell1
    elif op == "sell" and level == 2:
        return sell2
    elif op == "sell" and level == 3:
        return sell3
    elif op == "sell" and level == 4:
        return sell4
    elif op == "sell" and level == 5:
        return sell5
    else:
        return float(stock[3])
tick = '601012'
price_level = 5
round_num = 2
price = round(get_price(tick, level=price_level, op='sell') , round_num)
print(price)