Sha256: bfcac2d2ac983f53064e90b264514b14b5d8608f3beabb3f2edcbb3f11a35153

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Cryptum
  # This module is used to Interact with the APIs
  module API
    # Module specifically related to orders history retrieval.
    module OrderHistory
      # Obtain latest order history
      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 StandardError => e
        raise e
      end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cryptum-0.0.386 lib/cryptum/api/order_history.rb
cryptum-0.0.385 lib/cryptum/api/order_history.rb
cryptum-0.0.384 lib/cryptum/api/order_history.rb
cryptum-0.0.383 lib/cryptum/api/order_history.rb
cryptum-0.0.382 lib/cryptum/api/order_history.rb
cryptum-0.0.381 lib/cryptum/api/order_history.rb