Here is a sample article based on your issue:
Ethereum API Error: Delphi + Binance API + Limit Order Issue
In this article, we will explain why you are encountering an invalid signature error when using the Ethereum API in Delphi. We will also discuss possible solutions and provide code samples to help you resolve the issue.
Problem
The error message “Invalid signature.” appears when your Binance API request does not match the required signature format. This can happen for a variety of reasons, such as:
- Invalid API endpoint or method
- Insufficient account balance or permissions
- Missing or mismatched parameters
Code sample
To reproduce this issue, let’s use a simple Delphi example. We will create a form that displays a button and attempts to place a limit order using the Binance API.
procedure TForm1.Button1Click(Host: ...
start
// Define your Binance API credentials (API key, secret key)
can
apiKey: string;
apiSecret: string;
// Initialize Binance API object
api := TbinanceApi.Create;
fire.SetFireKey(fireKey);
api.SetApiSecret(apiSecret);
// Get current account balance
var balance: integer;
api.GetBalance('ETH', 'usdt', balance, null, null);
// Create new order
var order: Trade;
order.Symbol: = 'BTC/USDT';
order.Side: = order.Buy;
order.Quantity: = 1;
order.MarketPrice: = float64(1000.00);
order.PricingFees: = float64(10.00); // Assume 10% fee
order.SellingFee: = float64(20.00); // Assume 20% fee
// Attempting to place an order
if api.Order('limit', 'buy', order) then
writeln('Order successfully placed!');
else
writeln('Error placing order.');
end;
Problem
In this example, we are trying to place a limit buy order (buy) on Bitcoin/USDT using the Binance API. We set our API credentials and get the current account balance. Then we create a new Orderer object with the desired properties.
Finally, we attempt to place an order using api.Order('limit', 'buy', order)'.
Solution
To resolve this issue, you will need to:
- Check your signature: Make sure your API endpoint and method match the required signature format. Binance API uses a special signature scheme for limit orders.
- Check your account balance: Make sure you have enough funds in your account to place the order.
- Use the correct Torder properties: Double-check the properties of the Torder object you pass to api.Order(). Specifically, check that the Market Price field matches the desired price.
Here is an updated example with some additional checks:
“ delphinst1.pass
procedure TForm1.Button1Click(Host: …
begin
// Define your Binance API credentials (API key, secret key)
can
apiKey: string;
apiSecret: string;
// Initialize the Binance API object
api := TbinanceApi.Create;
fire.SetFireKey(fireKey);
api.SetApiSecret(apiSecret);
// Get the current account balance
var balance: integer;
if api.GetBalance(‘ETH’, ‘usdt’, balance, null, null) then
writeln(‘Account balance is valid.’);
else
writeln(‘Error getting account balance:’, api.GetBalanceError);
end;
// Create a new order
var order: Integer;
if order.Symbol = ‘BTC/USDT’ then
order.Side: = order.Buy;
order.Quantity: = 1;
order.MarketPrice: = float64(1000.00); // Assume market price is 10,000 USD
order.PricingFee: = float64(10.00); // Assume 10% fee
order.SellingFee: = float64(20.00); // Assume 20% fee
// Attempting to place an order
if api.Order(‘limit’, ‘buy’, order) then
writeln(‘Order successfully placed!’);
else
writeln(‘Error placing order:’, api.GetBalanceError);
end;
else
writeln(‘Invalid symbol:’, order.