lib/cubits/helpers.rb
# Executes "Sell bitcoins" API call.
#
# Creates a transaction to sell bitcoins from your Cubits wallet and receive amount
# in specified fiat currency. Fiat funds will be credited to your Cubits account.
#
# @param params [Hash]
# @param params[:sender] [Hash] Sender attributes define spending part of transaction
# @param params[:sender][:amount] [String] Amount in bitcoins to be spent,
#                                          decimal number as a String (e.g. "0.01250000")
# @param params[:receiver] [Hash] Receiver attributes define receiving part of transaction
# @param params[:receiver][:currency] [String] ISO 4217 code of the currency, that you want
#                                            to receive (e.g. "EUR")
#
Executes "Sell bitcoins" API call.
Creates a transaction to sell bitcoins from your Cubits wallet and receive amount
in specified fiat currency. Fiat funds will be credited to your Cubits account.
Executes " Sell bitcoins " API call . Creates a transaction to sell bitcoins from your Cubits wallet and receive amount in specified fiat currency . Fiat funds will be credited to your Cubits account .
def sell(params)
      fail ArgumentError, 'Hash is expected as params' unless params.is_a?(Hash)
      fail ArgumentError, 'Hash is expected as :sender' unless params[:sender].is_a?(Hash)
      sender = params[:sender]
      fail ArgumentError, 'String is expected as sender[:amount]' unless sender[:amount].is_a?(String)
      fail ArgumentError, 'Invalid amount format' unless sender[:amount] =~ /^\d+\.\d+$/
      fail ArgumentError, 'Hash is expected as :receiver' unless params[:receiver].is_a?(Hash)
      receiver = params[:receiver]
      fail ArgumentError, 'String is expected as receiver[:currency]' unless receiver[:currency].is_a?(String)
      Cubits.connection.post(
        '/api/v1/sell',
        sender: {
          amount: sender[:amount]
        },
        receiver: {
          currency: receiver[:currency]
        }
      )
    end
def sell ( params ) fail ArgumentError , 'Hash is expected as params' unless params . is_a? ( Hash ) fail ArgumentError , 'Hash is expected as :sender' unless params [ :sender ] . is_a? ( Hash ) sender = params [ :sender ] fail ArgumentError , 'String is expected as sender[:amount]' unless sender [ :amount ] . is_a? ( String ) fail ArgumentError , 'Invalid amount format' unless sender [ :amount ] =~ / ^ \d + \. \d +$ / fail ArgumentError , 'Hash is expected as :receiver' unless params [ :receiver ] . is_a? ( Hash ) receiver = params [ :receiver ] fail ArgumentError , 'String is expected as receiver[:currency]' unless receiver [ :currency ] . is_a? ( String ) Cubits . connection . post ( '/api/v1/sell' , sender : { amount : sender [ :amount ] } , receiver : { currency : receiver [ :currency ] } ) end
Executes "Sell bitcoins" API call.
Executes " Sell bitcoins " API call .
params
[Hash] Receiver attributes define receiving part of transaction
[ Hash ] Receiver attributes define receiving part of transaction
[String] ISO 4217 code of the currency, that you want to receive
[ String ] ISO 4217 code of the currency that you want to receive