Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we have option to disable ssl? #110

Closed
andrewpros opened this issue Apr 13, 2018 · 15 comments
Closed

Can we have option to disable ssl? #110

andrewpros opened this issue Apr 13, 2018 · 15 comments

Comments

@andrewpros
Copy link

The title says it all, i'm testing on localhost but there is that annoying curl ssl cert error and after every update i need to manually add this again in httpRequest method

#ssl hackfix
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );

@dmzoneill
Copy link
Collaborator

dave@dave-laptop:~/Desktop/crypto/php-binance-api$ cat /home/dave/.config/jaggedsoft/php-binance-api-1.json
{
    "// no money in this account": "dream on",
    "api-key": "z5RQZ9n8JcS3HLDQmPpfLQIGGQN6TTs5pCP5CTnn4nYk2ImFcew49v4ZrmP3MGl5",
    "api-secret": "ZqePF1DcLb6Oa0CfcLWH0Tva59y8qBBIqu789JEY27jq0RkOKXpNl9992By1PN9Z",
    "curlOpts": {
	    "CURLOPT_SSL_VERIFYPEER": 0,
	    "INVALID_CONSTANT_NAME": 42
    }
}

load via constructor, filename or paramters

new Binance( null,null, $options[ 'curlOpts' = [] ]);
// or
new Binance( "apth to file above" );

@dmzoneill
Copy link
Collaborator

dmzoneill commented Apr 13, 2018

@dmzoneill dmzoneill reopened this Apr 13, 2018
@andrewpros
Copy link
Author

andrewpros commented Apr 13, 2018

@dmzoneill
i was happy too quickly there is a typo making it impossible to use it

46d2642#diff-5dbeba22e806b45539eff4e47a00a391R132

46d2642#diff-5dbeba22e806b45539eff4e47a00a391R153

Also server time must be called after curl opts.

Also is this correct? https://github.com/jaggedsoft/php-binance-api/blob/v0.2.5/php-binance-api.php#L125 it will throw proxyConf error

@dmzoneill
Copy link
Collaborator

fixed

@dmzoneill dmzoneill reopened this Apr 13, 2018
@andrewpros
Copy link
Author

Still needs fixing
there is another https://github.com/jaggedsoft/php-binance-api/blob/master/php-binance-api.php#L153
and useServerTime() must be always after assigning curlOpts

also construct3 doesn't have proxyConf var

@dmzoneill
Copy link
Collaborator

dmzoneill commented Apr 13, 2018

thanks for the feedback, this is resolved

the actual constructor calls ___constructX depending on number of parameters passed.
___construct4 if you pass 4 parameters,
___construct3 if you pass 3 parameters

as PHP doesn't support method overloading, we're limited by the language here.

public function __construct() {
      $param = func_get_args();
      switch( func_num_args() ) {
         case 0:
            $this->__construct0();
         break;
         case 1:
            $this->__construct1( $param[ 0 ] );
         break;
         case 2:
            $this->__construct2( $param[ 0 ], $param[ 1 ] );
         break;
         case 3:
            $this->__construct3( $param[ 0 ], $param[ 1 ], $param[ 2 ] );
         break;
         case 4:
            $this->__construct4( $param[ 0 ], $param[ 1 ], $param[ 2 ], $param[ 3 ] );
         break;
      }
   }

@andrewpros
Copy link
Author

Well i know this, i know php, but i feel we are not on the same page here.

This is a bug and it was there from the start, multiple constructors was introduced just couple of days ago c750049#diff-5dbeba22e806b45539eff4e47a00a391R122 and following commits changes/fixes , maybe no one noticed it yet, but there is no $proxyConf parameter in construct3 function, so it will throw Undefined variable.
We can just use construct4 with null proxy parameter, but then, why we even have construct3?

But this is a non issue really, as it works with 4th parameter, we don't really need costruct4, 3 can have the same parameters with def null proxy.

The most important bug now is still wrong function order, UseServerTime() function MUST BE called always after assigning curlOpts https://github.com/jaggedsoft/php-binance-api/blob/master/php-binance-api.php#L129

in every constructor it is used, as it makes a binance api call to get time, so curlOpts must be already assigned to prevent for example ssl cert error by adding CURLOPT_SSL_VERIFYPEER =>false

Hope i explained it clearly now.

@jaggedsoft
Copy link
Owner

jaggedsoft commented Apr 13, 2018

Thank you for your report
useServerTime can also be used outside of the constructor, which will likely solve your problem in this case:

require 'vendor/autoload.php';
$options = [ "curlOpts" => ["CURLOPT_SSL_VERIFYPEER" => 0] ];
$api = new Binance\API("<api key>", "<secret>", $options);
$api->useServerTime();

@andrewpros
Copy link
Author

still, should be also fixed in all constructors as it is a bug

@jaggedsoft
Copy link
Owner

jaggedsoft commented Apr 13, 2018

construct3 doesn't have these lines but everything else should be ok:

      $this->setupApiConfigFromFile();
      $this->setupProxyConfigFromFile();
      $this->setupCurlOptsFromFile();

https://github.com/jaggedsoft/php-binance-api/wiki/5.-$HOME-Config-(API---Proxy)

@jaggedsoft
Copy link
Owner

jaggedsoft commented Apr 13, 2018

His fixes are available in v0.2.6 .. if you can help us with a pull request for anything else it would be much appreciated

@dmzoneill
Copy link
Collaborator

Hi @andrewpros

would greatly appreciate a pull requests! seems like you are on the ball.

I've been getting the units test and coverage in place for node-binance-api. Once i have it up for a fair standard, i plan to come back here to complete the remaining coverage tests and checks for PHP.

If you could help, that would be aweomse!

Thanks again dude @andrewpros

@andrewpros
Copy link
Author

@jaggedsoft @dmzoneill

Wow, just wow, so you will insist on not fixing a know bug... This is beyond my understanding, if there is a function that can be called but i doesn't work as expected even if someone provide valid parameters then it is a bug and it cant stay like that.

The function order is still not fixed, the expected result is to work with any valid parameters, also we don't need construct3 at all, i didn't bother with a PR as i assumed it is a simple fix, i assumed it will be fixed in no time.

In fact everything should be set always before making the first and any binance api call, as that setup may have impact on any call just like with those ssl cert errors, so useServerTime should be called always last.

So so you don't say i did nothing here it is, my pr

#111

@dmzoneill
Copy link
Collaborator

Thanks for the feedback again man.
As i said, i plan to finish out the remaining unit tests and coverage tests very soon.
Rest assured your concerns will be actioned! Enjoy

@dmzoneill dmzoneill reopened this Apr 14, 2018
@andrewpros
Copy link
Author

Well ok then, thx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants