Module: Cryptum::API::OrderHistory

Defined in:
lib/cryptum/api/order_history.rb

Overview

Module specifically related to orders history retrieval.

Class Method Summary collapse

Class Method Details

.get(opts = {}) ⇒ Object

Obtain latest order history



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
# File 'lib/cryptum/api/order_history.rb', line 9

public_class_method def self.get(opts = {})
  option_choice = opts[:option_choice]
  env = opts[:env]

  product_id = option_choice.symbol.to_s.gsub('_', '-').upcase

  orders_api_call = '/orders'
  params = {}
  params[:product_id] = product_id
  params[:status] = 'all'

  order_history = Cryptum::API::Rest.call(
    option_choice: option_choice,
    env: env,
    http_method: :GET,
    api_call: orders_api_call,
    params: params
  )

  # Cast UTC Timestamps as local times
  order_history.each do |order|
    order[:created_at] = Time.parse(
      order[:created_at]
    ).localtime.to_s

    next unless order[:done_at]

    order[:done_at] = Time.parse(
      order[:done_at]
    ).localtime.to_s
  end

  order_history
rescue Interrupt, StandardError => e
  Cryptum::Log.append(level: :error, msg: e, which_self: self)
end

.helpObject

Display Usage for this Module



47
48
49
50
51
52
53
# File 'lib/cryptum/api/order_history.rb', line 47

public_class_method def self.help
  puts "USAGE:
    order_history = #{self}.get_order_history(
      env: 'required - Coinbase::Option::Environment.get Object'
    )
  "
end