Class: Parsbank::Binance
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
Instance Method Summary collapse
-
#generate_payment_address(asset:, network: nil) ⇒ Object
Generate a payment address for a given cryptocurrency.
-
#initialize(args = {}) ⇒ Binance
constructor
A new instance of Binance.
-
#latest_transactions(asset:, limit: 10) ⇒ Object
Get the latest transactions for a given asset.
-
#verify_transaction(tx_id:, asset:) ⇒ Object
Verify a transaction by checking its status.
Methods inherited from Gates
Constructor Details
#initialize(args = {}) ⇒ Binance
Returns a new instance of Binance.
11 12 13 14 15 16 17 18 19 |
# File 'lib/parsbank/binance/binance.rb', line 11 def initialize(args = {}) @api_key = args.fetch(:api_key, default_config(:api_key)) @secret_key = args.fetch(:secret_key, default_config(:secret_key)) @connection = Faraday.new(default_config(:endpoint)) do |conn| conn.request :json conn.response :json, content_type: 'application/json' conn.adapter Faraday.default_adapter end end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
9 10 11 |
# File 'lib/parsbank/binance/binance.rb', line 9 def api_key @api_key end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
9 10 11 |
# File 'lib/parsbank/binance/binance.rb', line 9 def endpoint @endpoint end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
9 10 11 |
# File 'lib/parsbank/binance/binance.rb', line 9 def secret_key @secret_key end |
Instance Method Details
#generate_payment_address(asset:, network: nil) ⇒ Object
Generate a payment address for a given cryptocurrency
23 24 25 26 27 28 29 30 31 |
# File 'lib/parsbank/binance/binance.rb', line 23 def generate_payment_address(asset:, network: nil) endpoint = '/sapi/v1/capital/deposit/address' params = { asset: asset, network: network } response = signed_request(:get, endpoint, params) response_body(response) end |
#latest_transactions(asset:, limit: 10) ⇒ Object
Get the latest transactions for a given asset
48 49 50 51 52 53 54 55 56 |
# File 'lib/parsbank/binance/binance.rb', line 48 def latest_transactions(asset:, limit: 10) endpoint = '/sapi/v1/capital/deposit/hisrec' params = { asset: asset, limit: limit } response = signed_request(:get, endpoint, params) response_body(response) end |
#verify_transaction(tx_id:, asset:) ⇒ Object
Verify a transaction by checking its status
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/parsbank/binance/binance.rb', line 34 def verify_transaction(tx_id:, asset:) endpoint = '/sapi/v1/capital/deposit/hisrec' params = { txId: tx_id, asset: asset } response = signed_request(:get, endpoint, params) transactions = response_body(response) transaction = transactions.find { |t| t['txId'] == tx_id } transaction && transaction['status'] == 1 end |