Binance API Withdrawal Error: "Signature for this request is not valid."

Binance API Withdrawal Error: "Signature for this request is not valid."

我遇到了 Binance API

的问题

每当我尝试提出提款请求时,returns“此请求的签名无效”。错误消息,即使我使用相同的功能请求帐户信息、资金余额、getAll 余额或其他任何内容,它仍然有效。

我已经尝试了几种解决方案,但似乎没有任何效果。这是我阅读类似问题的一些尝试

我正在使用 NodeJs、axios 来发出请求。这是我的功能:

    /**
     * Send Request to withdraw USDT funds from the selected wallet to a specified address
     * @param wallet 
     * @param amount 
     * @param address 
     * @returns 
     * @link https://binance-docs.github.io/apidocs/spot/en/#withdraw-user_data
     */
    makeWithdrawal(
        wallet: WalletType = 'SPOT',
        amount: number,
        address: string
    ) {
        const walletIndex = WalletEnum[wallet];
        return this.makeRequest<{ id: string }>(
            'sapi/v1/capital/withdraw/apply',
            'POST',
            {
                coin: 'USDT',
                amount,
                wallet: walletIndex,
                address,
                network: 'TRX',
                name: '_'
            }
        );
    }


    /**
     * Makes Request to Binance Pay API
     * @param endpoint 
     * @param method 
     * @param params 
     * @returns 
     * @link https://binance-docs.github.io/apidocs/spot/en
     */
    private makeRequest<T>(
        endpoint: string,
        method: Method = 'GET',
        params: {[key: string]: string | number} = {}
    ): Promise<T> {
        const timestamp = Number(new Date().getTime()).toFixed(0);

        let query = `timestamp=${timestamp}`;
        for (const key in params) {
            if (Object.prototype.hasOwnProperty.call(params, key)) {
                const value = params[key];
                query += `&${key}=${value}`
            }
        }
            
        const signature = this.sign(query);

        const headers: AxiosRequestHeaders = {
            'X-MBX-APIKEY': process.env.BINANCE_API_KEY,
        };

        const requestObservable = this.httpService.request<T>({
            method,
            url: `${process.env.BINANCE_API_URL}/${endpoint}`,
            params: {...params, timestamp, signature},
            headers
        }).pipe(
            map(res => res.data)
        );
        

        return lastValueFrom(requestObservable);
    }

    /**
     * Signs payload with private key
     * @param payload 
     * @returns 
     */
    private sign(query: string) {
        return createHmac('sha256', process.env.BINANCE_API_SECRET)
            .update(query)
            .digest('hex');
    }

我真的不明白这是怎么回事,如果有人能帮我解决这个问题,因为我正在阅读这是一个常见问题,但我真的尝试了解决方案但没有希望。

谢谢

对于遇到此问题的任何人,问题是我在“params”而不是 url 内发送请求,奇怪的是,它没有正确处理它,所以做这个小改动:

const requestObservable = this.httpService.request<T>({
            method,
            url: `${process.env.BINANCE_API_URL}/${endpoint}?${query}&signature=${signature}`,
            headers
        }).pipe(
            map(res => res.data)
        );

你很高兴去