Coinbase API спот, цена покупки и продажи для разных валют
Я использую Coinbase API, чтобы получить спотовую цену, купить и продать биткойн. Я добавил вид сборщика со всеми поддерживаемыми валютами, и когда я меняю валюту, спотовая цена изменяется, но для цены покупки и продажи она не меняется. Вот мой код, не уверен, почему не работает...
@IBOutlet weak var btcSpotPrice: UILabel!
@IBOutlet weak var btcBuyPrice: UILabel!
@IBOutlet weak var btcSellPrice: UILabel!
@IBOutlet weak var selectedCurrency: UIButton!
@IBOutlet weak var currencyPicker: UIPickerView!
var currencies: [CoinbaseCurrency]?
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
self.selectedCurrency.setTitle(currencies?[row].iso, for: .normal)
getSpotPrice()
getBuyPrice()
getSellPrice()
}
func getSpotPrice()
{
Coinbase().getSpotRate(withCurrency: self.selectedCurrency.currentTitle) { (spotPrice: CoinbaseBalance?, error: Error?) in
if let error = error
{
let alert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
alert.present(alert, animated: true, completion: nil)
}
else
{
self.btcSpotPrice.text = spotPrice!.amount! + " " + spotPrice!.currency!
}
}
}
func getBuyPrice()
{
Coinbase().getBuyPrice(withQuantity: "1", currency: "GBP") { (btc: CoinbaseBalance?, fees: [Any]?, subtotal: CoinbaseBalance?, total: CoinbaseBalance?, error: Error?) in
if let error = error
{
let alert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
alert.present(alert, animated: true, completion: nil)
}
else
{
self.btcBuyPrice.text = total!.currency!
}
}
}
func getSellPrice()
{
Coinbase().getSellPrice(withQuantity: "1", currency: self.selectedCurrency.currentTitle) { (btc: CoinbaseBalance?, fees: [Any]?, subtotal: CoinbaseBalance?, total: CoinbaseBalance?, error: Error?) in
if let error = error
{
let alert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
alert.present(alert, animated: true, completion: nil)
}
else
{
self.btcSellPrice.text = total!.amount!
}
}
}
В моем методе getBuyPrice, даже при жестком кодировании валюты в британский фунт "фунт стерлингов" на этикетке btcBuyPrice по-прежнему отображается USD Он отлично работает для метода spotPrice, но не для цены покупки и продажи.