@@ -40,25 +40,6 @@ function createSignature($timestamp, $method, $url, $body, $apiSecret) {
4040 return $ signature ;
4141}
4242
43- function createCurl ($ url , $ method , $ params ) {
44- $ curl = curl_init ();
45- if ( $ method == "GET " ) {
46- curl_setopt ($ curl , CURLOPT_HTTPGET , true );
47- } else if ($ method == "POST " ) {
48- curl_setopt ($ curl , CURLOPT_POST , true );
49- } else if ($ method == "DELETE " ) {
50- curl_setopt ($ curl , CURLOPT_CUSTOMREQUEST , "DELETE " );
51- }
52- $ query = http_build_query ($ params , '' , '& ' );
53- if (count ($ params ) > 0 ) {
54- curl_setopt ($ curl , CURLOPT_URL , $ url .'? ' . $ query );
55- } else {
56- curl_setopt ($ curl , CURLOPT_URL , $ url );
57- }
58- curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , true );
59- return $ curl ;
60- }
61-
6243function errorToConsole ($ message ) {
6344 if (is_array ($ message )) {
6445 $ message = implode (', ' , $ message );
@@ -129,8 +110,27 @@ public function debugToConsole($message) {
129110 }
130111 }
131112
113+ function createCurl ($ url , $ method , $ params ) {
114+ $ curl = curl_init ();
115+ if ( $ method == "GET " ) {
116+ curl_setopt ($ curl , CURLOPT_HTTPGET , true );
117+ } else if ($ method == "POST " ) {
118+ curl_setopt ($ curl , CURLOPT_POST , true );
119+ } else if ($ method == "DELETE " ) {
120+ curl_setopt ($ curl , CURLOPT_CUSTOMREQUEST , "DELETE " );
121+ }
122+ $ query = http_build_query ($ params , '' , '& ' );
123+ if (count ($ params ) > 0 ) {
124+ curl_setopt ($ curl , CURLOPT_URL , $ url .'? ' . $ query );
125+ } else {
126+ curl_setopt ($ curl , CURLOPT_URL , $ url );
127+ }
128+ curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , true );
129+ return $ curl ;
130+ }
131+
132132 function sendPublic ($ url , $ params , $ method , $ data ) {
133- $ curl = createCurl ($ url , $ method , $ params );
133+ $ curl = $ this -> createCurl ($ url , $ method , $ params );
134134 $ endpoint = str_replace (array ($ this ->base ), array ('' ), $ url );
135135 if ($ this ->apiKey != "" ) {
136136 $ now = (time ()*1000 );
@@ -164,7 +164,7 @@ function sendPrivate($endpoint, $params, $body, $method, $apiSecret, $base, $api
164164 $ endpointParams = $ endpoint ;
165165 }
166166 $ sig = createSignature ($ now , $ method , $ endpointParams , $ body , $ apiSecret );
167- $ curl = createCurl ($ base . $ endpoint , $ method , $ params );
167+ $ curl = $ this -> createCurl ($ base . $ endpoint , $ method , $ params );
168168 $ headers = array (
169169 'Bitvavo-Access-Key: ' . $ apiKey ,
170170 'Bitvavo-Access-Signature: ' . $ sig ,
@@ -439,14 +439,16 @@ public function addToBook($msg, $isNewBook) {
439439 $ this ->localBook [$ msg ["market " ]]["nonce " ] = $ msg ["nonce " ];
440440 call_user_func ($ this ->subscriptionBookCallback [$ msg ["market " ]], $ this ->localBook [$ msg ["market " ]]);
441441 } else {
442- if ($ msg ["nonce " ] != $ this ->localBook [$ msg ["market " ]]["nonce " ] + 1 ) {
443- $ this ->subscriptionBook ($ msg ["market " ], $ this ->subscriptionBookCallback [$ msg ["market " ]]);
444- return ;
442+ if (isset ($ this ->localBook [$ msg ["market " ]]["nonce " ])) {
443+ if ($ msg ["nonce " ] != $ this ->localBook [$ msg ["market " ]]["nonce " ] + 1 ) {
444+ $ this ->subscriptionBook ($ msg ["market " ], $ this ->subscriptionBookCallback [$ msg ["market " ]]);
445+ return ;
446+ }
447+ $ this ->localBook [$ msg ["market " ]]["bids " ] = sortAndInsert ($ msg ["bids " ], $ this ->localBook [$ msg ["market " ]]["bids " ], "sortBids " );
448+ $ this ->localBook [$ msg ["market " ]]["asks " ] = sortAndInsert ($ msg ["asks " ], $ this ->localBook [$ msg ["market " ]]["asks " ], "sortAsks " );
449+ $ this ->localBook [$ msg ["market " ]]["nonce " ] = $ msg ["nonce " ];
450+ call_user_func ($ this ->subscriptionBookCallback [$ msg ["market " ]], $ this ->localBook [$ msg ["market " ]]);
445451 }
446- $ this ->localBook [$ msg ["market " ]]["bids " ] = sortAndInsert ($ msg ["bids " ], $ this ->localBook [$ msg ["market " ]]["bids " ], "sortBids " );
447- $ this ->localBook [$ msg ["market " ]]["asks " ] = sortAndInsert ($ msg ["asks " ], $ this ->localBook [$ msg ["market " ]]["asks " ], "sortAsks " );
448- $ this ->localBook [$ msg ["market " ]]["nonce " ] = $ msg ["nonce " ];
449- call_user_func ($ this ->subscriptionBookCallback [$ msg ["market " ]], $ this ->localBook [$ msg ["market " ]]);
450452 }
451453 return ;
452454 }
0 commit comments