### Get Market Spread for All Symbols Source: https://github.com/binance-exchange/binanceapi/blob/master/README.md Fetches the bid and ask prices and quantities for all trading pairs on Binance. The Objective-C version returns an NSDictionary, and the Swift version provides strongly-typed access to these details. ```objc [api allBookTickersWithResponseHandler:^(NSDictionary * _Nullable result, NSError * _Nullable error) { if (error != nil) { return; } for (NSString *asset in result) { NSDictionary *dict = [result valueForKey:asset]; NSDecimalNumber *bidPrice = [dict valueForKey:@"bidPrice"]; NSDecimalNumber *bidQuantity = [dict valueForKey:@"bidQuantity"]; NSDecimalNumber *askPrice = [dict valueForKey:@"askPrice"]; NSDecimalNumber *askQuantity = [dict valueForKey:@"askQuantity"]; NSLog(@"%@: %@ @ %@ - %@ @ %@", asset, bidPrice, bidQuantity, askPrice, askQuantity); } }]; ``` ```swift let request = BinanceAllBookTickersRequest() api.send(request) { response in assert(response.result.isSuccess) let elements = response.result.value!.elements for (asset, prices) in elements { let bidPrice = prices.bidPrice let bidQuantity = prices.bidQuantity let askPrice = prices.askPrice let askQuantity = prices.askQuantity print("\(asset): \(bidPrice) @ \(bidQuantity) - \(askPrice) @ \(askQuantity)") } } ``` -------------------------------- ### Get Latest Price for All Symbols Source: https://github.com/binance-exchange/binanceapi/blob/master/README.md Retrieves the latest trading price for all trading pairs supported by Binance. The Objective-C version returns an NSDictionary, while the Swift version returns a strongly-typed struct. ```objc [api allPricesWithResponseHandler:^(NSDictionary * _Nullable result, NSError * _Nullable error) { if (error != nil) { return; } for (NSString *symbol in result) { NSLog(@"%@: %@", symbol, [result valueForKey:symbol]); } }]; ``` ```swift let request = BinanceAllPricesRequest() api.send(request) { response in assert(request.result.isSuccess) let elements = response.result.value!.elements for (symbol, price) in elements { print("\(symbol): \(price)") } } ``` -------------------------------- ### Get Market Depth for a Symbol Source: https://github.com/binance-exchange/binanceapi/blob/master/README.md Retrieves the order book (bids and asks) for a specific trading symbol. The Objective-C version returns an NSDictionary, while the Swift version provides structured access to the data. ```objc [api depthWithSymbol:@"ETHBTC" limit:0 responseHandler:^(NSDictionary * _Nullable result, NSError * _Nullable error) { if (error != nil) { return; } NSLog(@"lastUpdateId: %@", [result valueForKey:@"lastUpdateId"]); NSLog(@"bids: %@", [result valueForKey:@"bids"]); NSLog(@"asks: %@", [result valueForKey:@"asks"]); }]; ``` ```swift let symbol = "ETHBTC" let request = BinanceDepthRequest(symbol: symbol) api.send(request) { response in assert(response.result.isSuccess) let value = response.result.value! print("lastUpdateId: \(value.lastUpdateId)") print("bids: \(value.bids)") print("asks: \(value.asks)") } ``` -------------------------------- ### Get Current Account Balances Source: https://github.com/binance-exchange/binanceapi/blob/master/README.md Fetches the current balance of all assets in the user's Binance account, including total, free, and locked amounts. The Objective-C version returns an NSDictionary, and the Swift version provides strongly-typed access. ```objc [api accountInformationWithResponseHandler:^(NSDictionary * _Nullable result, NSError * _Nullable error) { if (error != nil) { return; } NSDictionary *> *balances = [result valueForKey:@"balances"]; NSLog(@"Balances"); for (NSString *asset in balances) { NSDictionary *balance = [balances valueForKey:asset]; NSLog(@"%@ %@", [balance valueForKey:@"total"], asset); // "free" and "locked" are also available keys } }]; ``` ```swift api.send(request) { response in assert(response.result.isSuccess) let account = response.result.value! let balances = account.balances for (asset, balance) in balances { print("\(balance.total) \(asset)") } } ``` -------------------------------- ### Place a New Order (Test) Source: https://github.com/binance-exchange/binanceapi/blob/master/README.md Demonstrates how to place a test order on the Binance exchange. This function is useful for verifying API connectivity and order parameters without executing a real trade. It requires the symbol, order side, order type, and quantity. ```Objective-C [api testNewOrderWithSymbol:@"ETHBTC" side:BinanceOrderSide.Buy type:BinanceOrderType.Market timeInForce:nil quantity:Decimal(string: "1.1") price:nil newClientOrderId:nil stopPrice:nil icebergQuantity:nil responseHandler:^(NSError * _Nullable error) { if (error != nil) { return; } }]; ``` -------------------------------- ### Place a New Order (Test) Source: https://github.com/binance-exchange/binanceapi/blob/master/README.md Demonstrates how to place a test order on the Binance exchange using Swift. This function is useful for verifying API connectivity and order parameters without executing a real trade. It requires the symbol, order side, order type, and quantity. ```Swift let request = BinanceTestNewOrderRequest( symbol: "ETHBTC", side: .buy, type: .market, quantity: Decimal(string: "1.1")!) api.send(request) { response in assert(response.result.isSuccess) } ``` -------------------------------- ### Initialize Binance API Object Source: https://github.com/binance-exchange/binanceapi/blob/master/README.md Demonstrates how to initialize the Binance API object for both signed and unsigned endpoints in Objective-C and Swift. For signed access, API keys and secret keys are required. ```objc BinanceApi *api = [[BinanceApi alloc] initWithApiKey:@"" secretKey:@""]; ``` ```swift let api = BinanceApi(apiKey: "", secretKey: "") ``` -------------------------------- ### Initialize Binance API Object (Unsigned Only) Source: https://github.com/binance-exchange/binanceapi/blob/master/README.md Shows how to initialize the Binance API object for accessing only unsigned endpoints in Objective-C and Swift. This initialization does not require API keys. ```objc BinanceApi *api = [[BinanceApi alloc] init]; ``` ```swift let api = BinanceApi() ``` -------------------------------- ### Query Order Status Source: https://github.com/binance-exchange/binanceapi/blob/master/README.md Retrieves the status of a specific order on the Binance exchange. This requires the order's symbol and ID. The response includes details such as the order's symbol and current status. ```Objective-C NSString *symbol = @""; UInt64 orderId = ; [api queryOrderWithSymbol:symbol orderId:orderId originalClientOrderId:nil responseHandler:^(NSDictionary * _Nullable result, NSError * _Nullable error) { if (error != nil) { return } NSLog(@"%@: %@", [result valueForKey:@"symbol"], [result valueForKey:@"status"]); }]; ``` -------------------------------- ### Query Order Status Source: https://github.com/binance-exchange/binanceapi/blob/master/README.md Retrieves the status of a specific order on the Binance exchange using Swift. This requires the order's symbol and ID. The response includes details such as the order's symbol and current status. ```Swift let request = BinanceQueryOrderRequest(symbol: self.querySymbol, orderId: self.queryOrderId) api.send(request) { response in assert(response.result.isSuccess) let order = response.result.value! print(order) } ``` -------------------------------- ### Cancel an Order Source: https://github.com/binance-exchange/binanceapi/blob/master/README.md Cancels a previously placed order on the Binance exchange. This operation requires the order's symbol and ID. Upon successful cancellation, it returns the ID of the cancelled order. ```Objective-C NSString *symbol = @""; UInt64 orderId = ; [api cancelOrderWithSymbol:symbol orderId:orderId originalClientOrderId:nil newClientOrderId:nil responseHandler:^(NSDictionary * _Nullable result, NSError * _Nullable error) { XCTAssertNil(error); XCTAssert(result); UInt64 orderId = [[result valueForKey:@"orderId"] unsignedLongLongValue]; NSLog(@"Cancelled order #%llu", orderId); }]; ``` -------------------------------- ### Cancel an Order Source: https://github.com/binance-exchange/binanceapi/blob/master/README.md Cancels a previously placed order on the Binance exchange using Swift. This operation requires the order's symbol and ID. Upon successful cancellation, it returns the ID of the cancelled order. ```Swift let symbol = "" let orderId = UInt64() let request = BinanceCancelOrderRequest(symbol: symbol, orderId: orderId) api.send(request) { response in assert(request.result.isSuccess) let value = response.result.value! print("Cancelled order #\(value.orderId)") } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.