|
| 1 | +<?php |
| 2 | + |
| 3 | +$allowedIps = [ |
| 4 | + '52.89.214.238', |
| 5 | + '34.212.75.30', |
| 6 | + '54.218.53.128', |
| 7 | + '52.32.178.7' |
| 8 | +]; |
| 9 | + |
| 10 | +// only allow requests from tradingview servers |
| 11 | +if (!in_array($_SERVER['REMOTE_ADDR'], $allowedIps)) { |
| 12 | + die('not allowed'); |
| 13 | +} |
| 14 | + |
| 15 | +$input = file_get_contents('php://input'); |
| 16 | + |
| 17 | +$inputArray = explode(',', $input); |
| 18 | +$symbol = $inputArray[0]; |
| 19 | +$side = $inputArray[1]; |
| 20 | +$quantity = 0.001; // increase if you want but first test your strategy (risk management) |
| 21 | + |
| 22 | +$data = [ |
| 23 | + 'symbol' => $symbol, |
| 24 | + 'side' => $side, |
| 25 | + 'type' => 'MARKET', |
| 26 | + 'quantity' => $quantity, |
| 27 | + 'recvWindow' => '5000', |
| 28 | + 'timestamp' => floor(microtime(true) * 1000) |
| 29 | +]; |
| 30 | + |
| 31 | +$totalParams = \http_build_query($data); |
| 32 | + |
| 33 | +// add your binance api and secret key with permissions to trade |
| 34 | +$apiKey = ''; |
| 35 | +$secretKey = ''; |
| 36 | + |
| 37 | +$signature = hash_hmac('sha256', $totalParams, $secretKey); |
| 38 | + |
| 39 | +$data['signature'] = $signature; |
| 40 | + |
| 41 | +$ch = curl_init(); |
| 42 | +curl_setopt($ch, CURLOPT_URL, 'https://api.binance.com/api/v3/order'); |
| 43 | +curl_setopt($ch, CURLOPT_HTTPHEADER, [sprintf('X-MBX-APIKEY: %s', $apiKey)]); |
| 44 | +curl_setopt($ch, CURLOPT_POST, 1); |
| 45 | +curl_setopt($ch, CURLOPT_POSTFIELDS, \http_build_query($data)); |
| 46 | +curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 47 | +$result = curl_exec($ch); |
| 48 | +curl_close($ch); |
| 49 | + |
| 50 | +$httpResponseCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); |
| 51 | + |
| 52 | +// do some more stuff if you want |
0 commit comments