Class: Itbit::Trade

Inherits:
Object
  • Object
show all
Defined in:
lib/itbit/trade.rb

Overview

List the full trading history for a given wallet

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Trade

Returns a new instance of Trade.



9
10
11
# File 'lib/itbit/trade.rb', line 9

def initialize(attrs)
  attrs.each{|k, v| send("#{k.underscore}=", v)}
end

Instance Attribute Details

#commission_currencyObject

Returns the value of attribute commission_currency.



4
5
6
# File 'lib/itbit/trade.rb', line 4

def commission_currency
  @commission_currency
end

#commission_paidObject

Returns the value of attribute commission_paid.



4
5
6
# File 'lib/itbit/trade.rb', line 4

def commission_paid
  @commission_paid
end

#currency1Object

Returns the value of attribute currency1.



4
5
6
# File 'lib/itbit/trade.rb', line 4

def currency1
  @currency1
end

#currency1_amountObject

Returns the value of attribute currency1_amount.



4
5
6
# File 'lib/itbit/trade.rb', line 4

def currency1_amount
  @currency1_amount
end

#currency2Object

Returns the value of attribute currency2.



4
5
6
# File 'lib/itbit/trade.rb', line 4

def currency2
  @currency2
end

#currency2_amountObject

Returns the value of attribute currency2_amount.



4
5
6
# File 'lib/itbit/trade.rb', line 4

def currency2_amount
  @currency2_amount
end

#directionObject

Returns the value of attribute direction.



4
5
6
# File 'lib/itbit/trade.rb', line 4

def direction
  @direction
end

#instrumentObject

Returns the value of attribute instrument.



4
5
6
# File 'lib/itbit/trade.rb', line 4

def instrument
  @instrument
end

#order_idObject

Returns the value of attribute order_id.



4
5
6
# File 'lib/itbit/trade.rb', line 4

def order_id
  @order_id
end

#rateObject

Returns the value of attribute rate.



4
5
6
# File 'lib/itbit/trade.rb', line 4

def rate
  @rate
end

#rebate_currencyObject

Returns the value of attribute rebate_currency.



4
5
6
# File 'lib/itbit/trade.rb', line 4

def rebate_currency
  @rebate_currency
end

#rebates_appliedObject

Returns the value of attribute rebates_applied.



4
5
6
# File 'lib/itbit/trade.rb', line 4

def rebates_applied
  @rebates_applied
end

#timestampObject

Returns the value of attribute timestamp.



4
5
6
# File 'lib/itbit/trade.rb', line 4

def timestamp
  @timestamp
end

Class Method Details

.all(opts = {}) ⇒ Array<Itbit::Trade>

Lists all trades for a wallet Results can be filtered and paginated by passing in these options.

wallet_id: String, defaults to Itbit.default_wallet_id 
page: Integer, starting page for pagination.
per_page: Integer, how many to show per page.
range_start: Integer timestamp, start showing at this date.
range_end: Integer timestamp, stop showing at this date.

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/itbit/trade.rb', line 39

def self.all(opts = {})
  wallet_id = opts[:wallet_id] || Itbit.default_wallet_id
  params = {}
  %w(range_start range_end page per_page).each do |a|
    params[a.camelize(:lower)] = opts[a.to_sym].to_i if opts[a.to_sym]
  end
  response = Api.request(:get, "/wallets/#{wallet_id}/trades", params)
  {
    total_number_of_records: response['totalNumberOfRecords'].to_i,
    current_page_number: response['currentPageNumber'].to_i,
    latest_execution_id: response['latestExecutionId'].to_i,
    records_per_page: response['recordsPerPage'].to_i,
    trading_history: response['tradingHistory'].collect{|x| new(x) }
  }
end