Class: Cex::Apimt

Inherits:
Object
  • Object
show all
Defined in:
lib/cex/apimt.rb

Overview

classe para processar dados no therock

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pky: ENV['THEROCK_API_KEY'], psc: ENV['THEROCK_API_SECRET'], ops: { www: 'https://api.therocktrading.com', ver: 1 }) ⇒ Apius

Returns API therock base.

Parameters:

  • pky (String) (defaults to: ENV['THEROCK_API_KEY'])

    API key

  • psc (String) (defaults to: ENV['THEROCK_API_SECRET'])

    API secret

  • ops (Hash) (defaults to: { www: 'https://api.therocktrading.com', ver: 1 })

    parametrizacao base da API



25
26
27
28
29
30
31
32
33
# File 'lib/cex/apimt.rb', line 25

def initialize(
  pky: ENV['THEROCK_API_KEY'],
  psc: ENV['THEROCK_API_SECRET'],
  ops: { www: 'https://api.therocktrading.com', ver: 1 }
)
  @aky = pky
  @asc = psc
  @urb = "#{ops[:www]}/v#{ops[:ver]}"
end

Instance Attribute Details

#akyString (readonly)

Returns API key.

Returns:

  • (String)

    API key



15
16
17
# File 'lib/cex/apimt.rb', line 15

def aky
  @aky
end

#ascString (readonly)

Returns API secret.

Returns:

  • (String)

    API secret



17
18
19
# File 'lib/cex/apimt.rb', line 17

def asc
  @asc
end

#urbString (readonly)

Returns API url base.

Returns:

  • (String)

    API url base



19
20
21
# File 'lib/cex/apimt.rb', line 19

def urb
  @urb
end

Instance Method Details

#accountHash

Returns saldos no therock.

Examples:

{
  balances: [
    { currency: 'BTC', balance: 0.0, trading_balance: 0.0 },
    { currency: 'ETH', balance: 0.0, trading_balance: 0.0 },
    { currency: 'EUR', balance: 0.0, trading_balance: 0.0 },
    { currency: 'DAI', balance: 0.0, trading_balance: 0.0 },
  ]
}

Returns:

  • (Hash)

    saldos no therock



45
46
47
48
# File 'lib/cex/apimt.rb', line 45

def 
  api_get('balances')[:balances].delete_if { |e| DC.include?(e[:currency]) }
                                .sort { |a, b| a[:currency] <=> b[:currency] }
end

#ledger(pag = 1, ary = []) ⇒ Hash

Returns ledger no therock.

Examples:

{
  transactions: [
    {
      id: 305_445,
      date: '2014-03-06T10:59:13.000Z',
      type: 'withdraw',
      price: 97.47,
      currency: 'EUR',
      fund_id: nil,
      order_id: nil,
      trade_id: nil,
      note: 'BOV withdraw',
      transfer_detail: nil
    },
    {}
  ],
  meta: {
    total_count: nil,
    first: { page: 1, href: 'https://api.therocktrading.com/v1/transactions?page=1' },
    previous: nil,
    current: { page: 1, href: 'https://api.therocktrading.com/v1/transactions?page=1' },
    next: { page: 2, href: 'https://api.therocktrading.com/v1/transactions?page=2' },
    last: nil
  }
}

Returns:

  • (Hash)

    ledger no therock



77
78
79
80
81
82
# File 'lib/cex/apimt.rb', line 77

def ledger(pag = 1, ary = [])
  r = api_get('transactions', page: pag)[:transactions]
  r.empty? ? ary : ledger(pag + r.size, ary + r)
rescue StandardError
  ary
end