├── .coveralls.yml ├── .github └── workflows │ └── php.yml ├── .gitignore ├── .travis.yml ├── .vscode └── launch.json ├── ISSUE_TEMPLATE.md ├── LICENSE ├── README.md ├── composer.json ├── composer.lock ├── examples ├── 0.example.php ├── agg_trades.php ├── asset.php ├── balances.php ├── book_prices.php ├── ca.pem ├── candles.php ├── constructor.php ├── depth.php ├── get_account_info.php ├── get_exchange_info.php ├── get_prices.php ├── home_directory_config.php ├── open_orders.php ├── orders.php ├── orders_test.php ├── orders_testnet.php ├── prevday.php ├── proxy_config.php ├── ratelimiter.php ├── report.php ├── single │ ├── binance-api-single.php │ └── single.php ├── specify_config_file.php ├── trade_history.php ├── web_socket_chart.php ├── web_socket_depth.php ├── web_socket_kline.php ├── web_socket_miniticker.php ├── web_socket_trades.php └── web_socket_userdata.php ├── php-binance-api-rate-limiter.php ├── php-binance-api.php └── tests ├── BinanceLiveTests.php └── BinanceStaticTests.php /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: travis-ci 2 | coverage_clover: build/logs/clover.xml 3 | json_path: build/logs/coveralls-upload.json 4 | -------------------------------------------------------------------------------- /.github/workflows/php.yml: -------------------------------------------------------------------------------- 1 | name: PHP Composer 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v4 19 | 20 | - name: Validate composer.json and composer.lock 21 | run: composer validate --strict 22 | 23 | - name: Cache Composer packages 24 | id: composer-cache 25 | uses: actions/cache@v3 26 | with: 27 | path: vendor 28 | key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} 29 | restore-keys: | 30 | ${{ runner.os }}-php- 31 | 32 | - name: Install dependencies 33 | run: composer install --prefer-dist --no-progress 34 | - name: Static Tests 35 | run: composer test 36 | - name: Live Tests 37 | run: composer live-tests 38 | 39 | # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" 40 | # Docs: https://getcomposer.org/doc/articles/scripts.md 41 | 42 | # - name: Run test suite 43 | # run: composer run-script test 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # composer.lock 2 | vendor** 3 | .buildpath 4 | .project 5 | .settings/** 6 | 7 | .DS_Store 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | sudo: required 3 | 4 | matrix: 5 | include: 6 | - php: 7.0 7 | - php: 7.1 8 | - php: 7.2 9 | env: 10 | - QUALITY=yes 11 | - PROXY_VALIDATION=yes 12 | - php: nightly 13 | - os: osx 14 | osx_image: xcode7.2 15 | allow_failures: 16 | - os: osx 17 | 18 | notifications: 19 | webhooks: https://www.travisbuddy.com/?insertMode=update 20 | 21 | before_script: 22 | - if [[ $PROXY_VALIDATION == "yes" ]]; then mkdir -vp /home/travis/.ssh/; fi 23 | - if [[ $PROXY_VALIDATION == "yes" ]]; then ssh-keygen -f /home/travis/.ssh/id_ecdsa -t ecdsa -N ''; fi 24 | - if [[ $PROXY_VALIDATION == "yes" ]]; then cat /home/travis/.ssh/*.pub > /home/travis/.ssh/authorized_keys; fi 25 | - if [[ $PROXY_VALIDATION == "yes" ]]; then chmod 600 /home/travis/.ssh/*; fi 26 | - if [[ $PROXY_VALIDATION == "yes" ]]; then chmod 700 /home/travis/.ssh/.; fi 27 | - if [[ $PROXY_VALIDATION == "yes" ]]; then ssh -f -o "StrictHostKeyChecking no" -D 9999 -q -N travis@localhost; fi 28 | - mkdir -vp ~/.config/jaggedsoft/ 29 | - mkdir -vp build/logs 30 | - travis_retry wget https://raw.githubusercontent.com/jaggedsoft/php-binance-api/gh-travis/composer-test.json -O composer-test.json 31 | - travis_retry wget https://raw.githubusercontent.com/jaggedsoft/php-binance-api/gh-travis/docs.sh -O docs.sh 32 | - travis_retry wget https://raw.githubusercontent.com/jaggedsoft/php-binance-api/gh-travis/doxy.gen -O doxy.gen 33 | - travis_retry wget https://raw.githubusercontent.com/jaggedsoft/php-binance-api/gh-travis/php-binance-api-test.php -O php-binance-api-test.php 34 | - travis_retry wget https://raw.githubusercontent.com/jaggedsoft/php-binance-api/gh-travis/phpunit.xml -O phpunit.xml 35 | - travis_retry wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.0.0/php-coveralls.phar -O coveralls.phar 36 | - travis_retry wget https://github.com/codacy/php-codacy-coverage/releases/download/1.4.2/codacy-coverage.phar -O codacy.phar 37 | - travis_retry wget https://github.com/dmzoneill/fmt/raw/master/fmt.phar -O fmt.phar 38 | - travis_retry wget https://codecov.io/bash -O codecov.sh 39 | - COMPOSER=composer-test.json composer -vvv install --no-interaction --no-suggest 40 | - chmod -v +x codecov.sh 41 | - chmod -v +x docs.sh 42 | - chmod -v +x coveralls.phar 43 | - travis_retry sudo apt-get install tinyproxy curl 44 | - if [[ $PROXY_VALIDATION == "yes" ]]; then tinyproxy; fi 45 | - if [[ $PROXY_VALIDATION == "yes" ]]; then travis_retry curl -v -I --proxy socks://127.0.0.1:9999 https://www.google.com; fi 46 | 47 | script: 48 | - ./vendor/bin/phpunit --verbose --debug --coverage-clover build/logs/clover.xml --bootstrap vendor/autoload.php php-binance-api-test 49 | - if [[ $PROXY_VALIDATION == "yes" ]]; then export socks_proxy=http://127.0.0.1:9999; fi 50 | - if [[ $PROXY_VALIDATION == "yes" ]]; then ./vendor/bin/phpunit --verbose --debug --coverage-clover build/logs/clover.xml --bootstrap vendor/autoload.php php-binance-api-test; fi 51 | - php fmt.phar -v --psr2 --indent_with_space=4 -o=php-binance-api.php.fmt php-binance-api.php 52 | - diff php-binance-api.php.fmt php-binance-api.php 53 | 54 | after_success: 55 | - if [[ $QUALITY == "yes" ]]; then travis_retry php coveralls.phar -v; fi 56 | - if [[ $QUALITY == "yes" ]]; then travis_retry php codacy.phar clover -vv build/logs/clover.xml; fi 57 | - if [[ $QUALITY == "yes" ]]; then travis_retry bash -x ./codecov.sh -f "!$TRAVIS_BUILD_DIR/php-binance-api-test.php"; fi 58 | - if [[ $QUALITY == "yes" ]]; then travis_retry bash -x ./docs.sh; fi 59 | 60 | branches: 61 | only: master 62 | 63 | env: 64 | global: 65 | - GH_REPO_NAME: php-binance-api 66 | - DOXYFILE: $TRAVIS_BUILD_DIR/doxy.gen 67 | - GH_REPO_REF: github.com/jaggedsoft/php-binance-api.git 68 | - DOXY_FILES: $TRAVIS_BUILD_DIR/php-binance-api.php 69 | - DOXY_FILES_EXCLUDE: $TRAVIS_BUILD_DIR/examples/* 70 | 71 | addons: 72 | apt: 73 | packages: 74 | - doxygen 75 | - doxygen-doc 76 | - doxygen-latex 77 | - doxygen-gui 78 | - graphviz 79 | 80 | cache: 81 | directories: 82 | - vendor 83 | - $HOME/.cache/composer 84 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Listen for XDebug", 9 | "type": "php", 10 | "request": "launch", 11 | "port": 9000 12 | }, 13 | { 14 | "name": "Launch currently open script", 15 | "type": "php", 16 | "request": "launch", 17 | "program": "${file}", 18 | "cwd": "${fileDirname}", 19 | "port": 9000 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | **Title** 2 | - bug: XYZ broken 3 | - feature: please add 4 | - enhancement: add this to existing features 5 | 6 | **Short Description:** 7 | - Unable to get a result from blah 8 | 9 | **Platform:** 10 | - windows 11 | - linux 12 | - macos 13 | 14 | **php version:** 15 | - 7.0.24 16 | 17 | **Long descrption** 18 | - Doing xyz results in ypr and failing when fph 19 | 20 | **code** 21 | ```php 22 | require 'vendor/autoload.php'; 23 | $api = new Binance\API("",""); 24 | $ticker = $api->prices(); 25 | print_r($ticker); // List prices of all symbols 26 | echo "Price of BNB: {$ticker['BNBBTC']} BTC"; 27 | ``` 28 | 29 | **result** 30 | ``` 31 | { 32 | "result":"result" 33 | } 34 | ``` 35 | 36 | thank you 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017+ Jon Eyrick - jaggedsoft@gmail.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Latest Version](https://img.shields.io/github/release/jaggedsoft/php-binance-api.svg?style=flat-square)](https://github.com/jaggedsoft/php-binance-api/releases) 2 | [![GitHub last commit](https://img.shields.io/github/last-commit/jaggedsoft/php-binance-api.svg?style=flat-square)](#) 3 | [![Packagist Downloads](https://img.shields.io/packagist/dt/jaggedsoft/php-binance-api.svg?style=flat-square)](https://packagist.org/packages/jaggedsoft/php-binance-api) 4 | 5 | 6 | 14 | # PHP Binance API 15 | This project is designed to help you make your own projects that interact with [Binance](https://accounts.binance.com/register?ref=PGDFCE46). You can stream candlestick chart data, market depth, or use other advanced features such as setting stop losses and iceberg orders. This project seeks to have complete API coverage (spot and futures) including WebSockets. 16 | 17 | #### Installation 18 | ``` 19 | composer require "jaggedsoft/php-binance-api @dev" 20 | ``` 21 |
22 | Click for help with installation 23 | 24 | ## Install Composer 25 | If the above step didn't work, install composer and try again. 26 | #### Debian / Ubuntu 27 | ``` 28 | sudo apt-get install curl php-curl 29 | curl -s http://getcomposer.org/installer | php 30 | php composer.phar install 31 | ``` 32 | Composer not found? Use this command instead: 33 | ``` 34 | php composer.phar require "jaggedsoft/php-binance-api @dev" 35 | ``` 36 | 37 | #### Windows: 38 | [Download installer for Windows](https://github.com/jaggedsoft/php-binance-api/#installing-on-windows) 39 | 40 |
41 | 42 | #### Getting started 43 | `composer require jaggedsoft/php-binance-api` 44 | ```php 45 | require 'vendor/autoload.php'; 46 | // 1. config in home directory 47 | $api = new Binance\API(); 48 | // 2. config in specified file 49 | $api = new Binance\API( "somefile.json" ); 50 | // 3. config by specifying api key and secret 51 | $api = new Binance\API("",""); 52 | // 4. config by specifying api key, api secret and testnet flag. By default the testnet is disabled 53 | $api = new Binance\API("","", true); 54 | // 5. Rate Limiting Support 55 | $api = new Binance\RateLimiter(new Binance\API()); 56 | ``` 57 | See [additional options](https://github.com/jaggedsoft/php-binance-api/#config-file-in-home-directory) for more options and help installing on Windows 58 | 59 | #### Rate Limiting 60 | This Feature is in beta, you can start using rate limiting as a wrapper to the main API class. 61 | ```php 62 | $api = new Binance\API( "somefile.json" ); 63 | $api = new Binance\RateLimiter($api); 64 | while(true) { 65 | $api->openOrders("BNBBTC"); // rate limited 66 | } 67 | ``` 68 | 69 | ======= 70 | #### Security - CA Bundles 71 | If you don't know what a CA bundle is, no action is required. If you do know and you don't like our auto upate feature. 72 | You can disable the downloading of the CA Bundle 73 | ```php 74 | $api = new Binance\API( "somefile.json" ); 75 | $api->caOverride = true; 76 | ``` 77 | 78 | #### Get latest price of all symbols 79 | ```php 80 | $ticker = $api->prices(); 81 | print_r($ticker); 82 | ``` 83 | 84 |
85 | View Response 86 | 87 | ``` 88 | Array 89 | ( 90 | [ETHBTC] => 0.05050800 91 | [LTCBTC] => 0.00967400 92 | [BNBBTC] => 0.00021479 93 | [NEOBTC] => 0.00479300 94 | [123456] => 0.00030000 95 | [QTUMETH] => 0.03482000 96 | [EOSETH] => 0.00176100 97 | [SNTETH] => 0.00008766 98 | [BNTETH] => 0.00662400 99 | [BCCBTC] => 0.05629200 100 | [GASBTC] => 0.00338500 101 | [BNBETH] => 0.00418603 102 | [BTMETH] => 0.00018900 103 | [HCCBTC] => 0.00000180 104 | [BTCUSDT] => 6028.95000000 105 | [ETHUSDT] => 304.98000000 106 | [HSRBTC] => 0.00289000 107 | [OAXETH] => 0.00136700 108 | [DNTETH] => 0.00020573 109 | [MCOETH] => 0.02685800 110 | [ICNETH] => 0.00395000 111 | [ELCBTC] => 0.00000053 112 | [MCOBTC] => 0.00133000 113 | [WTCBTC] => 0.00117000 114 | [WTCETH] => 0.02300000 115 | [LLTBTC] => 0.00001669 116 | [LRCBTC] => 0.00001100 117 | [LRCETH] => 0.00016311 118 | [QTUMBTC] => 0.00178400 119 | [YOYOBTC] => 0.00000481 120 | [OMGBTC] => 0.00125600 121 | [OMGETH] => 0.02497000 122 | [ZRXBTC] => 0.00003376 123 | [ZRXETH] => 0.00067001 124 | [STRATBTC] => 0.00052100 125 | [STRATETH] => 0.00950200 126 | [SNGLSBTC] => 0.00002216 127 | [SNGLSETH] => 0.00043508 128 | [BQXBTC] => 0.00010944 129 | [BQXETH] => 0.00241250 130 | [KNCBTC] => 0.00017060 131 | [KNCETH] => 0.00340090 132 | [FUNBTC] => 0.00000313 133 | [FUNETH] => 0.00006184 134 | [SNMBTC] => 0.00001761 135 | [SNMETH] => 0.00035599 136 | [NEOETH] => 0.09500000 137 | [IOTABTC] => 0.00006783 138 | [IOTAETH] => 0.00136000 139 | [LINKBTC] => 0.00004476 140 | [LINKETH] => 0.00087796 141 | [XVGBTC] => 0.00000081 142 | [XVGETH] => 0.00001611 143 | [CTRBTC] => 0.00009408 144 | [CTRETH] => 0.00187010 145 | [SALTBTC] => 0.00044400 146 | [SALTETH] => 0.00890000 147 | [MDABTC] => 0.00021973 148 | [MDAETH] => 0.00435550 149 | [MTLBTC] => 0.00116900 150 | [MTLETH] => 0.02470000 151 | [SUBBTC] => 0.00002163 152 | [SUBETH] => 0.00042901 153 | [EOSBTC] => 0.00008822 154 | [SNTBTC] => 0.00000438 155 | [ETC] => 0.00000000 156 | [ETCETH] => 0.03600000 157 | [ETCBTC] => 0.00180800 158 | [MTHBTC] => 0.00001425 159 | [MTHETH] => 0.00028092 160 | [ENGBTC] => 0.00007040 161 | [ENGETH] => 0.00138220 162 | [DNTBTC] => 0.00001052 163 | [ZECBTC] => 0.00000000 164 | [ZECETH] => 0.00000000 165 | [BNTBTC] => 0.00033501 166 | [ASTBTC] => 0.00004528 167 | [ASTETH] => 0.00083990 168 | [DASHBTC] => 0.04651300 169 | [DASHETH] => 0.90520000 170 | ) 171 | Price of BNB: 0.00021479 BTC. 172 | ``` 173 |
174 | 175 | #### Get latest price of a symbol 176 | ```php 177 | $price = $api->price("BNBBTC"); 178 | echo "Price of BNB: {$price} BTC.".PHP_EOL; 179 | ``` 180 | 181 | #### Get miniTicker for all symbols 182 | ```php 183 | $api->miniTicker(function($api, $ticker) { 184 | print_r($ticker); 185 | }); 186 | ``` 187 | 188 |
189 | View Response 190 | 191 | ``` 192 | [7] => Array 193 | ( 194 | [symbol] => LTCUSDT 195 | [close] => 182.85000000 196 | [open] => 192.62000000 197 | [high] => 195.25000000 198 | [low] => 173.08000000 199 | [volume] => 238603.66451000 200 | [quoteVolume] => 43782422.11276660 201 | [eventTime] => 1520497914289 202 | ) 203 | 204 | [8] => Array 205 | ( 206 | [symbol] => ICXBTC 207 | [close] => 0.00029790 208 | [open] => 0.00030550 209 | [high] => 0.00031600 210 | [low] => 0.00026850 211 | [volume] => 8468620.53000000 212 | [quoteVolume] => 2493.60935828 213 | [eventTime] => 1520497915200 214 | ) 215 | 216 | ``` 217 |
218 | 219 | #### Get balances for all of your positions, including estimated BTC value 220 | ```php 221 | $ticker = $api->prices(); // Make sure you have an updated ticker object for this to work 222 | $balances = $api->balances($ticker); 223 | print_r($balances); 224 | echo "BTC owned: ".$balances['BTC']['available'].PHP_EOL; 225 | echo "ETH owned: ".$balances['ETH']['available'].PHP_EOL; 226 | echo "Estimated Value: ".$api->btc_value." BTC".PHP_EOL; 227 | ``` 228 | 229 |
230 | View Response 231 | 232 | ``` 233 | [WTC] => Array 234 | ( 235 | [available] => 909.61000000 236 | [onOrder] => 0.00000000 237 | [btcValue] => 0.94015470 238 | ) 239 | 240 | [BNB] => Array 241 | ( 242 | [available] => 1045.94316876 243 | [onOrder] => 0.00000000 244 | [btcValue] => 0.21637426 245 | ) 246 | ... (more) 247 | ``` 248 |
249 | 250 | 251 | #### Get all bid/ask prices 252 | ```php 253 | $bookPrices = $api->bookPrices(); 254 | print_r($bookPrices); 255 | echo "Bid price of BNB: {$bookPrices['BNBBTC']['bid']}".PHP_EOL; 256 | ``` 257 | 258 |
259 | View Response 260 | 261 | ``` 262 | Price of BNB: 0.00021491 263 | 264 | Array 265 | ( 266 | [ETHBTC] => Array 267 | ( 268 | [bid] => 0.05053000 269 | [bids] => 7.21000000 270 | [ask] => 0.05076000 271 | [asks] => 13.73600000 272 | ) 273 | [LTCBTC] => Array 274 | ( 275 | [bid] => 0.00966500 276 | [bids] => 62.57000000 277 | [ask] => 0.00967100 278 | [asks] => 5.48000000 279 | ) 280 | [BNBBTC] => Array 281 | ( 282 | [bid] => 0.00021010 283 | [bids] => 6.00000000 284 | [ask] => 0.00021479 285 | [asks] => 76.00000000 286 | ) 287 | [NEOBTC] => Array 288 | ( 289 | [bid] => 0.00476600 290 | [bids] => 5.16000000 291 | [ask] => 0.00479900 292 | [asks] => 276.00000000 293 | ) 294 | [QTUMETH] => Array 295 | ( 296 | [bid] => 0.03515000 297 | [bids] => 11.87000000 298 | [ask] => 0.03599900 299 | [asks] => 0.60000000 300 | ) 301 | [EOSETH] => Array 302 | ( 303 | [bid] => 0.00176000 304 | [bids] => 52.63000000 305 | [ask] => 0.00177900 306 | [asks] => 654.44000000 307 | ) 308 | [SNTETH] => Array 309 | ( 310 | [bid] => 0.00008522 311 | [bids] => 2347.00000000 312 | [ask] => 0.00008764 313 | [asks] => 2151.00000000 314 | ) 315 | [BNTETH] => Array 316 | ( 317 | [bid] => 0.00662400 318 | [bids] => 1940.32000000 319 | [ask] => 0.00683900 320 | [asks] => 64.89000000 321 | ) 322 | [BCCBTC] => Array 323 | ( 324 | [bid] => 0.05614300 325 | [bids] => 2.15000000 326 | [ask] => 0.05710000 327 | [asks] => 0.75900000 328 | ) 329 | [GASBTC] => Array 330 | ( 331 | [bid] => 0.00337800 332 | [bids] => 597.29000000 333 | [ask] => 0.00338500 334 | [asks] => 14.63000000 335 | ) 336 | [BNBETH] => Array 337 | ( 338 | [bid] => 0.00411497 339 | [bids] => 375.00000000 340 | [ask] => 0.00418603 341 | [asks] => 4.00000000 342 | ) 343 | [BTMETH] => Array 344 | ( 345 | [bid] => 0.00000000 346 | [bids] => 0.00000000 347 | [ask] => 0.00000000 348 | [asks] => 0.00000000 349 | ) 350 | [HCCBTC] => Array 351 | ( 352 | [bid] => 0.00000000 353 | [bids] => 0.00000000 354 | [ask] => 0.00000000 355 | [asks] => 0.00000000 356 | ) 357 | [BTCUSDT] => Array 358 | ( 359 | [bid] => 5970.00000000 360 | [bids] => 0.00500000 361 | [ask] => 5989.96000000 362 | [asks] => 0.26295200 363 | ) 364 | [ETHUSDT] => Array 365 | ( 366 | [bid] => 303.86000000 367 | [bids] => 4.27000000 368 | [ask] => 304.99000000 369 | [asks] => 0.11361000 370 | ) 371 | [HSRBTC] => Array 372 | ( 373 | [bid] => 0.00000000 374 | [bids] => 0.00000000 375 | [ask] => 0.00000000 376 | [asks] => 0.00000000 377 | ) 378 | [OAXETH] => Array 379 | ( 380 | [bid] => 0.00137100 381 | [bids] => 145.88000000 382 | [ask] => 0.00139500 383 | [asks] => 960.81000000 384 | ) 385 | [DNTETH] => Array 386 | ( 387 | [bid] => 0.00020421 388 | [bids] => 19401.00000000 389 | [ask] => 0.00020573 390 | [asks] => 1.00000000 391 | ) 392 | [MCOETH] => Array 393 | ( 394 | [bid] => 0.02630000 395 | [bids] => 20.36000000 396 | [ask] => 0.02684100 397 | [asks] => 75.35000000 398 | ) 399 | [ICNETH] => Array 400 | ( 401 | [bid] => 0.00391600 402 | [bids] => 51.07000000 403 | [ask] => 0.00396800 404 | [asks] => 146.69000000 405 | ) 406 | [ELCBTC] => Array 407 | ( 408 | [bid] => 0.00000000 409 | [bids] => 0.00000000 410 | [ask] => 0.00000000 411 | [asks] => 0.00000000 412 | ) 413 | [MCOBTC] => Array 414 | ( 415 | [bid] => 0.00132800 416 | [bids] => 24.64000000 417 | [ask] => 0.00133200 418 | [asks] => 8.26000000 419 | ) 420 | [WTCBTC] => Array 421 | ( 422 | [bid] => 0.00116640 423 | [bids] => 104.00000000 424 | [ask] => 0.00118000 425 | [asks] => 1572.00000000 426 | ) 427 | [WTCETH] => Array 428 | ( 429 | [bid] => 0.02311400 430 | [bids] => 0.99000000 431 | [ask] => 0.02330000 432 | [asks] => 27.68000000 433 | ) 434 | [LLTBTC] => Array 435 | ( 436 | [bid] => 0.00000000 437 | [bids] => 0.00000000 438 | [ask] => 0.00000000 439 | [asks] => 0.00000000 440 | ) 441 | [LRCBTC] => Array 442 | ( 443 | [bid] => 0.00000000 444 | [bids] => 0.00000000 445 | [ask] => 0.00000000 446 | [asks] => 0.00000000 447 | ) 448 | [LRCETH] => Array 449 | ( 450 | [bid] => 0.00000000 451 | [bids] => 0.00000000 452 | [ask] => 0.00000000 453 | [asks] => 0.00000000 454 | ) 455 | [QTUMBTC] => Array 456 | ( 457 | [bid] => 0.00178700 458 | [bids] => 328.30000000 459 | [ask] => 0.00180500 460 | [asks] => 50.00000000 461 | ) 462 | [YOYOBTC] => Array 463 | ( 464 | [bid] => 0.00000000 465 | [bids] => 0.00000000 466 | [ask] => 0.00000000 467 | [asks] => 0.00000000 468 | ) 469 | [OMGBTC] => Array 470 | ( 471 | [bid] => 0.00126100 472 | [bids] => 61.00000000 473 | [ask] => 0.00126400 474 | [asks] => 8.50000000 475 | ) 476 | [OMGETH] => Array 477 | ( 478 | [bid] => 0.02467200 479 | [bids] => 60.99000000 480 | [ask] => 0.02527500 481 | [asks] => 7.98000000 482 | ) 483 | [ZRXBTC] => Array 484 | ( 485 | [bid] => 0.00003370 486 | [bids] => 69.00000000 487 | [ask] => 0.00003377 488 | [asks] => 7437.00000000 489 | ) 490 | [ZRXETH] => Array 491 | ( 492 | [bid] => 0.00065565 493 | [bids] => 68.00000000 494 | [ask] => 0.00069171 495 | [asks] => 123.00000000 496 | ) 497 | [STRATBTC] => Array 498 | ( 499 | [bid] => 0.00051200 500 | [bids] => 387.00000000 501 | [ask] => 0.00052100 502 | [asks] => 17.90000000 503 | ) 504 | [STRATETH] => Array 505 | ( 506 | [bid] => 0.00988800 507 | [bids] => 299.97000000 508 | [ask] => 0.01084600 509 | [asks] => 133.91000000 510 | ) 511 | [SNGLSBTC] => Array 512 | ( 513 | [bid] => 0.00002211 514 | [bids] => 1028.00000000 515 | [ask] => 0.00002217 516 | [asks] => 536.00000000 517 | ) 518 | [SNGLSETH] => Array 519 | ( 520 | [bid] => 0.00043801 521 | [bids] => 892.00000000 522 | [ask] => 0.00043902 523 | [asks] => 1585.00000000 524 | ) 525 | [BQXBTC] => Array 526 | ( 527 | [bid] => 0.00011061 528 | [bids] => 1814.00000000 529 | [ask] => 0.00011496 530 | [asks] => 1707.00000000 531 | ) 532 | [BQXETH] => Array 533 | ( 534 | [bid] => 0.00220610 535 | [bids] => 109.00000000 536 | [ask] => 0.00241190 537 | [asks] => 2606.00000000 538 | ) 539 | [KNCBTC] => Array 540 | ( 541 | [bid] => 0.00017061 542 | [bids] => 1109.00000000 543 | [ask] => 0.00017297 544 | [asks] => 63.00000000 545 | ) 546 | [KNCETH] => Array 547 | ( 548 | [bid] => 0.00340090 549 | [bids] => 3.00000000 550 | [ask] => 0.00342860 551 | [asks] => 515.00000000 552 | ) 553 | [FUNBTC] => Array 554 | ( 555 | [bid] => 0.00000314 556 | [bids] => 17100.00000000 557 | [ask] => 0.00000317 558 | [asks] => 15600.00000000 559 | ) 560 | [FUNETH] => Array 561 | ( 562 | [bid] => 0.00006186 563 | [bids] => 4473.00000000 564 | [ask] => 0.00006467 565 | [asks] => 42036.00000000 566 | ) 567 | [SNMBTC] => Array 568 | ( 569 | [bid] => 0.00001760 570 | [bids] => 3695.00000000 571 | [ask] => 0.00001781 572 | [asks] => 623.00000000 573 | ) 574 | [SNMETH] => Array 575 | ( 576 | [bid] => 0.00034783 577 | [bids] => 507.00000000 578 | [ask] => 0.00035350 579 | [asks] => 1501.00000000 580 | ) 581 | [NEOETH] => Array 582 | ( 583 | [bid] => 0.09414500 584 | [bids] => 12.38000000 585 | [ask] => 0.09599700 586 | [asks] => 23.38000000 587 | ) 588 | [IOTABTC] => Array 589 | ( 590 | [bid] => 0.00006791 591 | [bids] => 2000.00000000 592 | [ask] => 0.00006857 593 | [asks] => 1861.00000000 594 | ) 595 | [IOTAETH] => Array 596 | ( 597 | [bid] => 0.00135101 598 | [bids] => 1461.00000000 599 | [ask] => 0.00138938 600 | [asks] => 21.00000000 601 | ) 602 | [LINKBTC] => Array 603 | ( 604 | [bid] => 0.00004400 605 | [bids] => 683.00000000 606 | [ask] => 0.00004491 607 | [asks] => 7292.00000000 608 | ) 609 | [LINKETH] => Array 610 | ( 611 | [bid] => 0.00086045 612 | [bids] => 682.00000000 613 | [ask] => 0.00087683 614 | [asks] => 4286.00000000 615 | ) 616 | [XVGBTC] => Array 617 | ( 618 | [bid] => 0.00000080 619 | [bids] => 96600.00000000 620 | [ask] => 0.00000081 621 | [asks] => 179622.00000000 622 | ) 623 | [XVGETH] => Array 624 | ( 625 | [bid] => 0.00001556 626 | [bids] => 96537.00000000 627 | [ask] => 0.00001675 628 | [asks] => 4.00000000 629 | ) 630 | [CTRBTC] => Array 631 | ( 632 | [bid] => 0.00009346 633 | [bids] => 2133.00000000 634 | [ask] => 0.00009470 635 | [asks] => 1992.00000000 636 | ) 637 | [CTRETH] => Array 638 | ( 639 | [bid] => 0.00187050 640 | [bids] => 501.00000000 641 | [ask] => 0.00189230 642 | [asks] => 105.00000000 643 | ) 644 | [SALTBTC] => Array 645 | ( 646 | [bid] => 0.00044400 647 | [bids] => 181.09000000 648 | [ask] => 0.00044700 649 | [asks] => 1144.81000000 650 | ) 651 | [SALTETH] => Array 652 | ( 653 | [bid] => 0.00866500 654 | [bids] => 216.71000000 655 | [ask] => 0.00893900 656 | [asks] => 237.00000000 657 | ) 658 | [MDABTC] => Array 659 | ( 660 | [bid] => 0.00021328 661 | [bids] => 555.00000000 662 | [ask] => 0.00021973 663 | [asks] => 236.00000000 664 | ) 665 | [MDAETH] => Array 666 | ( 667 | [bid] => 0.00425610 668 | [bids] => 450.00000000 669 | [ask] => 0.00441450 670 | [asks] => 511.00000000 671 | ) 672 | [MTLBTC] => Array 673 | ( 674 | [bid] => 0.00114500 675 | [bids] => 194.48000000 676 | [ask] => 0.00117000 677 | [asks] => 1.40000000 678 | ) 679 | [MTLETH] => Array 680 | ( 681 | [bid] => 0.02156000 682 | [bids] => 183.00000000 683 | [ask] => 0.02436700 684 | [asks] => 200.97000000 685 | ) 686 | [SUBBTC] => Array 687 | ( 688 | [bid] => 0.00002116 689 | [bids] => 520.00000000 690 | [ask] => 0.00002177 691 | [asks] => 957.00000000 692 | ) 693 | [SUBETH] => Array 694 | ( 695 | [bid] => 0.00042121 696 | [bids] => 202.00000000 697 | [ask] => 0.00044390 698 | [asks] => 69.00000000 699 | ) 700 | [EOSBTC] => Array 701 | ( 702 | [bid] => 0.00008837 703 | [bids] => 52.00000000 704 | [ask] => 0.00008901 705 | [asks] => 565.00000000 706 | ) 707 | [SNTBTC] => Array 708 | ( 709 | [bid] => 0.00000431 710 | [bids] => 11731.00000000 711 | [ask] => 0.00000439 712 | [asks] => 9000.00000000 713 | ) 714 | [ETC] => Array 715 | ( 716 | [bid] => 0.00000000 717 | [bids] => 0.00000000 718 | [ask] => 0.00000000 719 | [asks] => 0.00000000 720 | ) 721 | [ETCETH] => Array 722 | ( 723 | [bid] => 0.03600000 724 | [bids] => 460.15000000 725 | [ask] => 0.03699600 726 | [asks] => 30.00000000 727 | ) 728 | [ETCBTC] => Array 729 | ( 730 | [bid] => 0.00181200 731 | [bids] => 6.90000000 732 | [ask] => 0.00183700 733 | [asks] => 2.72000000 734 | ) 735 | [MTHBTC] => Array 736 | ( 737 | [bid] => 0.00001400 738 | [bids] => 400.00000000 739 | [ask] => 0.00001467 740 | [asks] => 615.00000000 741 | ) 742 | [MTHETH] => Array 743 | ( 744 | [bid] => 0.00027316 745 | [bids] => 399.00000000 746 | [ask] => 0.00029096 747 | [asks] => 24939.00000000 748 | ) 749 | [ENGBTC] => Array 750 | ( 751 | [bid] => 0.00006927 752 | [bids] => 2896.00000000 753 | [ask] => 0.00007040 754 | [asks] => 75.00000000 755 | ) 756 | [ENGETH] => Array 757 | ( 758 | [bid] => 0.00138220 759 | [bids] => 1111.00000000 760 | [ask] => 0.00142990 761 | [asks] => 2010.00000000 762 | ) 763 | [DNTBTC] => Array 764 | ( 765 | [bid] => 0.00001053 766 | [bids] => 11295.00000000 767 | [ask] => 0.00001065 768 | [asks] => 8272.00000000 769 | ) 770 | [ZECBTC] => Array 771 | ( 772 | [bid] => 0.00000000 773 | [bids] => 0.00000000 774 | [ask] => 0.00000000 775 | [asks] => 0.00000000 776 | ) 777 | [ZECETH] => Array 778 | ( 779 | [bid] => 0.00000000 780 | [bids] => 0.00000000 781 | [ask] => 0.00000000 782 | [asks] => 0.00000000 783 | ) 784 | [BNTBTC] => Array 785 | ( 786 | [bid] => 0.00033500 787 | [bids] => 15.00000000 788 | [ask] => 0.00033996 789 | [asks] => 679.00000000 790 | ) 791 | [ASTBTC] => Array 792 | ( 793 | [bid] => 0.00004133 794 | [bids] => 9513.00000000 795 | [ask] => 0.00004528 796 | [asks] => 4170.00000000 797 | ) 798 | [ASTETH] => Array 799 | ( 800 | [bid] => 0.00083830 801 | [bids] => 4296.00000000 802 | [ask] => 0.00084900 803 | [asks] => 999.00000000 804 | ) 805 | [DASHBTC] => Array 806 | ( 807 | [bid] => 0.04651200 808 | [bids] => 0.25000000 809 | [ask] => 0.04659000 810 | [asks] => 1.00000000 811 | ) 812 | [DASHETH] => Array 813 | ( 814 | [bid] => 0.90420000 815 | [bids] => 63.96400000 816 | [ask] => 0.94375000 817 | [asks] => 0.36900000 818 | ) 819 | ) 820 | ``` 821 |
822 | 823 | #### Place a LIMIT order 824 | ```php 825 | $quantity = 1; 826 | $price = 0.0005; 827 | $order = $api->buy("BNBBTC", $quantity, $price); 828 | ``` 829 | 830 | ```php 831 | $quantity = 1; 832 | $price = 0.0006; 833 | $order = $api->sell("BNBBTC", $quantity, $price); 834 | ``` 835 | 836 | #### Place a MARKET order 837 | ```php 838 | $quantity = 1; 839 | $order = $api->marketBuy("BNBBTC", $quantity); 840 | ``` 841 | 842 | ```php 843 | $quantity = 0.01; 844 | $order = $api->marketSell("ETHBTC", $quantity); 845 | ``` 846 | 847 |
848 | View Response 849 | 850 | ``` 851 | ( 852 | [symbol] => BNBBTC 853 | [orderId] => 7652393 854 | [clientOrderId] => aAE7BNUhITQj3eg04iG1sY 855 | [transactTime] => 1508564815865 856 | [price] => 0.00000000 857 | [origQty] => 1.00000000 858 | [executedQty] => 1.00000000 859 | [status] => FILLED 860 | [timeInForce] => GTC 861 | [type] => MARKET 862 | [side] => BUY 863 | ) 864 | ``` 865 |
866 | 867 | 868 | #### Place a STOP LOSS order 869 | ```php 870 | // When the stop is reached, a stop order becomes a market order 871 | $type = "STOP_LOSS"; // Set the type STOP_LOSS (market) or STOP_LOSS_LIMIT, and TAKE_PROFIT (market) or TAKE_PROFIT_LIMIT 872 | $quantity = 1; 873 | $price = 0.5; // Try to sell it for 0.5 btc 874 | $stopPrice = 0.4; // Sell immediately if price goes below 0.4 btc 875 | $order = $api->sell("BNBBTC", $quantity, $price, $type, ["stopPrice"=>$stopPrice]); 876 | print_r($order); 877 | ``` 878 | 879 | #### Place an ICEBERG order 880 | ```php 881 | // Iceberg orders are intended to conceal the true order quantity. 882 | $type = "LIMIT"; // LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT 883 | $quantity = 1; 884 | $price = 0.5; 885 | $icebergQty = 10; 886 | $order = $api->sell("BNBBTC", $quantity, $price, $type, ["icebergQty"=>$icebergQty]); 887 | print_r($order); 888 | ``` 889 | 890 | #### Getting 24hr ticker price change statistics for a symbol 891 | ```php 892 | $prevDay = $api->prevDay("BNBBTC"); 893 | print_r($prevDay); 894 | echo "BNB price change since yesterday: ".$prevDay['priceChangePercent']."%".PHP_EOL; 895 | ``` 896 | 897 | #### Complete Account Trade History 898 | ```php 899 | $history = $api->history("BNBBTC"); 900 | print_r($history); 901 | ``` 902 | 903 |
904 | View Response 905 | 906 | ``` 907 | Array ( 908 | [0] => Array ( 909 | [id] => 831585 910 | [orderId] => 3635308 911 | [price] => 0.00028800 912 | [qty] => 4.00000000 913 | [commission] => 0.00200000 914 | [commissionAsset] => BNB 915 | [time] => 1504805561369 916 | [isBuyer] => 1 917 | [isMaker] => 918 | [isBestMatch] => 1 919 | ) 920 | 921 | [1] => Array ( 922 | [id] => 1277334 923 | [orderId] => 6126625 924 | [price] => 0.00041054 925 | [qty] => 16.00000000 926 | [commission] => 0.00800000 927 | [commissionAsset] => BNB 928 | [time] => 1507059468604 929 | [isBuyer] => 1 930 | [isMaker] => 931 | [isBestMatch] => 1 932 | ) 933 | 934 | [2] => Array ( 935 | [id] => 1345995 936 | [orderId] => 6407202 937 | [price] => 0.00035623 938 | [qty] => 30.00000000 939 | [commission] => 0.01500000 940 | [commissionAsset] => BNB 941 | [time] => 1507434311489 942 | [isBuyer] => 1 943 | [isMaker] => 1 944 | [isBestMatch] => 1 945 | ) 946 | ) 947 | ... (more) 948 | ``` 949 |
950 | 951 | #### Get Market Depth 952 | ```php 953 | $depth = $api->depth("ETHBTC"); 954 | print_r($depth); 955 | ``` 956 | 957 | #### Get Open Orders 958 | ```php 959 | $openorders = $api->openOrders("BNBBTC"); 960 | print_r($openorders); 961 | ``` 962 | 963 | #### Get Order Status 964 | ```php 965 | $orderid = "7610385"; 966 | $orderstatus = $api->orderStatus("ETHBTC", $orderid); 967 | print_r($orderstatus); 968 | ``` 969 | 970 | #### Cancel an Order 971 | ```php 972 | $response = $api->cancel("ETHBTC", $orderid); 973 | print_r($response); 974 | ``` 975 | 976 | #### Market History / Aggregate Trades 977 | ```php 978 | $trades = $api->aggTrades("BNBBTC"); 979 | print_r($trades); 980 | ``` 981 | 982 | #### Get all account orders; active, canceled, or filled. 983 | ```php 984 | $orders = $api->orders("BNBBTC"); 985 | print_r($orders); 986 | ``` 987 | 988 | #### Get Kline/candlestick data for a symbol 989 | ```php 990 | //Periods: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M 991 | $ticks = $api->candlesticks("BNBBTC", "5m"); 992 | print_r($ticks); 993 | ``` 994 |
995 | View Response 996 | 997 | ``` 998 | [1508560200000] => Array 999 | ( 1000 | [open] => 0.00019691 1001 | [high] => 0.00019695 1002 | [low] => 0.00019502 1003 | [close] => 0.00019503 1004 | [volume] => 0.13712290 1005 | ) 1006 | 1007 | [1508560500000] => Array 1008 | ( 1009 | [open] => 0.00019502 1010 | [high] => 0.00019693 1011 | [low] => 0.00019501 1012 | [close] => 0.00019692 1013 | [volume] => 1.03216357 1014 | ) 1015 | 1016 | [1508560800000] => Array 1017 | ( 1018 | [open] => 0.00019692 1019 | [high] => 0.00019692 1020 | [low] => 0.00019689 1021 | [close] => 0.00019692 1022 | [volume] => 0.22270990 1023 | ) 1024 | ... (more) 1025 | ``` 1026 |
1027 | 1028 | ## WebSocket API 1029 | 1030 | #### miniTicker return the latest candlestick information for every symbol 1031 | ```php 1032 | $api->miniTicker(function($api, $ticker) { 1033 | print_r($ticker); 1034 | }); 1035 | ``` 1036 | 1037 |
1038 | View Response 1039 | 1040 | ``` 1041 | [18] => Array 1042 | ( 1043 | [symbol] => ONTBNB 1044 | [close] => 0.37649000 1045 | [open] => 0.30241000 1046 | [high] => 0.38112000 1047 | [low] => 0.29300000 1048 | [volume] => 975240.72000000 1049 | [quoteVolume] => 326908.77744250 1050 | [eventTime] => 1523395389582 1051 | ) 1052 | 1053 | [19] => Array 1054 | ( 1055 | [symbol] => WANBTC 1056 | [close] => 0.00063657 1057 | [open] => 0.00054151 1058 | [high] => 0.00063900 1059 | [low] => 0.00053900 1060 | [volume] => 4443618.00000000 1061 | [quoteVolume] => 2637.76413131 1062 | [eventTime] => 1523395389551 1063 | ) 1064 | ``` 1065 |
1066 | 1067 | #### Realtime Complete Chart Updates via WebSockets 1068 | ```php 1069 | $api->chart(["BNBBTC"], "15m", function($api, $symbol, $chart) { 1070 | echo "{$symbol} chart update\n"; 1071 | print_r($chart); 1072 | }); 1073 | ``` 1074 |
1075 | View Response 1076 | 1077 | ``` 1078 | [1508560200000] => Array 1079 | ( 1080 | [open] => 0.00019691 1081 | [high] => 0.00019695 1082 | [low] => 0.00019502 1083 | [close] => 0.00019503 1084 | [volume] => 0.13712290 1085 | ) 1086 | 1087 | [1508560500000] => Array 1088 | ( 1089 | [open] => 0.00019502 1090 | [high] => 0.00019693 1091 | [low] => 0.00019501 1092 | [close] => 0.00019692 1093 | [volume] => 1.03216357 1094 | ) 1095 | 1096 | [1508560800000] => Array 1097 | ( 1098 | [open] => 0.00019692 1099 | [high] => 0.00019692 1100 | [low] => 0.00019689 1101 | [close] => 0.00019692 1102 | [volume] => 0.22270990 1103 | ) 1104 | ... (more) 1105 | ``` 1106 |
1107 | 1108 | #### Get latest candlestick data only 1109 | ```php 1110 | $api->kline(["BTCUSDT", "EOSBTC"], "5m", function($api, $symbol, $chart) { 1111 | //echo "{$symbol} ({$interval}) candlestick update\n"; 1112 | $interval = $chart->i; 1113 | $tick = $chart->t; 1114 | $open = $chart->o; 1115 | $high = $chart->h; 1116 | $low = $chart->l; 1117 | $close = $chart->c; 1118 | $volume = $chart->q; // +trades buyVolume assetVolume makerVolume 1119 | echo "{$symbol} price: {$close}\t volume: {$volume}\n"; 1120 | }); 1121 | ``` 1122 | 1123 | #### Trade Updates via WebSocket 1124 | ```php 1125 | $api->trades(["BNBBTC"], function($api, $symbol, $trades) { 1126 | echo "{$symbol} trades update".PHP_EOL; 1127 | print_r($trades); 1128 | }); 1129 | ``` 1130 | 1131 | #### Get ticker updates for all symbols via WebSocket 1132 | ```php 1133 | $api->ticker(false, function($api, $symbol, $ticker) { 1134 | print_r($ticker); 1135 | }); 1136 | ``` 1137 | 1138 | #### Get ticker updates for a specific symbol via WebSocket 1139 | ```php 1140 | $api->ticker("BNBBTC", function($api, $symbol, $ticker) { 1141 | print_r($ticker); 1142 | }); 1143 | ``` 1144 | 1145 | #### Realtime updated depth cache via WebSockets 1146 | ```php 1147 | $api->depthCache(["BNBBTC"], function($api, $symbol, $depth) { 1148 | echo "{$symbol} depth cache update".PHP_EOL; 1149 | //print_r($depth); // Print all depth data 1150 | $limit = 11; // Show only the closest asks/bids 1151 | $sorted = $api->sortDepth($symbol, $limit); 1152 | $bid = $api->first($sorted['bids']); 1153 | $ask = $api->first($sorted['asks']); 1154 | echo $api->displayDepth($sorted); 1155 | echo "ask: {$ask}".PHP_EOL; 1156 | echo "bid: {$bid}".PHP_EOL; 1157 | }); 1158 | ``` 1159 |
1160 | View Response 1161 | 1162 | ``` 1163 | asks: 1164 | 0.00020649 1,194 0.24654906 1165 | 0.00020600 375 0.07725000 1166 | 0.00020586 4 0.00823440 1167 | 0.00020576 1 0.00205760 1168 | 0.00020564 226 0.04647464 1169 | 0.00020555 38 0.00781090 1170 | 0.00020552 98 0.02014096 1171 | 0.00020537 121 0.02484977 1172 | 0.00020520 46 0.09439200 1173 | 0.00020519 29 0.05950510 1174 | 0.00020518 311 0.06381098 1175 | bids: 1176 | 0.00022258 5,142 1.14450636 1177 | 0.00020316 7 0.00142212 1178 | 0.00020315 82 0.01665830 1179 | 0.00020314 16 0.00325024 1180 | 0.00020313 512 0.10400256 1181 | 0.00020238 5 0.01011900 1182 | 0.00020154 1,207 0.24325878 1183 | 0.00020151 1 0.02015100 1184 | 0.00020150 3 0.60450000 1185 | 0.00020140 217 0.04370380 1186 | 0.00020135 1 0.02013500 1187 | ask: 0.00020518 1188 | bid: 0.00022258 1189 | 1190 | ``` 1191 |
1192 | 1193 | #### User Data: Account Balance Updates, Trade Updates, New Orders, Filled Orders, Cancelled Orders via WebSocket 1194 | ```php 1195 | $balance_update = function($api, $balances) { 1196 | print_r($balances); 1197 | echo "Balance update".PHP_EOL; 1198 | }; 1199 | 1200 | $order_update = function($api, $report) { 1201 | echo "Order update".PHP_EOL; 1202 | print_r($report); 1203 | $price = $report['price']; 1204 | $quantity = $report['quantity']; 1205 | $symbol = $report['symbol']; 1206 | $side = $report['side']; 1207 | $orderType = $report['orderType']; 1208 | $orderId = $report['orderId']; 1209 | $orderStatus = $report['orderStatus']; 1210 | $executionType = $report['orderStatus']; 1211 | if ( $executionType == "NEW" ) { 1212 | if ( $executionType == "REJECTED" ) { 1213 | echo "Order Failed! Reason: {$report['rejectReason']}".PHP_EOL; 1214 | } 1215 | echo "{$symbol} {$side} {$orderType} ORDER #{$orderId} ({$orderStatus})".PHP_EOL; 1216 | echo "..price: {$price}, quantity: {$quantity}".PHP_EOL; 1217 | return; 1218 | } 1219 | //NEW, CANCELED, REPLACED, REJECTED, TRADE, EXPIRED 1220 | echo "{$symbol} {$side} {$executionType} {$orderType} ORDER #{$orderId}".PHP_EOL; 1221 | }; 1222 | $api->userData($balance_update, $order_update); 1223 | ``` 1224 | 1225 |
1226 | View Response 1227 | 1228 | ``` 1229 | Order update 1230 | [symbol] => BNBETH 1231 | [side] => BUY 1232 | [orderType] => LIMIT 1233 | [quantity] => 2.00000000 1234 | [price] => 0.00623005 1235 | [executionType] => NEW 1236 | [orderStatus] => NEW 1237 | [rejectReason] => NONE 1238 | [orderId] => 4102532 1239 | [clientOrderId] => ULtH25RPmICFH0jvsQiq8y 1240 | [orderTime] => 1508637831437 1241 | [eventTime] => 1508637831440 1242 | 1243 | BNBETH BUY LIMIT ORDER #4102532 (NEW) 1244 | ..price: 0.00623005, quantity: 2.00000000 1245 | 1246 | Balance update 1247 | [BTC] => Array 1248 | ( 1249 | [available] => 0.18167974 1250 | [onOrder] => 0.00000000 1251 | ) 1252 | 1253 | [LTC] => Array 1254 | ( 1255 | [available] => 0.00000000 1256 | [onOrder] => 0.00000000 1257 | ) 1258 | 1259 | [ETH] => Array 1260 | ( 1261 | [available] => 26.68739238 1262 | [onOrder] => 2.55103500 1263 | ) 1264 | ...(more) 1265 | ``` 1266 |
1267 | 1268 | 1269 | #### Withdraw 1270 | ```php 1271 | $asset = "BTC"; 1272 | $address = "1C5gqLRs96Xq4V2ZZAR1347yUCpHie7sa"; 1273 | $amount = 0.2; 1274 | $response = $api->withdraw($asset, $address, $amount); 1275 | print_r($response); 1276 | ``` 1277 | 1278 | #### Withdraw with addressTag 1279 | ```php 1280 | //Required for coins like XMR, XRP, etc. 1281 | $address = "44tLjmXrQNrWJ5NBsEj2R77ZBEgDa3fEe9GLpSf2FRmhexPvfYDUAB7EXX1Hdb3aMQ9FLqdJ56yaAhiXoRsceGJCRS3Jxkn"; 1282 | $addressTag = "0e5e38a01058dbf64e53a4333a5acf98e0d5feb8e523d32e3186c664a9c762c1 1283 | "; 1284 | $amount = 0.1; 1285 | $response = $api->withdraw($asset, $address, $amount, $addressTag); 1286 | print_r($response); 1287 | ``` 1288 | 1289 | #### Get All Withdraw History 1290 | ```php 1291 | $withdrawHistory = $api->withdrawHistory(); 1292 | print_r($withdrawHistory); 1293 | ``` 1294 | 1295 | #### Get Withdraw History for a specific asset 1296 | ```php 1297 | $withdrawHistory = $api->withdrawHistory("BTC"); 1298 | print_r($withdrawHistory); 1299 | ``` 1300 | 1301 | #### Get Deposit Address 1302 | ```php 1303 | $depositAddress = $api->depositAddress("VEN"); 1304 | print_r($depositAddress); 1305 | ``` 1306 | 1307 | #### Get All Deposit History 1308 | ```php 1309 | $depositHistory = $api->depositHistory(); 1310 | print_r($depositHistory); 1311 | ``` 1312 | 1313 | ### Troubleshooting 1314 | If you get the following errors, please synchronize your system time. 1315 | ``` 1316 | signedRequest error: {"code":-1021,"msg":"Timestamp for this request was 1000ms ahead of the server's time."} 1317 | signedRequest error: {"code":-1021,"msg":"Timestamp for this request is outside of the recvWindow."} 1318 | balanceData error: Please make sure your system time is synchronized, or pass the useServerTime option. 1319 | ``` 1320 | 1321 | #### useServerTime 1322 | ```php 1323 | //Call this before running any functions 1324 | $api->useServerTime(); 1325 | ``` 1326 | 1327 | #### Installing on Windows 1328 | Download and install composer: 1329 | 1. https://getcomposer.org/download/ 1330 | 2. Create a folder on your drive like C:\Binance 1331 | 3. Run command prompt and type `cd C:\Binance` 1332 | 4. ```composer require jaggedsoft/php-binance-api``` 1333 | 5. Once complete copy the vendor folder into your project. 1334 | 1335 | #### Config file in home directory 1336 | If you dont wish to store your API key and secret in your scripts, load it from your home directory 1337 | ```bash 1338 | mkdir -vp ~/.config/jaggedsoft/ 1339 | cat > ~/.config/jaggedsoft/php-binance-api.json << EOF 1340 | { 1341 | "api-key": "", 1342 | "api-secret": "" 1343 | } 1344 | EOF 1345 | ``` 1346 | 1347 | #### Config file in home directory to operate on testnet 1348 | Testnet have its own credentials, see the [testnet documentation page](https://testnet.binance.vision/) for more details. 1349 | ```bash 1350 | mkdir -vp ~/.config/jaggedsoft/ 1351 | cat > ~/.config/jaggedsoft/php-binance-api.json << EOF 1352 | { 1353 | "api-key": "", 1354 | "api-secret": "", 1355 | "use-testnet": true 1356 | } 1357 | EOF 1358 | ``` 1359 | 1360 | #### Config file in home directory with curl options 1361 | ```bash 1362 | mkdir -vp ~/.config/jaggedsoft/ 1363 | cat > ~/.config/jaggedsoft/php-binance-api.json << EOF 1364 | { 1365 | "api-key": "", 1366 | "api-secret": "", 1367 | "curlOpts": { 1368 | "CURLOPT_SSL_VERIFYPEER": 0, 1369 | "INVALID_CONSTANT_NAME": 42 1370 | } 1371 | 1372 | } 1373 | EOF 1374 | ``` 1375 | 1376 | 1377 | Optionally add proxy configuration 1378 | ```bash 1379 | mkdir -vp ~/.config/jaggedsoft/ 1380 | cat > ~/.config/jaggedsoft/php-binance-api.json << EOF 1381 | { 1382 | "api-key": "", 1383 | "api-secret": "", 1384 | "proto": "https", 1385 | "address": "proxy.domain.com", 1386 | "port": "1080" 1387 | } 1388 | EOF 1389 | ``` 1390 | 1391 | custom location 1392 | ```php 1393 | $api = new Binance\API( "myfile.json" ); 1394 | ``` 1395 | 1396 | 1397 | #### Basic stats: Get api call counter 1398 | ```php 1399 | $api->getRequestCount(); 1400 | ``` 1401 | 1402 | #### Basic stats: Get total data transferred 1403 | ```php 1404 | $api->getTransfered(); 1405 | ``` 1406 | 1407 | #### Security - Disable downloading of CA Bundles 1408 | You can disable the downloading of the CA Bundle: 1409 | ```php 1410 | $api = new Binance\API( "somefile.json" ); 1411 | $api->caOverride = true; 1412 | ``` 1413 | 1414 | ### Documentation 1415 | > There are also numerous other formats available here: 1416 | https://github.com/jaggedsoft/php-binance-api/tree/gh-pages 1417 | 1418 | 1419 | [![Vitality](https://github.com/user-attachments/assets/0981aae2-3e12-4b57-8d2f-c5ae2b3b8b1c)](https://vitalitycrypto.com/) 1420 | 1421 | ## Star History 1422 | 1423 | [![Star History Chart](https://api.star-history.com/svg?repos=ccxt/php-binance-api&type=Date)](https://www.star-history.com/#ccxt/php-binance-api&Date) 1424 | 1425 | ## Contribution 1426 | - Give us a star :star: 1427 | - Fork and Clone! Awesome 1428 | - Select existing [issues](https://github.com/jaggedsoft/php-binance-api/issues) or create a [new issue](https://github.com/jaggedsoft/php-binance-api/issues/new) and give us a PR with your bugfix or improvement after. We love it ❤️ 1429 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jaggedsoft/php-binance-api", 3 | "description": "PHP Binance API is an asynchronous PHP library for the Binance API designed to be easy to use.", 4 | "keywords": ["Binance","cryptocurrency","WebSocket", "trading", "crypto"], 5 | "license": "MIT", 6 | "repositories": [ { 7 | "type": "vcs", 8 | "url": "https://github.com/jaggedsoft/php-binance-api" 9 | }], 10 | "require": { 11 | "php": ">=7.4", 12 | "ext-curl": "*", 13 | "ratchet/pawl": "^0.4.0", 14 | "react/socket": "^1.0 || ^0.8 || ^0.7", 15 | "ratchet/rfc6455": "^0.3" 16 | }, 17 | "require-dev": { 18 | "phpunit/phpunit": "^12.0", 19 | "codacy/coverage": "dev-master" 20 | }, 21 | "config": { 22 | "optimize-autoloader": true, 23 | "minimum-stability": "stable" 24 | }, 25 | "autoload": { 26 | "classmap": [ 27 | "php-binance-api.php", 28 | "php-binance-api-rate-limiter.php" 29 | ] 30 | }, 31 | "scripts": { 32 | "test": "phpunit tests/BinanceStaticTests.php", 33 | "live-tests": "phpunit tests/BinanceLiveTests.php" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /examples/0.example.php: -------------------------------------------------------------------------------- 1 | ",""); 4 | 5 | // Get latest price of all symbols 6 | $tickers = $api->prices(); 7 | print_r($tickers); // List prices of all symbols 8 | 9 | // Get latest price of a symbol 10 | $price = $api->price('BNBBTC'); 11 | echo "Price of BNB: {$price} BTC.\n"; 12 | 13 | // Get all of your positions, including estimated BTC value 14 | $balances = $api->balances($tickers); 15 | print_r($balances); 16 | 17 | // Get all bid/ask prices 18 | $bookPrices = $api->bookPrices(); 19 | print_r($bookPrices); 20 | echo "BTC owned: ".$balances['BTC']['available']."\n"; 21 | echo "ETH owned: ".$balances['ETH']['available']."\n"; 22 | echo "Estimated Value: ".$api->btc_value." BTC\n"; 23 | 24 | // Place a LIMIT order 25 | //$quantity = 1; 26 | //$price = 0.0005; 27 | //$order = $api->buy("BNBBTC", $quantity, $price); 28 | 29 | // Place a MARKET order 30 | //$quantity = 1; 31 | //$order = $api->buy("BNBBTC", $quantity, 0, "MARKET"); 32 | 33 | // Place a STOP LOSS order 34 | // When the stop is reached, a stop order becomes a market order 35 | //$quantity = 1; 36 | //$price = 0.5; // Try to sell it for 0.5 btc 37 | //$stopPrice = 0.4; // Sell immediately if price goes below 0.4 btc 38 | //$order = $api->sell("BNBBTC", $quantity, $price, "LIMIT", ["stopPrice"=>$stopPrice]); 39 | //print_r($order); 40 | 41 | // Place an ICEBERG order 42 | // Iceberg orders are intended to conceal the true order quantity. 43 | //$quantity = 1; 44 | //$price = 0.5; 45 | //$icebergQty = 10; 46 | //$order = $api->sell("BNBBTC", $quantity, $price, "LIMIT", ["icebergQty"=>$icebergQty]); 47 | //print_r($order); 48 | 49 | // Get Market Depth 50 | //$depth = $api->depth("ETHBTC"); 51 | //print_r($depth); 52 | 53 | // Get Open Orders 54 | //$openorders = $api->openOrders("BNBBTC"); 55 | //print_r($openorders); 56 | 57 | // Get Order Status 58 | //$orderid = "7610385"; 59 | //$orderstatus = $api->orderStatus("ETHBTC", $orderid); 60 | //print_r($orderstatus); 61 | 62 | // Cancel an Order 63 | //$response = $api->cancel("ETHBTC", $orderid); 64 | //print_r($response); 65 | 66 | // Get Trade History 67 | //$history = $api->history("BNBBTC"); 68 | //print_r($history); 69 | 70 | // Get Kline/candlestick data for a symbol 71 | // Periods: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M 72 | $ticks = $api->candlesticks("BNBBTC", "5m"); 73 | print_r($ticks); 74 | 75 | // Aggregate Trades List 76 | //$trades = $api->aggTrades("BNBBTC"); 77 | //print_r($trades); 78 | 79 | // Trade Updates via WebSocket 80 | //$api->trades(["BNBBTC"], function($api, $symbol, $trades) { 81 | // echo "{$symbol} trades update".PHP_EOL; 82 | // print_r($trades); 83 | //}); 84 | 85 | 86 | // Get complete realtime chart data via WebSockets 87 | //$api->chart(["BNBBTC"], "15m", function($api, $symbol, $chart) { 88 | // echo "{$symbol} chart update\n"; 89 | // print_r($chart); 90 | //}); 91 | 92 | 93 | // Grab realtime updated depth cache via WebSockets 94 | $api->depthCache(["BNBBTC"], function($api, $symbol, $depth) { 95 | echo "{$symbol} depth cache update\n"; 96 | $limit = 11; // Show only the closest asks/bids 97 | $sorted = $api->sortDepth($symbol, $limit); 98 | $bid = $api->first($sorted['bids']); 99 | $ask = $api->first($sorted['asks']); 100 | echo $api->displayDepth($sorted); 101 | echo "ask: {$ask}\n"; 102 | echo "bid: {$bid}\n"; 103 | }); 104 | -------------------------------------------------------------------------------- /examples/agg_trades.php: -------------------------------------------------------------------------------- 1 | aggTrades("BNBBTC"); 11 | print_r($trades); 12 | -------------------------------------------------------------------------------- /examples/asset.php: -------------------------------------------------------------------------------- 1 | assetDetail(); 7 | print_r($asset); 8 | -------------------------------------------------------------------------------- /examples/balances.php: -------------------------------------------------------------------------------- 1 | balances(); 11 | print_r($balances); 12 | -------------------------------------------------------------------------------- /examples/book_prices.php: -------------------------------------------------------------------------------- 1 | bookPrices(); 11 | print_r($bookPrices); 12 | -------------------------------------------------------------------------------- /examples/candles.php: -------------------------------------------------------------------------------- 1 | candlesticks("EOSBTC", "1m"); 12 | print_r($ticks); 13 | //$ticks = $api->candlesticks("BNBBTC", "15m"); 14 | //print_r($ticks); 15 | //$ticks = $api->candlesticks("BNBBTC", "8h"); 16 | //print_r($ticks); 17 | //$ticks = $api->candlesticks("BNBBTC", "2h"); 18 | //print_r($ticks); 19 | //$ticks = $api->candlesticks("BNBBTC", "1d"); 20 | //print_r($ticks); 21 | //$ticks = $api->candlesticks("BNBBTC", "30m"); 22 | //print_r($ticks); 23 | //$ticks = $api->candlesticks("BNBBTC", "1M"); 24 | //print_r($ticks); 25 | -------------------------------------------------------------------------------- /examples/constructor.php: -------------------------------------------------------------------------------- 1 | marketBuy( "BNBBTC", 1 ); 10 | print_r( $result ) . "\n"; 11 | 12 | $api_key = "z5RQZ9n8JcS3HLDQmPpfLQIGGQN6TTs5pCP5CTnn4nYk2ImFcew49v4ZrmP3MGl5"; 13 | $api_secret = "intentionally wrong"; 14 | 15 | $api = new Binance\API($api_key, $api_secret); 16 | $result = $api->marketBuy( "BNBBTC", 1 ); 17 | print_r( $result ) . "\n"; 18 | 19 | 20 | $api_key = "YDjDADdXLCkY1BnjFxKVvBzheIyFjtafSU4yyadffiBXdezyViMi0ngiVBawwd3x"; 21 | $api_secret = "CtWl7kkYB4eKePyosmuGbJH8FBH4ArTB2qOIedHcOYfzALDG2eD46mWVGsf7lrHJ"; // trading disabled 22 | 23 | $api = new Binance\API($api_key, $api_secret); 24 | $result = $api->marketBuy( "BNBBTC", 1 ); 25 | print_r( $result ) . "\n"; 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /examples/depth.php: -------------------------------------------------------------------------------- 1 | depth("ETHBTC"); 11 | print_r($depth); 12 | -------------------------------------------------------------------------------- /examples/get_account_info.php: -------------------------------------------------------------------------------- 1 | account(); 10 | print_r($account); 11 | -------------------------------------------------------------------------------- /examples/get_exchange_info.php: -------------------------------------------------------------------------------- 1 | exchangeInfo(); 10 | print_r($exchangeInfo); 11 | -------------------------------------------------------------------------------- /examples/get_prices.php: -------------------------------------------------------------------------------- 1 | prices(); 11 | print_r($tickers); // List prices of all symbols 12 | 13 | // Get latest price of a symbol 14 | $price = $api->price('BNBBTC'); 15 | echo "Price of BNB: {$price} BTC.\n"; 16 | -------------------------------------------------------------------------------- /examples/home_directory_config.php: -------------------------------------------------------------------------------- 1 | ~/.config/jaggedsoft/php-binance-api.json << EOF 8 | { 9 | "api-key": "", 10 | "api-secret": "" 11 | } 12 | */ 13 | 14 | $api = new Binance\API(); 15 | 16 | $tickers = $api->prices(); 17 | print_r($tickers); // List prices of all symbols 18 | -------------------------------------------------------------------------------- /examples/open_orders.php: -------------------------------------------------------------------------------- 1 | openOrders("BNBBTC"); 11 | print_r($openorders); 12 | -------------------------------------------------------------------------------- /examples/orders.php: -------------------------------------------------------------------------------- 1 | buy("BNBBTC", $quantity, $price); 13 | print_r($order); 14 | 15 | // Place a MARKET order 16 | $quantity = 1; 17 | $order = $api->buy("BNBBTC", $quantity, 0, "MARKET"); 18 | print_r($order); 19 | 20 | // Place a STOP LOSS order 21 | // When the stop is reached, a stop order becomes a market order 22 | $quantity = 1; 23 | $price = 0.5; // Try to sell it for 0.5 btc 24 | $stopPrice = 0.4; // Sell immediately if price goes below 0.4 btc 25 | $order = $api->sell("BNBBTC", $quantity, $price, "STOP_LOSS", ["stopPrice"=>$stopPrice]); 26 | print_r($order); 27 | 28 | // Place a take profit order 29 | // When the stop is reached, a stop order becomes a market order 30 | $quantity = 1; 31 | $price = 0.5; // Try to sell it for 0.5 btc 32 | $stopPrice = 0.4; // Sell immediately if price goes below 0.4 btc 33 | $order = $api->sell("TRXBTC", $quantity, $price, "TAKE_PROFIT", ["stopPrice"=>$stopPrice]); 34 | print_r($order); 35 | 36 | // Place an ICEBERG order 37 | // Iceberg orders are intended to conceal the true order quantity. 38 | $quantity = 20; 39 | $price = 0.5; 40 | $icebergQty = 10; 41 | $order = $api->sell("BNBBTC", $quantity, $price, "LIMIT", ["icebergQty"=>$icebergQty]); 42 | print_r($order); 43 | -------------------------------------------------------------------------------- /examples/orders_test.php: -------------------------------------------------------------------------------- 1 | buyTest("BNBBTC", $quantity, $price); 13 | print_r($order); 14 | 15 | // Place a MARKET order 16 | $quantity = 1; 17 | $order = $api->buyTest("BNBBTC", $quantity, 0, "MARKET"); 18 | print_r($order); 19 | 20 | // Place a STOP LOSS order 21 | // When the stop is reached, a stop order becomes a market order 22 | $quantity = 1; 23 | $price = 0.5; // Try to sell it for 0.5 btc 24 | $stopPrice = 0.4; // Sell immediately if price goes below 0.4 btc 25 | $order = $api->sellTest("BNBBTC", $quantity, $price, "STOP_LOSS", ["stopPrice"=>$stopPrice]); 26 | print_r($order); 27 | 28 | // Place a take profit order 29 | // When the stop is reached, a stop order becomes a market order 30 | $quantity = 1; 31 | $price = 0.5; // Try to sell it for 0.5 btc 32 | $stopPrice = 0.4; // Sell immediately if price goes below 0.4 btc 33 | $order = $api->sellTest("TRXBTC", $quantity, $price, "TAKE_PROFIT", ["stopPrice"=>$stopPrice]); 34 | print_r($order); 35 | 36 | // Place an ICEBERG order 37 | // Iceberg orders are intended to conceal the true order quantity. 38 | $quantity = 20; 39 | $price = 0.5; 40 | $icebergQty = 10; 41 | $order = $api->sellTest("BNBBTC", $quantity, $price, "LIMIT", ["icebergQty"=>$icebergQty]); 42 | print_r($order); 43 | -------------------------------------------------------------------------------- /examples/orders_testnet.php: -------------------------------------------------------------------------------- 1 | ","", true); 8 | 9 | // Place a LIMIT order using the testnet 10 | $quantity = 1000; 11 | $price = 0.0005; 12 | $order = $api->buy("BNBBTC", $quantity, $price); 13 | print_r($order); 14 | 15 | -------------------------------------------------------------------------------- /examples/prevday.php: -------------------------------------------------------------------------------- 1 | prevDay("BNBBTC"); 10 | print_r($prevDay); 11 | echo "BNB price change since yesterday: ".$prevDay['priceChangePercent']."%".PHP_EOL; 12 | 13 | // Getting 24hr ticker price change statistics for all symbols 14 | $prevDay = $api->prevDay(); 15 | print_r($prevDay); -------------------------------------------------------------------------------- /examples/proxy_config.php: -------------------------------------------------------------------------------- 1 | 'http', 7 | 'address' => '192.168.1.1', 8 | 'port' => '8080', 9 | 'user' => 'dude', 10 | 'pass' => 'd00d' 11 | ]; 12 | 13 | // @see home_directory_config.php 14 | // use config from ~/.confg/jaggedsoft/php-binance-api.json 15 | $api = new Binance\API("","",["useServerTime"=>false],$proxyConf); 16 | 17 | $tickers = $api->prices(); 18 | print_r($tickers); // List prices of all symbols 19 | 20 | // Get balances for all of your positions, including estimated BTC value 21 | $balances = $api->balances($tickers); 22 | print_r($balances); 23 | echo "BTC owned: ".$balances['BTC']['available'].PHP_EOL; 24 | echo "ETH owned: ".$balances['ETH']['available'].PHP_EOL; 25 | echo "Estimated Value: ".$api->btc_value." BTC".PHP_EOL; 26 | 27 | // Getting 24hr ticker price change statistics for a symbol 28 | $prevDay = $api->prevDay("BNBBTC"); 29 | print_r($prevDay); 30 | echo "BNB price change since yesterday: ".$prevDay['priceChangePercent']."%".PHP_EOL; 31 | -------------------------------------------------------------------------------- /examples/ratelimiter.php: -------------------------------------------------------------------------------- 1 | price("BNBBTC"); 12 | echo "Price of BNB: {$price} BTC.\n"; 13 | 14 | while(true) 15 | { 16 | $api->openOrders("BNBBTC"); 17 | } -------------------------------------------------------------------------------- /examples/report.php: -------------------------------------------------------------------------------- 1 | report(); 7 | -------------------------------------------------------------------------------- /examples/single/binance-api-single.php: -------------------------------------------------------------------------------- 1 | api_key = $api_key; 11 | $this->api_secret = $api_secret; 12 | } 13 | public function ping() { 14 | return $this->request("v1/ping"); 15 | } 16 | public function time() { 17 | return $this->request("v1/time"); 18 | } 19 | public function exchangeInfo() { 20 | return $this->request("v1/exchangeInfo"); 21 | } 22 | public function buy_test($symbol, $quantity, $price, $type = "LIMIT", $flags = []) { 23 | return $this->order_test("BUY", $symbol, $quantity, $price, $type, $flags); 24 | } 25 | public function sell_test($symbol, $quantity, $price, $type = "LIMIT", $flags = []) { 26 | return $this->order_test("SELL", $symbol, $quantity, $price, $type, $flags); 27 | } 28 | public function buy($symbol, $quantity, $price, $type = "LIMIT", $flags = []) { 29 | return $this->order("BUY", $symbol, $quantity, $price, $type, $flags); 30 | } 31 | public function sell($symbol, $quantity, $price, $type = "LIMIT", $flags = []) { 32 | return $this->order("SELL", $symbol, $quantity, $price, $type, $flags); 33 | } 34 | public function cancel($symbol, $orderid) { 35 | return $this->signedRequest("v3/order",["symbol"=>$symbol, "orderId"=>$orderid], "DELETE"); 36 | } 37 | public function orderStatus($symbol, $orderid) { 38 | return $this->signedRequest("v3/order",["symbol"=>$symbol, "orderId"=>$orderid]); 39 | } 40 | public function openOrders($symbol) { 41 | return $this->signedRequest("v3/openOrders",["symbol"=>$symbol]); 42 | } 43 | public function orders($symbol, $limit = 500) { 44 | return $this->signedRequest("v3/allOrders",["symbol"=>$symbol, "limit"=>$limit]); 45 | } 46 | public function trades($symbol) { 47 | return $this->signedRequest("v3/myTrades",["symbol"=>$symbol]); 48 | } 49 | public function prices() { 50 | return $this->priceData($this->request("v1/ticker/allPrices")); 51 | } 52 | public function bookPrices() { 53 | return $this->bookPriceData($this->request("v1/ticker/allBookTickers")); 54 | } 55 | public function account() { 56 | return $this->signedRequest("v3/account"); 57 | } 58 | public function depth($symbol) { 59 | return $this->request("v1/depth",["symbol"=>$symbol]); 60 | } 61 | public function balances($priceData = false) { 62 | return $this->balanceData($this->signedRequest("v3/account"),$priceData); 63 | } 64 | public function prevDay($symbol) { 65 | return $this->request("v1/ticker/24hr", ["symbol"=>$symbol]); 66 | } 67 | private function request($url, $params = [], $method = "GET") { 68 | $opt = [ 69 | "http" => [ 70 | "method" => $method, 71 | "header" => "User-Agent: Mozilla/4.0 (compatible; PHP Binance API)\r\n" 72 | ] 73 | ]; 74 | $context = stream_context_create($opt); 75 | $query = http_build_query($params, '', '&'); 76 | return json_decode(file_get_contents($this->base.$url.'?'.$query, false, $context), true); 77 | } 78 | private function signedRequest($url, $params = [], $method = "GET") { 79 | $params['timestamp'] = number_format(microtime(true)*1000,0,'.',''); 80 | $query = http_build_query($params, '', '&'); 81 | $signature = hash_hmac('sha256', $query, $this->api_secret); 82 | $opt = [ 83 | "http" => [ 84 | "method" => $method, 85 | "ignore_errors" => true, 86 | "header" => "User-Agent: Mozilla/4.0 (compatible; PHP Binance API)\r\nX-MBX-APIKEY: {$this->api_key}\r\nContent-type: application/x-www-form-urlencoded\r\n" 87 | ] 88 | ]; 89 | if ( $method == 'GET' ) { 90 | // parameters encoded as query string in URL 91 | $endpoint = "{$this->base}{$url}?{$query}&signature={$signature}"; 92 | } else { 93 | // parameters encoded as POST data (in $context) 94 | $endpoint = "{$this->base}{$url}"; 95 | $postdata = "{$query}&signature={$signature}"; 96 | $opt['http']['content'] = $postdata; 97 | } 98 | $context = stream_context_create($opt); 99 | return json_decode(file_get_contents($endpoint, false, $context), true); 100 | } 101 | private function order_test($side, $symbol, $quantity, $price, $type = "LIMIT", $flags = []) { 102 | $opt = [ 103 | "symbol" => $symbol, 104 | "side" => $side, 105 | "type" => $type, 106 | "quantity" => $quantity, 107 | "recvWindow" => 60000 108 | ]; 109 | if ( $type == "LIMIT" ) { 110 | $opt["price"] = $price; 111 | $opt["timeInForce"] = "GTC"; 112 | } 113 | // allow additional options passed through $flags 114 | if ( isset($flags['recvWindow']) ) $opt['recvWindow'] = $flags['recvWindow']; 115 | if ( isset($flags['timeInForce']) ) $opt['timeInForce'] = $flags['timeInForce']; 116 | if ( isset($flags['stopPrice']) ) $opt['stopPrice'] = $flags['stopPrice']; 117 | if ( isset($flags['icebergQty']) ) $opt['icebergQty'] = $flags['icebergQty']; 118 | return $this->signedRequest("v3/order/test", $opt, "POST"); 119 | } 120 | private function order($side, $symbol, $quantity, $price, $type = "LIMIT", $flags = []) { 121 | $opt = [ 122 | "symbol" => $symbol, 123 | "side" => $side, 124 | "type" => $type, 125 | "quantity" => $quantity, 126 | "recvWindow" => 60000 127 | ]; 128 | if ( $type == "LIMIT" ) { 129 | $opt["price"] = $price; 130 | $opt["timeInForce"] = "GTC"; 131 | } 132 | // allow additional options passed through $flags 133 | if ( isset($flags['recvWindow']) ) $opt["recvWindow"] = $flags['recvWindow']; 134 | if ( isset($flags['timeInForce']) ) $opt["timeInForce"] = $flags['timeInForce']; 135 | if ( isset($flags['stopPrice']) ) $opt['stopPrice'] = $flags['stopPrice']; 136 | if ( isset($flags['icebergQty']) ) $opt['icebergQty'] = $flags['icebergQty']; 137 | return $this->signedRequest("v3/order", $opt, "POST"); 138 | } 139 | //1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M 140 | public function candlesticks($symbol, $interval = "5m") { 141 | return $this->request("v1/klines",["symbol"=>$symbol, "interval"=>$interval]); 142 | } 143 | private function balanceData($array, $priceData = false) { 144 | if ( $priceData ) $btc_value = 0.00; 145 | $balances = []; 146 | foreach ( $array['balances'] as $obj ) { 147 | $asset = $obj['asset']; 148 | $balances[$asset] = ["available"=>$obj['free'], "onOrder"=>$obj['locked'], "btcValue"=>0.00000000]; 149 | if ( $priceData ) { 150 | if ( $obj['free'] < 0.00000001 ) continue; 151 | if ( $asset == 'BTC' ) { 152 | $balances[$asset]['btcValue'] = $obj['free']; 153 | $btc_value+= $obj['free']; 154 | continue; 155 | } 156 | $btcValue = number_format($obj['free'] * $priceData[$asset.'BTC'],8,'.',''); 157 | $balances[$asset]['btcValue'] = $btcValue; 158 | $btc_value+= $btcValue; 159 | } 160 | } 161 | if ( $priceData ) { 162 | uasort($balances, function($a, $b) { return $a['btcValue'] < $b['btcValue']; }); 163 | $this->btc_value = $btc_value; 164 | } 165 | return $balances; 166 | } 167 | private function bookPriceData($array) { 168 | $bookprices = []; 169 | foreach ( $array as $obj ) { 170 | $bookprices[$obj['symbol']] = [ 171 | "bid"=>$obj['bidPrice'], 172 | "bids"=>$obj['bidQty'], 173 | "ask"=>$obj['askPrice'], 174 | "asks"=>$obj['askQty'] 175 | ]; 176 | } 177 | return $bookprices; 178 | } 179 | private function priceData($array) { 180 | $prices = []; 181 | foreach ( $array as $obj ) { 182 | $prices[$obj['symbol']] = $obj['price']; 183 | } 184 | return $prices; 185 | } 186 | } 187 | 188 | // https://www.binance.com/restapipub.html 189 | -------------------------------------------------------------------------------- /examples/single/single.php: -------------------------------------------------------------------------------- 1 | ",""); 5 | 6 | // Get latest price of all symbols 7 | $tickers = $api->prices(); 8 | print_r($tickers); // List prices of all symbols 9 | 10 | // Get latest price of a symbol 11 | $price = $api->price("BNBBTC"); 12 | echo "Price of BNB: {$price} BTC.".PHP_EOL; 13 | 14 | // Get balances for all of your positions, including estimated BTC value 15 | $balances = $api->balances($tickers); 16 | print_r($balances); 17 | echo "BTC owned: ".$balances['BTC']['available'].PHP_EOL; 18 | echo "ETH owned: ".$balances['ETH']['available'].PHP_EOL; 19 | echo "Estimated Value: ".$api->btc_value." BTC".PHP_EOL; 20 | 21 | // Getting 24hr ticker price change statistics for a symbol 22 | $prevDay = $api->prevDay("BNBBTC"); 23 | print_r($prevDay); 24 | echo "BNB price change since yesterday: ".$prevDay['priceChangePercent']."%".PHP_EOL; 25 | -------------------------------------------------------------------------------- /examples/specify_config_file.php: -------------------------------------------------------------------------------- 1 | account(); 10 | print_r($account); 11 | -------------------------------------------------------------------------------- /examples/trade_history.php: -------------------------------------------------------------------------------- 1 | history("TRXBTC"); 11 | print_r($history); 12 | -------------------------------------------------------------------------------- /examples/web_socket_chart.php: -------------------------------------------------------------------------------- 1 | chart(["BNBBTC"], "15m", function($api, $symbol, $chart) { 12 | echo "{$symbol} chart update\n"; 13 | print_r($chart); 14 | $endpoint = strtolower( $symbol ) . '@kline_' . "15m"; 15 | $api->terminate( $endpoint ); 16 | }); 17 | -------------------------------------------------------------------------------- /examples/web_socket_depth.php: -------------------------------------------------------------------------------- 1 | depthCache(["BNBBTC"], function($api, $symbol, $depth) { 11 | echo "{$symbol} depth cache update\n"; 12 | $limit = 11; // Show only the closest asks/bids 13 | $sorted = $api->sortDepth($symbol, $limit); 14 | $bid = $api->first($sorted['bids']); 15 | $ask = $api->first($sorted['asks']); 16 | echo $api->displayDepth($sorted); 17 | echo "ask: {$ask}\n"; 18 | echo "bid: {$bid}\n"; 19 | $endpoint = strtolower( $symbol ) . '@depthCache'; 20 | $api->terminate( $endpoint ); 21 | }); -------------------------------------------------------------------------------- /examples/web_socket_kline.php: -------------------------------------------------------------------------------- 1 | kline(["BTCUSDT", "EOSBTC"], "5m", function($api, $symbol, $chart) { 13 | var_dump( $chart ); 14 | //echo "{$symbol} ({$interval}) candlestick update\n"; 15 | $interval = $chart->i; 16 | $tick = $chart->t; 17 | $open = $chart->o; 18 | $high = $chart->h; 19 | $low = $chart->l; 20 | $close = $chart->c; 21 | $volume = $chart->q; // +trades buyVolume assetVolume makerVolume 22 | echo "{$symbol} price: {$close}\t volume: {$volume}\n"; 23 | 24 | $endpoint = strtolower( $symbol ) . '@kline_' . "5m"; 25 | $api->terminate( $endpoint ); 26 | }); -------------------------------------------------------------------------------- /examples/web_socket_miniticker.php: -------------------------------------------------------------------------------- 1 | miniTicker( function ( $api, $ticker ) use ( &$count ) { 14 | print_r( $ticker ); 15 | $count++; 16 | print $count . "\n"; 17 | if($count > 2) { 18 | $endpoint = '@miniticker'; 19 | $api->terminate( $endpoint ); 20 | } 21 | } ); -------------------------------------------------------------------------------- /examples/web_socket_trades.php: -------------------------------------------------------------------------------- 1 | trades(["BNBBTC"], function($api, $symbol, $trades) { 13 | echo "{$symbol} trades update".PHP_EOL; 14 | print_r($trades); 15 | $endpoint = strtolower( $symbol ) . '@trades'; 16 | $api->terminate( $endpoint ); 17 | }); 18 | -------------------------------------------------------------------------------- /examples/web_socket_userdata.php: -------------------------------------------------------------------------------- 1 | userData($balance_update, $order_update); -------------------------------------------------------------------------------- /php-binance-api-rate-limiter.php: -------------------------------------------------------------------------------- 1 | api = $api; 46 | 47 | $this->weights = array( 48 | 'account' => 5, 49 | 'addToTransfered' => 0, 50 | 'aggTrades' => 1, 51 | 'balances' => 1, 52 | 'bookPrices' => 1, 53 | 'buy' => 1, 54 | 'buyTest' => 1, 55 | 'cancel' => 1, 56 | 'candlesticks' => 1, 57 | 'chart' => 0, 58 | 'cumulative' => 0, 59 | 'depositAddress' => 1, 60 | 'depositHistory' => 1, 61 | 'assetDetail' => 1, 62 | 'depth' => 1, 63 | 'depthCache' => 1, 64 | 'displayDepth' => 1, 65 | 'exchangeInfo' => 1, 66 | 'first' => 0, 67 | 'getProxyUriString' => 0, 68 | 'getRequestCount' => 0, 69 | 'getTransfered' => 0, 70 | 'highstock' => 1, 71 | 'history' => 5, 72 | 'keepAlive' => 0, 73 | 'kline' => 1, 74 | 'last' => 0, 75 | 'marketBuy' => 1, 76 | 'marketBuyTest' => 1, 77 | 'marketSell' => 1, 78 | 'marketSellTest' => 1, 79 | 'miniTicker' => 1, 80 | 'openOrders' => 2, 81 | 'order' => 1, 82 | 'orders' => 5, 83 | 'orderStatus' => 1, 84 | 'prevDay' => 2, 85 | 'prices' => 1, 86 | 'report' => 0, 87 | 'sell' => 1, 88 | 'sellTest' => 1, 89 | 'setProxy' => 0, 90 | 'sortDepth' => 1, 91 | 'terminate' => 0, 92 | 'ticker' => 1, 93 | 'time' => 1, 94 | 'trades' => 5, 95 | 'userData' => 1, 96 | 'useServerTime' => 1, 97 | 'withdraw' => 1, 98 | 'withdrawFee' => 1, 99 | 'withdrawHistory' => 1, 100 | ); 101 | 102 | $this->ordersfunctions = array( 103 | 'buy', 104 | 'buyTest', 105 | 'cancel', 106 | 'history', 107 | 'marketBuy', 108 | 'marketBuyTest', 109 | 'marketSell', 110 | 'marketSellTest', 111 | 'openOrders', 112 | 'order', 113 | 'orders', 114 | 'orderStatus', 115 | 'sell', 116 | 'sellTest', 117 | 'trades', 118 | ); 119 | 120 | $this->init(); 121 | } 122 | 123 | private function init() 124 | { 125 | $exchangeLimits = $this->api->exchangeInfo()['rateLimits']; 126 | 127 | if (is_array($exchangeLimits) === false) { 128 | print "Problem getting exchange limits\n"; 129 | return; 130 | } 131 | 132 | foreach ($exchangeLimits as $exchangeLimit) { 133 | switch ($exchangeLimit['rateLimitType']) { 134 | case "REQUESTS": 135 | $this->exchangeRequestsRateLimit = round($exchangeLimit['limit'] * 0.95); 136 | break; 137 | case "ORDERS": 138 | if ($exchangeLimit['interval'] === "SECOND") { 139 | $this->exchangeOrdersRateLimit = round($exchangeLimit['limit'] * 0.9); 140 | } 141 | if ($exchangeLimit['interval'] === "DAY") { 142 | $this->exchangeOrdersDailyLimit = round($exchangeLimit['limit'] * 0.98); 143 | } 144 | break; 145 | } 146 | } 147 | } 148 | 149 | /** 150 | * magic get for private and protected members 151 | * 152 | * @param $file string the name of the property to return 153 | * @return null 154 | */ 155 | public function __get(string $member) 156 | { 157 | return $this->api->$member; 158 | } 159 | 160 | /** 161 | * magic set for private and protected members 162 | * 163 | * @param $member string the name of the member property 164 | * @param $value the value of the member property 165 | */ 166 | public function __set(string $member, $value) 167 | { 168 | $this->api->$member = $value; 169 | } 170 | 171 | private function requestsPerMinute() 172 | { 173 | // requests per minute restrictions 174 | if (count($this->requestsQueue) === 0) { 175 | return; 176 | } 177 | 178 | while (count($this->requestsQueue) > $this->exchangeOrdersDailyLimit) { 179 | $oldest = isset($this->requestsQueue[0]) ? $this->requestsQueue[0] : time(); 180 | while ($oldest < time() - 60) { 181 | array_shift($this->requestsQueue); 182 | $oldest = isset($this->requestsQueue[0]) ? $this->requestsQueue[0] : time(); 183 | } 184 | print "Rate limiting in effect for requests " . PHP_EOL; 185 | sleep(1); 186 | } 187 | } 188 | 189 | private function ordersPerSecond() 190 | { 191 | // orders per second restrictions 192 | if (count($this->ordersQueue) === 0) { 193 | return; 194 | } 195 | 196 | while (count($this->ordersQueue) > $this->exchangeOrdersRateLimit) { 197 | $oldest = isset($this->ordersQueue[0]) ? $this->ordersQueue[0] : time(); 198 | while ($oldest < time() - 1) { 199 | array_shift($this->ordersQueue); 200 | $oldest = isset($this->ordersQueue[0]) ? $this->ordersQueue[0] : time(); 201 | } 202 | print "Rate limiting in effect for orders " . PHP_EOL; 203 | sleep(1); 204 | } 205 | } 206 | 207 | private function ordersPerDay() 208 | { 209 | // orders per day restrictions 210 | if (count($this->ordersDayQueue) === 0) { 211 | return; 212 | } 213 | 214 | $yesterday = time() - (24 * 60 * 60); 215 | while (count($this->ordersDayQueue) > round($this->exchangeOrdersDailyLimit * 0.8)) { 216 | $oldest = isset($this->ordersDayQueue[0]) ? $this->ordersDayQueue[0] : time(); 217 | while ($oldest < $yesterday) { 218 | array_shift($this->ordersDayQueue); 219 | $oldest = isset($this->ordersDayQueue[0]) ? $this->ordersDayQueue[0] : time(); 220 | } 221 | print "Rate limiting in effect for daily order limits " . PHP_EOL; 222 | 223 | $remainingRequests = round($this->exchangeOrdersDailyLimit * 0.2); 224 | $remainingSeconds = $this->ordersDayQueue[0] - $yesterday; 225 | 226 | $sleepTime = ($remainingSeconds > $remainingRequests) ? round($remainingSeconds / $remainingRequests) : 1; 227 | sleep($sleepTime); 228 | } 229 | } 230 | 231 | /** 232 | * magic call to redirect call to the API, capturing and monitoring the weight limit 233 | * 234 | * @param $name the function to call 235 | * @param $arguments the paramters to the function 236 | */ 237 | public function __call(string $name, array $arguments) 238 | { 239 | $weight = $this->weights[$name] ?? false; 240 | 241 | if ($weight && $weight > 0) { 242 | $this->requestsPerMinute(); 243 | if (in_array($name, $this->ordersfunctions) === true) { 244 | $this->ordersPerSecond(); 245 | $this->ordersPerDay(); 246 | } 247 | 248 | $c_time = time(); 249 | 250 | for ($w = 0; $w < $weight; $w++) { 251 | $this->requestsQueue[] = $c_time; 252 | } 253 | 254 | if (in_array($name, $this->ordersfunctions) === true) { 255 | for ($w = 0; $w < $weight; $w++) { 256 | $this->ordersQueue[] = $c_time; 257 | $this->ordersDayQueue[] = $c_time; 258 | } 259 | } 260 | } 261 | 262 | return call_user_func_array(array(&$this->api, $name), $arguments); 263 | } 264 | } 265 | -------------------------------------------------------------------------------- /tests/BinanceLiveTests.php: -------------------------------------------------------------------------------- 1 | spotBinance = new API('X4BHNSimXOK6RKs2FcKqExquJtHjMxz5hWqF0BBeVnfa5bKFMk7X0wtkfEz0cPrJ', 'x8gLihunpNq0d46F2q0TWJmeCDahX5LMXSlv3lSFNbMI3rujSOpTDKdhbcmPSf2i'); 17 | $this->spotBinance->useTestnet = true; 18 | 19 | $this->futuresBinance = new API('227719da8d8499e8d3461587d19f259c0b39c2b462a77c9b748a6119abd74401', 'b14b935f9cfacc5dec829008733c40da0588051f29a44625c34967b45c11d73c'); 20 | $this->futuresBinance->useTestnet = true; 21 | } 22 | 23 | // Default values for the tests 24 | private $symbol = 'ETHUSDT'; 25 | private $quantity = '1.23400000'; 26 | private $price = '1000.00000000'; 27 | private $stopprice = '1100.00000000'; 28 | private $stoplimitprice = '900.00000000'; 29 | private $type = 'LIMIT'; 30 | private $limit = 2; 31 | private $symbols = ['ETHUSDT','BTCUSDT']; 32 | private $asset = 'USDT'; 33 | private $assets = ['IOST','AAVE','CHZ']; 34 | private $address = '0x1234567890abcdef1234567890abcdef12345678'; 35 | private $amount = 10.1; 36 | private $addressTag = '123456'; 37 | private $addressName = 'MyAddress'; 38 | private $transactionFeeFlag = true; 39 | private $network = 'TESTNetwork'; 40 | private $fromSymbol = 'USDT'; 41 | private $toSymbol = 'BNB'; 42 | private $recvWindow = 1000; 43 | private $side = 'BUY'; 44 | private $test = false; 45 | private $interval = '15m'; 46 | private $nbrDays = 6; 47 | private $baseAsset = 'ETH'; 48 | private $quoteAsset = 'USDT'; 49 | private $quoteQty = 10.3; 50 | private $fromId = 1; 51 | private $contractType = 'CURRENT_QUARTER'; 52 | private $period = '15m'; 53 | private $origClientOrderId = 'test client order id'; 54 | private $orderIdList = ['123456', '654321']; 55 | private $origClientOrderIdList = ['test client order id 1', 'test client order id 2']; 56 | private $countdownTime = 100; 57 | private $autoCloseType = 'LIQUIDATION'; 58 | private $marginType = 'CROSSED'; 59 | private $dualSidePosition = true; 60 | private $leverage = 10; 61 | private $multiAssetsMarginMode = true; 62 | private $positionSide = 'SHORT'; 63 | private $incomeType = 'COMMISSION_REBATE'; 64 | private $page = 3; 65 | private $downloadId = 'testDownloadId'; 66 | private $fromAsset = 'USDT'; 67 | private $toAsset = 'BNB'; 68 | private $fromAmount = '100'; 69 | private $validTime = '10s'; 70 | private $quoteId = 'testQuoteId'; 71 | private $timeInForce = 'GTC'; 72 | 73 | private $SPOT_ORDER_PREFIX = "x-HNA2TXFJ"; 74 | private $CONTRACT_ORDER_PREFIX = "x-Cb7ytekJ"; 75 | 76 | public function testPricesSpot() 77 | { 78 | $res = $this->spotBinance->prices(); 79 | $this->assertIsArray($res); 80 | $this->assertArrayHasKey('BTCUSDT', $res); 81 | $this->assertIsString($res['BTCUSDT']); 82 | } 83 | 84 | public function testBalanceSpot() 85 | { 86 | $res = $this->spotBinance->balances(); 87 | $this->assertIsArray($res); 88 | // $this->assertArrayHasKey('USDT', $res); 89 | // $this->assertIsString($res['USDT']['free']); 90 | } 91 | 92 | public function testBalanceFutures() 93 | { 94 | $res = $this->futuresBinance->futuresAccount(); 95 | $this->assertIsArray($res); 96 | $assets = $res['assets']; 97 | $first = $assets[0]; 98 | $this->assertArrayHasKey('asset', $first); 99 | $this->assertArrayHasKey('walletBalance', $first); 100 | } 101 | 102 | public function testBuyTestSpot() 103 | { 104 | $res = $this->spotBinance->buyTest($this->symbol, $this->quantity, $this->price, $this->type); 105 | $this->assertIsArray($res); 106 | } 107 | 108 | public function testSellTestSpot() 109 | { 110 | $res = $this->spotBinance->sellTest($this->symbol, $this->quantity, $this->price, $this->type); 111 | $this->assertIsArray($res); 112 | } 113 | 114 | public function testMarketQuoteBuyTestSpot() 115 | { 116 | $res = $this->spotBinance->marketQuoteBuyTest($this->symbol, 10); 117 | $this->assertIsArray($res); 118 | } 119 | 120 | public function testMarketBuyTestSpot() 121 | { 122 | $res = $this->spotBinance->marketBuyTest($this->symbol, $this->quantity); 123 | $this->assertIsArray($res); 124 | } 125 | 126 | public function testMarketQuoteSellTestSpot() 127 | { 128 | $res = $this->spotBinance->marketQuoteSellTest($this->symbol, 10); 129 | $this->assertIsArray($res); 130 | } 131 | 132 | public function testUseServerTimeSpot() 133 | { 134 | $this->spotBinance->useServerTime(); 135 | $offset = $this->spotBinance->info['timeOffset']; 136 | $this->assertTrue(0 !== $offset); 137 | } 138 | 139 | public function testTimeSpot() 140 | { 141 | $res = $this->spotBinance->time(); 142 | $this->assertIsArray($res); 143 | $this->assertArrayHasKey('serverTime', $res); 144 | $this->assertIsInt($res['serverTime']); 145 | } 146 | 147 | public function testExchangeInfoSpot() 148 | { 149 | $res = $this->spotBinance->exchangeInfo($this->symbols); 150 | $this->assertIsArray($res); 151 | $this->assertArrayHasKey('timezone', $res); 152 | $this->assertArrayHasKey('serverTime', $res); 153 | $this->assertIsInt($res['serverTime']); 154 | $this->assertArrayHasKey('rateLimits', $res); 155 | $this->assertIsArray($res['rateLimits']); 156 | $this->assertArrayHasKey('exchangeFilters', $res); 157 | $this->assertIsArray($res['exchangeFilters']); 158 | $this->assertArrayHasKey('symbols', $res); 159 | $this->assertIsArray($res['symbols']); 160 | 161 | // Check if the symbols are present in the exchange info 162 | $symbol1 = $this->symbols[0]; 163 | $symbol2 = $this->symbols[1]; 164 | $symbolsInfo = $this->spotBinance->exchangeInfo['symbols']; 165 | $this->assertArrayHasKey($symbol1, $symbolsInfo); 166 | $this->assertArrayHasKey($symbol2, $symbolsInfo); 167 | $this->assertIsArray($symbolsInfo[$symbol1]); 168 | $this->assertIsArray($symbolsInfo[$symbol2]); 169 | } 170 | 171 | public function testAccountSpot() 172 | { 173 | $res = $this->spotBinance->account(); 174 | $this->assertIsArray($res); 175 | $this->assertArrayHasKey('makerCommission', $res); 176 | $this->assertArrayHasKey('takerCommission', $res); 177 | $this->assertArrayHasKey('buyerCommission', $res); 178 | $this->assertArrayHasKey('sellerCommission', $res); 179 | $this->assertArrayHasKey('commissionRates', $res); 180 | $this->assertIsArray($res['commissionRates']); 181 | $this->assertArrayHasKey('canTrade', $res); 182 | $this->assertArrayHasKey('canWithdraw', $res); 183 | $this->assertArrayHasKey('canDeposit', $res); 184 | $this->assertArrayHasKey('brokered', $res); 185 | $this->assertArrayHasKey('requireSelfTradePrevention', $res); 186 | $this->assertArrayHasKey('preventSor', $res); 187 | $this->assertArrayHasKey('updateTime', $res); 188 | $this->assertArrayHasKey('accountType', $res); 189 | $this->assertEquals('SPOT', $res['accountType']); 190 | $this->assertArrayHasKey('balances', $res); 191 | $this->assertIsArray($res['balances']); 192 | } 193 | 194 | public function testPrevDaySpot() 195 | { 196 | $res = $this->spotBinance->prevDay($this->symbol); 197 | $this->assertIsArray($res); 198 | $this->assertEquals($this->symbol, $res['symbol']); 199 | $this->assertArrayHasKey('priceChange', $res); 200 | $this->assertIsNumeric($res['priceChange']); 201 | $this->assertArrayHasKey('priceChangePercent', $res); 202 | $this->assertIsNumeric($res['priceChangePercent']); 203 | $this->assertArrayHasKey('weightedAvgPrice', $res); 204 | $this->assertIsNumeric($res['weightedAvgPrice']); 205 | $this->assertArrayHasKey('prevClosePrice', $res); 206 | $this->assertIsNumeric($res['prevClosePrice']); 207 | $this->assertArrayHasKey('lastPrice', $res); 208 | $this->assertIsNumeric($res['lastPrice']); 209 | $this->assertArrayHasKey('lastQty', $res); 210 | $this->assertIsNumeric($res['lastQty']); 211 | $this->assertArrayHasKey('bidPrice', $res); 212 | $this->assertIsNumeric($res['bidPrice']); 213 | $this->assertArrayHasKey('bidQty', $res); 214 | $this->assertIsNumeric($res['bidQty']); 215 | $this->assertArrayHasKey('askPrice', $res); 216 | $this->assertIsNumeric($res['askPrice']); 217 | $this->assertArrayHasKey('askQty', $res); 218 | $this->assertIsNumeric($res['askQty']); 219 | $this->assertArrayHasKey('openPrice', $res); 220 | $this->assertIsNumeric($res['openPrice']); 221 | $this->assertArrayHasKey('highPrice', $res); 222 | $this->assertIsNumeric($res['highPrice']); 223 | $this->assertArrayHasKey('lowPrice', $res); 224 | $this->assertIsNumeric($res['lowPrice']); 225 | $this->assertArrayHasKey('volume', $res); 226 | $this->assertIsNumeric($res['volume']); 227 | $this->assertArrayHasKey('quoteVolume', $res); 228 | $this->assertIsNumeric($res['quoteVolume']); 229 | $this->assertArrayHasKey('openTime', $res); 230 | $this->assertIsInt($res['openTime']); 231 | $this->assertArrayHasKey('closeTime', $res); 232 | $this->assertIsInt($res['closeTime']); 233 | $this->assertArrayHasKey('firstId', $res); 234 | $this->assertIsInt($res['firstId']); 235 | $this->assertArrayHasKey('lastId', $res); 236 | $this->assertIsInt($res['lastId']); 237 | $this->assertArrayHasKey('count', $res); 238 | $this->assertIsInt($res['count']); 239 | } 240 | 241 | public function testTradingDaySpot() 242 | { 243 | $res = $this->spotBinance->tradingDay($this->symbol); 244 | $this->assertIsArray($res); 245 | $this->assertEquals($this->symbol, $res['symbol']); 246 | $this->assertArrayHasKey('priceChange', $res); 247 | $this->assertIsNumeric($res['priceChange']); 248 | $this->assertArrayHasKey('priceChangePercent', $res); 249 | $this->assertIsNumeric($res['priceChangePercent']); 250 | $this->assertArrayHasKey('weightedAvgPrice', $res); 251 | $this->assertIsNumeric($res['weightedAvgPrice']); 252 | $this->assertArrayHasKey('openPrice', $res); 253 | $this->assertIsNumeric($res['openPrice']); 254 | $this->assertArrayHasKey('highPrice', $res); 255 | $this->assertIsNumeric($res['highPrice']); 256 | $this->assertArrayHasKey('lowPrice', $res); 257 | $this->assertIsNumeric($res['lowPrice']); 258 | $this->assertArrayHasKey('volume', $res); 259 | $this->assertIsNumeric($res['volume']); 260 | $this->assertArrayHasKey('quoteVolume', $res); 261 | $this->assertIsNumeric($res['quoteVolume']); 262 | $this->assertArrayHasKey('openTime', $res); 263 | $this->assertIsInt($res['openTime']); 264 | $this->assertArrayHasKey('closeTime', $res); 265 | $this->assertIsInt($res['closeTime']); 266 | $this->assertArrayHasKey('firstId', $res); 267 | $this->assertIsInt($res['firstId']); 268 | $this->assertArrayHasKey('lastId', $res); 269 | $this->assertIsInt($res['lastId']); 270 | $this->assertArrayHasKey('count', $res); 271 | $this->assertIsInt($res['count']); 272 | } 273 | 274 | public function testRollingWindowPriceChangeSpot() 275 | { 276 | $res = $this->spotBinance->rollingWindowPriceChange($this->symbol, null, '3m'); 277 | $this->assertIsArray($res); 278 | $this->assertEquals($this->symbol, $res['symbol']); 279 | $this->assertArrayHasKey('priceChange', $res); 280 | $this->assertIsNumeric($res['priceChange']); 281 | $this->assertArrayHasKey('priceChangePercent', $res); 282 | $this->assertIsNumeric($res['priceChangePercent']); 283 | $this->assertArrayHasKey('weightedAvgPrice', $res); 284 | $this->assertIsNumeric($res['weightedAvgPrice']); 285 | $this->assertArrayHasKey('openPrice', $res); 286 | $this->assertIsNumeric($res['openPrice']); 287 | $this->assertArrayHasKey('highPrice', $res); 288 | $this->assertIsNumeric($res['highPrice']); 289 | $this->assertArrayHasKey('lowPrice', $res); 290 | $this->assertIsNumeric($res['lowPrice']); 291 | $this->assertArrayHasKey('volume', $res); 292 | $this->assertIsNumeric($res['volume']); 293 | $this->assertArrayHasKey('quoteVolume', $res); 294 | $this->assertIsNumeric($res['quoteVolume']); 295 | $this->assertArrayHasKey('openTime', $res); 296 | $this->assertIsInt($res['openTime']); 297 | $this->assertArrayHasKey('closeTime', $res); 298 | $this->assertIsInt($res['closeTime']); 299 | $this->assertArrayHasKey('firstId', $res); 300 | $this->assertIsInt($res['firstId']); 301 | $this->assertArrayHasKey('lastId', $res); 302 | $this->assertIsInt($res['lastId']); 303 | $this->assertArrayHasKey('count', $res); 304 | $this->assertIsInt($res['count']); 305 | } 306 | 307 | public function testAggTradesSpot() 308 | { 309 | $res = $this->spotBinance->aggTrades($this->symbol); 310 | $this->assertIsArray($res); 311 | $this->assertIsArray($res[0]); 312 | $trade = $res[0]; 313 | $this->assertArrayHasKey('price', $trade); 314 | $this->assertIsNumeric($trade['price']); 315 | $this->assertArrayHasKey('quantity', $trade); 316 | $this->assertIsNumeric($trade['quantity']); 317 | $this->assertArrayHasKey('timestamp', $trade); 318 | $this->assertIsInt($trade['timestamp']); 319 | $this->assertArrayHasKey('maker', $trade); 320 | $this->assertIsString($trade['maker']); 321 | } 322 | 323 | public function testHistoricalTradesSpot() 324 | { 325 | $res = $this->spotBinance->historicalTrades($this->symbol, $this->limit); 326 | $this->assertIsArray($res); 327 | $this->assertIsArray($res[0]); 328 | $this->assertArrayHasKey('id', $res[0]); 329 | $this->assertIsNumeric($res[0]['id']); 330 | $this->assertArrayHasKey('price', $res[0]); 331 | $this->assertIsNumeric($res[0]['price']); 332 | $this->assertArrayHasKey('qty', $res[0]); 333 | $this->assertIsNumeric($res[0]['qty']); 334 | $this->assertArrayHasKey('time', $res[0]); 335 | $this->assertIsNumeric($res[0]['time']); 336 | $this->assertArrayHasKey('isBuyerMaker', $res[0]); 337 | $this->assertIsBool($res[0]['isBuyerMaker']); 338 | $this->assertArrayHasKey('isBestMatch', $res[0]); 339 | $this->assertIsBool($res[0]['isBestMatch']); 340 | } 341 | 342 | public function testDepthSpot() 343 | { 344 | $res = $this->spotBinance->depth($this->symbol, $this->limit); 345 | $this->assertIsArray($res); 346 | 347 | $this->assertArrayHasKey('bids', $res); 348 | $this->assertIsArray($res['bids']); 349 | $this->assertArrayHasKey('asks', $res); 350 | $this->assertIsArray($res['asks']); 351 | } 352 | 353 | public function testCandlesticksSpot() 354 | { 355 | $res = $this->spotBinance->candlesticks($this->symbol, $this->interval, $this->limit); 356 | $this->assertIsArray($res); 357 | $firstKey = array_key_first($res); 358 | $this->assertIsNumeric($firstKey); 359 | $candle = $res[$firstKey]; 360 | $this->assertArrayHasKey('open', $candle); 361 | $this->assertIsNumeric($candle['open']); 362 | $this->assertArrayHasKey('high', $candle); 363 | $this->assertIsNumeric($candle['high']); 364 | $this->assertArrayHasKey('low', $candle); 365 | $this->assertIsNumeric($candle['low']); 366 | $this->assertArrayHasKey('close', $candle); 367 | $this->assertIsNumeric($candle['close']); 368 | $this->assertArrayHasKey('volume', $candle); 369 | $this->assertIsNumeric($candle['volume']); 370 | $this->assertArrayHasKey('openTime', $candle); 371 | $this->assertIsInt($candle['openTime']); 372 | $this->assertArrayHasKey('closeTime', $candle); 373 | $this->assertIsInt($candle['closeTime']); 374 | $this->assertArrayHasKey('assetVolume', $candle); 375 | $this->assertIsNumeric($candle['assetVolume']); 376 | $this->assertArrayHasKey('baseVolume', $candle); 377 | $this->assertIsNumeric($candle['baseVolume']); 378 | $this->assertArrayHasKey('trades', $candle); 379 | $this->assertIsInt($candle['trades']); 380 | $this->assertArrayHasKey('assetBuyVolume', $candle); 381 | $this->assertIsNumeric($candle['assetBuyVolume']); 382 | $this->assertArrayHasKey('takerBuyVolume', $candle); 383 | $this->assertIsNumeric($candle['takerBuyVolume']); 384 | } 385 | 386 | public function testUiCandlesticksSpot() 387 | { 388 | $res = $this->spotBinance->uiCandlesticks($this->symbol, $this->interval, $this->limit); 389 | $this->assertIsArray($res); 390 | $candle = $res[0]; 391 | $this->assertIsInt($candle[0]); // Kline open time 392 | $this->assertIsNumeric($candle[1]); // Open price 393 | $this->assertIsNumeric($candle[2]); // High price 394 | $this->assertIsNumeric($candle[3]); // Low price 395 | $this->assertIsNumeric($candle[4]); // Close price 396 | $this->assertIsNumeric($candle[5]); // Volume 397 | $this->assertIsInt($candle[6]); // Kline close time 398 | $this->assertIsNumeric($candle[7]); // Quote asset volume 399 | $this->assertIsInt($candle[8]); // Number of trades 400 | $this->assertIsNumeric($candle[9]); // Taker buy base asset volume 401 | $this->assertIsNumeric($candle[10]); // Taker buy quote asset volume 402 | } 403 | 404 | // could throw an error: https://github.com/ccxt/php-binance-api/actions/runs/14491775733/job/40649647274?pr=511 405 | // public function testSystemStatusSpot() 406 | // { 407 | // $this->spotBinance->useTestnet = false; // set to false for sapi request 408 | // $res = $this->spotBinance->systemStatus(); 409 | // $this->assertIsArray($res); 410 | // $this->assertArrayHasKey('api', $res); 411 | // $this->assertIsArray($res['api']); 412 | // $this->assertArrayHasKey('status', $res['api']); 413 | // $this->assertArrayHasKey('fapi', $res); 414 | // $this->assertIsArray($res['fapi']); 415 | // $this->assertArrayHasKey('status', $res['fapi']); 416 | // $this->assertArrayHasKey('sapi', $res); 417 | // $this->assertIsArray($res['sapi']); 418 | // $this->assertArrayHasKey('status', $res['sapi']); 419 | // $this->spotBinance->useTestnet = true; // reset to true for other tests 420 | // } 421 | 422 | public function testAvgPriceSpot() 423 | { 424 | $res = $this->spotBinance->avgPrice($this->symbol); 425 | $this->assertIsNumeric($res); 426 | } 427 | 428 | public function testPreventedMatchesSpot() 429 | { 430 | $res = $this->spotBinance->preventedMatches($this->symbol, null, '0123456789'); 431 | $this->assertIsArray($res); 432 | } 433 | 434 | public function testCommissionRateSpot() 435 | { 436 | $res = $this->spotBinance->commissionRate($this->symbol); 437 | $this->assertIsArray($res); 438 | $this->assertArrayHasKey('symbol', $res); 439 | $this->assertEquals($this->symbol, $res['symbol']); 440 | $this->assertArrayHasKey('standardCommission', $res); 441 | 442 | $standardCommission = $res['standardCommission']; 443 | $this->assertIsArray($standardCommission); 444 | $this->assertArrayHasKey('maker', $standardCommission); 445 | $this->assertIsNumeric($standardCommission['maker']); 446 | $this->assertArrayHasKey('taker', $standardCommission); 447 | $this->assertIsNumeric($standardCommission['taker']); 448 | $this->assertArrayHasKey('buyer', $standardCommission); 449 | $this->assertIsNumeric($standardCommission['buyer']); 450 | $this->assertArrayHasKey('seller', $standardCommission); 451 | $this->assertIsNumeric($standardCommission['seller']); 452 | 453 | $this->assertArrayHasKey('taxCommission', $res); 454 | $taxCommission = $res['taxCommission']; 455 | $this->assertIsArray($taxCommission); 456 | $this->assertArrayHasKey('maker', $taxCommission); 457 | $this->assertIsNumeric($taxCommission['maker']); 458 | $this->assertArrayHasKey('taker', $taxCommission); 459 | $this->assertIsNumeric($taxCommission['taker']); 460 | $this->assertArrayHasKey('buyer', $taxCommission); 461 | $this->assertIsNumeric($taxCommission['buyer']); 462 | $this->assertArrayHasKey('seller', $taxCommission); 463 | 464 | $this->assertArrayHasKey('discount', $res); 465 | $discount = $res['discount']; 466 | $this->assertIsArray($discount); 467 | $this->assertArrayHasKey('enabledForAccount', $discount); 468 | $this->assertIsBool($discount['enabledForAccount']); 469 | $this->assertArrayHasKey('enabledForSymbol', $discount); 470 | $this->assertIsBool($discount['enabledForSymbol']); 471 | $this->assertArrayHasKey('discountAsset', $discount); 472 | $this->assertArrayHasKey('discount', $discount); 473 | $this->assertIsNumeric($discount['discount']); 474 | } 475 | 476 | public function testAllocationsSpot() 477 | { 478 | $res = $this->spotBinance->allocations($this->symbol); 479 | $this->assertIsArray($res); 480 | } 481 | 482 | public function testTimeFutures() 483 | { 484 | $res = $this->futuresBinance->futuresTime(); 485 | $this->assertIsArray($res); 486 | $this->assertArrayHasKey('serverTime', $res); 487 | $this->assertIsInt($res['serverTime']); 488 | } 489 | 490 | public function testExchangeInfoFutures() 491 | { 492 | $res = $this->futuresBinance->futuresExchangeInfo(); 493 | $this->assertIsArray($res); 494 | $this->assertArrayHasKey('timezone', $res); 495 | $this->assertArrayHasKey('serverTime', $res); 496 | $this->assertIsInt($res['serverTime']); 497 | $this->assertArrayHasKey('futuresType', $res); 498 | $this->assertArrayHasKey('rateLimits', $res); 499 | $this->assertIsArray($res['rateLimits']); 500 | $this->assertArrayHasKey('exchangeFilters', $res); 501 | $this->assertIsArray($res['exchangeFilters']); 502 | $this->assertArrayHasKey('assets', $res); 503 | $this->assertIsArray($res['assets']); 504 | $this->assertArrayHasKey('symbols', $res); 505 | $this->assertIsArray($res['symbols']); 506 | } 507 | 508 | public function testDepthFutures() 509 | { 510 | $res = $this->futuresBinance->futuresDepth($this->symbol, 5); 511 | $this->assertIsArray($res); 512 | $this->assertArrayHasKey('bids', $res); 513 | $this->assertIsArray($res['bids']); 514 | $this->assertArrayHasKey('asks', $res); 515 | $this->assertIsArray($res['asks']); 516 | } 517 | 518 | public function testRecentTradesFutures() 519 | { 520 | $res = $this->futuresBinance->futuresRecentTrades($this->symbol, $this->limit); 521 | $this->assertIsArray($res); 522 | $this->assertIsArray($res[0]); 523 | $this->assertArrayHasKey('id', $res[0]); 524 | $this->assertIsNumeric($res[0]['id']); 525 | $this->assertArrayHasKey('price', $res[0]); 526 | $this->assertIsNumeric($res[0]['price']); 527 | $this->assertArrayHasKey('qty', $res[0]); 528 | $this->assertIsNumeric($res[0]['qty']); 529 | $this->assertArrayHasKey('quoteQty', $res[0]); 530 | $this->assertIsNumeric($res[0]['quoteQty']); 531 | $this->assertArrayHasKey('time', $res[0]); 532 | $this->assertIsNumeric($res[0]['time']); 533 | $this->assertArrayHasKey('isBuyerMaker', $res[0]); 534 | $this->assertIsBool($res[0]['isBuyerMaker']); 535 | } 536 | 537 | public function testHistoricalTradesFutures() 538 | { 539 | $res = $this->futuresBinance->futuresHistoricalTrades($this->symbol, $this->limit); 540 | $this->assertIsArray($res); 541 | $this->assertIsArray($res[0]); 542 | $this->assertArrayHasKey('id', $res[0]); 543 | $this->assertIsNumeric($res[0]['id']); 544 | $this->assertArrayHasKey('price', $res[0]); 545 | $this->assertIsNumeric($res[0]['price']); 546 | $this->assertArrayHasKey('qty', $res[0]); 547 | $this->assertIsNumeric($res[0]['qty']); 548 | $this->assertArrayHasKey('quoteQty', $res[0]); 549 | $this->assertIsNumeric($res[0]['quoteQty']); 550 | $this->assertArrayHasKey('time', $res[0]); 551 | $this->assertIsNumeric($res[0]['time']); 552 | $this->assertArrayHasKey('isBuyerMaker', $res[0]); 553 | $this->assertIsBool($res[0]['isBuyerMaker']); 554 | } 555 | 556 | public function testAggTradesFutures() 557 | { 558 | $res = $this->futuresBinance->futuresAggTrades($this->symbol); 559 | $this->assertIsArray($res); 560 | $this->assertIsArray($res[0]); 561 | $this->assertArrayHasKey('price', $res[0]); 562 | $this->assertIsNumeric($res[0]['price']); 563 | $this->assertArrayHasKey('quantity', $res[0]); 564 | $this->assertIsNumeric($res[0]['quantity']); 565 | $this->assertArrayHasKey('timestamp', $res[0]); 566 | $this->assertIsInt($res[0]['timestamp']); 567 | $this->assertArrayHasKey('maker', $res[0]); 568 | $this->assertIsString($res[0]['maker']); 569 | } 570 | 571 | public function testCandlesticksFutures() 572 | { 573 | $res = $this->futuresBinance->futuresCandlesticks($this->symbol, $this->interval, $this->limit); 574 | $this->assertIsArray($res); 575 | $firstKey = array_key_first($res); 576 | $this->assertIsNumeric($firstKey); 577 | $candle = $res[$firstKey]; 578 | $this->assertArrayHasKey('open', $candle); 579 | $this->assertIsNumeric($candle['open']); 580 | $this->assertArrayHasKey('high', $candle); 581 | $this->assertIsNumeric($candle['high']); 582 | $this->assertArrayHasKey('low', $candle); 583 | $this->assertIsNumeric($candle['low']); 584 | $this->assertArrayHasKey('close', $candle); 585 | $this->assertIsNumeric($candle['close']); 586 | $this->assertArrayHasKey('volume', $candle); 587 | $this->assertIsNumeric($candle['volume']); 588 | $this->assertArrayHasKey('openTime', $candle); 589 | $this->assertIsInt($candle['openTime']); 590 | $this->assertArrayHasKey('closeTime', $candle); 591 | $this->assertIsInt($candle['closeTime']); 592 | $this->assertArrayHasKey('assetVolume', $candle); 593 | $this->assertIsNumeric($candle['assetVolume']); 594 | $this->assertArrayHasKey('baseVolume', $candle); 595 | $this->assertIsNumeric($candle['baseVolume']); 596 | $this->assertArrayHasKey('trades', $candle); 597 | $this->assertIsInt($candle['trades']); 598 | $this->assertArrayHasKey('assetBuyVolume', $candle); 599 | $this->assertIsNumeric($candle['assetBuyVolume']); 600 | $this->assertArrayHasKey('takerBuyVolume', $candle); 601 | $this->assertIsNumeric($candle['takerBuyVolume']); 602 | } 603 | 604 | public function testContinuousCandlesticksFutures() 605 | { 606 | $res = $this->futuresBinance->futuresContinuousCandlesticks($this->symbol, $this->interval, $this->limit, null, null, $this->contractType); 607 | $this->assertIsArray($res); 608 | $firstKey = array_key_first($res); 609 | $this->assertIsNumeric($firstKey); 610 | $candle = $res[$firstKey]; 611 | $this->assertArrayHasKey('open', $candle); 612 | $this->assertIsNumeric($candle['open']); 613 | $this->assertArrayHasKey('high', $candle); 614 | $this->assertIsNumeric($candle['high']); 615 | $this->assertArrayHasKey('low', $candle); 616 | $this->assertIsNumeric($candle['low']); 617 | $this->assertArrayHasKey('close', $candle); 618 | $this->assertIsNumeric($candle['close']); 619 | $this->assertArrayHasKey('volume', $candle); 620 | $this->assertIsNumeric($candle['volume']); 621 | $this->assertArrayHasKey('openTime', $candle); 622 | $this->assertIsInt($candle['openTime']); 623 | $this->assertArrayHasKey('closeTime', $candle); 624 | $this->assertIsInt($candle['closeTime']); 625 | $this->assertArrayHasKey('assetVolume', $candle); 626 | $this->assertIsNumeric($candle['assetVolume']); 627 | $this->assertArrayHasKey('baseVolume', $candle); 628 | $this->assertIsNumeric($candle['baseVolume']); 629 | $this->assertArrayHasKey('trades', $candle); 630 | $this->assertIsInt($candle['trades']); 631 | $this->assertArrayHasKey('assetBuyVolume', $candle); 632 | $this->assertIsNumeric($candle['assetBuyVolume']); 633 | $this->assertArrayHasKey('takerBuyVolume', $candle); 634 | $this->assertIsNumeric($candle['takerBuyVolume']); 635 | } 636 | 637 | public function testIndexPriceCandlesticksFutures() 638 | { 639 | $res = $this->futuresBinance->futuresIndexPriceCandlesticks($this->symbol, $this->interval, $this->limit); 640 | $this->assertIsArray($res); 641 | $firstKey = array_key_first($res); 642 | $this->assertIsNumeric($firstKey); 643 | $candle = $res[$firstKey]; 644 | $this->assertArrayHasKey('open', $candle); 645 | $this->assertIsNumeric($candle['open']); 646 | $this->assertArrayHasKey('high', $candle); 647 | $this->assertIsNumeric($candle['high']); 648 | $this->assertArrayHasKey('low', $candle); 649 | $this->assertIsNumeric($candle['low']); 650 | $this->assertArrayHasKey('close', $candle); 651 | $this->assertIsNumeric($candle['close']); 652 | $this->assertArrayHasKey('volume', $candle); 653 | $this->assertIsNumeric($candle['volume']); 654 | $this->assertArrayHasKey('openTime', $candle); 655 | $this->assertIsInt($candle['openTime']); 656 | $this->assertArrayHasKey('closeTime', $candle); 657 | $this->assertIsInt($candle['closeTime']); 658 | $this->assertArrayHasKey('assetVolume', $candle); 659 | $this->assertIsNumeric($candle['assetVolume']); 660 | $this->assertArrayHasKey('baseVolume', $candle); 661 | $this->assertIsNumeric($candle['baseVolume']); 662 | $this->assertArrayHasKey('trades', $candle); 663 | $this->assertIsInt($candle['trades']); 664 | $this->assertArrayHasKey('assetBuyVolume', $candle); 665 | $this->assertIsNumeric($candle['assetBuyVolume']); 666 | $this->assertArrayHasKey('takerBuyVolume', $candle); 667 | $this->assertIsNumeric($candle['takerBuyVolume']); 668 | } 669 | 670 | public function testMarkPriceCandlesticksFutures() 671 | { 672 | $res = $this->futuresBinance->futuresMarkPriceCandlesticks($this->symbol, $this->interval, $this->limit); 673 | $this->assertIsArray($res); 674 | $firstKey = array_key_first($res); 675 | $this->assertIsNumeric($firstKey); 676 | $candle = $res[$firstKey]; 677 | $this->assertArrayHasKey('open', $candle); 678 | $this->assertIsNumeric($candle['open']); 679 | $this->assertArrayHasKey('high', $candle); 680 | $this->assertIsNumeric($candle['high']); 681 | $this->assertArrayHasKey('low', $candle); 682 | $this->assertIsNumeric($candle['low']); 683 | $this->assertArrayHasKey('close', $candle); 684 | $this->assertIsNumeric($candle['close']); 685 | $this->assertArrayHasKey('volume', $candle); 686 | $this->assertIsNumeric($candle['volume']); 687 | $this->assertArrayHasKey('openTime', $candle); 688 | $this->assertIsInt($candle['openTime']); 689 | $this->assertArrayHasKey('closeTime', $candle); 690 | $this->assertIsInt($candle['closeTime']); 691 | $this->assertArrayHasKey('assetVolume', $candle); 692 | $this->assertIsNumeric($candle['assetVolume']); 693 | $this->assertArrayHasKey('baseVolume', $candle); 694 | $this->assertIsNumeric($candle['baseVolume']); 695 | $this->assertArrayHasKey('trades', $candle); 696 | $this->assertIsInt($candle['trades']); 697 | $this->assertArrayHasKey('assetBuyVolume', $candle); 698 | $this->assertIsNumeric($candle['assetBuyVolume']); 699 | $this->assertArrayHasKey('takerBuyVolume', $candle); 700 | $this->assertIsNumeric($candle['takerBuyVolume']); 701 | } 702 | 703 | public function testPremiumIndexCandlesticksFutures() 704 | { 705 | $res = $this->futuresBinance->futuresPremiumIndexCandlesticks($this->symbol, $this->interval, $this->limit); 706 | $this->assertIsArray($res); 707 | $firstKey = array_key_first($res); 708 | $this->assertIsNumeric($firstKey); 709 | $candle = $res[$firstKey]; 710 | $this->assertArrayHasKey('open', $candle); 711 | $this->assertIsNumeric($candle['open']); 712 | $this->assertArrayHasKey('high', $candle); 713 | $this->assertIsNumeric($candle['high']); 714 | $this->assertArrayHasKey('low', $candle); 715 | $this->assertIsNumeric($candle['low']); 716 | $this->assertArrayHasKey('close', $candle); 717 | $this->assertIsNumeric($candle['close']); 718 | $this->assertArrayHasKey('volume', $candle); 719 | $this->assertIsNumeric($candle['volume']); 720 | $this->assertArrayHasKey('openTime', $candle); 721 | $this->assertIsInt($candle['openTime']); 722 | $this->assertArrayHasKey('closeTime', $candle); 723 | $this->assertIsInt($candle['closeTime']); 724 | $this->assertArrayHasKey('assetVolume', $candle); 725 | $this->assertIsNumeric($candle['assetVolume']); 726 | $this->assertArrayHasKey('baseVolume', $candle); 727 | $this->assertIsNumeric($candle['baseVolume']); 728 | $this->assertArrayHasKey('trades', $candle); 729 | $this->assertIsInt($candle['trades']); 730 | $this->assertArrayHasKey('assetBuyVolume', $candle); 731 | $this->assertIsNumeric($candle['assetBuyVolume']); 732 | $this->assertArrayHasKey('takerBuyVolume', $candle); 733 | $this->assertIsNumeric($candle['takerBuyVolume']); 734 | } 735 | 736 | public function testMarkPriceFutures() 737 | { 738 | $res = $this->futuresBinance->futuresMarkPrice($this->symbol); 739 | $this->assertIsArray($res); 740 | $this->assertEquals($this->symbol, $res['symbol']); 741 | $this->assertArrayHasKey('markPrice', $res); 742 | $this->assertIsNumeric($res['markPrice']); 743 | $this->assertArrayHasKey('indexPrice', $res); 744 | $this->assertIsNumeric($res['indexPrice']); 745 | $this->assertArrayHasKey('estimatedSettlePrice', $res); 746 | $this->assertIsNumeric($res['estimatedSettlePrice']); 747 | $this->assertArrayHasKey('lastFundingRate', $res); 748 | $this->assertIsNumeric($res['lastFundingRate']); 749 | $this->assertArrayHasKey('interestRate', $res); 750 | $this->assertIsNumeric($res['interestRate']); 751 | $this->assertArrayHasKey('nextFundingTime', $res); 752 | $this->assertIsInt($res['nextFundingTime']); 753 | $this->assertArrayHasKey('time', $res); 754 | $this->assertIsInt($res['time']); 755 | } 756 | 757 | public function testFundingRateHistoryFutures() 758 | { 759 | $res = $this->futuresBinance->futuresFundingRateHistory($this->symbol, $this->limit); 760 | $this->assertIsArray($res); 761 | $this->assertIsArray($res[0]); 762 | $entry = $res[0]; 763 | $this->assertArrayHasKey('symbol', $entry); 764 | $this->assertEquals($this->symbol, $entry['symbol']); 765 | $this->assertArrayHasKey('fundingTime', $entry); 766 | $this->assertIsInt($entry['fundingTime']); 767 | $this->assertArrayHasKey('fundingRate', $entry); 768 | $this->assertIsNumeric($entry['fundingRate']); 769 | $this->assertArrayHasKey('markPrice', $entry); 770 | $this->assertIsNumeric($entry['markPrice']); 771 | } 772 | 773 | public function testPrevDayFutures() 774 | { 775 | $res = $this->futuresBinance->futuresPrevDay($this->symbol); 776 | $this->assertIsArray($res); 777 | $this->assertEquals($this->symbol, $res['symbol']); 778 | $this->assertArrayHasKey('priceChange', $res); 779 | $this->assertIsNumeric($res['priceChange']); 780 | $this->assertArrayHasKey('priceChangePercent', $res); 781 | $this->assertIsNumeric($res['priceChangePercent']); 782 | $this->assertArrayHasKey('weightedAvgPrice', $res); 783 | $this->assertIsNumeric($res['weightedAvgPrice']); 784 | $this->assertArrayHasKey('lastPrice', $res); 785 | $this->assertIsNumeric($res['lastPrice']); 786 | $this->assertArrayHasKey('lastQty', $res); 787 | $this->assertIsNumeric($res['lastQty']); 788 | $this->assertArrayHasKey('openPrice', $res); 789 | $this->assertIsNumeric($res['openPrice']); 790 | $this->assertArrayHasKey('highPrice', $res); 791 | $this->assertIsNumeric($res['highPrice']); 792 | $this->assertArrayHasKey('lowPrice', $res); 793 | $this->assertIsNumeric($res['lowPrice']); 794 | $this->assertArrayHasKey('volume', $res); 795 | $this->assertIsNumeric($res['volume']); 796 | $this->assertArrayHasKey('quoteVolume', $res); 797 | $this->assertIsNumeric($res['quoteVolume']); 798 | $this->assertArrayHasKey('openTime', $res); 799 | $this->assertIsInt($res['openTime']); 800 | $this->assertArrayHasKey('closeTime', $res); 801 | $this->assertIsInt($res['closeTime']); 802 | $this->assertArrayHasKey('firstId', $res); 803 | $this->assertIsInt($res['firstId']); 804 | $this->assertArrayHasKey('lastId', $res); 805 | $this->assertIsInt($res['lastId']); 806 | $this->assertArrayHasKey('count', $res); 807 | $this->assertIsInt($res['count']); 808 | } 809 | 810 | public function testPriceFutures() 811 | { 812 | $res = $this->futuresBinance->futuresPrice($this->symbol); 813 | $this->assertIsNumeric($res); 814 | } 815 | 816 | public function testPricesFutures() 817 | { 818 | $res = $this->futuresBinance->futuresPrices(); 819 | $this->assertIsArray($res); 820 | $this->assertArrayHasKey($this->symbol, $res); 821 | $this->assertIsNumeric($res[$this->symbol]); 822 | } 823 | 824 | public function testPriceV2Futures() 825 | { 826 | $res = $this->futuresBinance->futuresPriceV2($this->symbol); 827 | $this->assertIsNumeric($res); 828 | } 829 | 830 | public function testPricesV2Futures() 831 | { 832 | $res = $this->futuresBinance->futuresPricesV2(); 833 | $this->assertIsArray($res); 834 | $this->assertArrayHasKey($this->symbol, $res); 835 | $this->assertIsNumeric($res[$this->symbol]); 836 | } 837 | 838 | public function testSymbolOrderBookTickerFutures() 839 | { 840 | $res = $this->futuresBinance->futuresSymbolOrderBookTicker($this->symbol); 841 | $this->assertIsArray($res); 842 | $this->assertEquals($this->symbol, $res['symbol']); 843 | $this->assertArrayHasKey('bidPrice', $res); 844 | $this->assertIsNumeric($res['bidPrice']); 845 | $this->assertArrayHasKey('bidQty', $res); 846 | $this->assertIsNumeric($res['bidQty']); 847 | $this->assertArrayHasKey('askPrice', $res); 848 | $this->assertIsNumeric($res['askPrice']); 849 | $this->assertArrayHasKey('askQty', $res); 850 | $this->assertIsNumeric($res['askQty']); 851 | $this->assertArrayHasKey('time', $res); 852 | $this->assertIsInt($res['time']); 853 | } 854 | 855 | 856 | // public function testDeliveryPriceFutures() // Could throw an error if useTestnet is set to false 857 | // { 858 | // $this->futuresBinance->useTestnet = false; // set to false for fapiData request 859 | // $res = $this->futuresBinance->futuresDeliveryPrice($this->symbol); 860 | // $this->assertIsArray($res); 861 | // $this->assertIsArray($res[0]); 862 | // $this->assertArrayHasKey('deliveryTime', $res[0]); 863 | // $this->assertIsInt($res[0]['deliveryTime']); 864 | // $this->assertArrayHasKey('deliveryPrice', $res[0]); 865 | // $this->assertIsNumeric($res[0]['deliveryPrice']); 866 | // $this->futuresBinance->useTestnet = true; // reset to true for other tests 867 | // } 868 | 869 | // public function testOpenInterestFutures() 870 | // { 871 | // $res = $this->futuresBinance->futuresOpenInterest($this->symbol); // for now the exchange returns null 872 | // $this->assertIsArray($res); 873 | // $this->assertEquals($this->symbol, $res['symbol']); 874 | // $this->assertArrayHasKey('openInterest', $res); 875 | // $this->assertIsNumeric($res['openInterest']); 876 | // $this->assertArrayHasKey('time', $res); 877 | // $this->assertIsInt($res['time']); 878 | // } 879 | 880 | // public function testOpenInterestHistoryFutures() // Could throw an error if useTestnet is set to false 881 | // { 882 | // $this->futuresBinance->useTestnet = false; // set to false for fapiData request 883 | // $res = $this->futuresBinance->futuresOpenInterestHistory($this->symbol, $this->period, $this->limit); 884 | // $this->assertIsArray($res); 885 | // $entry = $res[0]; 886 | // $this->assertIsArray($entry); 887 | // $this->assertArrayHasKey('symbol', $entry); 888 | // $this->assertEquals($this->symbol, $entry['symbol']); 889 | // $this->assertArrayHasKey('sumOpenInterest', $entry); 890 | // $this->assertIsNumeric($entry['sumOpenInterest']); 891 | // $this->assertArrayHasKey('sumOpenInterestValue', $entry); 892 | // $this->assertIsNumeric($entry['sumOpenInterestValue']); 893 | // $this->assertArrayHasKey('timestamp', $entry); 894 | // $this->assertIsInt($entry['timestamp']); 895 | // $this->futuresBinance->useTestnet = true; // reset to true for other tests 896 | // } 897 | 898 | // public function testTopLongShortPositionRatioFutures() // Could throw an error if useTestnet is set to false 899 | // { 900 | // $this->futuresBinance->useTestnet = false; // set to false for fapiData request 901 | // $res = $this->futuresBinance->futuresTopLongShortPositionRatio($this->symbol, $this->period, $this->limit); 902 | // $this->assertIsArray($res); 903 | // $entry = $res[0]; 904 | // $this->assertIsArray($entry); 905 | // $this->assertArrayHasKey('symbol', $entry); 906 | // $this->assertEquals($this->symbol, $entry['symbol']); 907 | // $this->assertArrayHasKey('longAccount', $entry); 908 | // $this->assertIsNumeric($entry['longAccount']); 909 | // $this->assertArrayHasKey('longShortRatio', $entry); 910 | // $this->assertIsNumeric($entry['longShortRatio']); 911 | // $this->assertArrayHasKey('shortAccount', $entry); 912 | // $this->assertIsNumeric($entry['shortAccount']); 913 | // $this->assertArrayHasKey('timestamp', $entry); 914 | // $this->assertIsInt($entry['timestamp']); 915 | // $this->futuresBinance->useTestnet = true; // reset to true for other tests 916 | // } 917 | 918 | // public function testTopLongShortAccountRatioFutures() // Could throw an error if useTestnet is set to false 919 | // { 920 | // $this->futuresBinance->useTestnet = false; // set to false for fapiData request 921 | // $res = $this->futuresBinance->futuresTopLongShortAccountRatio($this->symbol, $this->period, $this->limit); 922 | // $this->assertIsArray($res); 923 | // $entry = $res[0]; 924 | // $this->assertIsArray($entry); 925 | // $this->assertArrayHasKey('symbol', $entry); 926 | // $this->assertEquals($this->symbol, $entry['symbol']); 927 | // $this->assertArrayHasKey('longAccount', $entry); 928 | // $this->assertIsNumeric($entry['longAccount']); 929 | // $this->assertArrayHasKey('longShortRatio', $entry); 930 | // $this->assertIsNumeric($entry['longShortRatio']); 931 | // $this->assertArrayHasKey('shortAccount', $entry); 932 | // $this->assertIsNumeric($entry['shortAccount']); 933 | // $this->assertArrayHasKey('timestamp', $entry); 934 | // $this->assertIsInt($entry['timestamp']); 935 | // $this->futuresBinance->useTestnet = true; // reset to true for other tests 936 | // } 937 | 938 | // public function testGlobalLongShortAccountRatioFutures() // Could throw an error if useTestnet is set to false 939 | // { 940 | // $this->futuresBinance->useTestnet = false; // set to false for fapiData request 941 | // $res = $this->futuresBinance->futuresGlobalLongShortAccountRatio($this->symbol, $this->period, $this->limit); 942 | // $this->assertIsArray($res); 943 | // $entry = $res[0]; 944 | // $this->assertIsArray($entry); 945 | // $this->assertArrayHasKey('symbol', $entry); 946 | // $this->assertEquals($this->symbol, $entry['symbol']); 947 | // $this->assertArrayHasKey('longAccount', $entry); 948 | // $this->assertIsNumeric($entry['longAccount']); 949 | // $this->assertArrayHasKey('longShortRatio', $entry); 950 | // $this->assertIsNumeric($entry['longShortRatio']); 951 | // $this->assertArrayHasKey('shortAccount', $entry); 952 | // $this->assertIsNumeric($entry['shortAccount']); 953 | // $this->assertArrayHasKey('timestamp', $entry); 954 | // $this->assertIsInt($entry['timestamp']); 955 | // $this->futuresBinance->useTestnet = true; // reset to true for other tests 956 | // } 957 | 958 | // public function testTakerLongShortRatioFutures() // Could throw an error if useTestnet is set to false 959 | // { 960 | // $this->futuresBinance->useTestnet = false; // set to false for fapiData request 961 | // $res = $this->futuresBinance->futuresTakerLongShortRatio($this->symbol, $this->period, $this->limit); 962 | // $this->assertIsArray($res); 963 | // $entry = $res[0]; 964 | // $this->assertIsArray($entry); 965 | // $this->assertArrayHasKey('buySellRatio', $entry); 966 | // $this->assertIsNumeric($entry['buySellRatio']); 967 | // $this->assertArrayHasKey('sellVol', $entry); 968 | // $this->assertIsNumeric($entry['sellVol']); 969 | // $this->assertArrayHasKey('buyVol', $entry); 970 | // $this->assertIsNumeric($entry['buyVol']); 971 | // $this->assertArrayHasKey('timestamp', $entry); 972 | // $this->assertIsInt($entry['timestamp']); 973 | // $this->futuresBinance->useTestnet = true; // reset to true for other tests 974 | // } 975 | 976 | // public function testBasisFutures() // Could throw an error if useTestnet is set to false 977 | // { 978 | // $this->futuresBinance->useTestnet = false; // set to false for fapiData request 979 | // $res = $this->futuresBinance->futuresBasis($this->symbol, $this->period, $this->limit, null, null, $this->contractType); 980 | // $this->assertIsArray($res); 981 | // $entry = $res[0]; 982 | // $this->assertIsArray($entry); 983 | // $this->assertArrayHasKey('indexPrice', $entry); 984 | // $this->assertIsNumeric($entry['indexPrice']); 985 | // $this->assertArrayHasKey('contractType', $entry); 986 | // $this->assertEquals($this->contractType, $entry['contractType']); 987 | // $this->assertArrayHasKey('basisRate', $entry); 988 | // $this->assertIsNumeric($entry['basisRate']); 989 | // $this->assertArrayHasKey('futuresPrice', $entry); 990 | // $this->assertIsNumeric($entry['futuresPrice']); 991 | // $this->assertArrayHasKey('annualizedBasisRate', $entry); 992 | // $this->assertIsNumeric($entry['annualizedBasisRate']); 993 | // $this->assertArrayHasKey('basis', $entry); 994 | // $this->assertIsNumeric($entry['basis']); 995 | // $this->assertArrayHasKey('pair', $entry); 996 | // $this->assertEquals($this->symbol, $entry['pair']); 997 | // $this->assertArrayHasKey('timestamp', $entry); 998 | // $this->assertIsInt($entry['timestamp']); 999 | // $this->futuresBinance->useTestnet = true; // reset to true for other tests 1000 | // } 1001 | 1002 | public function testIndexInfoFutures() 1003 | { 1004 | $compositeIndex = 'DEFIUSDT'; 1005 | $res = $this->futuresBinance->futuresIndexInfo($compositeIndex); 1006 | $this->assertIsArray($res); 1007 | $this->assertArrayHasKey('symbol', $res); 1008 | $this->assertEquals($compositeIndex, $res['symbol']); 1009 | $this->assertArrayHasKey('time', $res); 1010 | $this->assertIsInt($res['time']); 1011 | $this->assertArrayHasKey('component', $res); 1012 | $this->assertArrayHasKey('baseAssetList', $res); 1013 | $this->assertIsArray($res['baseAssetList']); 1014 | } 1015 | 1016 | public function testAssetIndexFutures() 1017 | { 1018 | $res = $this->futuresBinance->futuresAssetIndex(); 1019 | $this->assertIsArray($res); 1020 | $entry = $res[0]; 1021 | $this->assertIsArray($entry); 1022 | $this->assertArrayHasKey('symbol', $entry); 1023 | $this->assertIsString($entry['symbol']); 1024 | $this->assertArrayHasKey('time', $entry); 1025 | $this->assertIsInt($entry['time']); 1026 | $this->assertArrayHasKey('index', $entry); 1027 | $this->assertIsNumeric($entry['index']); 1028 | $this->assertArrayHasKey('bidBuffer', $entry); 1029 | $this->assertIsNumeric($entry['bidBuffer']); 1030 | $this->assertArrayHasKey('askBuffer', $entry); 1031 | $this->assertIsNumeric($entry['askBuffer']); 1032 | $this->assertArrayHasKey('bidRate', $entry); 1033 | $this->assertIsNumeric($entry['bidRate']); 1034 | $this->assertArrayHasKey('askRate', $entry); 1035 | $this->assertIsNumeric($entry['askRate']); 1036 | $this->assertArrayHasKey('autoExchangeBidBuffer', $entry); 1037 | $this->assertIsNumeric($entry['autoExchangeBidBuffer']); 1038 | $this->assertArrayHasKey('autoExchangeAskBuffer', $entry); 1039 | $this->assertIsNumeric($entry['autoExchangeAskBuffer']); 1040 | $this->assertArrayHasKey('autoExchangeBidRate', $entry); 1041 | $this->assertIsNumeric($entry['autoExchangeBidRate']); 1042 | $this->assertArrayHasKey('autoExchangeAskRate', $entry); 1043 | $this->assertIsNumeric($entry['autoExchangeAskRate']); 1044 | } 1045 | 1046 | public function testConstituentsFutures() 1047 | { 1048 | $res = $this->futuresBinance->futuresConstituents($this->symbol); 1049 | $this->assertIsArray($res); 1050 | $this->assertEquals($this->symbol, $res['symbol']); 1051 | $this->assertArrayHasKey('time', $res); 1052 | $this->assertIsInt($res['time']); 1053 | $this->assertArrayHasKey('constituents', $res); 1054 | $this->assertIsArray($res['constituents']); 1055 | } 1056 | 1057 | public function testOrderAmendmentFutures() 1058 | { 1059 | $res = $this->futuresBinance->futuresOrderAmendment($this->symbol); 1060 | $this->assertIsArray($res); 1061 | } 1062 | 1063 | public function testCountdownCancelAllOrdersFutures() 1064 | { 1065 | $countdownTime = 1000; 1066 | $res = $this->futuresBinance->futuresCountdownCancelAllOrders($this->symbol, $countdownTime); 1067 | $this->assertIsArray($res); 1068 | $this->assertArrayHasKey('symbol', $res); 1069 | $this->assertEquals($this->symbol, $res['symbol']); 1070 | $this->assertArrayHasKey('countdownTime', $res); 1071 | $this->assertEquals($countdownTime, $res['countdownTime']); 1072 | } 1073 | 1074 | public function testAllOrdersFutures() 1075 | { 1076 | $res = $this->futuresBinance->futuresAllOrders($this->symbol); 1077 | $this->assertIsArray($res); 1078 | } 1079 | 1080 | public function testOpenOrdersFutures() 1081 | { 1082 | $res = $this->futuresBinance->futuresOpenOrders($this->symbol); 1083 | $this->assertIsArray($res); 1084 | } 1085 | 1086 | public function testForceOrdersFutures() 1087 | { 1088 | $res = $this->futuresBinance->futuresForceOrders(); 1089 | $this->assertIsArray($res); 1090 | } 1091 | 1092 | public function testMyTradesFutures() 1093 | { 1094 | $res = $this->futuresBinance->futuresMyTrades($this->symbol); 1095 | $this->assertIsArray($res); 1096 | } 1097 | 1098 | public function testHistoryFutures() 1099 | { 1100 | $res = $this->futuresBinance->futuresHistory($this->symbol); 1101 | $this->assertIsArray($res); 1102 | } 1103 | 1104 | public function testPositionModeFutures() 1105 | { 1106 | $res = $this->futuresBinance->futuresPositionMode(); 1107 | $this->assertIsArray($res); 1108 | $this->assertArrayHasKey('dualSidePosition', $res); 1109 | $this->assertIsBool($res['dualSidePosition']); 1110 | } 1111 | 1112 | public function testMultiAssetsMarginModeFutures() 1113 | { 1114 | $res = $this->futuresBinance->futuresMultiAssetsMarginMode(); 1115 | $this->assertIsArray($res); 1116 | $this->assertArrayHasKey('multiAssetsMargin', $res); 1117 | $this->assertIsBool($res['multiAssetsMargin']); 1118 | } 1119 | 1120 | public function testPositionsFutures() 1121 | { 1122 | $res = $this->futuresBinance->futuresPositions($this->symbol); 1123 | $this->assertIsArray($res); 1124 | } 1125 | 1126 | public function testPositionsV2Futures() 1127 | { 1128 | $res = $this->futuresBinance->futuresPositionsV2($this->symbol); 1129 | $this->assertIsArray($res); 1130 | } 1131 | 1132 | public function testPositionsV3Futures() 1133 | { 1134 | $res = $this->futuresBinance->futuresPositionsV3($this->symbol); 1135 | $this->assertIsArray($res); 1136 | } 1137 | 1138 | public function testPositionFutures() 1139 | { 1140 | $res = $this->futuresBinance->futuresPosition($this->symbol); 1141 | $this->assertIsArray($res); 1142 | } 1143 | 1144 | public function testPositionV2Futures() 1145 | { 1146 | $res = $this->futuresBinance->futuresPositionV2($this->symbol); 1147 | $this->assertIsArray($res); 1148 | } 1149 | 1150 | public function testPositionV3Futures() 1151 | { 1152 | $res = $this->futuresBinance->futuresPositionV3($this->symbol); 1153 | $this->assertIsArray($res); 1154 | } 1155 | 1156 | public function testAdlQuantileFutures() 1157 | { 1158 | $res = $this->futuresBinance->futuresAdlQuantile($this->symbol); 1159 | $this->assertIsArray($res); 1160 | $this->assertEquals($this->symbol, $res['symbol']); 1161 | $this->assertArrayHasKey('adlQuantile', $res); 1162 | $this->assertIsArray($res['adlQuantile']); 1163 | } 1164 | 1165 | public function testPositionMarginChangeHistoryFutures() 1166 | { 1167 | $res = $this->futuresBinance->futuresPositionMarginChangeHistory($this->symbol); 1168 | $this->assertIsArray($res); 1169 | } 1170 | 1171 | public function testBalancesFutures() 1172 | { 1173 | $res = $this->futuresBinance->futuresBalances(); 1174 | $this->assertIsArray($res); 1175 | $firstKey = array_key_first($res); 1176 | $this->assertIsString($firstKey); 1177 | $firstValue = $res[$firstKey]; 1178 | $this->assertIsArray($firstValue); 1179 | $this->assertArrayHasKey('available', $firstValue); 1180 | $this->assertIsNumeric($firstValue['available']); 1181 | $this->assertArrayHasKey('onOrder', $firstValue); 1182 | $this->assertIsNumeric($firstValue['onOrder']); 1183 | $this->assertArrayHasKey('total', $firstValue); 1184 | $this->assertIsNumeric($firstValue['total']); 1185 | $this->assertArrayHasKey('info', $firstValue); 1186 | $info = $firstValue['info']; 1187 | $this->assertIsArray($info); 1188 | $this->assertArrayHasKey('accountAlias', $info); 1189 | $this->assertIsString($info['accountAlias']); 1190 | $this->assertArrayHasKey('asset', $info); 1191 | $this->assertIsString($info['asset']); 1192 | $this->assertArrayHasKey('balance', $info); 1193 | $this->assertIsNumeric($info['balance']); 1194 | $this->assertArrayHasKey('crossWalletBalance', $info); 1195 | $this->assertIsNumeric($info['crossWalletBalance']); 1196 | $this->assertArrayHasKey('crossUnPnl', $info); 1197 | $this->assertIsNumeric($info['crossUnPnl']); 1198 | $this->assertArrayHasKey('availableBalance', $info); 1199 | $this->assertIsNumeric($info['availableBalance']); 1200 | $this->assertArrayHasKey('maxWithdrawAmount', $info); 1201 | $this->assertIsNumeric($info['maxWithdrawAmount']); 1202 | $this->assertArrayHasKey('marginAvailable', $info); 1203 | $this->assertIsBool($info['marginAvailable']); 1204 | $this->assertArrayHasKey('updateTime', $info); 1205 | $this->assertIsInt($info['updateTime']); 1206 | } 1207 | 1208 | public function testBalancesV2Futures() 1209 | { 1210 | $res = $this->futuresBinance->futuresBalancesV2(); 1211 | $this->assertIsArray($res); 1212 | $firstKey = array_key_first($res); 1213 | $this->assertIsString($firstKey); 1214 | $firstValue = $res[$firstKey]; 1215 | $this->assertIsArray($firstValue); 1216 | $this->assertArrayHasKey('available', $firstValue); 1217 | $this->assertIsNumeric($firstValue['available']); 1218 | $this->assertArrayHasKey('onOrder', $firstValue); 1219 | $this->assertIsNumeric($firstValue['onOrder']); 1220 | $this->assertArrayHasKey('total', $firstValue); 1221 | $this->assertIsNumeric($firstValue['total']); 1222 | $this->assertArrayHasKey('info', $firstValue); 1223 | $info = $firstValue['info']; 1224 | $this->assertIsArray($info); 1225 | $this->assertArrayHasKey('accountAlias', $info); 1226 | $this->assertIsString($info['accountAlias']); 1227 | $this->assertArrayHasKey('asset', $info); 1228 | $this->assertIsString($info['asset']); 1229 | $this->assertArrayHasKey('balance', $info); 1230 | $this->assertIsNumeric($info['balance']); 1231 | $this->assertArrayHasKey('crossWalletBalance', $info); 1232 | $this->assertIsNumeric($info['crossWalletBalance']); 1233 | $this->assertArrayHasKey('crossUnPnl', $info); 1234 | $this->assertIsNumeric($info['crossUnPnl']); 1235 | $this->assertArrayHasKey('availableBalance', $info); 1236 | $this->assertIsNumeric($info['availableBalance']); 1237 | $this->assertArrayHasKey('maxWithdrawAmount', $info); 1238 | $this->assertIsNumeric($info['maxWithdrawAmount']); 1239 | $this->assertArrayHasKey('marginAvailable', $info); 1240 | $this->assertIsBool($info['marginAvailable']); 1241 | $this->assertArrayHasKey('updateTime', $info); 1242 | $this->assertIsInt($info['updateTime']); 1243 | } 1244 | 1245 | public function testBalancesV3Futures() 1246 | { 1247 | $res = $this->futuresBinance->futuresBalancesV3(); 1248 | $this->assertIsArray($res); 1249 | $firstKey = array_key_first($res); 1250 | $this->assertIsString($firstKey); 1251 | $firstValue = $res[$firstKey]; 1252 | $this->assertIsArray($firstValue); 1253 | $this->assertArrayHasKey('available', $firstValue); 1254 | $this->assertIsNumeric($firstValue['available']); 1255 | $this->assertArrayHasKey('onOrder', $firstValue); 1256 | $this->assertIsNumeric($firstValue['onOrder']); 1257 | $this->assertArrayHasKey('total', $firstValue); 1258 | $this->assertIsNumeric($firstValue['total']); 1259 | $this->assertArrayHasKey('info', $firstValue); 1260 | $info = $firstValue['info']; 1261 | $this->assertIsArray($info); 1262 | $this->assertArrayHasKey('accountAlias', $info); 1263 | $this->assertIsString($info['accountAlias']); 1264 | $this->assertArrayHasKey('asset', $info); 1265 | $this->assertIsString($info['asset']); 1266 | $this->assertArrayHasKey('balance', $info); 1267 | $this->assertIsNumeric($info['balance']); 1268 | $this->assertArrayHasKey('crossWalletBalance', $info); 1269 | $this->assertIsNumeric($info['crossWalletBalance']); 1270 | $this->assertArrayHasKey('crossUnPnl', $info); 1271 | $this->assertIsNumeric($info['crossUnPnl']); 1272 | $this->assertArrayHasKey('availableBalance', $info); 1273 | $this->assertIsNumeric($info['availableBalance']); 1274 | $this->assertArrayHasKey('maxWithdrawAmount', $info); 1275 | $this->assertIsNumeric($info['maxWithdrawAmount']); 1276 | $this->assertArrayHasKey('marginAvailable', $info); 1277 | $this->assertIsBool($info['marginAvailable']); 1278 | $this->assertArrayHasKey('updateTime', $info); 1279 | $this->assertIsInt($info['updateTime']); 1280 | } 1281 | 1282 | public function testAccountFutures() 1283 | { 1284 | $res = $this->futuresBinance->futuresAccount(); 1285 | $this->assertIsArray($res); 1286 | $this->assertArrayHasKey('totalInitialMargin', $res); 1287 | $this->assertIsNumeric($res['totalInitialMargin']); 1288 | $this->assertArrayHasKey('totalMaintMargin', $res); 1289 | $this->assertIsNumeric($res['totalMaintMargin']); 1290 | $this->assertArrayHasKey('totalWalletBalance', $res); 1291 | $this->assertIsNumeric($res['totalWalletBalance']); 1292 | $this->assertArrayHasKey('totalUnrealizedProfit', $res); 1293 | $this->assertIsNumeric($res['totalUnrealizedProfit']); 1294 | $this->assertArrayHasKey('totalMarginBalance', $res); 1295 | $this->assertIsNumeric($res['totalMarginBalance']); 1296 | $this->assertArrayHasKey('totalPositionInitialMargin', $res); 1297 | $this->assertIsNumeric($res['totalPositionInitialMargin']); 1298 | $this->assertArrayHasKey('totalOpenOrderInitialMargin', $res); 1299 | $this->assertIsNumeric($res['totalOpenOrderInitialMargin']); 1300 | $this->assertArrayHasKey('totalCrossWalletBalance', $res); 1301 | $this->assertIsNumeric($res['totalCrossWalletBalance']); 1302 | $this->assertArrayHasKey('totalCrossUnPnl', $res); 1303 | $this->assertIsNumeric($res['totalCrossUnPnl']); 1304 | $this->assertArrayHasKey('availableBalance', $res); 1305 | $this->assertIsNumeric($res['availableBalance']); 1306 | $this->assertArrayHasKey('maxWithdrawAmount', $res); 1307 | $this->assertIsNumeric($res['maxWithdrawAmount']); 1308 | $this->assertArrayHasKey('assets', $res); 1309 | $this->assertIsArray($res['assets']); 1310 | $this->assertArrayHasKey('positions', $res); 1311 | $this->assertIsArray($res['positions']); 1312 | } 1313 | 1314 | public function testAccountV2Futures() 1315 | { 1316 | $res = $this->futuresBinance->futuresAccountV2(); 1317 | $this->assertIsArray($res); 1318 | $this->assertArrayHasKey('totalInitialMargin', $res); 1319 | $this->assertIsNumeric($res['totalInitialMargin']); 1320 | $this->assertArrayHasKey('totalMaintMargin', $res); 1321 | $this->assertIsNumeric($res['totalMaintMargin']); 1322 | $this->assertArrayHasKey('totalWalletBalance', $res); 1323 | $this->assertIsNumeric($res['totalWalletBalance']); 1324 | $this->assertArrayHasKey('totalUnrealizedProfit', $res); 1325 | $this->assertIsNumeric($res['totalUnrealizedProfit']); 1326 | $this->assertArrayHasKey('totalMarginBalance', $res); 1327 | $this->assertIsNumeric($res['totalMarginBalance']); 1328 | $this->assertArrayHasKey('totalPositionInitialMargin', $res); 1329 | $this->assertIsNumeric($res['totalPositionInitialMargin']); 1330 | $this->assertArrayHasKey('totalOpenOrderInitialMargin', $res); 1331 | $this->assertIsNumeric($res['totalOpenOrderInitialMargin']); 1332 | $this->assertArrayHasKey('totalCrossWalletBalance', $res); 1333 | $this->assertIsNumeric($res['totalCrossWalletBalance']); 1334 | $this->assertArrayHasKey('totalCrossUnPnl', $res); 1335 | $this->assertIsNumeric($res['totalCrossUnPnl']); 1336 | $this->assertArrayHasKey('availableBalance', $res); 1337 | $this->assertIsNumeric($res['availableBalance']); 1338 | $this->assertArrayHasKey('maxWithdrawAmount', $res); 1339 | $this->assertIsNumeric($res['maxWithdrawAmount']); 1340 | $this->assertArrayHasKey('assets', $res); 1341 | $this->assertIsArray($res['assets']); 1342 | $this->assertArrayHasKey('positions', $res); 1343 | $this->assertIsArray($res['positions']); 1344 | } 1345 | 1346 | public function testAccountV3Futures() 1347 | { 1348 | $res = $this->futuresBinance->futuresAccountV3(); 1349 | $this->assertIsArray($res); 1350 | $this->assertArrayHasKey('totalInitialMargin', $res); 1351 | $this->assertIsNumeric($res['totalInitialMargin']); 1352 | $this->assertArrayHasKey('totalMaintMargin', $res); 1353 | $this->assertIsNumeric($res['totalMaintMargin']); 1354 | $this->assertArrayHasKey('totalWalletBalance', $res); 1355 | $this->assertIsNumeric($res['totalWalletBalance']); 1356 | $this->assertArrayHasKey('totalUnrealizedProfit', $res); 1357 | $this->assertIsNumeric($res['totalUnrealizedProfit']); 1358 | $this->assertArrayHasKey('totalMarginBalance', $res); 1359 | $this->assertIsNumeric($res['totalMarginBalance']); 1360 | $this->assertArrayHasKey('totalPositionInitialMargin', $res); 1361 | $this->assertIsNumeric($res['totalPositionInitialMargin']); 1362 | $this->assertArrayHasKey('totalOpenOrderInitialMargin', $res); 1363 | $this->assertIsNumeric($res['totalOpenOrderInitialMargin']); 1364 | $this->assertArrayHasKey('totalCrossWalletBalance', $res); 1365 | $this->assertIsNumeric($res['totalCrossWalletBalance']); 1366 | $this->assertArrayHasKey('totalCrossUnPnl', $res); 1367 | $this->assertIsNumeric($res['totalCrossUnPnl']); 1368 | $this->assertArrayHasKey('availableBalance', $res); 1369 | $this->assertIsNumeric($res['availableBalance']); 1370 | $this->assertArrayHasKey('maxWithdrawAmount', $res); 1371 | $this->assertIsNumeric($res['maxWithdrawAmount']); 1372 | $this->assertArrayHasKey('assets', $res); 1373 | $this->assertIsArray($res['assets']); 1374 | $this->assertArrayHasKey('positions', $res); 1375 | $this->assertIsArray($res['positions']); 1376 | } 1377 | 1378 | public function testTradeFeeFutures() 1379 | { 1380 | $res = $this->futuresBinance->futuresTradeFee($this->symbol); 1381 | $this->assertIsArray($res); 1382 | $this->assertArrayHasKey('symbol', $res); 1383 | $this->assertEquals($this->symbol, $res['symbol']); 1384 | $this->assertArrayHasKey('makerCommissionRate', $res); 1385 | $this->assertIsNumeric($res['makerCommissionRate']); 1386 | $this->assertArrayHasKey('takerCommissionRate', $res); 1387 | $this->assertIsNumeric($res['takerCommissionRate']); 1388 | } 1389 | 1390 | public function testAccountConfigFutures() 1391 | { 1392 | $res = $this->futuresBinance->futuresAccountConfig(); 1393 | $this->assertIsArray($res); 1394 | $this->assertArrayHasKey('feeTier', $res); 1395 | $this->assertIsInt($res['feeTier']); 1396 | $this->assertArrayHasKey('canTrade', $res); 1397 | $this->assertIsBool($res['canTrade']); 1398 | $this->assertArrayHasKey('canDeposit', $res); 1399 | $this->assertIsBool($res['canDeposit']); 1400 | $this->assertArrayHasKey('canWithdraw', $res); 1401 | $this->assertIsBool($res['canWithdraw']); 1402 | $this->assertArrayHasKey('dualSidePosition', $res); 1403 | $this->assertIsBool($res['dualSidePosition']); 1404 | $this->assertArrayHasKey('updateTime', $res); 1405 | $this->assertIsInt($res['updateTime']); 1406 | $this->assertArrayHasKey('multiAssetsMargin', $res); 1407 | $this->assertIsBool($res['multiAssetsMargin']); 1408 | $this->assertArrayHasKey('tradeGroupId', $res); 1409 | } 1410 | 1411 | public function testMarginModesFutures() 1412 | { 1413 | $res = $this->futuresBinance->futuresMarginModes($this->symbol); 1414 | $this->assertIsArray($res); 1415 | $firstEntry = $res[0]; 1416 | $this->assertIsArray($firstEntry); 1417 | $this->assertArrayHasKey('symbol', $firstEntry); 1418 | $this->assertEquals($this->symbol, $firstEntry['symbol']); 1419 | $this->assertArrayHasKey('marginType', $firstEntry); 1420 | $this->assertIsString($firstEntry['marginType']); 1421 | $this->assertArrayHasKey('isAutoAddMargin', $firstEntry); 1422 | $this->assertIsBool($firstEntry['isAutoAddMargin']); 1423 | $this->assertArrayHasKey('leverage', $firstEntry); 1424 | $this->assertIsNumeric($firstEntry['leverage']); 1425 | $this->assertArrayHasKey('maxNotionalValue', $firstEntry); 1426 | $this->assertIsNumeric($firstEntry['maxNotionalValue']); 1427 | } 1428 | 1429 | public function testOrderRateLimitFutures() 1430 | { 1431 | $res = $this->futuresBinance->futuresOrderRateLimit(); 1432 | $this->assertIsArray($res); 1433 | $firstEntry = $res[0]; 1434 | $this->assertIsArray($firstEntry); 1435 | $this->assertArrayHasKey('rateLimitType', $firstEntry); 1436 | $this->assertEquals('ORDERS', $firstEntry['rateLimitType']); 1437 | $this->assertArrayHasKey('interval', $firstEntry); 1438 | $this->assertIsString($firstEntry['interval']); 1439 | $this->assertArrayHasKey('intervalNum', $firstEntry); 1440 | $this->assertIsNumeric($firstEntry['intervalNum']); 1441 | $this->assertArrayHasKey('limit', $firstEntry); 1442 | $this->assertIsInt($firstEntry['limit']); 1443 | } 1444 | 1445 | public function testOrderRateLimitSpot() 1446 | { 1447 | $res = $this->spotBinance->orderRateLimit(); 1448 | $this->assertIsArray($res); 1449 | $firstEntry = $res[0]; 1450 | $this->assertIsArray($firstEntry); 1451 | $this->assertArrayHasKey('rateLimitType', $firstEntry); 1452 | $this->assertEquals('ORDERS', $firstEntry['rateLimitType']); 1453 | $this->assertArrayHasKey('interval', $firstEntry); 1454 | $this->assertIsString($firstEntry['interval']); 1455 | $this->assertArrayHasKey('intervalNum', $firstEntry); 1456 | $this->assertIsNumeric($firstEntry['intervalNum']); 1457 | $this->assertArrayHasKey('limit', $firstEntry); 1458 | $this->assertIsInt($firstEntry['limit']); 1459 | } 1460 | 1461 | public function testLeveragesFutures() 1462 | { 1463 | $res = $this->futuresBinance->futuresLeverages($this->symbol); 1464 | $this->assertIsArray($res); 1465 | $firstEntry = $res[0]; 1466 | $this->assertIsArray($firstEntry); 1467 | $this->assertArrayHasKey('symbol', $firstEntry); 1468 | $this->assertEquals($this->symbol, $firstEntry['symbol']); 1469 | $this->assertArrayHasKey('brackets', $firstEntry); 1470 | $this->assertIsArray($firstEntry['brackets']); 1471 | $firstBracket = $firstEntry['brackets'][0]; 1472 | $this->assertIsArray($firstBracket); 1473 | $this->assertArrayHasKey('bracket', $firstBracket); 1474 | $this->assertIsInt($firstBracket['bracket']); 1475 | $this->assertArrayHasKey('initialLeverage', $firstBracket); 1476 | $this->assertIsNumeric($firstBracket['initialLeverage']); 1477 | $this->assertArrayHasKey('notionalCap', $firstBracket); 1478 | $this->assertIsNumeric($firstBracket['notionalCap']); 1479 | $this->assertArrayHasKey('notionalFloor', $firstBracket); 1480 | $this->assertIsNumeric($firstBracket['notionalFloor']); 1481 | $this->assertArrayHasKey('maintMarginRatio', $firstBracket); 1482 | $this->assertIsNumeric($firstBracket['maintMarginRatio']); 1483 | $this->assertArrayHasKey('cum', $firstBracket); 1484 | $this->assertIsNumeric($firstBracket['cum']); 1485 | } 1486 | 1487 | public function testLedgerFutures() 1488 | { 1489 | $res = $this->futuresBinance->futuresLedger(); 1490 | $this->assertIsArray($res); 1491 | } 1492 | 1493 | public function testTradingStatusFutures() 1494 | { 1495 | $res = $this->futuresBinance->futuresTradingStatus(); 1496 | $this->assertIsArray($res); 1497 | $this->assertArrayHasKey('indicators', $res); 1498 | $this->assertIsArray($res['indicators']); 1499 | $this->assertArrayHasKey('updateTime', $res); 1500 | $this->assertIsInt($res['updateTime']); 1501 | } 1502 | 1503 | public function testFeeBurnStatusFutures() 1504 | { 1505 | $res = $this->futuresBinance->futuresFeeBurnStatus(); 1506 | $this->assertIsArray($res); 1507 | $this->assertArrayHasKey('feeBurn', $res); 1508 | $this->assertIsBool($res['feeBurn']); 1509 | } 1510 | } 1511 | --------------------------------------------------------------------------------