{"id":18895653,"url":"https://github.com/binance/binance-connector-php","last_synced_at":"2025-04-13T05:13:17.901Z","repository":{"id":37926944,"uuid":"493964233","full_name":"binance/binance-connector-php","owner":"binance","description":"This is a thin library that working as a connector to the Binance public API.","archived":false,"fork":false,"pushed_at":"2024-12-17T14:03:40.000Z","size":262,"stargazers_count":87,"open_issues_count":7,"forks_count":23,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-13T05:13:10.681Z","etag":null,"topics":["api","binance-api","connector","crypto","library","market-data","php","real-time","trading"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/binance.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-19T07:22:55.000Z","updated_at":"2025-04-10T09:11:24.000Z","dependencies_parsed_at":"2024-05-30T04:43:57.368Z","dependency_job_id":"b075756a-cd7a-45eb-a736-3cf3893a2f2e","html_url":"https://github.com/binance/binance-connector-php","commit_stats":{"total_commits":16,"total_committers":3,"mean_commits":5.333333333333333,"dds":0.125,"last_synced_commit":"912673d2c679bb7c1f3879e8ad2dd741ddabe12f"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-connector-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-connector-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-connector-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-connector-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binance","download_url":"https://codeload.github.com/binance/binance-connector-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248665746,"owners_count":21142123,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","binance-api","connector","crypto","library","market-data","php","real-time","trading"],"created_at":"2024-11-08T08:29:15.009Z","updated_at":"2025-04-13T05:13:17.871Z","avatar_url":"https://github.com/binance.png","language":"PHP","readme":"# Binance Connector PHP\n\nThis is a thin library that working as a connector to the Binance public API.\n\n\n## Installation\n\n```php\n\ncomposer require binance/binance-connector-php\n\n```\n\n## How to use\n\n```php\n\nrequire_once 'vendor/autoload.php';\n\n$client = new \\Binance\\Spot();\n$response = $client-\u003etime();\necho json_encode($response);\n\n\n$client = new \\Binance\\Spot(['key' =\u003e $key, 'secret' =\u003e $secret]);\n$response = $client-\u003eaccount();\necho json_encode($response);\n```\n\nPlease find `examples` folder for more endpoints\n\n### RSA Signature\nRSA signature is supported.\n\n```php\n\n# RSA Key(Unencrypted) Authentication\n$key = ''; # api key is also required\n$privateKey = 'file:///path/to/rsa/private/key.pem';\n\n$client = new \\Binance\\Spot([\n    'key'  =\u003e $key,\n    'privateKey'  =\u003e $privateKey, # pass the key file directly\n    'baseURL' =\u003e 'https://testnet.binance.vision'\n]);\n\n# RSA key(Encrypted) Authentication\n$key = '';\n$encryptedPrivateKey = 'file:///path/to/rsa/private/key.pem';\n$privateKey = openssl_pkey_get_private($encryptedPrivateKey, 'password');\n\n$client = new \\Binance\\Spot([\n    'key'  =\u003e $key,\n    'privateKey'  =\u003e $privateKey,\n    'baseURL' =\u003e 'https://testnet.binance.vision'\n]);\n\n```\n\n\n### Testnet\n\nThe [spot testnet](https://testnet.binance.vision/) is available. In order to test on testnet:\n\n```php\n\n$client = new \\Binance\\Spot([\n    'baseURL' =\u003e 'https://testnet.binance.vision'\n]);\n```\n\n### RecvWindow\n\nFrom Binance API, recvWindow is available for all endpoints require signature. By default, it's 5000ms. You are allowed to set this parameter to any value less than 60000, number beyond this limit will receive error from Binance server.\n\n```php\n\n$client = new \\Binance\\Spot(['key' =\u003e $key, 'secret' =\u003e $secret]);\n$response = $client-\u003egetOrder('BNBUSDT', [\n        'orderId'    =\u003e '11',\n        'recvWindow' =\u003e 10000\n    ]\n);\n\n```\n\n### Optional parameters\n\nFor the optional parameters in the endpoint, pass exactly the field name from API document into the optional parameter array. e.g\n\n```php\n\n$response = $client-\u003ecancelOCOOrder('BNBUSDT',\n    [\n        'orderListId' =\u003e '12'\n    ]\n);\n\n```\n\nThe mandartory parameter is validated in the library level, missing required parameter will throw `Binance\\Exception\\MissingArgumentException`.\n\n### Timeout\n\nTime out in seconds.\n\n```php\n\n$client = new \\Binance\\Spot(['timeout' =\u003e 0.5]);\n\n$response = $client-\u003etime();\n\necho json_encode($response);\n\n```\n\n### Display meta info\n\nBinance API server returns weight usage in the header of each response. This is very useful to indentify the current usage. To reveal this value, simpily intial the client with show_weight_usage=True as:\n\n```php\n\n$client = new \\Binance\\Spot(['showWeightUsage' =\u003e true]);\n$response = $client-\u003etime();\necho json_encode($response);\n```\n\nthis will returns:\n\n```json\n{\"data\":{\"serverTime\":1590579807751},\"weight_usage\":{\"x-mbx-used-weight\":[\"2\"],\"x-mbx-used-weight-1m\":[\"2\"]}}\n```\n\nIt's also able to print out all headers, which may be very helpful for debug:\n\n```php\n\n$client = new \\Binance\\Spot(['showHeader' =\u003e true]);\n$response = $client-\u003etime();\necho json_encode($response);\n```\nthe returns will be like:\n\n```json\n\n{\"data\":{\"serverTime\":1590579942001},\"header\":{\"Content-Type\":[\"application/json;charset=utf-8\"],\"Transfer-Encoding\":[\"chunked\"],...}}\n```\n\n## Websocket\n\n```php\n\n$client = new \\Binance\\Websocket\\Spot();\n\n$callbacks = [\n    'message' =\u003e function($conn, $msg){\n        echo $msg.PHP_EOL;\n    },\n    'ping' =\u003e function($conn, $msg) {\n        echo \"received ping from server\".PHP_EOL;\n    }\n];\n\n$client-\u003eaggTrade('btcusdt', $callbacks);\n\n```\n\nIt's able to provide a customlized websocket connector.\n\n```php\n\n$loop = \\React\\EventLoop\\Factory::create();\n$reactConnector = new \\React\\Socket\\Connector($loop);\n$connector = new \\Ratchet\\Client\\Connector($loop, $reactConnector);\n$client = new \\Binance\\Websocket\\Spot(['wsConnector' =\u003e $connector]);\n\n$callbacks = [\n    'message' =\u003e function($conn, $msg){\n        echo \"received message\".PHP_EOL;\n    },\n    'pong' =\u003e function($conn) {\n        echo \"received pong from server\".PHP_EOL;\n    },\n    'ping' =\u003e function($conn) {\n        echo \"received ping from server\".PHP_EOL;\n    },\n    'close' =\u003e function($conn) {\n        echo \"receive closed.\".PHP_EOL;\n    }\n];\n\n$client-\u003eminiTicker('btcusdt', $callbacks);\n\n# send ping to server intervally\n$loop-\u003eaddPeriodicTimer(2, function () use ($client) {\n    $client-\u003eping();\n    echo \"ping sent \".PHP_EOL;\n});\n\n$loop-\u003erun();\n\n```\n\nListen to combined stream:\n```php\n\n$client-\u003ecombined([\n    'btcusdt@miniTicker',\n    'ethusdt@miniTicker'\n], $callbacks);\n\n```\n\n## Test\n\n```shell\n\n# install the packages\ncomposer install\n\nvendor/bin/phpunit\n```\n\n## Limitation\nFutures and Vanilla Options APIs are not supported:\n\n- /fapi/*\n- /dapi/*\n- /vapi/*\n- Associated Websocket Market and User Data Streams\n\n\n## Contributing\nContributions are welcome.\nIf you've found a bug within this project, please open an issue to discuss what you would like to change.\nIf it's an issue with the API, please open a topic at Binance Developer Community\n\n## License\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinance%2Fbinance-connector-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinance%2Fbinance-connector-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinance%2Fbinance-connector-php/lists"}