KittyCatTech / cryptopia-api-php

Cryptopia API Wrapper in PHP and Sample Trading Bot
Other
26 stars 28 forks source link

Can't Connect to Cryptopia, Error: #1

Open plogic opened 7 years ago

plogic commented 7 years ago

Dear KittyCatTech,

Although i am a real beginner your code in cryptopia-api-php looked clear to me. But using it will every time come with an "Can't Connect to Cryptopia, Error: ". (No real error is written out.) Does it have something to do with the API problem? You wrote : "There is a bug in the API if you send no parameters it will return Success:true Error: Market not found." How can this be handeld? Did you find a solution already?

With regards, Paul van den Elsaker

iansmellis commented 7 years ago

I am getting this same error. I have not found a solution as of yet either.

dexter369 commented 7 years ago

It is because of the way nonce is calculated, the api cannot make more than one call per second. The api is already making a call in constructor to get balance, so any other call is failing. Just update constructor to:

public function __construct($priv, $pub) {
      $this->privateKey = $priv;
      $this->publicKey = $pub;    
   }
iansmellis commented 7 years ago

That is already in this https://github.com/KittyCatTech/cryptopia-api-php/blob/master/cryptopiaAPI.php is that what you are taling about?

dexter369 commented 7 years ago

Yes replace __construct there with above.

iansmellis commented 7 years ago

I am not sure what you are trying to tell me, That is already there

public function __construct($priv, $pub) { $this->privateKey = $priv; $this->publicKey = $pub; $result = json_decode($this->apiCall("GetBalance", array( 'Currency'=> 'BTC' )), true); // There is a bug in the API if you send no parameters it will return Success:true Error: Market not found. // Array // ( // [Success] => 1 // [Message] => // [Data] => // [Error] => Market not found. // ) // print_r($result); if( $result['Success'] != "true" ) { throw new Exception("Can't Connect to Cryptopia, Error: " . $result['Error'] ); return false; } return true; }

dexter369 commented 7 years ago

simply replace the whole thing you pasted above with:

public function __construct($priv, $pub) {
      $this->privateKey = $priv;
      $this->publicKey = $pub;    
   }

you dont lose anything by deleting unnecessary code.

iansmellis commented 7 years ago

Thank you for helping me. That worked perfectly!

I really appreciate it!

valala commented 7 years ago

i'm sorry but i'm a real noob, i don't know what i have to do with the code. What I have to do with exactly?