Class: BudaApi::Models::Order

Inherits:
BaseModel show all
Defined in:
lib/buda_api/models.rb

Overview

Order model

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#raw, #to_h, #to_json

Constructor Details

#initialize(data) ⇒ Order

Returns a new instance of Order.



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/buda_api/models.rb', line 205

def initialize(data)
  super(data)
  @id = data["id"]
  @account_id = data["account_id"]
  @amount = parse_amount(data["amount"])
  @created_at = parse_datetime(data["created_at"])
  @fee_currency = data["fee_currency"]
  @limit = parse_amount(data["limit"])
  @market_id = data["market_id"]
  @original_amount = parse_amount(data["original_amount"])
  @paid_fee = parse_amount(data["paid_fee"])
  @price_type = data["price_type"]
  @state = data["state"]
  @total_exchanged = parse_amount(data["total_exchanged"])
  @traded_amount = parse_amount(data["traded_amount"])
  @type = data["type"]
end

Instance Attribute Details

#account_id ⇒ Object (readonly)

Returns the value of attribute account_id.



223
224
225
# File 'lib/buda_api/models.rb', line 223

def 
  @account_id
end

#amount ⇒ Object (readonly)

Returns the value of attribute amount.



223
224
225
# File 'lib/buda_api/models.rb', line 223

def amount
  @amount
end

#created_at ⇒ Object (readonly)

Returns the value of attribute created_at.



223
224
225
# File 'lib/buda_api/models.rb', line 223

def created_at
  @created_at
end

#fee_currency ⇒ Object (readonly)

Returns the value of attribute fee_currency.



223
224
225
# File 'lib/buda_api/models.rb', line 223

def fee_currency
  @fee_currency
end

#id ⇒ Object (readonly)

Returns the value of attribute id.



223
224
225
# File 'lib/buda_api/models.rb', line 223

def id
  @id
end

#limit ⇒ Object (readonly)

Returns the value of attribute limit.



223
224
225
# File 'lib/buda_api/models.rb', line 223

def limit
  @limit
end

#market_id ⇒ Object (readonly)

Returns the value of attribute market_id.



223
224
225
# File 'lib/buda_api/models.rb', line 223

def market_id
  @market_id
end

#original_amount ⇒ Object (readonly)

Returns the value of attribute original_amount.



223
224
225
# File 'lib/buda_api/models.rb', line 223

def original_amount
  @original_amount
end

Returns the value of attribute paid_fee.



223
224
225
# File 'lib/buda_api/models.rb', line 223

def paid_fee
  @paid_fee
end

#price_type ⇒ Object (readonly)

Returns the value of attribute price_type.



223
224
225
# File 'lib/buda_api/models.rb', line 223

def price_type
  @price_type
end

#state ⇒ Object (readonly)

Returns the value of attribute state.



223
224
225
# File 'lib/buda_api/models.rb', line 223

def state
  @state
end

#total_exchanged ⇒ Object (readonly)

Returns the value of attribute total_exchanged.



223
224
225
# File 'lib/buda_api/models.rb', line 223

def total_exchanged
  @total_exchanged
end

#traded_amount ⇒ Object (readonly)

Returns the value of attribute traded_amount.



223
224
225
# File 'lib/buda_api/models.rb', line 223

def traded_amount
  @traded_amount
end

#type ⇒ Object (readonly)

Returns the value of attribute type.



223
224
225
# File 'lib/buda_api/models.rb', line 223

def type
  @type
end

Instance Method Details

#filled_percentage ⇒ Object



227
228
229
230
231
# File 'lib/buda_api/models.rb', line 227

def filled_percentage
  return 0 unless @original_amount&.amount && @original_amount.amount > 0
  
  ((@traded_amount&.amount || 0) / @original_amount.amount * 100).round(2)
end

#is_active? ⇒ Boolean

Returns:



237
238
239
# File 'lib/buda_api/models.rb', line 237

def is_active?
  %w[received pending].include?(@state)
end

#is_cancelled? ⇒ Boolean

Returns:



241
242
243
# File 'lib/buda_api/models.rb', line 241

def is_cancelled?
  %w[canceled canceling].include?(@state)
end

#is_filled? ⇒ Boolean

Returns:



233
234
235
# File 'lib/buda_api/models.rb', line 233

def is_filled?
  @state == "traded"
end