{"id":18895636,"url":"https://github.com/binance/binance-connector-ruby","last_synced_at":"2025-04-04T18:08:46.564Z","repository":{"id":38210115,"uuid":"426814034","full_name":"binance/binance-connector-ruby","owner":"binance","description":"A simple connector to Binance Public API","archived":false,"fork":false,"pushed_at":"2025-01-13T11:48:19.000Z","size":224,"stargazers_count":40,"open_issues_count":2,"forks_count":23,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-28T17:10:05.015Z","etag":null,"topics":["api","binance","connector","crypto","library","market-data","real-time","ruby","trading"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/binance.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","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":"2021-11-10T23:53:02.000Z","updated_at":"2025-03-26T09:50:41.000Z","dependencies_parsed_at":"2024-04-10T02:35:19.653Z","dependency_job_id":"201cbfee-0dda-4e2d-8031-37b592c0f229","html_url":"https://github.com/binance/binance-connector-ruby","commit_stats":{"total_commits":25,"total_committers":4,"mean_commits":6.25,"dds":0.52,"last_synced_commit":"d400ee243ab2a7f103eb53adef8700e9b0e505b0"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-connector-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-connector-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-connector-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-connector-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binance","download_url":"https://codeload.github.com/binance/binance-connector-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247226215,"owners_count":20904465,"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","connector","crypto","library","market-data","real-time","ruby","trading"],"created_at":"2024-11-08T08:29:10.461Z","updated_at":"2025-04-04T18:08:46.540Z","avatar_url":"https://github.com/binance.png","language":"Ruby","readme":"# Binance Connector Ruby\n\n[![Gem Version](https://badge.fury.io/rb/binance-connector-ruby.svg)](https://badge.fury.io/rb/binance-connector-ruby)\n[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop-hq/rubocop)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nThis is a lightweight library that works as a connector to [Binance public API](https://github.com/binance/binance-spot-api-docs). It’s designed to be simple, clean, and easy to use with minimal dependencies.\n\n- Supported APIs:\n    - `/api/*`\n    - `/sapi/*`\n    - Spot Websocket Market Stream\n    - Spot User Data Stream\n- Inclusion of test cases and examples\n- Customizable base URL, request timeout\n- Response metadata can be displayed\n- Customizable Logger\n\n## Installation\n\n1. Include the library in Gemfile and then install it when execute the bundler.\n\n\tAdd this line in the Gemfile.\n\n\t```ruby\n\tgem 'binance-connector-ruby'\n\t```\n\n\tAnd then execute the bundler via CLI:\n\n  ```shell\n   bundle\n  ```\n2. Install it with CLI:\n  ```shell\n  gem install binance-connector-ruby\n  ```\n\n## Documentation\n\n[https://www.rubydoc.info/gems/binance-connector-ruby](https://www.rubydoc.info/gems/binance-connector-ruby)\n\n## Restful APIs\n\n```ruby\nrequire 'binance'\n\n# Create a new client instance.\n# If the APIs do not require the keys, (e.g. market data), key and secret can be omitted.\nclient = Binance::Spot.new(key: key, secret: secret)\n\n# Send a request to query server time\nputs client.time\n\n# Send a request to query BTCUSDT ticker\nputs client.ticker_24hr(symbol: 'BTCUSDT')\n\n# Send a request to get account information\nputs client.account\n\n# Place an order\nresponse = client.new_order(symbol: 'BNBUSDT', side: 'BUY', price: 20, quantity: 1, type: 'LIMIT', timeInForce: 'GTC')\n```\n\n\nPlease find `examples` folder to check for more endpoints.\n\n\n### Testnet\n\nWhile `/sapi/*` endpoints don't have testnet environment yet, `/api/*` endpoints can be tested in \n[Spot Testnet](https://testnet.binance.vision/). You can use it by changing the base URL:\n\n```ruby\nclient = Binance::Spot.new(base_url: 'https://testnet.binance.vision')\nputs client.time\n```\n\n### Base URL\n\nIf `base_url` is not provided, it defaults to `api.binance.com`.\n\nIt's recommended to pass in the `base_url` parameter, even in production as Binance provides alternative URLs in case of performance issues:\n\n- `https://api1.binance.com`\n- `https://api2.binance.com`\n- `https://api3.binance.com`\n\n### RSA Signature\n\nBinance support both HMAC and RSA signature. Please find the example at `examples/trade/account.rb` for how to sign in both solutions.\n\n### RecvWindow\n\nFrom Binance API, recvWindow is available for all endpoints require signature. By default, it's 5000ms.\nYou are allowed to set this parameter to any value less than 60000, number beyond this limit will receive error from Binance server.\n```ruby\n\nresponse = client.account(recvWindow: 2_000)\n\n```\n\n### Optional parameters\n\nFor the optional parameters in the endpoint, pass exactly the field name from API document into method.\ne.g\n\n```ruby\nclient = Binance::Spot.new\n\n# correct\nresponse = client.cancel_order(symbol: 'BNBUSDT', orderId: 25)\n\n# this is incorrect\nresponse = client.cancel_order(symbol: 'BNBUSDT', order_id: 25)\n```\n\n### Timeout\n\nTimeout (unit: second) can be specified when initializing a client instance. If `timeout` is not set, the default is **no timeout**.\n\n```ruby\nclient = Binance::Spot.new(timeout: 2)\n```\n\n### Response Metadata\n\nThe Binance API server provides weight usages in the headers of each response. This information can be fetched from `headers` property. `x-mbx-used-weight` and `x-mbx-used-weight-1m` show the total weight consumed within 1 minute. This is very useful to indentify the current usage.\nTo display this value, specify `show_weight_usage: true` when intializing a new client instance.\n\n```ruby\nclient = Binance::Spot.new(show_weight_usage: true)\n```\n\nThen, take server time API (`GET /api/v3/time`) as an example, the response data is shown as below:\n\n```ruby\n{:data=\u003e{:serverTime=\u003e1589860878546}, :weight_usage=\u003e{\"x-mbx-used-weight\"=\u003e\"1\", \"x-mbx-used-weight-1m\"=\u003e\"1\"}}\n```\n\nWhen `show_header: true`, the library has the ability to print out all response headers, which may be very helpful for debugging the program.\n\n```ruby\nclient = Binance::Spot.new(show_header: true)\n```\n\nThen, take the same example as above, the response data becomes:\n\n```ruby\n{:data=\u003e{:serverTime=\u003e1589863539220}, :header=\u003e{\"content-type\"=\u003e\"application/json;charset=utf-8\",...}}\n```\n\n### Custom Logger Integration\n\nThe client class accepts a [Logger](https://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/Logger.html) instance as an input parameter.\n\n```ruby\nlogger = Logger.new(STDOUT)\nclient = Binance::Spot.new(logger: logger)\nlogger.info(client.time)\n```\n\n### Exception\n\nThere are 3 types of exceptions:\n- `Binance::RequiredParameterError`\n  - When missing required param\n  - Not sending out the request\n- `Binance::ClientError`\n  - This is thrown when API server returns `4XX`, it's an issue from client side.\n  - The following properties may be helpful to resolve the issue:\n    - Response header - Please refer to `Response Metadata` section for more details.\n    - HTTP status code\n    - Error code - Server's error code, e.g. `-1102`\n    - Error message - Server's error message, e.g. `Unknown order sent.`\n    - Request config - Configuration send to the server, which can include URL, request method and headers.\n- `Binance::ServerError`\n  - When API server returning 5XX\n  - sending out the request\n\nThey all inherit from `Binance::Error`\n\n```ruby\nbegin\n  response = client.time\nrescue Binance::ClientError =\u003e e\n  e.response[:status]\n  e.response[:headers]\n  e.response[:body]\nend\n```\n\n## Websocket\n\n```ruby\nrequire 'binance'\nrequire 'eventmachine'\n\nclient = Binance::Spot::WebSocket.new\n\nEM.run do\n  onopen = proc { logger.info('connected to server') }\n  onmessage = proc { |msg, _type| logger.info(msg) }\n  onerror   = proc { |e| logger.error(e) }\n  onclose   = proc { logger.info('connection closed') }\n\n  callbacks = {\n    onopen: onopen,\n    onmessage: onmessage,\n    onerror: onerror,\n    onclose: onclose\n  }\n\n  client.kline(symbol: 'btcusdt', interval: '30m', callbacks: callbacks)\nend\n```\n\nMore websocket examples are available in the `examples` folder\n\n### Auto response\nBinance requires `pong` for heartbeat, response is sent automatically.\n\n## Limitation\n\nFutures and Vanilla Options APIs are not supported:\n\n  - `/fapi/*`\n  - `/dapi/*`\n  - `/vapi/*`\n  -  Associated Websocket Market and User Data Streams\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinance%2Fbinance-connector-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinance%2Fbinance-connector-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinance%2Fbinance-connector-ruby/lists"}