Larme

Untitled

May 8th, 2021 (edited)
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 3.18 KB | None | 0 0
  1. import Cocoa
  2.  
  3. class exchangeInfo {
  4.  
  5.     var exchangeInformations: exchangeInformation? //Exchange information
  6.     let exchangeInformationURL: String = "https://api.binance.com/api/v3/exchangeInfo"
  7.    
  8.     struct exchangeInformation: Codable {
  9.         var timezone: String //UTC
  10.         var serverTime: Int //1565246363776
  11.         var rateLimits: [rateLimits] = []//Rate limits
  12.         var exchangeFilters: [exchangeFilters] = [] //Exchange filters
  13.         var symbols: [symbols] //Symbols
  14.     }
  15.    
  16.     struct rateLimits: Codable { //Rate limits
  17.         var rateLimitType: String //REQUEST_WEIGHT, ORDERS, RAW_REQUESTS
  18.         var interval: String //interval
  19.         var intervalNum: UInt16 //1
  20.         var limit: UInt32 //1200
  21.     }
  22.    
  23.     struct exchangeFilters: Codable {
  24.         var filterType: String
  25.         var minPrice, maxPrice, tickSize, multiplierUp, multiplierDown, minQty, maxQty, stepSize, minNotional, maxPosition: String?
  26.         var avgPriceMins, limit, maxNumOrders, maxNumAlgoOrders, maxNumIcebergOrders: UInt16?
  27.         var applyToMarket: Bool?
  28.     }
  29.    
  30.     struct symbols: Codable { //Symbols
  31.         var symbol: String //ETHBTC
  32.         var status: String //TRADING
  33.         var baseAsset: String //ETH
  34.         var baseAssetPrecision: UInt16 //8
  35.         var quoteAsset: String //BTC
  36.         var quotePrecision: UInt16 //8
  37.         var quoteAssetPrecision: UInt16 //8
  38.         var baseCommissionPrecision: UInt16 //8
  39.         var quoteCommissionPrecision: UInt16 //8
  40.         var orderTypes: [String] //orderTypes
  41.         var icebergAllowed: Bool //true
  42.         var ocoAllowed: Bool //true
  43.         var quoteOrderQtyMarketAllowed: Bool //true
  44.         var isSpotTradingAllowed: Bool //true
  45.         var isMarginTradingAllowed: Bool //true
  46.         var filters: [exchangeFilters] = [] //Filters
  47.         var permissions: [String] //Permissions
  48.     }
  49.    
  50.     init() {
  51.        
  52.         guard let url = URL(string: exchangeInformationURL) else {
  53.             print("URL is not valid")
  54.             return
  55.         }
  56.        
  57.         let request = URLRequest(url: url)
  58.        
  59.         let configuration = URLSessionConfiguration.ephemeral
  60.         let session = URLSession(configuration: configuration)
  61.        
  62.         session.dataTask(with: request) { data, response, error in
  63.             print("dataTask(with:completion: closure")
  64.             do {
  65.                 if let adat = data {
  66.                    
  67.                     if let decodedResult = try? JSONDecoder().decode(exchangeInformation.self, from: adat) {
  68.                         DispatchQueue.main.async {
  69.                             print("Will set self.exchangeInformations with \(decodedResult)")
  70.                             self.exchangeInformations = decodedResult
  71.                         }
  72.                     }
  73.                    
  74.                 }
  75.             } catch {
  76.                 print("Error: \(error.localizedDescription)")
  77.             }
  78.         }.resume()
  79.     }
  80. }
  81.  
  82. var informacio = exchangeInfo()
  83. print("exchangeInfo has been created")
  84.  
  85. if let serverTime = informacio.exchangeInformations?.serverTime {
  86.     print (serverTime)
  87. }
  88. print("After trying to access to serverTime")
  89.  
Add Comment
Please, Sign In to add comment