rsi 7 gün 35 al sat 65 üstü sat
forma girdiğiniz değerler üzerinden 2 dakikada bir işlem açar
İşlem Yapılacak Birim: XRPUSDT yada CGPTUSDT yada hangi birimleri kullanıyorsanız DOGEUSDT gibi gibi yazın ( BÜYÜK HARFLERLE)
İşlem Miktarı: %10 30 50 70 100 elinizdeki birimin ne kadarı ile işlem yapacaksanız
botu çalıştır dediğinizde siz durdurana kadar 2 dakikada bir işlem açar.
lokal hostta denemelerini yaptım kar yada zarar etmedim riskli işlem seviyorsanız ona göre botu düzenleyebilir / düzenletebilirsiniz..

index.html
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Trading Bot</title>
<!-- jQuery ekleyin -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
#output {
margin-top: 20px;
padding: 10px;
background-color: #f9f9f9;
border: 1px solid #ddd;
border-radius: 5px;
}
button {
margin-top: 10px;
}
</style>
</head>
<body>
<h1>Otomatik Trading Botu</h1>
<form id="botForm">
<label for="symbol">İşlem Yapılacak Birim:</label>
<input type="text" name="symbol" id="symbol" required placeholder="Örnek: CGPTUSDT">
<br><br>
<label for="tradePercentage">İşlem Miktarı:</label>
<select name="tradePercentage" id="tradePercentage" required>
<option value="10">%10</option>
<option value="30">%30</option>
<option value="50">%50</option>
<option value="70">%70</option>
<option value="100">%100</option>
</select>
<br><br>
<button type="submit" id="startButton">Botu Başlat</button>
<button type="button" id="stopButton" disabled>Botu Durdur</button>
</form>
<div id="output"></div>
<script>
$(document).ready(function() {
let intervalId = null; // Interval ID'sini saklamak için
// Botu başlat
$('#botForm').on('submit', function(e) {
e.preventDefault(); // Formun sayfayı yenilemesini engelle
const symbol = $('#symbol').val();
const tradePercentage = $('#tradePercentage').val();
// Başlat butonunu devre dışı bırak, Durdur butonunu etkinleştir
$('#startButton').prop('disabled', true);
$('#stopButton').prop('disabled', false);
// İlk işlemi hemen yap
runBot(symbol, tradePercentage);
// 5 dakikada bir işlem yap
intervalId = setInterval(function() {
runBot(symbol, tradePercentage);
}, 1 * 60 * 1000); // 5 dakika = 300.000 milisaniye
});
// Botu durdur
$('#stopButton').on('click', function() {
if (intervalId !== null) {
clearInterval(intervalId); // Interval'i temizle
intervalId = null;
$('#output').append('<p>Bot durduruldu.</p>');
}
// Durdur butonunu devre dışı bırak, Başlat butonunu etkinleştir
$('#startButton').prop('disabled', false);
$('#stopButton').prop('disabled', true);
});
// Botu çalıştır
function runBot(symbol, tradePercentage) {
$.ajax({
url: 'bot.php',
type: 'POST',
data: {
symbol: symbol,
tradePercentage: tradePercentage
},
success: function(response) {
$('#output').append('<p>' + response + '</p>'); // Yanıtı ekrana ekle
},
error: function(xhr, status, error) {
$('#output').append('<p style="color: red;">Bir hata oluştu: ' + error + '</p>');
}
});
}
});
</script>
</body>
</html>bot.php<?php
// config.php dosyasını include et
require_once 'config.php';
// Binance API isteği gönderen fonksiyon
function binanceRequest($url, $params = [], $method = 'GET', $isPrivate = false) {
global $api_key, $api_secret;
// Parametreleri query string'e çevir
$query = http_build_query($params, '', '&');
// Eğer private endpoint ise imza ekle
if ($isPrivate) {
$signature = hash_hmac('sha256', $query, $api_secret);
$query .= "&signature=$signature";
}
// API endpoint'i oluştur
$endpoint = "https://api.binance.com$url?$query";
// cURL başlat
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"X-MBX-APIKEY: $api_key"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
// CA sertifikası kullan
curl_setopt($ch, CURLOPT_CAINFO, 'D:\lokal\www\kripto_bot\cacert.pem');
// İsteği gönder ve yanıtı al
$response = curl_exec($ch);
// Hata kontrolü
if (curl_errno($ch)) {
return 'cURL Hatası: ' . curl_error($ch);
}
// cURL'i kapat
curl_close($ch);
// Yanıtı JSON olarak decode et
return json_decode($response, true);
}
// Belirli bir birimin fiyatını al
function getPrice($symbol) {
$ticker = binanceRequest('/api/v3/ticker/price', ['symbol' => $symbol]);
return $ticker['price'] ?? null;
}
// RSI hesapla
function calculateRsi($symbol, $period = 14) {
$klines = binanceRequest('/api/v3/klines', [
'symbol' => $symbol,
'interval' => '15m', // 5 dakikalık mum verileri
'limit' => $period + 1
]);
if (empty($klines)) {
return null;
}
$gains = [];
$losses = [];
for ($i = 1; $i < count($klines); $i++) {
$change = (float)$klines[$i][4] - (float)$klines[$i - 1][4]; // Kapanış fiyatları arasındaki fark
if ($change > 0) {
$gains[] = $change;
$losses[] = 0;
} else {
$gains[] = 0;
$losses[] = abs($change);
}
}
$avgGain = array_sum($gains) / $period;
$avgLoss = array_sum($losses) / $period;
if ($avgLoss == 0) {
return 100;
}
$rs = $avgGain / $avgLoss;
return 100 - (100 / (1 + $rs));
}
// Alım emri ver
function placeBuyOrder($symbol, $quantity) {
$params = [
'symbol' => $symbol,
'side' => 'BUY',
'type' => 'MARKET', // Piyasa fiyatından alım
'quantity' => $quantity,
'timestamp' => round(microtime(true) * 1000)
];
return binanceRequest('/api/v3/order', $params, 'POST', true);
}
// Satım emri ver
function placeSellOrder($symbol, $quantity) {
$params = [
'symbol' => $symbol,
'side' => 'SELL',
'type' => 'MARKET', // Piyasa fiyatından satım
'quantity' => $quantity,
'timestamp' => round(microtime(true) * 1000)
];
return binanceRequest('/api/v3/order', $params, 'POST', true);
}
// Bakiyeyi kontrol et
function getBalance($asset) {
$account = binanceRequest('/api/v3/account', [], 'GET', true);
// Yanıtın geçerli olup olmadığını kontrol et
if ($account === null || !isset($account['balances']) || !is_array($account['balances'])) {
return 0; // Hata durumunda 0 döndür
}
foreach ($account['balances'] as $balance) {
if ($balance['asset'] === $asset) {
return (float)$balance['free'];
}
}
return 0;
}
// Botun ana mantığı
function runBot($symbol, $tradePercentage) {
// Risk yönetimi ayarları
$stopLossPercentage = 1; // Stop-loss yüzdesi (%1)
$takeProfitPercentage = 2; // Take-profit yüzdesi (%2)
// RSI ayarları
$rsiPeriod = 7; // RSI periyodu
$rsiBuyThreshold = 35; // RSI < 30 ise alım sinyali
$rsiSellThreshold = 65; // RSI > 70 ise satım sinyali
// Belirli bir birimin fiyatını al
$price = getPrice($symbol);
if ($price === null) {
return "Fiyat bilgisi alınamadı.\n";
}
$output = "$symbol Güncel Fiyat: $price\n";
// RSI hesapla
$rsi = calculateRsi($symbol, $rsiPeriod);
if ($rsi === null) {
return "RSI hesaplanamadı.\n";
}
$output .= "RSI: $rsi\n";
// USDT ve seçilen birimin bakiyesini kontrol et
$usdtBalance = getBalance('USDT');
$assetBalance = getBalance(explode('USDT', $symbol)[0]);
// Alım-satım stratejisi
if ($rsi < $rsiBuyThreshold && $usdtBalance > 0) {
// Alım yap
$quantity = ($usdtBalance * ($tradePercentage / 100)) / $price; // İşlem miktarı
$output .= "Alım yapılıyor...\n";
$result = placeBuyOrder($symbol, $quantity);
$output .= print_r($result, true);
// Stop-loss ve take-profit seviyelerini belirle (1:2 risk/getiri oranı)
$stopLossPrice = $price * (1 - ($stopLossPercentage / 100));
$takeProfitPrice = $price * (1 + ($takeProfitPercentage / 100));
$output .= "Stop-Loss: $stopLossPrice, Take-Profit: $takeProfitPrice\n";
// Satım koşullarını kontrol et
while (true) {
$currentPrice = getPrice($symbol);
if ($currentPrice <= $stopLossPrice || $currentPrice >= $takeProfitPrice) {
$output .= "Satım yapılıyor...\n";
$result = placeSellOrder($symbol, $quantity);
$output .= print_r($result, true);
break;
}
sleep(10); // 10 saniye bekle
}
} elseif ($rsi > $rsiSellThreshold && $assetBalance > 0) {
// Satım yap
$quantity = $assetBalance * ($tradePercentage / 100); // İşlem miktarı
$output .= "Satım yapılıyor...\n";
$result = placeSellOrder($symbol, $quantity);
$output .= print_r($result, true);
} else {
$output .= "İşlem yapılacak sinyal yok.\n";
}
return $output;
}
// Formdan gelen verileri al
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$symbol = $_POST['symbol'] ?? 'CGPTUSDT'; // Varsayılan: CGPTUSDT
$tradePercentage = $_POST['tradePercentage'] ?? 50; // Varsayılan: %50
// Botu çalıştır ve sonuçları döndür
echo runBot($symbol, $tradePercentage);
}
?>config.php<?php $api_key = 'api anahtarı buraya'; $api_secret = 'scret key buraya'; ?>binance api kütüphanesini indirin ve lokal host www / bot klasörünüz / klasörüne yükleyin
kodun hata vermemesi için cacert.pem'i bot.php nin olduğu dizine yükleyin ve satırı düzenleyin
curl_setopt($ch, CURLOPT_CAINFO, 'D:lokalwwwkripto_botcacert.pem');
başarılar.
Daha gelişmiş hali;
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kripto Alım-Satım Botu</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
background-color: #f8f9fa;
}
.container {
max-width: 600px;
margin-top: 50px;
}
.form-group label {
font-weight: bold;
}
#results {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1 class="text-center mb-4">Kripto Alım-Satım Botu</h1>
<form id="tradingForm">
<div class="form-group">
<label for="asset">İşlem Yapılacak Birim (Örnek: XRPUSDT, BTCUSDT)</label>
<input type="text" class="form-control" id="asset" placeholder="Örnek: XRPUSDT" required>
</div>
<div class="form-group">
<label for="amount">İşlem Miktarı (%)</label>
<input type="number" class="form-control" id="amount" placeholder="Örnek: 50" min="1" max="100" required>
</div>
<button type="button" id="startBot" class="btn btn-success btn-block">Botu Başlat</button>
<button type="button" id="stopBot" class="btn btn-danger btn-block">Botu Durdur</button>
</form>
<div id="results" class="mt-4"></div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
// Botu Başlat Butonu
$('#startBot').click(function() {
const asset = $('#asset').val().toUpperCase(); // Büyük harfe çevir
const amount = $('#amount').val();
if (!asset || !amount) {
alert('Lütfen tüm alanları doldurun!');
return;
}
$.post('bot.php', { action: 'start', asset: asset, amount: amount }, function(response) {
$('#results').html('<div class="alert alert-success">Bot başlatıldı: ' + asset + ' - %' + amount + '</div>');
}).fail(function() {
$('#results').html('<div class="alert alert-danger">Bot başlatılamadı!</div>');
});
});
// Botu Durdur Butonu
$('#stopBot').click(function() {
$.post('bot.php', { action: 'stop' }, function(response) {
$('#results').html('<div class="alert alert-danger">Bot durduruldu!</div>');
}).fail(function() {
$('#results').html('<div class="alert alert-danger">Bot durdurulamadı!</div>');
});
});
});
</script>
</body>
</html>bot.php<?php
include 'config.php';
require BINANCE_API_PATH . '/BinanceAPI.php';
use BinanceAPI\BinanceAPI;
$api = new BinanceAPI(BINANCE_API_KEY, BINANCE_SECRET_KEY);
// Bot durumu
$isRunning = false;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'];
if ($action === 'start') {
$asset = $_POST['asset'];
$amount = $_POST['amount'];
$isRunning = true;
while ($isRunning) {
// Fiyat verilerini al
$prices = $api->getPriceData($asset);
// Teknik analizleri hesapla
$rsi = calculateRSI($prices);
$ema = calculateEMA($prices);
$macd = calculateMACD($prices);
// Alım/Satım mantığı
if ($rsi < 30 && $ema > $macd) {
$order = placeOrder($asset, 'BUY', $amount);
logTransaction($asset, 'BUY', $amount, $order['price']);
applyStoploss($asset, $order['price']);
} elseif ($rsi > 70 && $ema < $macd) {
$order = placeOrder($asset, 'SELL', $amount);
logTransaction($asset, 'SELL', $amount, $order['price']);
}
// 1 dakika bekle
sleep(60);
}
} elseif ($action === 'stop') {
$isRunning = false;
echo 'Bot durduruldu!';
}
}
function calculateRSI($prices, $period = 14) {
// RSI hesaplama mantığı
$gains = [];
$losses = [];
for ($i = 1; $i < count($prices); $i++) {
$change = $prices[$i] - $prices[$i - 1];
if ($change > 0) {
$gains[] = $change;
$losses[] = 0;
} else {
$gains[] = 0;
$losses[] = abs($change);
}
}
$avgGain = array_sum($gains) / $period;
$avgLoss = array_sum($losses) / $period;
$rs = $avgGain / $avgLoss;
return 100 - (100 / (1 + $rs));
}
function calculateEMA($prices, $period = 10) {
// EMA hesaplama mantığı
$multiplier = 2 / ($period + 1);
$ema = $prices[0];
for ($i = 1; $i < count($prices); $i++) {
$ema = ($prices[$i] - $ema) * $multiplier + $ema;
}
return $ema;
}
function calculateMACD($prices) {
// MACD hesaplama mantığı
$ema12 = calculateEMA($prices, 12);
$ema26 = calculateEMA($prices, 26);
return $ema12 - $ema26;
}
function placeOrder($asset, $type, $amount) {
global $api;
return $api->placeOrder($asset, $type, $amount);
}
function logTransaction($asset, $type, $amount, $price) {
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$stmt = $conn->prepare("INSERT INTO transactions (asset, type, amount, price) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssdd", $asset, $type, $amount, $price);
$stmt->execute();
$stmt->close();
$conn->close();
}
function applyStoploss($asset, $entryPrice) {
global $api;
$currentPrice = $api->getPriceData($asset);
$stoplossPrice = $entryPrice * (1 - STOPLOSS_PERCENT / 100);
$takeProfitPrice = $entryPrice * (1 + TAKE_PROFIT_PERCENT / 100);
if ($currentPrice <= $stoplossPrice || $currentPrice >= $takeProfitPrice) {
$api->placeOrder($asset, 'SELL', 100); // %100 pozisyonu kapat
}
}
?>config.php<?php
// Binance API Bilgileri
define('BINANCE_API_KEY', 'your_api_key_here');
define('BINANCE_SECRET_KEY', 'your_secret_key_here');
// MySQL Veritabanı Bilgileri
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', 'password');
define('DB_NAME', 'trading_bot');
// Binance API Kütüphanesi Yolu
define('BINANCE_API_PATH', __DIR__ . '/binance-api-php');
// Stoploss Ayarları
define('STOPLOSS_PERCENT', 2); // %2 stoploss
define('TAKE_PROFIT_PERCENT', 4); // %4 kar al
?>veritabanıCREATE TABLE transactions (
id INT AUTO_INCREMENT PRIMARY KEY,
asset VARCHAR(10) NOT NULL,
type ENUM('BUY', 'SELL') NOT NULL,
amount DECIMAL(10, 2) NOT NULL,
price DECIMAL(20, 8) NOT NULL,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);ne değişti ?rsi
ema
ve macd verileri analiz ederek
%2 zarar sat %4 kar al yapıldı
veriler veri tabanına yazıldı
her işelm sonucu kar zarar takibi yapılabilir duruma getirildi
7 kişi bunu beğendi.
