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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
//! Types for Bittrex API.

use chrono::NaiveDateTime;

/// Market information structure.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct MarketInfo {
    /// Currency of the market.
    market_currency: String,
    /// Base currency of the market.
    base_currency: String,
    /// Long name of the currency of the market.
    market_currency_long: String,
    /// Long name of the base currency of the market.
    base_currency_long: String,
    /// Minimum trade size.
    min_trade_size: f64,
    /// Market name.
    market_name: String,
    /// Wether the market is active or not.
    is_active: bool,
    /// Creation date and time of the market.
    created: NaiveDateTime,
    /// Notice about the market.
    notice: Option<String>,
    /// Wether the market is sponsored.
    is_sponsored: Option<bool>,
    /// The logo URL for the market.
    logo_url: Option<String>,
}

impl MarketInfo {
    /// Gets the market currency.
    pub fn market_currency(&self) -> &str {
        &self.market_currency
    }

    /// Gets the base currency.
    pub fn base_currency(&self) -> &str {
        &self.base_currency
    }

    /// Gets the long name of the market currency.
    pub fn market_currency_long(&self) -> &str {
        &self.market_currency_long
    }

    /// Gets the long name of the base currency.
    pub fn base_currency_long(&self) -> &str {
        &self.base_currency_long
    }

    /// Gets the minimum trade size.
    pub fn min_trade_size(&self) -> f64 {
        self.min_trade_size
    }

    /// Gets the market name.
    pub fn market_name(&self) -> &str {
        &self.market_name
    }

    /// Gets wether the market is active or not.
    pub fn is_active(&self) -> bool {
        self.is_active
    }

    /// Gets the market creation time.
    pub fn created(&self) -> NaiveDateTime {
        self.created
    }

    /// Gets the optional notice in the market.
    pub fn notice(&self) -> Option<&String> {
        self.notice.as_ref()
    }

    /// Gets wether the market is sponsored
    pub fn is_sponsored(&self) -> Option<bool> {
        self.is_sponsored
    }

    /// Gets the logo URL for the market.
    pub fn logo_url(&self) -> Option<&String> {
        self.logo_url.as_ref()
    }
}

/// Currency information structure.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct CurrencyInfo {
    /// 3-letter currency code.
    currency: String,
    /// Long currency name.
    currency_long: String,
    /// Minimum number of confirmations to credit the account.
    min_confirmation: u32,
    /// Transaction fee.
    tx_fee: f32,
    /// Wether the currency is active or not.
    is_active: bool,
    /// Coin type string constant.
    coin_type: String,
    /// Optional base address for the coin at Bittrex.
    base_address: Option<String>,
    /// Optional notice about the currency.
    notice: Option<String>,
}

impl CurrencyInfo {
    /// Gets the 3-letter currency code.
    pub fn currency(&self) -> &str {
        &self.currency
    }

    /// Gets the long currency name.
    pub fn currency_long(&self) -> &str {
        &self.currency_long
    }

    /// Gets the minimum number of confirmations to credit the account.
    pub fn min_confirmation(&self) -> u32 {
        self.min_confirmation
    }

    /// Gets the transaction fee.
    pub fn tx_fee(&self) -> f32 {
        self.tx_fee
    }

    /// Gets wether the currency is active or not.
    pub fn is_active(&self) -> bool {
        self.is_active
    }

    /// Gets the coin type string constant.
    pub fn coin_type(&self) -> &str {
        &self.coin_type
    }

    /// Gets the base address for the coin at Bittrex.
    pub fn base_address(&self) -> Option<&String> {
        self.base_address.as_ref()
    }

    /// Gets the optional notice about the currency.
    pub fn notice(&self) -> Option<&String> {
        self.notice.as_ref()
    }
}

/// Ticker information structure.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct TickerInfo {
    /// Current bidding/buying price for the market.
    bid: f32,
    /// Current asking/selling price for the market.
    ask: f32,
    /// Last transaction price.
    last: f32,
}

impl TickerInfo {
    /// Gets the current bidding/buying price for the market.
    pub fn bid(&self) -> f32 {
        self.bid
    }

    /// Gets the current asking/selling price for the market.
    pub fn ask(&self) -> f32 {
        self.ask
    }

    /// Gets the last transaction price.
    pub fn last(&self) -> f32 {
        self.last
    }
}

/// Market summary structure
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct MarketSummary {
    /// Name of the market.
    market_name: String,
    /// Highest transaction value in the last 24 hours for the market.
    high: Option<f32>,
    /// Lowest transaction value in the last 24 hours for the market.
    low: Option<f32>,
    /// Last transaction price.
    last: Option<f32>,
    /// Current bidding/buying price.
    bid: Option<f32>,
    /// Current asking/selling price.
    ask: Option<f32>,
    /// Volume of the market.
    volume: Option<f32>,
    /// Base volume of the market.
    base_volume: Option<f32>,
    /// Timestamp of the information.
    time_stamp: NaiveDateTime,
    /// Number of open buying orders.
    open_buy_orders: Option<u32>,
    /// Number of open selling orders.
    open_sell_orders: Option<u32>,
    prev_day: f32,
    /// Market creation time.
    created: NaiveDateTime,
    /// Name to display for the market.
    display_market_name: Option<String>,
}

impl MarketSummary {
    /// Gets the name of the market.
    pub fn market_name(&self) -> &str {
        &self.market_name
    }

    /// Gets the highest transaction value in the last 24 hours for the market.
    pub fn high(&self) -> Option<f32> {
        self.high
    }

    /// Gets the lowest transaction value in the last 24 hours for the market.
    pub fn low(&self) -> Option<f32> {
        self.low
    }

    /// Gets the last transaction price.
    pub fn last(&self) -> Option<f32> {
        self.last
    }

    /// Gets the current bidding/buying price.
    pub fn bid(&self) -> Option<f32> {
        self.bid
    }

    /// Gets the current asking/selling price.
    pub fn ask(&self) -> Option<f32> {
        self.ask
    }

    /// Gets the volume of the market.
    pub fn volume(&self) -> Option<f32> {
        self.volume
    }

    /// Gets the base volume of the market.
    pub fn base_volume(&self) -> Option<f32> {
        self.base_volume
    }

    /// Gets the timestamp of the information.
    pub fn time_stamp(&self) -> NaiveDateTime {
        self.time_stamp
    }

    /// Gets the number of open buying orders.
    pub fn open_buy_orders(&self) -> Option<u32> {
        self.open_buy_orders
    }

    /// Gets the number of open selling orders.
    pub fn open_sell_orders(&self) -> Option<u32> {
        self.open_sell_orders
    }

    /// Gets the price of the previous day.
    pub fn prev_day(&self) -> f32 {
        self.prev_day
    }

    /// Gets the market creation time.
    pub fn created(&self) -> NaiveDateTime {
        self.created
    }

    /// Gets the name to display for the market.
    pub fn display_market_name(&self) -> Option<&String> {
        self.display_market_name.as_ref()
    }
}

/// Structure representing an order book.
#[derive(Debug, Clone, Deserialize)]
pub struct OrderBook {
    /// List of buying orders.
    buy: Box<[Order]>,
    /// List of selling orders.
    sell: Box<[Order]>,
}

impl OrderBook {
    pub(crate) fn new<B, S>(buy: B, sell: S) -> OrderBook
    where
        B: Into<Box<[Order]>>,
        S: Into<Box<[Order]>>,
    {
        OrderBook {
            buy: buy.into(),
            sell: sell.into(),
        }
    }
    /// Gets the list of buying orders.
    pub fn buy(&self) -> &[Order] {
        &self.buy
    }

    /// Gets the list of selling orders.
    pub fn sell(&self) -> &[Order] {
        &self.sell
    }
}

/// Structure representing an order.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct Order {
    /// Quantity being ordered.
    quantity: f32,
    /// Rate/price of the order
    rate: f32,
}

impl Order {
    /// Gets the quantity being ordered.
    pub fn quantity(&self) -> f32 {
        self.quantity
    }

    /// Gets the rate/price of the order.
    pub fn rate(&self) -> f32 {
        self.rate
    }
}

/// Structure representing a currency balance information.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct BalanceInfo {
    /// Currency code.
    currency: String,
    /// Balance for the currency.
    balance: f32,
    /// Available balance for the currency.
    available: f32,
    /// Pending balance for the currency.
    pending: f32,
    /// Address of the currency for deposits.
    crypto_address: Option<String>,
    /// Wether a withdrawal has been requested.
    requested: Option<bool>,
    /// UUID of the currency.
    uuid: Option<String>,
}

impl BalanceInfo {
    /// Gets the currency code.
    pub fn currency(&self) -> &str {
        &self.currency
    }

    /// Gets the balance for the currency.
    pub fn balance(&self) -> f32 {
        self.balance
    }

    /// Gets the available balance for the currency.
    pub fn available(&self) -> f32 {
        self.available
    }

    /// Gets the pending balance for the currency.
    pub fn pending(&self) -> f32 {
        self.pending
    }

    /// Gets the address of the currency for deposits.
    pub fn crypto_address(&self) -> Option<&str> {
        match self.crypto_address {
            Some(ref addr) => Some(&addr),
            None => None,
        }
    }

    /// Gets wether a withdrawal has been requested.
    pub fn requested(&self) -> bool {
        self.requested == Some(true)
    }

    /// Gets the UUID of the currency.
    pub fn uuid(&self) -> Option<&str> {
        match self.uuid {
            Some(ref uuid) => Some(&uuid),
            None => None,
        }
    }
}