Ejemplo n.º 1
0
def futures_order_trigger_place(token, contract_code, direction, price, quantity, lever, trigger_type, trigger_price,
                                source="app"):
    # 6726-计划委托下单
    url = "%s/api/v1/futures/order/trigger/place" % B4_url
    body = {
        "token": token,
        "contract_code": contract_code,  # 合约代号
        "direction": direction,  # 交易方向,取值范围:buy_open=买入开多 buy_close=买入平空 sell_open=卖出开空 sell_close=卖出平多
        "price": price,  # 下单价格,0=按市价下单
        "quantity": quantity,  # 下单数量
        "source": source,  # 订单来源,取值范围:app | web
        "lever": lever,  # 杠杆倍数
        "trigger_type": trigger_type,  # 触发类型,取值范围:ge=大于等于(最新价比触发价大) le=小于等于(最新价比触发价小)
        "trigger_price": trigger_price  # 触发价格
    }
    run = RunMain(url=url, params=None, data=body,
                  headers=get_signture(Android_apikey, Android_apisecret, body), method='POST')
    out_log(url, send_msg=body, response_msg=json.loads(run.response))
    if json.loads(run.response)["code"] == 1000:
        order_id = json.loads(run.response)["data"]["order_id"]
        print("计划委托单号:" + order_id,
              "合约代号:" + contract_code,  # 合约代号
              "交易方向:" + direction,  # 交易方向,取值范围:buy=买入 sell=卖出
              "下单价格:" + price,  # 下单价格,0=按市价下单
              "下单数量:" + quantity,  # 下单数量
              "杠杆倍数:" + lever,  # 杠杆倍数
              "触发类型:" + trigger_type,  # 触发类型,取值范围:ge=大于等于(最新价比触发价大) le=小于等于(最新价比触发价小)
              "触发价格:" + trigger_price  # 触发价格
              )
    else:
        print(json.loads(run.response))
Ejemplo n.º 2
0
def futures_add_order(token, contract_code, direction, quantity, price, lever, source):
    # 3342-合约下单
    url = "%s/api/v1/futures/order/place" % B4_url
    body = {
        "token": token,
        "contract_code": contract_code,  # 合约代号
        "direction": direction,  # 交易方向,取值范围:sell_close=卖出平仓 sell_open=卖出开仓 buy_close=买入平仓 buy_open=买入开仓
        "quantity": quantity,  # 下单数量
        "price": price,  # 下单价格,0=按对手价下单
        "lever": lever,  # 杠杆倍数
        "source": source  # 订单来源,取值范围:app | web
    }
    run = RunMain(url=url, params=None, data=body,
                  headers=get_signture(Android_apikey, Android_apisecret, body), method='POST')
    out_log(url, send_msg=body, response_msg=json.loads(run.response))
    if json.loads(run.response)["code"] == 1000:
        order_id = json.loads(run.response)["data"]["order_id"]
        print("单号:" + order_id,
              "下单数量:" + quantity,
              "下单价格:" + price,
              "杠杆倍数:" + lever,
              "交易方向:" + direction
              )
    else:
        print(json.loads(run.response))
Ejemplo n.º 3
0
def online_apikey_modify(account,
                         token,
                         api_key,
                         bind_ip,
                         remark,
                         permission,
                         dialing_code="86"):
    #修改ApiKey信息
    url = "%s/api/v1/merchant/apikey/modify" % B4_url
    # verification_id = send_email_sms(sms_type="9", account=account,token=token, language="zh")
    verification_id = send_sms(sms_type="9",
                               account=account,
                               token=token,
                               language="zh",
                               dialing_code=dialing_code)
    verification_code = input("验证码:")
    body = {
        "token": token,
        "api_key": api_key,
        "verification_code": verification_code,
        "verification_id": verification_id,
        "bind_ip": bind_ip,
        "remark": remark,
        "permission": permission
    }
    run = RunMain(url=url,
                  params=None,
                  data=body,
                  headers=get_signture(H5_apikey, H5_apisecret, body),
                  method='POST')
    out_log(url, send_msg=body, response_msg=json.loads(run.response))
    print(json.loads(run.response))
Ejemplo n.º 4
0
def payway_add(token, pay_way, pay_detail, account, dialing_code=""):
    #添加收付款方式
    url = "%s/api/v1/payway/add" % B4_url
    # verification_id = send_sms(sms_type="6", account=account, dialing_code=dialing_code, token=token, language="zh")
    verification_id = send_email_sms(sms_type="6",
                                     account=account,
                                     token=token)
    db = DB('mysql.b4dev.xyz', 3306, 'b4_api', 'eYKRj3Vp@zM0SGWj',
            'b4')  # B4devDB
    verification_code = db.query(
        "SELECT verification_code FROM `user_verification_code` WHERE user_account = '%s' ORDER BY code_over_time DESC LIMIT 1"
        % (dialing_code + account))[0][0]
    pay_detail = json.dumps(pay_detail, ensure_ascii=False)
    body = {
        "token": token,
        "pay_way": pay_way,
        "pay_detail": pay_detail,
        "verification_id": verification_id,
        "verification_code": verification_code
    }
    run = RunMain(url=url,
                  params=None,
                  data=body,
                  headers=get_signture(H5_apikey, H5_apisecret, body),
                  method='POST')
    out_log(url, response_msg=json.loads(run.response))
    print(json.loads(run.response))
Ejemplo n.º 5
0
def apikey_create(account,
                  token,
                  permission,
                  bind_ip,
                  remark,
                  dialing_code="86"):
    #申请ApiKey
    url = "%s/api/v1/merchant/apikey/create" % B4_url
    db = DB(host, port, user, password, database)  # B4devDB
    # verification_id = send_email_sms(sms_type="8", account=account,token=token, language="zh")
    verification_id = send_sms(sms_type="8",
                               account=account,
                               token=token,
                               language="zh",
                               dialing_code=dialing_code)
    verification_code = db.query(
        "SELECT verification_code FROM `user_verification_code` WHERE user_account = '%s' ORDER BY code_over_time DESC LIMIT 1"
        % (dialing_code + account))[0][0]
    body = {
        "token": token,
        "permission": permission,  #权限类型,取值范围:1=读取 2=交易 4=划转,可组合使用
        "verification_code": verification_code,
        "verification_id": verification_id,
        "bind_ip": bind_ip,
        "remark": remark
    }
    run = RunMain(url=url,
                  params=None,
                  data=body,
                  headers=get_signture(H5_apikey, H5_apisecret, body),
                  method='POST')
    out_log(url, send_msg=body, response_msg=json.loads(run.response))
    print(json.loads(run.response))
Ejemplo n.º 6
0
def authentication_kyc(token,
                       name,
                       certificate_type,
                       certificate_no,
                       face_photo="",
                       nationality="156"):
    #提交KYC实名认证
    url = "%s/api/v1/authentication/kyc" % B4_url
    body = {
        "token": token,
        "name": name,
        "certificate_type": certificate_type,  #证件类型,0=其他 1=护照 2=身份证
        "certificate_front": "ff4e9cac40a2d5e8e4538e36df2b5b35.png",
        "certificate_back": "ff4e9cac40a2d5e8e4538e36df2b5b35.png",
        "certificate_handheld": "ff4e9cac40a2d5e8e4538e36df2b5b35.png",
        "certificate_no": certificate_no,  #证件号码
        "nationality": nationality,
        "face_photo": face_photo  #人脸识别照片
    }
    run = RunMain(url=url,
                  params=None,
                  data=body,
                  headers=get_signture(IOS_apikey, IOS_apisecret, body),
                  method='POST')
    out_log(url, send_msg=body, response_msg=json.loads(run.response))
    print(json.loads(run.response))
Ejemplo n.º 7
0
def futures_get_contracts():
    # 3279-获取合约基本配置
    url = "%s/api/v1/futures/contract/contract_config" % B4_url
    run = RunMain(url=url, params=None, data=None,
                  headers=get_signture(Android_apikey, Android_apisecret), method='GET')
    out_log(url, response_msg=json.loads(run.response))
    print(json.loads(run.response))
Ejemplo n.º 8
0
def oneclick_matched_orders(token,
                            side,
                            base_currency,
                            amount="",
                            trx_cash="",
                            quote_currency="CNY",
                            nationality=""):
    # 获取一键下单匹配的广告
    url = "%s/api/v1/otc/oneclick/matched_orders" % B4_url
    body = {
        "token": token,
        "side": side,
        "base_currency": base_currency,
        "amount": amount,
        "trx_cash": trx_cash,
        "quote_currency": quote_currency,
        "nationality": nationality,
    }
    run = RunMain(url=url,
                  params=None,
                  data=body,
                  headers=get_signture(H5_apikey, H5_apisecret, body),
                  method='POST')
    out_log(url, send_msg=body, response_msg=json.loads(run.response))
    print(json.loads(run.response))
Ejemplo n.º 9
0
def cancel_all_orders(token_wen):
    # 下架商户所有广告
    url = "%s/api/v1/otc/get_orders" % B4_url
    body = {
        "token": token_wen,
        "page_number": "1",
        "page_size": "20",
        "state": "1"
    }
    # print(parmas_cancel_all_orders)
    run = RunMain(url=url,
                  params=None,
                  data=body,
                  headers=get_signture(H5_apikey, H5_apisecret, body),
                  method='POST')
    out_log(url, response_msg=json.loads(run.response))
    if json.loads(run.response)["code"] == 1000:
        data = json.loads(run.response)["data"]
        # print(data)
        if data != []:
            for i in data:
                order_id = i["order_id"]
                cancel_order(token_wen, order_id)
        else:
            print("没有可下架广告")
        return run.response
    else:
        print(json.loads(run.response))
Ejemplo n.º 10
0
def buy_payway_detail(token_wen):
    # 获取收付款列表
    url = "%s/api/v1/payway/get_list" % B4_url
    body = {"token": token_wen}
    run = RunMain(url=url,
                  params=None,
                  data=body,
                  headers=get_signture(H5_apikey, H5_apisecret, body),
                  method='POST')
    out_log(url, response_msg=json.loads(run.response))
    if json.loads(run.response)["code"] == 1000:
        # print(json.loads(run.response))
        # 发布广告的收付款详情
        pay = json.loads(run.response)["data"]
        payway = 0
        buy_pay_detail = []
        for i in pay:
            p = payway
            payway = (payway | i['pay_way'])
            if p != payway:
                buy_pay_detail.append({"pay_way": i['pay_way']})
        # print(buy_pay_detail)
        print("获取发布买广告需要的payway_detail")
        return buy_pay_detail
    else:
        print(json.loads(run.response))
Ejemplo n.º 11
0
def user_sell_transaction(token_junxin, order_id, amount, price):
    # 客户下卖单
    url = "%s/api/v1/otc/add_transaction" % B4_url
    user_sell_pay_detail = json.dumps(sell_payway_detail(token_wen)[0])
    body = {
        "token": token_junxin,
        "order_id": order_id,
        "amount": str(format(amount, ".8f")),
        "pay_way": sell_payway_detail(token_wen)[0]["pay_way"],
        "pay_detail": user_sell_pay_detail,
        "trx_cash": str(format(price * amount, ".2f"))
    }
    # print(parmas_sell_transaction)
    run = RunMain(url=url,
                  params=None,
                  data=body,
                  headers=get_signture(H5_apikey, H5_apisecret, body),
                  method='POST')
    out_log(url, send_msg=body, response_msg=json.loads(run.response))
    if json.loads(run.response)["code"] == 1000:
        trx_id = json.loads(run.response)["data"]["trx_id"]
        print("客户下卖单trx_id:%s" % trx_id)
        return trx_id
    else:
        print(json.loads(run.response))
Ejemplo n.º 12
0
def send_email_sms(sms_type, account, token="", language="zh"):
    #发送邮箱验证码-验证码发送成功后服务器返回的验证码ID
    url = "%s/api/v1/send/mail" % B4_url
    body = {
        "type":
        sms_type,  #验证码类型,1=注册 2=登录 3=重置登录密码 4=修改登录密码 5=重置交易密码 6=添加收款方式 7=钱包提现 8=申请ApiKey  9=编辑ApiKey 10=绑定谷歌验证器
        "account": account,
        "token": token,  #用户令牌 type > 3时必填
        "language": language  #语言,取值:"zh"=简体中文, "en"=英文, 默认"zh"
    }
    run = RunMain(url=url,
                  params=None,
                  data=body,
                  headers=get_signture(Android_apikey, Android_apisecret,
                                       body),
                  method='POST')
    out_log(url, body, json.loads(run.response))
    # print(json.loads(run.response))
    code = json.loads(run.response)["code"]
    # print(code)
    # print(json.loads(run.response))
    if code == 1000:
        verification_id = json.loads(run.response)["data"]["verification_id"]
        # print(verification_id)
        return verification_id
    elif code == 2994:
        wait_time = json.loads(run.response)["data"]["wait_time"]
        print("重新获取验证需等待%d秒" % wait_time)
    else:
        print(json.loads(run.response))
Ejemplo n.º 13
0
def get_orders(token_wen,
               state="7",
               pay_way="0",
               nationality="0",
               base_currency="",
               quote_currency=""):
    #获取商户发布的广告
    url = "%s/api/v1/otc/get_orders" % B4_url
    body = {
        "token": token_wen,
        "page_number": "2",
        "page_size": "10",
        "state": state,  #广告状态,取值:1=可交易;2=完全成交;4=已下架 可组合使用
        "pay_way":
        pay_way,  #【2020.1.13新增】支持的收付款方式,1=银行卡,2=微信,4=支付宝,可组合使用,0=全部,默认值:0
        "nationality": nationality,  #【2020.1.13新增】所属国家或地区(3位数字代码),0=全部,默认值:0
        "base_currency": base_currency,  #【2020.1.13新增】基础币种,""=全部,默认值:""
        "quote_currency": quote_currency  #【2020.1.13新增】报价币种,""=全部,默认值:""
    }
    run = RunMain(url=url,
                  params=None,
                  data=body,
                  headers=get_signture(H5_apikey, H5_apisecret, body),
                  method='POST')
    out_log(url, response_msg=json.loads(run.response))
    if json.loads(run.response)["code"] == 1000:
        print("获取商户发布的广告")
    else:
        print(json.loads(run.response))
Ejemplo n.º 14
0
def register(account,
             password,
             verification_id,
             verification_code,
             type,
             dialing_code="",
             invitation_code="",
             platform="2"):
    #注册
    url = "%s/api/v1/user/register" % B4_url
    password = str(hashlib.sha256(password.encode('utf-8')).hexdigest())
    body = {
        "account": account,
        "password": password,
        "verification_id": verification_id,  # 验证码发送成功后服务器返回的验证码ID
        "type": type,  # 账号类型,1=手机号码 2=邮箱地址
        "dialing_code": dialing_code,  # 国际电话区号,仅当type=1 时有效
        "verification_code": verification_code,  # 验证码
        "invitation_code": invitation_code,  # 邀请码 (非必填)
        "platform": platform  # 终端类型,1=移动端 2=PC端
    }
    run = RunMain(url=url,
                  params=None,
                  data=body,
                  headers=get_signture(Android_apikey, Android_apisecret,
                                       body),
                  method='POST')
    out_log(url, body, json.loads(run.response))
    # print(password)
    code = json.loads(run.response)["code"]
    if code == 1000:
        token = json.loads(run.response)["data"]["token"]
        return token
    else:
        print(json.loads(run.response))
Ejemplo n.º 15
0
def online_modify_login_pwd(token, password, account, dialing_code=""):
    #线上修改登录密码
    url = "%s/api/v1/user/modify_login_pwd" % B4_url
    # verification_id = send_email_sms(sms_type="4", account=account, token=token, language="zh")
    verification_id = send_sms(sms_type="4",
                               account=account,
                               dialing_code=dialing_code,
                               token=token,
                               language="zh")
    verification_code = input("验证码:")
    password = str(hashlib.sha256(password.encode('utf-8')).hexdigest())
    body = {
        "token": token,
        "password": password,
        "verification_code": verification_code,
        "verification_id": verification_id
    }
    run = RunMain(url=url,
                  params=None,
                  data=body,
                  headers=get_signture(H5_apikey, H5_apisecret, body),
                  method='POST')
    out_log(url, send_msg=body, response_msg=json.loads(run.response))
    # print(password)
    print(json.loads(run.response))
Ejemplo n.º 16
0
def reset_login_pwd(password, account, token="", dialing_code=""):
    # 重置登录密码
    url = "%s/api/v1/user/reset_login_pwd" % B4_url
    db = DB('mysql.b4dev.xyz', 3306, 'b4_api', 'eYKRj3Vp@zM0SGWj',
            'b4')  # B4devDB
    # verification_id = send_email_sms(sms_type="4", account=account, token=token, language="zh")
    verification_id = send_sms(sms_type="3",
                               account=account,
                               dialing_code=dialing_code,
                               token=token,
                               language="zh")
    verification_code = db.query(
        "SELECT verification_code FROM `user_verification_code` WHERE user_account = '%s' ORDER BY code_over_time DESC LIMIT 1"
        % (dialing_code + account))[0][0]
    print(verification_code)
    password = str(hashlib.sha256(password.encode('utf-8')).hexdigest())
    print(password)
    body = {
        "token": token,
        "account": account + dialing_code,
        "password": password,
        "verification_code": verification_code,
        "verification_id": verification_id
    }
    run = RunMain(url=url,
                  params=None,
                  data=body,
                  headers=get_signture(H5_apikey, H5_apisecret, body),
                  method='POST')
    out_log(url, send_msg=body, response_msg=json.loads(run.response))
    # print(password)
    print(json.loads(run.response))
Ejemplo n.º 17
0
def login_step2(verification_token,
                verification_id,
                verification_code,
                account,
                platform="2",
                dialing_code=""):
    url = "%s/api/v1/user/login/step2" % B4_url
    body = {
        "verification_token": verification_token,  # 登录步骤1验证通过后返回的登录验证令牌
        "verification_code": verification_code,  # 验证码
        "verification_id": verification_id,  # 验证码发送成功后服务器返回的验证码ID
        "account": dialing_code + account,  #账号(国际电话区号+手机号码/邮箱地址)
        "platform": platform  #终端类型,1=移动端 2=PC端
    }
    run = RunMain(url=url,
                  params=None,
                  data=body,
                  headers=get_signture(H5_apikey, H5_apisecret, body),
                  method='POST')
    out_log(url, body, json.loads(run.response))
    code = json.loads(run.response)["code"]
    if code == 1000:
        token = json.loads(run.response)["data"]["token"]
        return token
    else:
        print(json.loads(run.response))
Ejemplo n.º 18
0
def parameter_get_currency_parameters():
    #获取币种配置参数
    url = "%s/api/v1/parameter/get_currency_parameters" % B4_url
    run = RunMain(url=url,
                  params=None,
                  data=None,
                  headers=get_signture(IOS_apikey, IOS_apisecret),
                  method='GET')
    out_log(url, response_msg=json.dumps(run.response, ensure_ascii=False))
    print(json.loads(run.response))
Ejemplo n.º 19
0
def get_tradePairs():
    # 获取交易对
    url = '%s/api/v1/common/get_tradePairs' % B4_url
    run = RunMain(url=url,
                  params=None,
                  data=None,
                  headers=get_signture(H5_apikey, H5_apisecret),
                  method='GET')
    out_log(url, response_msg=json.loads(run.response))
    print(json.loads(run.response))
Ejemplo n.º 20
0
def employee_role_info(token):
    # 3711-获取当前用户的代理商或员工角色信息
    url = "%s/api/v1/futures/agent/role_info" % B4_url
    body = {
        "token": token,
    }
    run = RunMain(url=url, params=None, data=body,
                  headers=get_signture(Android_apikey, Android_apisecret, body), method='POST')
    out_log(url, response_msg=json.loads(run.response))
    print(json.loads(run.response))
Ejemplo n.º 21
0
def common_partitions():
    #获取所有交易区
    url = "%s/api/v1/common/partitions" % B4_url
    run = RunMain(url=url,
                  params=None,
                  data=None,
                  headers=get_signture(IOS_apikey, IOS_apisecret),
                  method='GET')
    out_log(url, response_msg=json.loads(run.response))
    print(json.loads(run.response))
Ejemplo n.º 22
0
def common_contracts_symbols():
    #合约交易-获取平台合约品种
    url = "%s/api/v1/futures/common/symbols" % B4_url
    run = RunMain(url=url,
                  params=None,
                  data=None,
                  headers=get_signture(H5_apikey, H5_apisecret),
                  method='GET')
    out_log(url, response_msg=json.loads(run.response))
    print(json.loads(run.response))
Ejemplo n.º 23
0
def get_assets_c2c(token):
    # 获取C2C账户资产列表
    url = "%s/api/v1/wallet/get_assets_c2c" % B4_url
    body = {
        "token": token,
    }
    run = RunMain(url=url, params=None, data=body,
                  headers=get_signture(H5_apikey, H5_apisecret, body), method='POST')
    out_log(url, send_msg=body, response_msg=json.loads(run.response))
    print(json.loads(run.response))
Ejemplo n.º 24
0
def invitation_my_stats(token):
    # 3756-获取我的邀请统计信息
    url = "%s/api/v1/invitation/my_stats" % B4_url
    body = {
        "token": token,
    }
    run = RunMain(url=url, params=None, data=body,
                  headers=get_signture(Android_apikey, Android_apisecret, body), method='POST')
    out_log(url, response_msg=json.loads(run.response))
    print(json.loads(run.response))
Ejemplo n.º 25
0
def common_timestamp():
    #获取系统当前时间
    url = "%s/api/v1/common/timestamp" % B4_url
    run = RunMain(url=url,
                  params=None,
                  data=None,
                  headers=get_signture(H5_apikey, H5_apisecret),
                  method='GET')
    out_log(url, response_msg=json.loads(run.response))
    print(json.loads(run.response))
Ejemplo n.º 26
0
def last10min_avg_index_price(symbol):
    # 获取最近一小时合约指数均价
    url = "%s/v2/futures/market/last10min_avg_index_price" % B4_url
    body = {
        "symbol": symbol,
    }
    run = RunMain(url=url, params=body, data=None,
                  headers=get_signture(Android_apikey, Android_apisecret, body), method='GET')
    out_log(url, response_msg=json.loads(run.response))
    print(json.loads(run.response))
Ejemplo n.º 27
0
def parameter_get_tradePair_config():
    #获取交易对配置参数
    url = "%s/api/v1/parameter/get_tradePair_config" % B4_url
    run = RunMain(url=url,
                  params=None,
                  data=None,
                  headers=get_signture(IOS_apikey, IOS_apisecret),
                  method='GET')
    out_log(url, response_msg=json.loads(run.response))
    print(json.loads(run.response))
Ejemplo n.º 28
0
def employee_stats(token):
    # 3666-获取代理商推广员邀请统计信息
    url = "%s/api/v1/futures/agent/employee/stats" % B4_url
    body = {
        "token": token,
    }
    run = RunMain(url=url, params=None, data=body,
                  headers=get_signture(Android_apikey, Android_apisecret, body), method='POST')
    out_log(url, response_msg=json.loads(run.response))
    print(json.loads(run.response))
Ejemplo n.º 29
0
def parameter_get_registration_countries():
    #获取开放注册的国家和地区
    url = "%s/api/v1/parameter/get_registration_countries" % B4_url
    run = RunMain(url=url,
                  params=None,
                  data=None,
                  headers=get_signture(IOS_apikey, IOS_apisecret),
                  method='GET')
    out_log(url, response_msg=json.loads(run.response))
    print(json.loads(run.response))
Ejemplo n.º 30
0
def futures_contract_open_interest(contract_code):
    # 6600-获取合约总持仓量
    url = "%s/api/v1/futures/market/contract_open_interest" % B4_url
    body = {
        "contract_code": contract_code,
    }
    run = RunMain(url=url, params=body, data=None,
                  headers=get_signture(Android_apikey, Android_apisecret, body), method='GET')
    out_log(url, response_msg=json.loads(run.response))
    print(json.loads(run.response))