### Install Binance Go Connector Source: https://github.com/binance/binance-connector-go Instructions on how to install the Binance Go Connector library using go get and how to import it into your Go project. ```go go get github.com/binance/binance-connector-go import ( "github.com/binance/binance-connector-go" ) ``` -------------------------------- ### Install Binance Connector Go Source: https://github.com/binance/binance-connector-go Installs the Binance Connector Go library using the go get command. This is the first step to integrate Binance API functionality into your Go projects. ```shell go get github.com/binance/binance-connector-go ``` -------------------------------- ### Install Binance Futures Connector Source: https://github.com/binance/binance-futures-connector-python Installs the Binance Futures Connector library using pip. This is the primary step to get started with the library for interacting with Binance Futures APIs. ```shell pip install binance-futures-connector ``` -------------------------------- ### Install Binance Spot Connector Source: https://github.com/binance/binance-connector-js Demonstrates how to install the Binance Spot Trading connector package using npm. This is a common starting point for integrating with Binance's trading services. ```bash npm install @binance/spot ``` -------------------------------- ### Binance .NET Logging Example Source: https://github.com/binance/binance-connector-dotnet Demonstrates how to integrate the Binance .NET SDK with a logging handler. This example shows the setup of a `BinanceLoggingHandler` with an `ILogger` and an `HttpClient` to enable logging for Binance API calls, such as `Wallet.SystemStatus()`. ```cs using System; using System.Net; using System.Net.Http; using Binance.Spot; public async Task LoggingExample(ILogger logger) { BinanceLoggingHandler loggingHandler = new BinanceLoggingHandler(logger: logger); HttpClient httpClient = new HttpClient(handler: loggingHandler); Wallet wallet = new Wallet(httpClient: httpClient); await wallet.SystemStatus(); } ``` -------------------------------- ### Binance Futures Connector Python Examples Source: https://github.com/binance/binance-futures-connector-python Demonstrates how to use the Binance Futures Connector library in Python. It covers initializing the client, fetching server time, getting account information, and placing a new order. Requires API keys for authenticated requests. ```python from binance.cm_futures import CMFutures cm_futures_client = CMFutures() # get server time print(cm_futures_client.time()) cm_futures_client = CMFutures(key='', secret='') # Get account information print(cm_futures_client.account()) # Post a new order params = { 'symbol': 'BTCUSDT', 'side': 'SELL', 'type': 'LIMIT', 'timeInForce': 'GTC', 'quantity': 0.002, 'price': 59808 } response = cm_futures_client.new_order(**params) print(response) ``` -------------------------------- ### Connect to Binance RESTful APIs using C# Source: https://github.com/binance/binance-connector-dotnet Demonstrates how to initialize the Binance Spot API connector and fetch the server time. This example uses the Market class to make a GET request to the Binance API. ```csharp using System; using System.Threading.Tasks; using Binance.Spot; class Program { static async Task Main(string[] args) { Market market = new Market(); string serverTime = await market.CheckServerTime(); Console.WriteLine(serverTime); } } ``` -------------------------------- ### Initialize Binance Go Client Source: https://github.com/binance/binance-connector-go Demonstrates the basic initialization of the Binance client using API keys and an optional base URL. ```go // The Client can be initiated with apiKey, secretKey and baseURL. // The baseURL is optional. If not specified, it will default to "https://api.binance.com". client := binance_connector.NewClient("yourApiKey", "yourSecretKey") ``` -------------------------------- ### Local Swagger UI Setup Script Source: https://github.com/binance/binance-api-swagger This snippet shows the command to run locally to set up and start the Swagger UI instance. It requires Docker to be installed. ```bash ./start.sh ``` -------------------------------- ### Instantiate Binance Spot Wallet for Testnet Source: https://github.com/binance/binance-connector-dotnet Demonstrates how to initialize the Binance Spot client using the C# SDK, specifically targeting the testnet environment by providing the testnet base URL. ```cs using Binance.Spot; Wallet wallet = new Wallet(baseUrl: "https://testnet.binance.vision"); ``` -------------------------------- ### Get Auto-repay Futures Status Response Example Source: https://context7_llms Example JSON response for the Get Auto-repay Futures Status API endpoint. It indicates whether auto-repay for futures is enabled or disabled. ```JSON { "autoRepay": true // "true" for turn on the auto-repay futures; "false" for turn off the auto-repay futures } ``` -------------------------------- ### Python Websocket Client Setup Source: https://github.com/binance/binance-sbe-rust-sample-app Instructions for setting up the Python environment to run websocket scripts. Requires the 'websocket-client' package for the 'create_connection' function. ```python import websocket # Example usage of create_connection (requires websocket-client package) # ws = websocket.create_connection("ws://echo.websocket.org/") # print(ws.recv()) # ws.close() ``` -------------------------------- ### Initialize Binance Client and Create Market Order (Go) Source: https://github.com/binance/binance-connector-go Demonstrates how to initialize the Binance Connector Go client with API keys and base URL, and then create a market buy order for BTCUSDT. Includes error handling and printing the order response. ```go package main import ( "context" "fmt" "github.com/binance/binance-connector-go" ) func main() { apiKey := "yourApiKey" secretKey := "yourSecretKey" baseURL := "https://testnet.binance.vision" // Initialise the client client := binance_connector.NewClient(apiKey, secretKey, baseURL) // Create new order newOrder, err := client.NewCreateOrderService(). Symbol("BTCUSDT"). Side("BUY"). Type("MARKET"). Quantity(0.001). Do(context.Background()) if err != nil { fmt.Println(err) return } fmt.Println(binance_connector.PrettyPrint(newOrder)) } ``` -------------------------------- ### Install Multiple Binance SDKs with Pip Source: https://github.com/binance/binance-connector-python Installs multiple Binance SDK connectors simultaneously using pip. This allows for efficient setup of several client libraries at once. ```shell pip install binance-sdk-spot binance-sdk-margin-trading binance-sdk-staking ``` -------------------------------- ### Binance Futures Connector Installation Source: https://github.com/binance/binance-futures-connector-python Installs the Binance Futures Public API Connector Python library using pip. This is the primary method to get the library into your Python environment. ```bash pip install binance-futures-connector ``` -------------------------------- ### Binance API: Get Income History Response Example Source: https://context7_llms Provides an example JSON structure for the Binance API's Get Income History endpoint. It details the fields returned for each income record, such as symbol, income type, amount, asset, and timestamps, used in futures trading. ```JSON [ { "symbol": "", // trade symbol, if existing "incomeType": "TRANSFER", // income type "income": "-0.37500000", // income amount "asset": "BTC", // income asset "info":"WITHDRAW", // extra information "time": 1570608000000, "tranId":"9689322392", // transaction id "tradeId": "" // trade id, if existing }, { "symbol": "BTCUSD_200925", "incomeType": "COMMISSION", "income": "-0.01000000", "asset": "BTC", "info":"", "time": 1570636800000, "tranId":"9689322392", "tradeId":"2059192" } ] ``` -------------------------------- ### Initialize Binance Go Client with Base URL Source: https://github.com/binance/binance-connector-go Shows how to initialize the Binance client with API keys and a specific base URL, along with optional configurations like Debug mode and TimeOffset. ```go client := binance_connector.NewClient("yourApiKey", "yourSecretKey", "https://api.binance.com") // Debug Mode client.Debug = true // TimeOffset (in milliseconds) - used to adjust the request timestamp by subtracting/adding the current time with it: client.TimeOffset = -1000 // implies adding: request timestamp = current time - (-1000) ``` -------------------------------- ### Install Binance Connectors Source: https://github.com/binance/binance-connector-python Instructions for installing Binance SDK connectors using pip or poetry. Multiple connectors can be installed simultaneously. ```shell pip install binance-sdk-spot ``` ```shell poetry add binance-sdk-spot ``` ```shell pip install binance-sdk-spot binance-sdk-margin-trading binance-sdk-staking ``` ```shell poetry add binance-sdk-spot binance-sdk-margin-trading binance-sdk-staking ``` -------------------------------- ### Install Binance Rust SDK with All Features Source: https://github.com/binance/binance-spot-connector-rust Shows how to include all available connectors and features for the Binance Rust SDK by using the 'all' feature flag in Cargo.toml. ```toml [dependencies] binance-sdk = { version = "1.0.0", features = ["all"] } ``` -------------------------------- ### Margin Interest History Response Example Source: https://context7_llms Example JSON structure for the response of the Get Margin Borrow/Loan Interest History API. ```JSON { "rows": [ { "txId": 1352286576452864727, "interestAccuredTime": 1672160400000, "asset": "USDT", "rawAsset": "USDT", "principal": "45.3313", "interest": "0.00024995", "interestRate": "0.00013233", "type": "ON_BORROW" } ], "total": 1 } ``` -------------------------------- ### Create Spot Order Example Source: https://github.com/binance/binance-connector-go A Go code example demonstrating how to create a new market order for a specified symbol using the Binance Go Connector. ```go package main import ( "context" "fmt" binance_connector "github.com/binance/binance-connector-go" ) func main() { apiKey := "yourApiKey" secretKey := "yourSecretKey" baseURL := "https://testnet.binance.vision" // Initialise the client client := binance_connector.NewClient(apiKey, secretKey, baseURL) // Create new order newOrder, err := client.NewCreateOrderService().Symbol("BTCUSDT"). Side("BUY").Type("MARKET").Quantity(0.001). Do(context.Background()) if err != nil { fmt.Println(err) return } fmt.Println(binance_connector.PrettyPrint(newOrder)) } ``` -------------------------------- ### PHP SpotRestApi Client Setup with Proxies Source: https://github.com/binance/binance-connector-php Demonstrates how to initialize the Binance Spot REST API client in PHP. It shows the process of building the configuration, defining proxy settings, applying them to the configuration, and then creating an instance of the SpotRestApi client. ```php $configurationBuilder = SpotRestApiUtil::getConfigurationBuilder(); // define the proxies $proxies = [ 'http' => 'http://localhost:8080', 'https' => 'http://localhost:8080', ]; $configurationBuilder->setProxy($proxies); $api = new SpotRestApi($configurationBuilder->build()); ``` -------------------------------- ### Get User Commission Rate Response Example Source: https://context7_llms Example JSON response structure for retrieving user commission rates for a specific symbol on Binance derivatives. ```JSON { "symbol": "BTCUSD_PERP", "makerCommissionRate": "0.00015", // 0.015% "takerCommissionRate": "0.00040" // 0.040% } ``` -------------------------------- ### WebSocket Client with Proxy Configuration (Python) Source: https://github.com/binance/binance-futures-connector-python Shows how to configure the Binance WebSocket client for futures trading with proxy support. Includes examples for basic proxy setup and proxy setup with authentication, and initializing the client. ```python proxies = { 'http': 'http://1.2.3.4:8080' } # WebSocket Stream Client import logging from binance.websocket.um_futures.websocket_client import UMFuturesWebsocketClient def message_handler(_, message): logging.info(message) my_client = UMFuturesWebsocketClient(proxies=proxies) # Example of proxy with authentication # proxies = { 'http': 'http://username:password@host:port' } ``` -------------------------------- ### Install Binance Spot Connector Source: https://github.com/binance/binance-connector-js Installs the Binance Spot connector package using npm. This command is used to set up the necessary client for interacting with Binance's spot trading services. ```shell npm install @binance/spot ``` -------------------------------- ### Binance FIX Message Example Source: https://context7_llms An example of a FIX (Financial Information eXchange) message used in the Binance API. The '|' character represents the Start of Header (SOH) delimiter. ```FIX 8=FIX.4.4|9=113|35=A|34=1|49=SPOT|52=20240612-08:52:21.636837|56=5JQmUOsm|98=0|108=30|25037=4392a152-3481-4499-921a-6d42c50702e2|10=051| ``` -------------------------------- ### Java Example: Setting Up Authenticated HTTP Proxy Source: https://github.com/binance/binance-futures-connector-java Shows how to configure an authenticated HTTP proxy using OkHttp's Authenticator. ```Java CMFuturesClientImpl client = new CMFuturesClientImpl(); Proxy proxyConn = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8080)); Authenticator auth = new Authenticator() { public Request authenticate(Route route, Response response) throws IOException { if (response.request().header("Proxy-Authorization") != null) { return null; // Give up, we've already failed to authenticate. } String credential = Credentials.basic("username", "password"); return response.request().newBuilder().header("Proxy-Authorization", credential).build(); } }; ProxyAuth proxy = new ProxyAuth(proxyConn, auth); client.setProxy(proxy); logger.info(client.market().time()); ``` -------------------------------- ### Binance Get Market Maker Protection Config Response Source: https://context7_llms Example JSON response structure for the Get Market Maker Protection Config endpoint, detailing protection parameters. ```JSON { "underlyingId": 2, "underlying": "BTCUSDT", "windowTimeInMilliseconds": 3000, "frozenTimeInMilliseconds": 300000, "qtyLimit": "2", "deltaLimit": "2.3", "lastTriggerTime": 0 } ``` -------------------------------- ### GitHub Code Search Syntax Tips Link Source: https://github.com/binance/binance-spot-api-docs/blob/master/faqs/stp_faq Provides a link to external documentation offering tips on how to effectively use GitHub's code search syntax. ```html ``` -------------------------------- ### Java Example: Setting Up HTTP Proxy Source: https://github.com/binance/binance-futures-connector-java Illustrates how to configure an HTTP proxy for API requests. ```Java CMFuturesClientImpl client = new CMFuturesClientImpl(); Proxy proxyConn = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8080)); ProxyAuth proxy = new ProxyAuth(proxyConn, null); client.setProxy(proxy); logger.info(client.market().time()); ``` -------------------------------- ### Binance Spot API: AggTrades and MyTrades Error Message Source: https://context7_llms Details changes to the GET /api/v3/aggTrades endpoint and provides an example of updated error messaging for the GET /api/v3/myTrades endpoint when the 'symbol' parameter is missing. ```APIDOC GET /api/v3/aggTrades - When `startTime` and `endTime` are provided, the oldest items are returned. GET /api/v3/myTrades - Changed error messaging when parameter `symbol` is not provided. ``` -------------------------------- ### Configure Binance API Client with Credentials Source: https://github.com/binance/binance-connector-php Demonstrates how to initialize the Binance Spot REST API client using a configuration builder. It shows setting API keys, private keys (from a file), and optionally a private key password for authentication. ```php $configurationBuilder = SpotRestApiUtil::getConfigurationBuilder(); // Set API key $configurationBuilder->apiKey('YOUR_API_KEY'); // Set private key from a file $configurationBuilder->privateKey('file:///path/to/your/private.key'); // If the private key is protected by a password $configurationBuilder->privateKeyPass('YOUR_PRIVATE_KEY_PASSWORD'); // Build the API client instance $api = new SpotRestApi($configurationBuilder->build()); ``` -------------------------------- ### Binance Get Portfolio Margin Asset Leverage API Source: https://context7_llms Retrieves the leverage information for assets within the Portfolio Margin Pro program. Specifies the HTTP GET request method and provides an example response structure. ```APIDOC Get Portfolio Margin Asset Leverage (USER_DATA): HTTP Request: GET /sapi/v1/portfolio/margin-asset-leverage Request Weight(IP): 50 Response Example: [ { "asset": "USDC", "leverage": 10 }, { "asset": "USDT", "leverage": 10 } ] ``` -------------------------------- ### Binance Connector .NET Logging Usage Example Source: https://github.com/binance/binance-connector-dotnet Demonstrates how to use the Binance .NET connector's logging handler. It shows the setup of a custom logging handler with HttpClient and the initialization of a Wallet client for API interactions. This example requires the ILogger interface from the .NET logging API. ```C# using System; using System.Net; using System.Net.Http; using Binance.Spot; public async Task LoggingExample(ILogger logger) { BinanceLoggingHandler loggingHandler = new BinanceLoggingHandler(logger: logger); HttpClient httpClient = new HttpClient(handler: loggingHandler); Wallet wallet = new Wallet(httpClient: httpClient); await wallet.SystemStatus(); } ``` -------------------------------- ### Binance API GET Request Example Source: https://github.com/binance/binance-connector-dotnet This entry details a sample GET request made to the Binance API. It includes the request method, URI with timestamp and signature, HTTP version, content details, status code, reason phrase, and the JSON response body indicating a successful operation. ```APIDOC Method: GET, RequestUri: 'https://www.binance.com/?timestamp=1631525776809&signature=f07558c98cb82bcb3556a6a21b8a8a2582bae93d0bb9604a0df72cae8c1c6642', Version: 1.1, Content: , Headers: { } StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: , Headers: {} {"status": 0,"msg": "normal"} ``` -------------------------------- ### Initialize Binance Client in Go Source: https://github.com/binance/binance-connector-go Demonstrates how to initialize the Binance Connector Go client with API keys, secret key, and base URL. It also shows how to enable debug mode and set a time offset for request timestamps. ```go client := binance_connector.NewClient("yourApiKey", "yourSecretKey", "https://api.binance.com") // Debug Mode client.Debug = true // TimeOffset (in milliseconds) - used to adjust the request timestamp by subtracting/adding the current time with it: client.TimeOffset = -1000 // implies adding: request timestamp = current time - (-1000) ``` -------------------------------- ### Binance Income History API Response Example Source: https://context7_llms Provides an example of the JSON response structure for the Get Income History API endpoint on Binance Derivatives. It details fields like symbol, income type, amount, asset, and transaction ID for different income events. ```JSON [ { "symbol": "", // trade symbol, if existing "incomeType": "TRANSFER", // income type "income": "-0.37500000", // income amount "asset": "USDT", // income asset "info":"TRANSFER", // extra information "time": 1570608000000, "tranId":9689322392, // transaction id "tradeId":"" // trade id, if existing }, { "symbol": "BTCUSDT", "incomeType": "COMMISSION", "income": "-0.01000000", "asset": "USDT", "info":"COMMISSION", "time": 1570636800000, "tranId":9689322392, "tradeId":"2059192" } ] ``` -------------------------------- ### Initialize WebSocket Client with Proxy Source: https://github.com/binance/binance-futures-connector-python Demonstrates initializing the UMFuturesWebsocketClient with proxy settings. It shows the required dictionary format for the 'proxies' parameter, including support for authentication, and how to subscribe to a symbol stream. ```python import time from binance.websocket.um_futures.websocket_client import UMFuturesWebsocketClient import logging proxies = {'http': 'http://1.2.3.4:8080'} def message_handler(_, message): logging.info(message) my_client = UMFuturesWebsocketClient(on_message=message_handler, proxies=proxies) # Subscribe to a single symbol stream my_client.agg_trade(symbol="bnbusdt") time.sleep(5) logging.info("closing ws connection") my_client.stop() ```