-
Notifications
You must be signed in to change notification settings - Fork 254
/
BTCCurrencyConverter.h
131 lines (107 loc) · 3.73 KB
/
BTCCurrencyConverter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// CoreBitcoin by Oleg Andreev <oleganza@gmail.com>, WTFPL.
#import <Foundation/Foundation.h>
#import "BTCUnitsAndLimits.h"
typedef NS_ENUM(NSInteger, BTCCurrencyConverterMode) {
/*!
* Uses the average exchange rate to convert btc to fiat and back.
*/
BTCCurrencyConverterModeAverage = 0,
/*!
* Uses the buy rate to convert btc to fiat and back.
* Assumes "buying bitcoins" mode:
* fiat -> btc: "How much btc will I buy for that much of fiat"
* btc -> fiat: "How much fiat should I spend to buy that much btc"
*/
BTCCurrencyConverterModeBuy = 10,
/*!
* Uses the sell rate to convert btc to fiat and back.
* Assumes "sell bitcoins" mode:
* fiat -> btc: "How much btc should I sell to get this much fiat"
* btc -> fiat: "How much fiat will I buy for that much of btc"
*/
BTCCurrencyConverterModeSell = 20,
/*!
* Instead of using simple buy rate, "eats" through order book asks.
*/
BTCCurrencyConverterModeBuyOrderBook = 11,
/*!
* Instead of using simple sell rate, "eats" through order book bids.
*/
BTCCurrencyConverterModeSellOrderBook = 21,
};
/*!
Currency converter allows converting according currency using various modes and sources.
*/
@interface BTCCurrencyConverter : NSObject<NSCopying>
/*!
* Conversion mode. Depending on your needs (selling or buying bitcoin) you may set various modes.
* Default is BTCCurrencyConverterModeAverage.
*/
@property(nonatomic) BTCCurrencyConverterMode mode;
/*!
* Average rate. When set, overwrites buy and sell rates.
*/
@property(nonatomic) NSDecimalNumber* averageRate;
/*!
* Buy exchange rate (price for 1 BTC when you buy BTC).
* When set, recomputes average exchange rate using sell rate.
* If sell rate is nil, it is set to buy rate.
*/
@property(nonatomic) NSDecimalNumber* buyRate;
/*!
* Sell exchange rate (price for 1 BTC when you sell BTC).
* When set, recomputes average exchange rate using buy rate.
* If buy rate is nil, it is set to sell rate.
*/
@property(nonatomic) NSDecimalNumber* sellRate;
/*!
* List of @[ NSNumber price-per-btc, NSNumber btcs ] pairs for order book asks.
* When set, updates buyRate to the lowest price.
*/
@property(nonatomic) NSArray* asks;
/*!
* List of @[ NSNumber price-per-btc, NSNumber btcs ] pairs for order book bids.
* When set, updates sellRate to the highest price.
*/
@property(nonatomic) NSArray* bids;
/*!
* Date of last update. It is set automatically when exchange rates are updated,
* but you can set it manually afterwards.
*/
@property(nonatomic) NSDate* date;
/*!
* Code of the fiat currency in which prices are expressed.
*/
@property(nonatomic) NSString* currencyCode;
/*!
* Code of the fiat currency used by exchange natively.
* Typically, it is the same as `currencyCode`, but may differ if,
* for instance, prices are expressed in USD, but exchange operates in EUR.
*/
@property(nonatomic) NSString* nativeCurrencyCode;
/*!
* Name of the exchange/market that provides this exchange rate.
* Deprecated. Use sourceName instead.
*/
@property(nonatomic) NSString* marketName DEPRECATED_ATTRIBUTE;
/*!
* Name of the exchange market or price index that provides this exchange rate.
*/
@property(nonatomic) NSString* sourceName;
/*!
* Serializes state into a plist/json dictionary.
*/
@property(nonatomic, readonly) NSDictionary* dictionary;
/*!
* Serializes state into a plist/json dictionary.
*/
- (id) initWithDictionary:(NSDictionary*)dict;
/*!
* Converts fiat amount to bitcoin amount in satoshis using specified mode.
*/
- (BTCAmount) bitcoinFromFiat:(NSDecimalNumber*)fiatAmount;
/*!
* Converts bitcoin amount to fiat amount using specified mode.
*/
- (NSDecimalNumber*) fiatFromBitcoin:(BTCAmount)satoshis;
@end