如何在 MEXC API KEY 下市价单?

问题描述 投票:0回答:1

我仅发送止盈价格变量。我还需要发送止损吗?

def post_place(symbol, price, vol, side, type, openType, leverage=None, positionId=None, externalOid=None, 
               stopLossPrice=None, takeProfitPrice=None, positionMode=None, reduceOnlt=None):
    """Place new order"""
    method = 'POST'
    path = '/api/v1/private/order/submit'
    url = '{}{}'.format(BASE_URL, path)
    
    print(f"Preparing to place trade with the following details:\n"
          f"Symbol: {symbol}, Price: {price}, Volume: {vol}, Side: {side}, Type: {type}, OpenType: {openType}, "
          f"Leverage: {leverage}, PositionId: {positionId}, ExternalOid: {externalOid}, "
          f"TakeProfitPrice: {takeProfitPrice}, StopLossPrice: {stopLossPrice}, PositionMode: {positionMode}, ReduceOnly: {reduceOnlt}")

    data_original = {
        'symbol': symbol,
        'price': price,
        'vol': vol,
        'side': side,
        'type': type,
        'openType': openType
    }
    
    if leverage:
        data_original.update({"leverage": leverage})
    if positionId:
        data_original.update({"positionId": positionId})
    if externalOid:
        data_original.update({"externalOid": externalOid})
    if takeProfitPrice:
        data_original.update({"takeProfitPrice": takeProfitPrice})
    if positionMode:
        data_original.update({"positionMode": positionMode})
    if reduceOnlt:
        data_original.update({"reduceOnlt": reduceOnlt})

    data = json.dumps(data_original)
    print(f"Data to be sent: {data}")

    params = _sign_v1(sign_params=data)
    headers = {
        "ApiKey": API_KEY,
        "Request-Time": str(_get_server_time()),
        "Signature": params,
        "Content-Type": "application/json"
    }
    print(f"Headers: {headers}")

    try:
        response = requests.request(method, url, data=data, headers=headers, timeout=10)
        print(f"Response received: Status Code: {response.status_code}, Response Text: {response.text}")
        response_json = response.json()
        print(f"Response JSON: {response_json}")
        return response_json
    except requests.exceptions.ConnectionError as e:
        print(f"Connection error occurred: {str(e)}")
        return {"error": "connection_error"}
    except requests.exceptions.Timeout:
        print("Error: The request timed out.")
        return {"error": "timeout"}
    except requests.exceptions.RequestException as e:
        print(f"Error occurred during the API request: {str(e)}")
        return {"error": str(e)}

我正在尝试向 MEXC 发送订单,以便在 MEXC 下订单。代码在发送到 API 后冻结,我不确定问题出在哪里。我不认为问题出在我的代码上,我只是不确定是否没有输入我应该输入的所有值,例如止损。

python trading
1个回答
0
投票

我认为路径应该是

path = '/api/v3/order'
© www.soinside.com 2019 - 2024. All rights reserved.