Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Cocoa
- class exchangeInfo {
- var exchangeInformations: exchangeInformation? //Exchange information
- let exchangeInformationURL: String = "https://api.binance.com/api/v3/exchangeInfo"
- struct exchangeInformation: Codable {
- var timezone: String //UTC
- var serverTime: Int //1565246363776
- var rateLimits: [rateLimits] = []//Rate limits
- var exchangeFilters: [exchangeFilters] = [] //Exchange filters
- var symbols: [symbols] //Symbols
- }
- struct rateLimits: Codable { //Rate limits
- var rateLimitType: String //REQUEST_WEIGHT, ORDERS, RAW_REQUESTS
- var interval: String //interval
- var intervalNum: UInt16 //1
- var limit: UInt32 //1200
- }
- struct exchangeFilters: Codable {
- var filterType: String
- var minPrice, maxPrice, tickSize, multiplierUp, multiplierDown, minQty, maxQty, stepSize, minNotional, maxPosition: String?
- var avgPriceMins, limit, maxNumOrders, maxNumAlgoOrders, maxNumIcebergOrders: UInt16?
- var applyToMarket: Bool?
- }
- struct symbols: Codable { //Symbols
- var symbol: String //ETHBTC
- var status: String //TRADING
- var baseAsset: String //ETH
- var baseAssetPrecision: UInt16 //8
- var quoteAsset: String //BTC
- var quotePrecision: UInt16 //8
- var quoteAssetPrecision: UInt16 //8
- var baseCommissionPrecision: UInt16 //8
- var quoteCommissionPrecision: UInt16 //8
- var orderTypes: [String] //orderTypes
- var icebergAllowed: Bool //true
- var ocoAllowed: Bool //true
- var quoteOrderQtyMarketAllowed: Bool //true
- var isSpotTradingAllowed: Bool //true
- var isMarginTradingAllowed: Bool //true
- var filters: [exchangeFilters] = [] //Filters
- var permissions: [String] //Permissions
- }
- init() {
- guard let url = URL(string: exchangeInformationURL) else {
- print("URL is not valid")
- return
- }
- let request = URLRequest(url: url)
- let configuration = URLSessionConfiguration.ephemeral
- let session = URLSession(configuration: configuration)
- session.dataTask(with: request) { data, response, error in
- print("dataTask(with:completion: closure")
- do {
- if let adat = data {
- if let decodedResult = try? JSONDecoder().decode(exchangeInformation.self, from: adat) {
- DispatchQueue.main.async {
- print("Will set self.exchangeInformations with \(decodedResult)")
- self.exchangeInformations = decodedResult
- }
- }
- }
- } catch {
- print("Error: \(error.localizedDescription)")
- }
- }.resume()
- }
- }
- var informacio = exchangeInfo()
- print("exchangeInfo has been created")
- if let serverTime = informacio.exchangeInformations?.serverTime {
- print (serverTime)
- }
- print("After trying to access to serverTime")
Add Comment
Please, Sign In to add comment