// Binance API Class - Fixed Version if (!class_exists('BTB_Binance_API')) { class BTB_Binance_API { private $api_key; private $api_secret; private $testnet; private $is_us; // Correct API endpoints private $base_url; private $futures_url; public function __construct($api_key, $api_secret, $testnet = false, $is_us = false) { $this->api_key = $api_key; $this->api_secret = $api_secret; $this->testnet = $testnet; $this->is_us = $is_us; // Set correct endpoints based on region if ($is_us) { $this->base_url = $testnet ? 'https://testnet.binance.vision' : 'https://api.binance.us'; $this->futures_url = $testnet ? 'https://testnet.binance.vision' : 'https://api.binance.us'; // Note: Binance.US does not support futures trading } else { $this->base_url = $testnet ? 'https://testnet.binance.vision' : 'https://api.binance.com'; $this->futures_url = $testnet ? 'https://testnet.binancefuture.com' : 'https://fapi.binance.com'; } } public function test_connection() { try { $time = $this->get_server_time(); if (isset($time['serverTime'])) { $exchange_type = $this->is_us ? 'Binance.US (Spot Only)' : 'Binance Global (Futures)'; return ['success' => true, 'message' => 'Connection successful', 'exchange_type' => $exchange_type]; } } catch (Exception $e) { return ['success' => false, 'message' => 'Connection failed: ' . $e->getMessage()]; } return ['success' => false, 'message' => 'Unknown error']; } private function get_server_time() { $base = $this->is_us ? $this->base_url : $this->futures_url; $endpoint = $this->is_us ? '/api/v3/time' : '/fapi/v1/time'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $base . $endpoint); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); curl_close($ch); return json_decode($response, true); } public function get_balances() { if ($this->is_us) { // Binance.US only supports spot try { $account = $this->get_account_info(false); return $account['balances'] ?? []; } catch (Exception $e) { return []; } } else { // Global Binance supports both try { $futures_account = $this->get_account_info(true); $balances = []; if (isset($futures_account['assets'])) { foreach ($futures_account['assets'] as $asset) { if ($asset['walletBalance'] > 0) { $balances[] = [ 'asset' => $asset['asset'], 'free' => $asset['walletBalance'], 'total' => $asset['walletBalance'] ]; } } } return $balances; } catch (Exception $e) { return []; } } } public function get_positions() { if ($this->is_us) { // Binance.US does not support futures return []; } else { try { $positions = $this->get_account_info(true); $open_positions = []; if (isset($positions['positions'])) { foreach ($positions['positions'] as $position) { if ($position['positionAmt'] != 0) { $pnl = floatval($position['unrealizedProfit']); $open_positions[] = [ 'symbol' => $position['symbol'], 'side' => $position['positionSide'], 'size' => abs($position['positionAmt']), 'entry_price' => $position['entryPrice'], 'mark_price' => $position['markPrice'], 'pnl' => number_format($pnl, 4) ]; } } } return $open_positions; } catch (Exception $e) { return []; } } } private function get_account_info($futures = false) { if ($this->is_us && $futures) { throw new Exception('Binance.US does not support futures trading'); } $params = [ 'timestamp' => round(microtime(true) * 1000) ]; $params['signature'] = $this->sign($params); $endpoint = $futures ? '/fapi/v2/account' : '/api/v3/account'; return $this->make_request($endpoint, 'GET', $params, $futures); } private function sign($params) { return hash_hmac('sha256', http_build_query($params), $this->api_secret); } private function make_request($endpoint, $method = 'GET', $params = [], $futures = false) { $base = $futures ? $this->futures_url : $this->base_url; $url = $base . $endpoint; if ($method === 'GET') { $url .= '?' . http_build_query($params); } $headers = [ 'X-MBX-APIKEY: ' . $this->api_key ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); if ($method === 'POST') { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); } curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $data = json_decode($response, true); if ($http_code !== 200) { throw new Exception('API Error: ' . ($data['msg'] ?? 'Unknown error')); } return $data; } } }// Bybit API Class if (!class_exists('BTB_Bybit_API')) { class BTB_Bybit_API { private $api_key; private $api_secret; private $testnet; public function __construct($api_key, $api_secret, $testnet = false) { $this->api_key = $api_key; $this->api_secret = $api_secret; $this->testnet = $testnet; } public function test_connection() { try { $time = $this->get_server_time(); if (isset($time['result']['time'])) { return ['success' => true, 'message' => 'Connection successful', 'exchange_type' => 'Bybit']; } } catch (Exception $e) { return ['success' => false, 'message' => 'Connection failed: ' . $e->getMessage()]; } return ['success' => false, 'message' => 'Unknown error']; } private function get_server_time() { $base_url = $this->testnet ? 'https://api-testnet.bybit.com' : 'https://api.bybit.com'; $endpoint = '/v5/market/time'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $base_url . $endpoint); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); curl_close($ch); return json_decode($response, true); } public function get_balances() { // Return empty array for now - to be implemented return []; } public function get_positions() { // Return empty array for now - to be implemented return []; } } }// OKX API Class if (!class_exists('BTB_OKX_API')) { class BTB_OKX_API { private $api_key; private $api_secret; private $passphrase; private $testnet; public function __construct($api_key, $api_secret, $passphrase, $testnet = false) { $this->api_key = $api_key; $this->api_secret = $api_secret; $this->passphrase = $passphrase; $this->testnet = $testnet; } public function test_connection() { try { $time = $this->get_server_time(); if (isset($time['data'][0]['ts'])) { return ['success' => true, 'message' => 'Connection successful', 'exchange_type' => 'OKX']; } } catch (Exception $e) { return ['success' => false, 'message' => 'Connection failed: ' . $e->getMessage()]; } return ['success' => false, 'message' => 'Unknown error']; } private function get_server_time() { $base_url = $this->testnet ? 'https://www.okx.com' : 'https://www.okx.com'; $endpoint = '/api/v5/public/time'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $base_url . $endpoint); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); curl_close($ch); return json_decode($response, true); } public function get_balances() { // Return empty array for now - to be implemented return []; } public function get_positions() { // Return empty array for now - to be implemented return []; } } } Transaction Failed - Best Product Ever - Page 31

Transaction Failed

Your transaction failed; please try again or contact site support.

Scroll to Top