|
25 | 25 | // SOFTWARE.
|
26 | 26 |
|
27 | 27 | import Foundation
|
28 |
| -import Result |
29 |
| -import SwiftyJSON |
30 | 28 |
|
31 | 29 |
|
32 | 30 | // MARK: - Bitcoin Currency
|
@@ -90,143 +88,3 @@ public typealias XBT = _Money<Currency.XBT>
|
90 | 88 | public typealias BTC = _Money<Currency.BTC>
|
91 | 89 |
|
92 | 90 |
|
93 |
| -// MARK - cex.io FX |
94 |
| - |
95 |
| -/** |
96 |
| - CEX.io Supported fiat currencies |
97 |
| - |
98 |
| - CEX only supports USD, EUR and RUB. |
99 |
| - |
100 |
| - - see: https://cex.io |
101 |
| -*/ |
102 |
| -public protocol CEXSupportedFiatCurrencyType: ISOCurrencyType { |
103 |
| - |
104 |
| - /** |
105 |
| - CEX.io charge a percentage based commission with FX transactions. |
106 |
| - - returns: a BankersDecimal representing the % commission. |
107 |
| - */ |
108 |
| - static var cex_commissionPercentage: BankersDecimal { get } |
109 |
| -} |
110 |
| - |
111 |
| -extension Currency.USD: CEXSupportedFiatCurrencyType { |
112 |
| - |
113 |
| - /// - returns: the commission charged for USD transactions, a BankersDecimal |
114 |
| - public static let cex_commissionPercentage: BankersDecimal = 0.2 |
115 |
| -} |
116 |
| - |
117 |
| -extension Currency.EUR: CEXSupportedFiatCurrencyType { |
118 |
| - |
119 |
| - /// - returns: the commission charged for EUR transactions, a BankersDecimal |
120 |
| - public static let cex_commissionPercentage: BankersDecimal = 0.2 |
121 |
| -} |
122 |
| - |
123 |
| -extension Currency.RUB: CEXSupportedFiatCurrencyType { |
124 |
| - |
125 |
| - /// - returns: the commission charged for RUB transactions, a BankersDecimal |
126 |
| - public static let cex_commissionPercentage: BankersDecimal = 0 |
127 |
| -} |
128 |
| - |
129 |
| -struct _CEXBuy<Base: MoneyType where Base.Currency: CEXSupportedFiatCurrencyType>: CryptoCurrencyMarketTransactionType { |
130 |
| - typealias BaseMoney = Base |
131 |
| - typealias CounterMoney = BTC |
132 |
| - typealias FiatCurrency = Base.Currency |
133 |
| - static var transactionKind: CurrencyMarketTransactionKind { return .Buy } |
134 |
| -} |
135 |
| - |
136 |
| -struct _CEXSell<Counter: MoneyType where Counter.Currency: CEXSupportedFiatCurrencyType>: CryptoCurrencyMarketTransactionType { |
137 |
| - typealias BaseMoney = BTC |
138 |
| - typealias CounterMoney = Counter |
139 |
| - typealias FiatCurrency = Counter.Currency |
140 |
| - static var transactionKind: CurrencyMarketTransactionKind { return .Sell } |
141 |
| -} |
142 |
| - |
143 |
| -class _CEX<T: CryptoCurrencyMarketTransactionType where T.FiatCurrency: CEXSupportedFiatCurrencyType>: FXRemoteProvider<T.BaseMoney, T.CounterMoney>, FXRemoteProviderType { |
144 |
| - |
145 |
| - static func name() -> String { |
146 |
| - return "CEX.IO \(BaseMoney.Currency.code)\(CounterMoney.Currency.code)" |
147 |
| - } |
148 |
| - |
149 |
| - static func request() -> NSURLRequest { |
150 |
| - let url = NSURL(string: "https://cex.io/api/convert/\(BTC.Currency.code)/\(T.FiatCurrency.code)") |
151 |
| - let request = NSMutableURLRequest(URL: url!) |
152 |
| - request.HTTPMethod = "POST" |
153 |
| - request.setValue("application/json", forHTTPHeaderField: "Content-Type") |
154 |
| - let data = try! JSON(["amnt": Double(1.0)]).rawData() |
155 |
| - request.HTTPBody = data |
156 |
| - return request |
157 |
| - } |
158 |
| - |
159 |
| - static func quoteFromNetworkResult(result: Result<(NSData?, NSURLResponse?), NSError>) -> Result<FXQuote, FXError> { |
160 |
| - return result.analysis( |
161 |
| - |
162 |
| - ifSuccess: { data, response in |
163 |
| - |
164 |
| - guard let data = data else { |
165 |
| - return Result(error: .NoData) |
166 |
| - } |
167 |
| - |
168 |
| - let json = JSON(data: data) |
169 |
| - |
170 |
| - if json.isEmpty { |
171 |
| - return Result(error: .InvalidData(data)) |
172 |
| - } |
173 |
| - |
174 |
| - guard let rateLiteral = json["amnt"].double else { |
175 |
| - return Result(error: .RateNotFound(name())) |
176 |
| - } |
177 |
| - |
178 |
| - let rate: BankersDecimal |
179 |
| - |
180 |
| - switch T.transactionKind { |
181 |
| - case .Buy: |
182 |
| - rate = BankersDecimal(floatLiteral: rateLiteral).reciprocal |
183 |
| - case .Sell: |
184 |
| - rate = BankersDecimal(floatLiteral: rateLiteral) |
185 |
| - } |
186 |
| - |
187 |
| - return Result(value: FXQuote(rate: rate, percentage: T.FiatCurrency.cex_commissionPercentage)) |
188 |
| - }, |
189 |
| - |
190 |
| - ifFailure: { error in |
191 |
| - return Result(error: .NetworkError(error)) |
192 |
| - } |
193 |
| - ) |
194 |
| - } |
195 |
| -} |
196 |
| - |
197 |
| -/** |
198 |
| - Represents the purchase of bitcoin using CEX.io. |
199 |
| - |
200 |
| - Usage is entirely type based - there is nothing to initialize. It is |
201 |
| - generic over USD, EUR or RUB, no other currency types. For example. |
202 |
| - |
203 |
| - ```swift |
204 |
| - CEXBuy<USD>.quote(1_000) { transaction in |
205 |
| - // etc. |
206 |
| - } |
207 |
| - ``` |
208 |
| - |
209 |
| - The above sample represents buying US$1,000 worth of BTC using CEX.io. |
210 |
| -*/ |
211 |
| -public final class CEXBuy<Base: MoneyType where Base.Currency: CEXSupportedFiatCurrencyType>: _CEX<_CEXBuy<Base>> { } |
212 |
| - |
213 |
| - /** |
214 |
| - Represents the sale of bitcoin using CEX.io. |
215 |
| - |
216 |
| - Usage is entirely type based - there is nothing to initialize. It is |
217 |
| - generic over USD, EUR or RUB, no other currency types. For example. |
218 |
| - |
219 |
| - ```swift |
220 |
| - CEXBuy<EUR>.quote(10) { transaction in |
221 |
| - // etc. |
222 |
| - } |
223 |
| - ``` |
224 |
| - |
225 |
| - The above sample represents selling 10 bitcoins for euros using CEX.io. |
226 |
| - */ |
227 |
| -public final class CEXSell<Counter: MoneyType where Counter.Currency: CEXSupportedFiatCurrencyType>: _CEX<_CEXSell<Counter>> { } |
228 |
| - |
229 |
| - |
230 |
| - |
231 |
| - |
232 |
| - |
0 commit comments