def oneclick_add_transaction(token,side,base_currency,amount,trx_cash,pay_way,quote_currency="CNY",nationality=""): # 客户一键下单 url = "%s/api/v1/otc/oneclick/add_transaction" % B3_url if side == "0": pay_detail = '' elif side == "1": payway_list = user_payway_get_list(token) if 0 >= int(pay_way) > 7 : return print("pay_way参数不合法") for pay in payway_list: if pay["pay_way"] == int(pay_way): pay_detail=json.dumps(pay["pay_detail"],ensure_ascii=False) print(pay_detail) break else: continue else: return print("参数错误") body = { "token": token, "side":side, "base_currency":base_currency, "amount":amount, "trx_cash":trx_cash, "pay_way":pay_way, "pay_detail":pay_detail, "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))
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))
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))
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))
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))
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))
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))
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))
def futures_trigger_close_orders(token, symbol, contract_code, state, direction, start_date="90", page_number="1", page_size="10"): # 6780-获取历史计划委托 url = "%s/api/v1/futures/order/trigger/close_orders" % B3_url body = { "token": token, "symbol": symbol, "contract_code": contract_code, "state": state, # 委托状态,取值范围:succeed=执行成功 failed=执行失败 canceled=已撤销 不传或传空字符串则默认为以上全部 "direction": direction, # 交易方向,取值范围:buy_open=买入开多 buy_close=买入平空 sell_open=卖出开空 sell_close=卖出平多,不传或传空字符串则默认为以上全部 "start_date": start_date, # 起始天数,取值范围:[1, 90],默认值:90 "page_number": page_number, "page_size": page_size } 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(demjson.decode(run.response))
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))
def futures_lighting_close_position(token, contract_code, direction, quantity, source="app"): # 6708-闪电平仓下单 url = "%s/api/v1/futures/order/lighting_close_position" % B3_url body = { "token": token, "contract_code": contract_code, # 合约代号 "direction": direction, # 交易方向,取值范围:buy=买入 sell=卖出 "quantity": quantity, # 下单数量 "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, "交易方向:" + direction) else: print(json.loads(run.response))
def futures_user_liquidation_orders(token, page_number, page_size, start_date="", contract_code="", direction="", symbol=""): # 6537-获取用户强平订单 url = "%s/api/v1/futures/order/liquidation_orders" % B3_url body = { "token": token, "symbol": symbol, "contract_code": contract_code, "direction": direction, # 交易方向,取值范围:buy_close=买入强平 sell_close=卖出强平,不传或传空字符创则默认为以上全部 "page_number": page_number, "page_size": page_size, "start_date": start_date # 查询起始天数,取值范围:[1, 90] } 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(demjson.decode(run.response))
def futures_history_trades(token, page_number, page_size, start_date, contract_code="", direction="", symbol=""): # 3783-获取历史成交记录 url = "%s/api/v1/futures/order/history_trades" % B3_url body = { "token": token, "symbol": symbol, "contract_code": contract_code, "direction": direction, "page_number": page_number, "page_size": page_size, "start_date": start_date # 查询起始天数,取值范围:[1, 90] } 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(demjson.decode(run.response))
def futures_close_orders(token, page_number, page_size, state="", contract_code="", symbol=""): # 3378-获取历史委托 url = "%s/api/v1/futures/order/close_orders" % B3_url body = { "token": token, "page_number": page_number, "page_size": page_size, "state": state, # 订单状态,取值范围:filled=已成交,cancelled=已撤销,不传或传空字符串则为全部 "symbol": symbol, # 合约品种,默认全部,不与contract_code同时生效,contract_code存在时优先使用contract_code "contract_code": contract_code # 合约代码,默认全部,不与symbol同时生效,contract_code存在时优先使用contract_code } 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)) print(json.loads(run.response))
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))
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))
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))
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))
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))
def send_email_sms(sms_type, account, token="", language="zh"): #发送邮箱验证码-验证码发送成功后服务器返回的验证码ID url = "%s/api/v1/send/mail" % B1_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(PC_apikey, PC_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))
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))
def online_modify_login_pwd(token, password, account, dialing_code=""): #线上修改登录密码 url = "%s/api/v1/user/modify_login_pwd" % B1_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 + "YDEXSS").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))
def login_step2(verification_token, verification_id, verification_code, account, platform="2", dialing_code=""): url = "%s/api/v1/user/login/step2" % B1_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))
def modify_login_pwd(token, password, account, dialing_code=""): # 修改登录密码 url = "%s/api/v1/user/modify_login_pwd" % B1_url db = DB('mysql.b1dev.xyz', 3306, 'gpex', 'H8WidnS054aM', 'gpex') # B1devDB 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 = 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 + "YDEXSS").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))
def login_step1(account, password, type, dialing_code=""): url = "%s/api/v1/user/login/step1" % B1_url password = str( hashlib.sha256((password + "YDEXSS").encode('utf-8')).hexdigest()) body = { "type": type, #账号类型,1=手机号码 2=邮箱地址 "dialing_code": dialing_code, #国际电话区号,仅当type=1 时有效 "account": account, "password": password #SHA256加密后的登录密码 } 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)) # print(password) code = json.loads(run.response)["code"] if code == 1000: verification_token = json.loads( run.response)["data"]["verification_token"] # print(verification_token) return verification_token else: print(json.loads(run.response))
def modify_nickname(token, nickname): url = "%s/api/v1/user/modify_nickname" % B1_url body = {"token": token, "nickname": nickname} run = RunMain(url=url, params=None, data=body, headers=get_signture(PC_apikey, PC_apisecret, body), method='POST') out_log(url, body, json.loads(run.response)) print(json.loads(run.response))
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))
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))
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))
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))