def batch_create_order(): data = [{ "volume": 0.1, "price": 7000.12, "direction": "ASK", "symbol": "BTC_USDT", "source": "WALLET", "type": "STOP_LIMIT", "stopPrice": "6900", "operator": "lte" }, { "volume": 0.1, "price": 7000.12, "direction": "ASK", "symbol": "BTC_USDT", "source": "WALLET", "type": "STOP_LIMIT", "stopPrice": "6900", "operator": "lte" }] url = API_ENDPOINT + BATCH_CREATE_ORDER + "?orders=" + json.dumps(data) headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'X_ACCESS_KEY': ACCESS_KEY, 'X_SIGNATURE': bkex_api_sign.get_sign(url), } res = requests.post(url=url, headers=headers) print(res.text)
def user_login(): current_time = str(int(round(time.time() * 1000))) ws.send(PRE_42_ACCOUNT + ',["userLogin",{"signature":"' + bkex_api_sign.get_sign(API_ENDPOINT + "?timestamp=" + current_time) + '",' '"accessKey":"' + ACCESS_KEY + '","timestamp":' + current_time + '}]')
def get_open_order_detail(): url = API_ENDPOINT + OPEN_ORDER_DETAIL + "?orderId=2213" headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'X_ACCESS_KEY': ACCESS_KEY, 'X_SIGNATURE': bkex_api_sign.get_sign(url), } res = requests.get(url=url, headers=headers) print(res.text)
def cancel_order(): url = API_ENDPOINT + CANCEL_ORDER + "?orderId=2213" headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'X_ACCESS_KEY': ACCESS_KEY, 'X_SIGNATURE': bkex_api_sign.get_sign(url), } res = requests.post(url=url, headers=headers) print(res.text)
def get_trade_orders(): url = API_ENDPOINT + TRADE_GET_ORDER + "?orderId=507904211109878016&orderType=LIMIT" headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'X_ACCESS_KEY': ACCESS_KEY, 'X_SIGNATURE': bkex_api_sign.get_sign(url), } res = requests.get(url=url, headers=headers) print(res.text)
def get_user_account(): url = API_ENDPOINT + USER_ACCOUNT headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'X_ACCESS_KEY': ACCESS_KEY, 'X_SIGNATURE': bkex_api_sign.get_sign(url), } res = requests.get(url=url, headers=headers) print(res.text)
def get_trade_positions(): url = API_ENDPOINT + TRADE_POSITIONS + "?symbol=BTC-SWAP&side=LONG" headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'X_ACCESS_KEY': ACCESS_KEY, 'X_SIGNATURE': bkex_api_sign.get_sign(url), } res = requests.get(url=url, headers=headers) print(res.text)
def get_history_orders(): url = API_ENDPOINT + TRADE_HISTORY_ORDERS + "?symbol=BTC-SWAP&orderType=LIMIT" headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'X_ACCESS_KEY': ACCESS_KEY, 'X_SIGNATURE': bkex_api_sign.get_sign(url), } res = requests.get(url=url, headers=headers) print(res.text)
def batch_cancel_order(): order_ids = ["2018062321121231231", "2018062321121231232"] url = API_ENDPOINT + BATCH_CANCEL_ORDER + "?orders=" + json.dumps( order_ids) headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'X_ACCESS_KEY': ACCESS_KEY, 'X_SIGNATURE': bkex_api_sign.get_sign(url), } res = requests.post(url=url, headers=headers) print(res.text)
def trade_modify_margin(): url = API_ENDPOINT + TRADE_MODIFY_MARGIN data = { "symbol": "BTC-SWAP", "amount": 0.2564, "side": "LONG" } # 字典转换k1=v1 & k2=v2 模式 data = parse.urlencode(data) headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'X_ACCESS_KEY': ACCESS_KEY, 'X_SIGNATURE': bkex_api_sign.get_sign(url + "?" + data), } res = requests.post(url=url, headers=headers, data=data) print(res.text)
def trade_cancel_order(): url = API_ENDPOINT + TRADE_CANCEL_ORDER data = { "orderType": "LIMIT", "orderId": "507904211109878016", "clientOrderId": "100011111100001" } # 字典转换k1=v1 & k2=v2 模式 data = parse.urlencode(data) headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'X_ACCESS_KEY': ACCESS_KEY, 'X_SIGNATURE': bkex_api_sign.get_sign(url + "?" + data), } res = requests.post(url=url, headers=headers, data=data) print(res.text)
def get_open_orders(): url = API_ENDPOINT + OPEN_ORDERS data = { "symbol": "BTC_USDT", "direction": "ASK", "source": "WALLET", "type": "LIMIT", "sortingWay": "TIME_ASC", "page": 1, "size": 10 } # 字典转换k1=v1 & k2=v2 模式 data = parse.urlencode(data) headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'X_ACCESS_KEY': ACCESS_KEY, 'X_SIGNATURE': bkex_api_sign.get_sign(url + "?" + data), } res = requests.get(url=url + "?" + data, headers=headers) print(res.text)
def create_order(): url = API_ENDPOINT + CREATE_ORDER data = { "volume": 0.1, "price": 7000.12, "direction": "ASK", "symbol": "BTC_USDT", "source": "WALLET", "type": "STOP_LIMIT", "stopPrice": 6900, "operator": "gte", } # 字典转换k1=v1 & k2=v2 模式 data = parse.urlencode(data) headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'X_ACCESS_KEY': ACCESS_KEY, 'X_SIGNATURE': bkex_api_sign.get_sign(url + "?" + data), } res = requests.post(url=url, headers=headers, data=data) print(res.text)
def trade_order(): url = API_ENDPOINT + TRADE_ORDER data = { "symbol": "BTC-SWAP", "side": "BUY_OPEN", "orderType": "LIMIT", "quantity": 10, "leverage": 10, "clientOrderId": "100011111100001", "price": 7928.6, "priceType": "INPUT" } # 字典转换k1=v1 & k2=v2 模式 data = parse.urlencode(data) headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'X_ACCESS_KEY': ACCESS_KEY, 'X_SIGNATURE': bkex_api_sign.get_sign(url + "?" + data), } res = requests.post(url=url, headers=headers, data=data) print(res.text)
def get_history_orders(): url = API_ENDPOINT + HISTORY_ORDER data = { "symbol": "BTC_USDT", "direction": "ASK", "type": "LIMIT", "sortingWay": "TIME_ASC", "filterCancelAll": "true", "page": 1, "size": 10, "startTime": 1532331292000, "endTime": 1532331295000 } # 字典转换k1=v1 & k2=v2 模式 data = parse.urlencode(data) headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'X_ACCESS_KEY': ACCESS_KEY, 'X_SIGNATURE': bkex_api_sign.get_sign(url + "?" + data), } res = requests.get(url=url + "?" + data, headers=headers) print(res.text)
def get_listen_key(): url = API_ENDPOINT + LISTEN_KEY_URL + "?recvWindow=500" data = { 'recvWindow': 500, } headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'X_ACCESS_KEY': ACCESS_KEY, 'X_SIGNATURE': bkex_api_sign.get_sign(url), } # 调用创建listen_key接口 response = requests.post(url=API_ENDPOINT + LISTEN_KEY_URL, headers=headers, data=data) # 转换为json解析 res = json.loads(response.text) listen_key = '' if res['code'] == 0: obj = res['data'] listen_key = obj['listenKey'] print("listen_key: " + listen_key) return listen_key