def marketPriceBuyAd(user_name='17727820013',
                     password='******',
                     currency=None,
                     payment=7,
                     amount=None,
                     floor=None,
                     ceiling=None):
    """
    发布市价买入广告
    """
    try:
        quotation = get_international_quotation.getInternationalQuotation(
            currency)
        mytoken = login(login_num=user_name,
                        password=password)["data"]["token"]
        jsonString = get_jsonstring_info.market_price_buy_ad_jsonString % (
            repr(currency), payment, amount, floor / quotation,
            ceiling / quotation)
        data = dict(jsonString=jsonString)
        headers = {"token": str(mytoken)}
        r = requests.post(get_url_info.advertising_url,
                          data=data,
                          headers=headers)
        if r.json()['msg'] == '操作完成':
            print("发布市价买入广告成功!")
        if r.json()['msg'] == '每个账户只能挂一张买单':
            print("该用户已经发布了一个买单,想要发布,请升级账户或者撤单再发布")
    except Exception as err:
        print(err)
def sellCurrencyByAmount(user_name=None, password='******', ad_ID_NO=None, trade_amount=None):
    """
    按照总额卖出货币
    """
    try:
        mytoken = login(login_num=user_name, password=password)["data"]["token"]
        advertiser_userid = get_ads_info_in_db.getAdInfo(ad_ID_NO=ad_ID_NO)[0]['userId']      
        currency = get_ads_info_in_db.getAdInfo(ad_ID_NO=ad_ID_NO)[0]['tradeCode']
        unit_price = get_ads_info_in_db.getAdInfo(ad_ID_NO=ad_ID_NO)[0]['priceVal']
        quotation_now = get_international_quotation.getInternationalQuotation(currency=currency)
        headers = {"token": mytoken}

        if get_ads_info_in_db.getAdInfo(ad_ID_NO=ad_ID_NO)[0]['buysell'] == 1:
            if get_ads_info_in_db.judgeIfLimitedPrice(ad_ID_NO=ad_ID_NO) == True:
                jsonString = get_jsonstring_info.sell_fiat_order_limited_jsonString %(repr(ad_ID_NO), 
                repr(advertiser_userid), trade_amount, trade_amount/unit_price, repr(currency))
                data = dict(jsonString=jsonString)
                r = requests.post(get_url_info.place_fiat_order_url, data=data, headers=headers)
                print(r.json()['msg'])
                return r.json()['data']['orderId']
            elif get_ads_info_in_db.judgeIfMarketdPrice(ad_ID_NO=ad_ID_NO) == True:
                jsonString = get_jsonstring_info.sell_fiat_order_market_by_amount_jsonString %(repr(ad_ID_NO),
                repr(advertiser_userid), trade_amount, trade_amount/quotation_now, repr(currency))
                data = dict(jsonString=jsonString)
                r = requests.post(get_url_info.place_fiat_order_url, data=data, headers=headers)
                print(r.json()['msg'])
                return r.json()['data']['orderId']
        elif get_ads_info_in_db.getAdInfo(ad_ID_NO=ad_ID_NO)[0]['buysell'] == 2:
            print('该广告单不是求购广告单')
    except Exception as err:
        print(err)