
Facilitates interaction with the Binance cryptocurrency exchange API, offering type-safe interfaces for REST and WebSocket operations, supporting spot and futures trading, with real-time data streams and comprehensive error handling.
A Kotlin Multiplatform library for interacting with the Binance cryptocurrency exchange API. This SDK provides a clean and type-safe interface for both REST and WebSocket operations, supporting spot and futures trading.
Add the following to your build.gradle.kts:
repositories {
mavenCentral()
}
dependencies {
implementation("com.velkonost:binance-sdk:1.0.0")
}// Initialize the SDK
BinanceSDK.setup(
apiKey = "your_api_key",
apiSecret = "your_api_secret"
)// Check API connectivity
BinanceSDK.General.ping()
// Get futures account balance
val balance = BinanceSDK.Futures.getBalance("USDT")
// Get open positions
val positions = BinanceSDK.Futures.getOpenPositions()
// Subscribe to real-time market data
BinanceSDK.Socket.startListenUpdates("BTCUSDT", KlineInterval.Minute1)The SDK provides comprehensive support for futures trading operations:
// Get account balance for a specific asset
val balance = BinanceSDK.Futures.getBalance("USDT")
// Get all open positions
val positions = BinanceSDK.Futures.getOpenPositions()
// Get available trading symbols
val symbols = BinanceSDK.Futures.getSymbols()
// Get historical kline data
val klines = BinanceSDK.Futures.getKlines(
symbol = "BTCUSDT",
interval = KlineInterval.Minute1,
start = "4 day ago"
)Real-time market data is available through WebSocket connections:
// Start listening to connection state
BinanceSDK.Socket.startListenConnections()
// Subscribe to updates for a specific symbol
BinanceSDK.Socket.startListenUpdates(
symbol = "BTCUSDT",
interval = KlineInterval.Minute1
)
// Subscribe to updates for all available symbols
BinanceSDK.Socket.startListenAllSymbolsUpdates(
delayBetweenLaunches = 1000L,
interval = KlineInterval.Minute1,
logConnectionsState = true
) { update ->
// Handle symbol update
println("Symbol: ${update.symbol}, Price: ${update.kline.close}")
}
// Stop listening to updates
BinanceSDK.Socket.stopListenUpdates("BTCUSDT")The SDK provides comprehensive error handling:
try {
val balance = BinanceSDK.Futures.getBalance("USDT")
} catch (e: BinanceSDKException) {
when (e) {
is BinanceSDKNotInitializedException -> {
// SDK not initialized
}
else -> {
// Handle other SDK exceptions
}
}
}The SDK provides strongly typed models for all API responses:
Kline: Candlestick data with open, high, low, close prices and volumeFuturesBalance: Account balance information for futures tradingFuturesOpenPosition: Detailed information about open positionsSymbolUpdate: Real-time market data updatesInitialization: Always initialize the SDK before use:
BinanceSDK.setup(apiKey, apiSecret)Error Handling: Use try-catch blocks to handle potential exceptions:
try {
// SDK operations
} catch (e: BinanceSDKException) {
// Handle exceptions
}WebSocket Management:
startListenConnections()
stopListenUpdates()
Rate Limiting: Be aware of Binance API rate limits and implement appropriate throttling
Contributions are welcome! Please feel free to submit a Pull Request.
For support, please open an issue in the GitHub repository.
A Kotlin Multiplatform library for interacting with the Binance cryptocurrency exchange API. This SDK provides a clean and type-safe interface for both REST and WebSocket operations, supporting spot and futures trading.
Add the following to your build.gradle.kts:
repositories {
mavenCentral()
}
dependencies {
implementation("com.velkonost:binance-sdk:1.0.0")
}// Initialize the SDK
BinanceSDK.setup(
apiKey = "your_api_key",
apiSecret = "your_api_secret"
)// Check API connectivity
BinanceSDK.General.ping()
// Get futures account balance
val balance = BinanceSDK.Futures.getBalance("USDT")
// Get open positions
val positions = BinanceSDK.Futures.getOpenPositions()
// Subscribe to real-time market data
BinanceSDK.Socket.startListenUpdates("BTCUSDT", KlineInterval.Minute1)The SDK provides comprehensive support for futures trading operations:
// Get account balance for a specific asset
val balance = BinanceSDK.Futures.getBalance("USDT")
// Get all open positions
val positions = BinanceSDK.Futures.getOpenPositions()
// Get available trading symbols
val symbols = BinanceSDK.Futures.getSymbols()
// Get historical kline data
val klines = BinanceSDK.Futures.getKlines(
symbol = "BTCUSDT",
interval = KlineInterval.Minute1,
start = "4 day ago"
)Real-time market data is available through WebSocket connections:
// Start listening to connection state
BinanceSDK.Socket.startListenConnections()
// Subscribe to updates for a specific symbol
BinanceSDK.Socket.startListenUpdates(
symbol = "BTCUSDT",
interval = KlineInterval.Minute1
)
// Subscribe to updates for all available symbols
BinanceSDK.Socket.startListenAllSymbolsUpdates(
delayBetweenLaunches = 1000L,
interval = KlineInterval.Minute1,
logConnectionsState = true
) { update ->
// Handle symbol update
println("Symbol: ${update.symbol}, Price: ${update.kline.close}")
}
// Stop listening to updates
BinanceSDK.Socket.stopListenUpdates("BTCUSDT")The SDK provides comprehensive error handling:
try {
val balance = BinanceSDK.Futures.getBalance("USDT")
} catch (e: BinanceSDKException) {
when (e) {
is BinanceSDKNotInitializedException -> {
// SDK not initialized
}
else -> {
// Handle other SDK exceptions
}
}
}The SDK provides strongly typed models for all API responses:
Kline: Candlestick data with open, high, low, close prices and volumeFuturesBalance: Account balance information for futures tradingFuturesOpenPosition: Detailed information about open positionsSymbolUpdate: Real-time market data updatesInitialization: Always initialize the SDK before use:
BinanceSDK.setup(apiKey, apiSecret)Error Handling: Use try-catch blocks to handle potential exceptions:
try {
// SDK operations
} catch (e: BinanceSDKException) {
// Handle exceptions
}WebSocket Management:
startListenConnections()
stopListenUpdates()
Rate Limiting: Be aware of Binance API rate limits and implement appropriate throttling
Contributions are welcome! Please feel free to submit a Pull Request.
For support, please open an issue in the GitHub repository.