{"id":18895649,"url":"https://github.com/binance/binance-connector-dotnet","last_synced_at":"2025-04-06T16:12:47.959Z","repository":{"id":39710319,"uuid":"422855242","full_name":"binance/binance-connector-dotnet","owner":"binance","description":"Lightweight connector for integration with Binance API","archived":false,"fork":false,"pushed_at":"2024-06-18T09:07:31.000Z","size":420,"stargazers_count":235,"open_issues_count":7,"forks_count":74,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-03-30T13:10:09.423Z","etag":null,"topics":["api","binance","binance-api","crypto","dotnet","library","market-data","real-time","spot","trading","websocket"],"latest_commit_sha":null,"homepage":"","language":"C#","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":null,"funding":null,"license":"LICENSE.md","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-10-30T10:55:18.000Z","updated_at":"2025-03-27T01:00:38.000Z","dependencies_parsed_at":"2024-06-18T10:26:55.114Z","dependency_job_id":null,"html_url":"https://github.com/binance/binance-connector-dotnet","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-connector-dotnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-connector-dotnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-connector-dotnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-connector-dotnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binance","download_url":"https://codeload.github.com/binance/binance-connector-dotnet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247509235,"owners_count":20950232,"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","binance-api","crypto","dotnet","library","market-data","real-time","spot","trading","websocket"],"created_at":"2024-11-08T08:29:14.771Z","updated_at":"2025-04-06T16:12:47.936Z","avatar_url":"https://github.com/binance.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Binance Public API Connector DotNET\n\n[![[Nuget]](https://img.shields.io/nuget/v/Binance.Spot)](https://www.nuget.org/packages/Binance.Spot)\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)\n\n- Supported APIs:\n    - `/api/*`\n    - `/sapi/*`\n    - Spot WebSocket Market Stream\n    - Spot User Data Stream\n    - Spot WebSocket API\n- Test cases and examples\n- Customizable base URL, request timeout and HTTP proxy\n- Response Metadata\n\n\n## Installation\n\n```bash\ndotnet add package Binance.Spot\n```\n\n## RESTful APIs\n\nUsage example\n```csharp\nusing System;\nusing System.Threading.Tasks;\nusing Binance.Spot;\n\nclass Program\n{\n    static async Task Main(string[] args)\n    {\n        Market market = new Market();\n\n        string serverTime = await market.CheckServerTime();\n\n        Console.WriteLine(serverTime);\n    }\n}\n```\n\nPlease find `Examples` folder to check for more endpoints.\n\n## WebSocket Stream\n\nUsage Example\n```csharp\nusing System;\nusing System.Threading;\nusing System.Threading.Tasks;\nusing Binance.Spot;\n\nclass Program\n{\n    static async Task Main(string[] args)\n    {\n        var websocket = new MarketDataWebSocket(\"btcusdt@aggTrade\");\n\n        websocket.OnMessageReceived(\n            (data) =\u003e\n        {\n            Console.WriteLine(data);\n\n            return Task.CompletedTask;\n        }, CancellationToken.None);\n\n        await websocket.ConnectAsync(CancellationToken.None);\n    }\n}\n```\nMore websocket examples are available in the `Examples` folder\n\n## WebSocket API\n\nUsage Example\n```csharp\nusing System.Threading;\nusing System.Threading.Tasks;\nusing Binance.Common;\nusing Binance.Spot;\n\npublic class NewOrder_Example\n{\n    public static async Task Main(string[] args)\n    {\n        var websocket = new WebSocketApi(\"wss://ws-api.testnet.binance.vision/ws-api/v3\", \"apiKey\", new BinanceHmac(\"apiSecret\"));\n\n        websocket.OnMessageReceived(\n            async (data) =\u003e\n        {\n            Console.WriteLine(data);\n            await Task.CompletedTask;\n        }, CancellationToken.None);\n\n        await websocket.ConnectAsync(CancellationToken.None);\n\n        await websocket.AccountTrade.NewOrderAsync(symbol: \"BNBUSDT\", side: Models.Side.BUY, type: Models.OrderType.LIMIT, timeInForce: Models.TimeInForce.GTC, price: 300, quantity: 1, cancellationToken: CancellationToken.None);\n\n        await Task.Delay(5000);\n        Console.WriteLine(\"Disconnect with WebSocket API Server\");\n        await websocket.DisconnectAsync(CancellationToken.None);\n    }\n}\n```\n\n- The `requestId` param is optional. If not sent, it defaults to a randomly created `GUID` (Globally Unique Identifier).\n- The `cancellationToken` is optional. If not sent, it defaults to `CancellationToken.None`.\n\nMore websocket API examples are available in the `Examples` folder\n\n## Authentication - RESTful APIs\n\nFor API endpoints that requires signature, new authentication interfaces are introduced to generate the signature since V2.\n\n```csharp\n// HMAC signature\nnew SpotAccountTrade(httpClient, new BinanceHmac(\"apiSecret\"), apiKey: \"apiKey\")\n\n// RSA signature\nstring privateKey = File.ReadAllText(\"/Users/john/ssl/PrivateKey.pem\");\nnew SpotAccountTrade(httpClient, new BinanceRsa(privateKey), apiKey: \"apiKey\")\n\n// Encrypted RSA signature\nnew SpotAccountTrade(httpClient, new BinanceRsa(privateKey, \"thePrivateKeyPassword\"), apiKey: \"apiKey\")\n\n```\n\nFor V1.x, it's required to pass `apiKey` and `apiSecret` directly.\n\n```csharp\nnew SpotAccountTrade(httpClient, apiKey: apiKey, apiSecret: apiSecret)\n```\n\nFor more details, please find the example from the endpoints `/api/v3/account` in file `AccountInformation_Example`.\n\n## Authentication - WebSocket API\n\n```csharp\n// HMAC signature\nnew WebSocketApi(apiKey: \"apiKey\", signatureService: new BinanceHmac(\"apiSecret\"));\n\n// RSA signature\nstring privateKey = File.ReadAllText(\"/Users/john/ssl/PrivateKey.pem\");\nnew WebSocketApi(apiKey: \"apiKey\", signatureService: new BinanceRsa(privateKey));\n\n// Encrypted RSA signature\nnew WebSocketApi(apiKey: \"apiKey\", signatureService: new BinanceRsa(privateKey, \"thePrivateKeyPassword\"));\n\n```\n\n### Heartbeat\n\nOnce connected, the websocket server sends a ping frame every 3 minutes and requires a response pong frame back within\na 10 minutes period. This package handles the pong responses automatically.\n\n### Testnet\n\n[Spot Testnet](https://testnet.binance.vision/) can be used to test `/api/*` endpoints, Spot Websocket Stream and WebSocket API.\n\n```csharp\nusing Binance.Spot;\n\nWallet wallet = new Wallet(baseUrl: \"https://testnet.binance.vision\");\n```\n\n### Base URL\n\nIf `baseUrl` is not provided, it defaults to `https://api.binance.com`.\n\nIt's recommended to pass in the `baseUrl` parameter, even in production as Binance provides alternative URLs\nin case of performance issues:\n- `https://api1.binance.com`\n- `https://api2.binance.com`\n- `https://api3.binance.com`\n- `https://api4.binance.com`\n\nFor Websocket Stream, `baseUrl` defaults to `wss://stream.binance.com:9443\"`.\nFor Websocket API, `baseUrl` defaults to `wss://ws-api.binance.com:443/ws-api/v3`.\n\n### RecvWindow parameter\n\nAdditional parameter `recvWindow` is available for endpoints requiring signature.\n\nIt defaults to `5000` (milliseconds) and can be any value lower than `60000`(milliseconds).\nAnything beyond the limit will result in an error response from Binance server.\n\n```csharp\nusing Binance.Spot;\n\nWallet wallet = new Wallet();\n\nawait wallet.AccountStatus(recvWindow=4000)\n```\n\n### Timeout\nThe default timeout is 100,000 milliseconds (100 seconds).  \n\nUsage Example\n```csharp\nusing System;\nusing System.Net.Http;\nusing Binance.Spot;\n\nHttpClient httpClient = new HttpClient() { \n    Timeout = TimeSpan.FromSeconds(10)\n}\n\nWallet wallet = new Wallet(httpClient: httpClient);\n```\n\n### Proxy\nUsage Example\n```csharp\nusing System;\nusing System.Net;\nusing System.Net.Http;\nusing Binance.Spot;\n\nWebProxy proxy = new WebProxy(new Uri(\"http://1.2.3.4:8080\"));\nHttpClientHandler proxyHandler = new HttpClientHandler { Proxy = proxy };\nHttpClient httpClient = new HttpClient(handler: proxyHandler);\n\nWallet wallet = new Wallet(httpClient: httpClient);\n```\n\n### Exceptions\n\nThere are 2 types of exceptions returned from the library:\n- `Binance.Common.BinanceClientException`\n    - This is thrown when server returns `4XX`, it's an issue from client side.\n    - Properties:\n        - `Code` - Server's error code, e.g. `-1102`\n        - `Message` - Server's error message, e.g. `Unknown order sent.`\n- `Binance.Common.BinanceServerException`\n    - This is thrown when server returns `5XX`, it's an issue from server side.\n\nBoth exceptions inherit `Binance.Common.BinanceHttpException` along with the following properties:\n- `StatusCode` - Response http status code, e.g. `401`\n- `Headers` -  Dictionary with response headers\n\n### Logging\nThis library implements the .NET logging API that works with a variety of built-in and third-party logging providers. \n\nFor more information on how to configure logging in .NET, visit [Microsoft's logging article](https://docs.microsoft.com/en-us/dotnet/core/extensions/logging?tabs=command-line)\n\nUsage Example\n```csharp\nusing System;\nusing System.Net;\nusing System.Net.Http;\nusing Binance.Spot;\n\npublic async Task LoggingExample(ILogger logger) {\n    BinanceLoggingHandler loggingHandler = new BinanceLoggingHandler(logger: logger);\n    HttpClient httpClient = new HttpClient(handler: loggingHandler);\n\n    Wallet wallet = new Wallet(httpClient: httpClient);\n\n    await wallet.SystemStatus();\n}\n```\n\nSample Output\n\n\n```\nMethod: GET, RequestUri: 'https://www.binance.com/?timestamp=1631525776809\u0026signature=f07558c98cb82bcb3556a6a21b8a8a2582bae93d0bb9604a0df72cae8c1c6642', Version: 1.1, Content: \u003cnull\u003e, Headers: { }\nStatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: \u003cnull\u003e, Headers: {}\n{\"status\": 0,\"msg\": \"normal\"}\n```\n\n## Test Cases\n\n```bash\ndotnet test\n```\n\n## Limitations\n\nFutures and Vanilla Options APIs are not supported:\n- /fapi/*\n- /dapi/*\n- /vapi/*\n- Associated WebSocket Market and User Data Streams\n\n## Contributing\n\nContributions are welcome.\n\nIf you've found a bug within this project, please open an issue to discuss what you would like to change.\n\nIf it's an issue with the API, please open a topic at [Binance Developer Community](https://dev.binance.vision)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinance%2Fbinance-connector-dotnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinance%2Fbinance-connector-dotnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinance%2Fbinance-connector-dotnet/lists"}