require_relative "base_client" module PortalConnectors class UsdtWalletClient < BaseClient def create_deposit_address(ref:) params = { nonce: next_nonce, external_ref: ref, postback_url: postback_url('deposit') } url = "#{host}/api/v1/btc_addresses/create_deposit_address" res = post_with_signature(url, params) [JSON.parse(res.body_str), %w[200 201].include?(res.response_code.to_s)] rescue => e return_error e end def repost_deposits(address:) params = { nonce: next_nonce, address: address } url = "#{host}/api/v1/btc_addresses/repost_deposits" res = post_with_signature(url, params) [JSON.parse(res.body_str), %w[200 201].include?(res.response_code.to_s)] rescue => e return_error e end def fetch_balance resp, ok = self.fetch_stocks if ok [resp["buffer"]["usdt"].to_d, true] else [resp, false] end end def fetch_stocks(coin: "usdt", report_time: Time.current, start_report_time: nil) params = { nonce: next_nonce, report_time: report_time.to_i, } params[:start_report_time] = start_report_time.to_i if start_report_time url = "#{host}/api/v1/stocks" res = get_with_signature(url, params) json_stocks = JSON.parse(res.body_str) self.class.cached_stocks = json_stocks [json_stocks, res.response_code == 200] rescue => e return_error e end def fetch_deposit(tx_hash:) params = { nonce: next_nonce, tx_hash: tx_hash } url = "#{host}/api/v1/deposits" res = get_with_signature(url, params) [JSON.parse(res.body_str), res.response_code == 200] rescue => e return_error e end def send_withdrawal(address:, amount:, identifier:) params = { nonce: next_nonce, amount: amount, identifier: identifier, postback_url: postback_url('withdrawal'), address: address } url = "#{host}/api/v1/withdrawals/request" res = post_with_signature(url, params) [JSON.parse(res.body_str), res.response_code == 201] rescue => e return_error e end def list_deposit_keys(from_time=Time.current, to_time=Time.current.beginning_of_day) params = { nonce: next_nonce, from_time: from_time.to_i, to_time: to_time.to_i, } url = "#{host}/api/v1/deposits/list_keys" res = get_with_signature(url, params) [JSON.parse(res.body_str), res.response_code == 200] rescue => e return_error e end def list_withdraw_keys(from_time=Time.current, to_time=Time.current.beginning_of_day) params = { nonce: next_nonce, from_time: from_time.to_i, to_time: to_time.to_i, } url = "#{host}/api/v1/withdrawals/list_keys" res = get_with_signature(url, params) [JSON.parse(res.body_str), res.response_code == 200] rescue => e return_error e end private def postback_url(type) "#{PortalConnectors.postbacks.usdt_wallet}/#{type}" end end end