Module: Bitfinex::RESTv2Funding

Included in:
RESTv2
Defined in:
lib/rest/v2/funding.rb

Instance Method Summary collapse

Instance Method Details

#cancel_funding_offer(offer) ⇒ Array

Cancel an active funding offer

Parameters:

  • offer (Hash|Array|FundingOffer|number)
    • must contain or be ID

Returns:

  • (Array)

    Raw notification



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rest/v2/funding.rb', line 28

def cancel_funding_offer(offer)
  if offer.is_a?(Numeric)
    id = offer
  elsif offer.is_a?(Array)
    id = offer[0]
  elsif offer.instance_of?(Models::FundingOffer)
    id = offer.id
  elsif offer.kind_of?(Hash)
    id = offer[:id] || order['id']
  else
    raise Exception, 'tried to cancel offer with invalid ID'
  end
  authenticated_post("auth/w/funding/offer/cancel", params: { :id => id }).body
end

#close_funding(funding) ⇒ Array

Close a funding loan/credit

Parameters:

  • funding (Hash|Array|FundingOffer|FundingLoan|FundingCredit|number)
    • must contain or be ID

Returns:

  • (Array)

    Raw notification



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rest/v2/funding.rb', line 50

def close_funding(funding)
  if funding.is_a?(Numeric)
    id = funding
  elsif funding.is_a?(Array)
    id = funding[0]
  elsif funding.instance_of?(Models::FundingOffer)
    id = funding.id
  elsif funding.instance_of?(Models::FundingLoan)
    id = funding.id
  elsif funding.instance_of?(Models::FundingCredit)
    id = funding.id
  elsif funding.kind_of?(Hash)
    id = funding[:id] || order['id']
  else
    raise Exception, 'tried to close funding with invalid ID'
  end
  authenticated_post("auth/w/funding/close", params: { :id => id }).body
end

#submit_funding_auto(currency, amount, period, rate = '0', status = 1) ⇒ Array

Submit a new auto funding request

Parameters:

  • currency (string)
    • urrency for which to enable auto-renew

  • amount (number)
    • amount to be auto-renewed (Minimum 50 USD equivalent)

  • rate (string) (defaults to: '0')
    • percentage rate at which to auto-renew. (rate == 0 to renew at FRR)

  • period (integer)
    • period in days

  • status (integer) (defaults to: 1)
    • 1 for activate and 0 for deactivate

Returns:

  • (Array)

    Raw notification



80
81
82
83
84
# File 'lib/rest/v2/funding.rb', line 80

def submit_funding_auto(currency, amount, period, rate='0', status=1)
  dec_amount = BigDecimal.new(amount, 8).to_s
  payload = { :status => status, :currency => currency, :amount => dec_amount, :period => period, :rate => rate }
  authenticated_post("auth/w/funding/auto", params: payload).body
end

#submit_funding_offer(offer) ⇒ Array

Submit a new funding offer

Parameters:

  • offer (Hash|FundingOffer)

Returns:

  • (Array)

    Raw notification



10
11
12
13
14
15
16
17
18
19
# File 'lib/rest/v2/funding.rb', line 10

def submit_funding_offer(offer)
  if offer.instance_of?(Models::FundingOffer)
    packet = offer.to_new_order_packet
  elsif offer.kind_of?(Hash)
    packet = Models::FundingOffer.new(offer).to_new_order_packet
  else
    raise Exception, 'tried to submit offer of unkown type'
  end
  authenticated_post("auth/w/funding/offer/submit", params: packet).body
end