class Bitmart::API::V1::Account

Constants

API_ENDPOINT

Attributes

api_key[R]
api_memo[R]
api_sign[R]
signature[R]
timestamp[R]

Public Class Methods

new(api_key = nil, api_sign = nil, api_memo = nil) click to toggle source
# File lib/bitmart/api_account.rb, line 13
def initialize(api_key = nil, api_sign = nil, api_memo = nil)
    @api_key = api_key
    @api_sign = api_sign
    @api_memo = api_memo
end

Public Instance Methods

get_currencies() click to toggle source

GET api-cloud.bitmart.com/account/v1/currencies

# File lib/bitmart/api_account.rb, line 20
def get_currencies
    request(
        http_method: :get,
        endpoint: "currencies"
    )
end
get_deposit_address(currency) click to toggle source

GET api-cloud.bitmart.com/account/v1/deposit/address

# File lib/bitmart/api_account.rb, line 40
def get_deposit_address(currency)
    params = {
        'currency': currency
    }
    request(
        http_method: :get,
        endpoint: "wallet",
        params: params
    )
end
get_deposit_withdraw_detail(id) click to toggle source

GET api-cloud.bitmart.com/account/v1/deposit-withdraw/detail

# File lib/bitmart/api_account.rb, line 95
def get_deposit_withdraw_detail(id)
    params = {
        'id': id
    }
    request(
        http_method: :get,
        endpoint: "deposit-withdraw/detail",
        params: params
    )
end
get_deposit_withdraw_history(currency, operationType, offset, limit) click to toggle source

GET api-cloud.bitmart.com/account/v1/deposit-withdraw/history

# File lib/bitmart/api_account.rb, line 80
def get_deposit_withdraw_history(currency, operationType, offset, limit)
    params = {
        'currency': currency,
        'limit': limit,
        'offset': offset,
        'operation_type': operationType,
    }
    request(
        http_method: :get,
        endpoint: "deposit-withdraw/history",
        params: params
    )
end
get_wallet(accountType) click to toggle source

GET api-cloud.bitmart.com/account/v1/wallet

# File lib/bitmart/api_account.rb, line 28
def get_wallet(accountType)
    params = {
        'account_type': accountType
    }
    request(
        http_method: :get,
        endpoint: "wallet",
        params: params
    )
end
get_withdraw_charge(currency) click to toggle source

GET api-cloud.bitmart.com/account/v1/withdraw/charge

# File lib/bitmart/api_account.rb, line 52
def get_withdraw_charge(currency)
    params = {
        'currency': currency
    }
    request(
        http_method: :get,
        endpoint: "withdraw/charge",
        params: params
    )
end
post_withdraw_apply(currency, amount, destination, address, address_memo) click to toggle source

POST api-cloud.bitmart.com/account/v1/withdraw/apply

# File lib/bitmart/api_account.rb, line 64
def post_withdraw_apply(currency, amount, destination, address, address_memo)
    params = {
        'address': address,
        'address_memo': address_memo,
        'amount': amount,
        'currency': currency,
        'destination': destination,
    }
    request(
        http_method: :post,
        endpoint: "withdraw/apply",
        params: params
    )
end

Private Instance Methods

client() click to toggle source
# File lib/bitmart/api_account.rb, line 108
def client
    @_client ||= Faraday.new(API_ENDPOINT) do |client|
        client.request :url_encoded
        client.adapter Faraday.default_adapter
        client.headers["Content-Type"] = "application/json"
        client.headers['X-BM-KEY'] = api_key unless api_key&.nil?
        client.headers['X-BM-SIGN'] = @signature if @signature
        client.headers['X-BM-TIMESTAMP'] = @timestamp if @timestamp
    end
end
request(http_method:, endpoint:, params: {}) click to toggle source
# File lib/bitmart/api_account.rb, line 119
def request(http_method:, endpoint:, params: {})
    if http_method == :post
        @timestamp = Bitmart::API::System.new.get_system_time["data"]["server_time"].to_s
        params = Oj.dump(params)
        data = [timestamp,"#",api_memo,"#",params].join 
        @signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), api_sign, data)
    end
    response = client.public_send(http_method, endpoint, params)
    Oj.load(response.body)
end