I'm using PHP Binance API. I make a limit order succesfuly.
For Example;
$quantity = 1500000;
$price = 0.00001000;
$order = $api->buy("SHIBUSDT", $quantity, $price);
But i don't want use quantity value. I want give a price and it must be calculate coin quantity.
For example;
$price = 0.00001000;
$quantity = 100 BNB or USDT;
Thanks for your help.
My Answer:
> buy('BTCUSDT', $quantity, $price, 'LIMIT');
However, I want to calculate the price dynamically based on a certain percentage difference from the current market price. How can I achieve this?
You can achieve this by first getting the current market price for the trading pair using the `price()` method provided by the PHP Binance API. Then, you can calculate the new price based on the desired percentage difference and use that calculated price in your buy order.
Here's an example code snippet to demonstrate this:
php
// Get the current market price
$currentPrice = $api->price('BTCUSDT');
// Define the percentage difference (e.g. 5%)
$percentageDifference = 5;
// Calculate the new price based on the percentage difference
$newPrice = $currentPrice * (1 + $percentageDifference / 100);
// Place the buy order with the dynamically calculated price
$order = $api->buy('BTCUSDT', $quantity, $newPrice, 'LIMIT');
In this example, we first get the current market price for the 'BTCUSDT' trading pair. We then define a percentage difference (e.g. 5%) and calculate the new price by adding the percentage difference to the current price. Finally, we place the buy order using the dynamically calculated price.
You can adjust the percentage difference and trading pair according to your requirements.
Rate this post
5 of 5 based on 3604 votesComments