|
| 1 | +# Binance Go Alpha SDK |
| 2 | + |
| 3 | +[](https://github.com/binance/binance-connector-go/actions) |
| 4 | +[](https://github.com/binance/binance-connector-go/issues) |
| 5 | +[](https://github.com/binance/binance-connector-go) |
| 6 | +[](https://github.com/binance/binance-connector-go/security) |
| 7 | +[](https://opensource.org/licenses/MIT) |
| 8 | + |
| 9 | +This is a client library for the Binance Alpha API, enabling developers to interact programmatically with Binance Alpha. The library provides tools to access curated early-stage token data, track Alpha project metrics and integrate discovery-focused market information into applications through the REST API: |
| 10 | + |
| 11 | +- [REST API](./src/restapi/rest_api.go) |
| 12 | + |
| 13 | +## Table of Contents |
| 14 | + |
| 15 | +- [Supported Features](#supported-features) |
| 16 | +- [Installation](#installation) |
| 17 | +- [Documentation](#documentation) |
| 18 | +- [REST APIs](#rest-apis) |
| 19 | +- [Testing](#testing) |
| 20 | +- [Migration Guide](#migration-guide) |
| 21 | +- [Contributing](#contributing) |
| 22 | +- [License](#license) |
| 23 | + |
| 24 | +## Supported Features |
| 25 | + |
| 26 | +- REST API Endpoints: |
| 27 | + - `/bapi/defi/v1/*` |
| 28 | +- Inclusion of test cases and examples for quick onboarding. |
| 29 | + |
| 30 | +## Installation |
| 31 | + |
| 32 | +To use this library, ensure you have Go installed (version **1.24** or higher is recommended). You can install the library using the following command: |
| 33 | + |
| 34 | +```bash |
| 35 | +go get github.com/binance/binance-connector-go/clients/alpha |
| 36 | +``` |
| 37 | + |
| 38 | +## Documentation |
| 39 | + |
| 40 | +For detailed information, refer to the [Binance API Documentation](https://developers.binance.com/docs/alpha). |
| 41 | + |
| 42 | +### REST APIs |
| 43 | + |
| 44 | +All REST API endpoints are available through the [`restapi`](./src/restapi/rest_api.go) module. Note that some endpoints require authentication using your Binance API credentials. |
| 45 | + |
| 46 | +```go |
| 47 | +package main |
| 48 | + |
| 49 | +import ( |
| 50 | + "context" |
| 51 | + "encoding/json" |
| 52 | + "log" |
| 53 | + |
| 54 | + client "github.com/binance/binance-connector-go/clients/alpha" |
| 55 | + "github.com/binance/binance-connector-go/common/common" |
| 56 | +) |
| 57 | + |
| 58 | +func main() { |
| 59 | + GetExchangeInfo() |
| 60 | +} |
| 61 | + |
| 62 | +func GetExchangeInfo() { |
| 63 | + configuration := common.NewConfigurationRestAPI( |
| 64 | + common.WithBasePath(common.AlphaRestApiProdUrl), |
| 65 | + common.WithApiKey("Your API Key"), |
| 66 | + ) |
| 67 | + apiClient := client.NewBinanceAlphaClient( |
| 68 | + client.WithRestAPI(configuration), |
| 69 | + ) |
| 70 | + resp, err := apiClient.RestApi.MarketDataAPI.GetExchangeInfo(context.Background()).Execute() |
| 71 | + if err != nil { |
| 72 | + log.Println(err) |
| 73 | + return |
| 74 | + } |
| 75 | + |
| 76 | + rateLimitsValue, _ := json.MarshalIndent(resp.RateLimits, "", " ") |
| 77 | + log.Printf("Rate limits: %s\n", string(rateLimitsValue)) |
| 78 | + |
| 79 | + dataValue, _ := json.MarshalIndent(resp.Data, "", " ") |
| 80 | + log.Printf("Response: %s\n", string(dataValue)) |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +More examples can be found in the [`examples/restapi`](./examples/restapi/) folder. |
| 85 | + |
| 86 | +#### Configuration Options |
| 87 | + |
| 88 | +The REST API supports the following advanced configuration options: |
| 89 | + |
| 90 | +- `Timeout`: Timeout for requests in milliseconds (default: 1000 ms). |
| 91 | +- `Proxy`: Proxy configuration: |
| 92 | + - `Host`: Proxy server hostname. |
| 93 | + - `Port`: Proxy server port. |
| 94 | + - `Protocol`: Proxy protocol (http or https). |
| 95 | + - `Auth`: Proxy authentication credentials: |
| 96 | + - `Username`: Proxy username. |
| 97 | + - `Password`: Proxy password. |
| 98 | +- `KeepAlive`: Enable HTTP keep-alive (default: true). |
| 99 | +- `Compression`: Enable response compression (default: true). |
| 100 | +- `Retries`: Number of retry attempts for failed requests (default: 3). |
| 101 | +- `Backoff`: Delay in milliseconds between retries (default: 1000 ms). |
| 102 | +- `HTTPSAgent`: Custom HTTPS agent for advanced TLS configuration. |
| 103 | +- `PrivateKey`: RSA or ED25519 private key for authentication. |
| 104 | +- `PrivateKeyPassphrase`: Passphrase for the private key, if encrypted. |
| 105 | + |
| 106 | +##### Timeout |
| 107 | + |
| 108 | +You can configure a timeout for requests in milliseconds. If the request exceeds the specified timeout, it will be aborted. See the [Timeout example](./docs/restapi/timeout.md) for detailed usage. |
| 109 | + |
| 110 | +##### Proxy |
| 111 | + |
| 112 | +The REST API supports HTTP/HTTPS proxy configurations. See the [Proxy example](./docs/restapi/proxy.md) for detailed usage. |
| 113 | + |
| 114 | +##### Keep-Alive |
| 115 | + |
| 116 | +Enable HTTP keep-alive for persistent connections. See the [Keep-Alive example](./docs/restapi/keep-alive.md) for detailed usage. |
| 117 | + |
| 118 | +##### Compression |
| 119 | + |
| 120 | +Enable or disable response compression. See the [Compression example](./docs/restapi/compression.md) for detailed usage. |
| 121 | + |
| 122 | +##### Retries |
| 123 | + |
| 124 | +Configure the number of retry attempts and delay in milliseconds between retries for failed requests. See the [Retries example](./docs/restapi/retries.md) for detailed usage. |
| 125 | + |
| 126 | +##### HTTPS Agent |
| 127 | + |
| 128 | +Customize the HTTPS agent for advanced TLS configurations. See the [HTTPS Agent example](./docs/restapi/https-agent.md) for detailed usage. |
| 129 | + |
| 130 | +##### Key Pair Based Authentication |
| 131 | + |
| 132 | +The REST API supports key pair-based authentication for secure communication. You can use `RSA` or `ED25519` keys for signing requests. See the [Key Pair Based Authentication example](./docs/restapi/key-pair-authentication.md) for detailed usage. |
| 133 | + |
| 134 | +##### Certificate Pinning |
| 135 | + |
| 136 | +To enhance security, you can use certificate pinning with the `HTTPSAgent` option in the configuration. This ensures the client only communicates with servers using specific certificates. See the [Certificate Pinning example](./docs/restapi/certificate-pinning.md) for detailed usage. |
| 137 | + |
| 138 | +#### Error Handling |
| 139 | + |
| 140 | +The REST API provides detailed error types to help you handle issues effectively: |
| 141 | + |
| 142 | +- `ConnectorClientError`: General client error. |
| 143 | +- `RequiredError`: Thrown when a required parameter is missing. |
| 144 | +- `UnauthorizedError`: Indicates missing or invalid authentication credentials. |
| 145 | +- `ForbiddenError`: Access to the requested resource is forbidden. |
| 146 | +- `TooManyRequestsError`: Rate limit exceeded. |
| 147 | +- `RateLimitBanError`: IP address banned for exceeding rate limits. |
| 148 | +- `ServerError`: Internal server error. |
| 149 | +- `NetworkError`: Issues with network connectivity. |
| 150 | +- `NotFoundError`: Resource not found. |
| 151 | +- `BadRequestError`: Invalid request. |
| 152 | + |
| 153 | +See the [Error Handling example](./docs/restapi/error-handling.md) for detailed usage. |
| 154 | + |
| 155 | +If `base_path` is not provided, it defaults to `https://www.binance.com`. |
| 156 | + |
| 157 | +## Testing |
| 158 | + |
| 159 | +To run the test cases, use the following command: |
| 160 | + |
| 161 | +```bash |
| 162 | +go test ./tests/... |
| 163 | +``` |
| 164 | + |
| 165 | +The tests cover: |
| 166 | +- REST API endpoints |
| 167 | +- Error handling and edge cases |
| 168 | + |
| 169 | +## Contributing |
| 170 | + |
| 171 | +Contributions are welcome! |
| 172 | + |
| 173 | +Since this repository contains auto-generated code, we encourage you to start by opening a GitHub issue to discuss your ideas or suggest improvements. This helps ensure that changes align with the project's goals and auto-generation processes. |
| 174 | + |
| 175 | +To contribute: |
| 176 | + |
| 177 | +1. Open a GitHub issue describing your suggestion or the bug you've identified. |
| 178 | +2. If it's determined that changes are necessary, the maintainers will merge the changes into the main branch. |
| 179 | + |
| 180 | +Please ensure that all tests pass if you're making a direct contribution. Submit a pull request only after discussing and confirming the change. |
| 181 | + |
| 182 | +Thank you for your contributions! |
| 183 | + |
| 184 | +## License |
| 185 | + |
| 186 | +This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details. |
0 commit comments