Jump to content

Poloniex API на PHP нужна помощь


denza

Recommended Posts

Posted

Доброго дня! Не могу получить ответ от сервера poloniex. Постоянно вылазит ошибка. Апи ключ и секретный в скрипт установлен. Пробовал работать с классом представленным в документации полоникса, а так же сторонних разработчиков, результат всегда один и тот же.  Может кто сталкивался подскажите в какую сторону копать.

 

Ошибка:

file_get_contents(......................): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden

 

Пример кода:

 

require("poloniex.php");

$polo = new Poloniex($key, $secret);
$ticker = $polo->returnTicker();
print_r($ticker);

 

p.s. В интерфейсе биржи в API стоит статус, что ни разу не было подключений.

 

Благодарю за помощь!

 

 

 

Posted

проблема решена размещением скриптов на другом хостинге

  • 1 month later...
Posted

У меня таже проблема, и хостинги менял и 2фа авторизацию включал и выключал и ключи пересоздавал...

Как вы решили в чем было дело ? вот мой код..

<?php
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);    
error_reporting(E_ALL);

            // API settings
    function query(array $req = array()) {
            $key = "ключ";
            $secret = "секретный_ключь";
            $trading_url = "https://poloniex.com/tradingApi";
        
            // generate a nonce to avoid problems with 32bit systems
            $mt = explode(' ', microtime());
            $req['nonce'] = $mt[1].substr($mt[0], 2, 6);
        
            // generate the POST data string
            $post_data = http_build_query($req, '', '&');
            $sign = hash_hmac('sha512', $post_data, $secret);
        
            // generate the extra headers
            $headers = array(
                'Key: '.$key,
                'Sign: '.$sign,
            );
            // curl handle (initialize if required)
            static $ch = null;
            if (is_null($ch)) {
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_USERAGENT,
                    'Mozilla/5.0 (X11; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0'
                );
            }
            curl_setopt($ch, CURLOPT_URL, $trading_url);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ch, CURLOPT_VERBOSE, true);

            // run the query
            $res = curl_exec($ch);

            if ($res === false) throw new Exception('Curl error: '.curl_error($ch));
            //echo $res;
            $dec = json_decode($res, true);
            if (!$dec){
                //throw new Exception('Invalid data: '.$res);
                return false;
            }else{
                return $dec;
            }
    }

        function get_balances() {
            return query(
                array(
                    'command' => 'returnBalances'
                )
            );
        }
        $zzz = get_balances();
        print_r($zzz);


?>
#####################################################################

диалог

*   Trying 104.20.12.48...
* TCP_NODELAY set
* Connected to poloniex.com (104.20.12.48) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: none
* SSL connection using TLSv1.2 / ECDHE-RSA-CHACHA20-POLY1305
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: OU=Domain Control Validated; CN=*.poloniex.com
*  start date: Dec  4 19:50:49 2015 GMT
*  expire date: Dec  4 19:50:49 2018 GMT
*  subjectAltName: host "poloniex.com" matched cert's "poloniex.com"
*  issuer: C=BE; O=GlobalSign nv-sa; CN=AlphaSSL CA - SHA256 - G2
*  SSL certificate verify ok.
> POST /tradingApi HTTP/1.1
Host: poloniex.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0
Accept: */*
Key: key
Sign: sign
Content-Length: 45
Content-Type: application/x-www-form-urlencoded

* upload completely sent off: 45 out of 45 bytes
< HTTP/1.1 403 Forbidden
< Date: Sat, 22 Jul 2017 16:09:16 GMT
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: close
< Set-Cookie: __cfduid=de0c2ff4b5f81c0d11028636aa08ca27f1500739756; expires=Sun, 22-Jul-18 16:09:16 GMT; path=/; domain=.poloniex.com; HttpOnly
< Cache-Control: max-age=2
< Expires: Sat, 22 Jul 2017 16:09:18 GMT
< X-Frame-Options: SAMEORIGIN
< Server: cloudflare-nginx
< CF-RAY: 3827a9d8293e64ff-FRA
<
* Closing connection 0
#######################################################

 

незнаю что уже делать, в супорт им написал но это похоже безнадежно..

  • 2 weeks later...
Posted

@schanger, обращайтесь, помогу отдебажить. В обмен на это вы расскажете для чего хотите это использовать :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...