class Bitmart::API::V1::Spot

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_spot.rb, line 16
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

basic API GET api-cloud.bitmart.com/spot/v1/currencies

# File lib/bitmart/api_spot.rb, line 24
def get_currencies
    request(
        http_method: :get,
        endpoint: "currencies"
    )
end
get_steps() click to toggle source

GET api-cloud.bitmart.com/spot/v1/steps

# File lib/bitmart/api_spot.rb, line 65
def get_steps
    request(
        http_method: :get,
        endpoint: "steps"
    )
end
get_symbol_book(symbol, precision = nil, size = nil) click to toggle source

GET api-cloud.bitmart.com/spot/v1/symbols/book

# File lib/bitmart/api_spot.rb, line 88
def get_symbol_book(symbol, precision = nil, size = nil)
    params = {
        'symbol' => symbol
    }
    param['precision'] = precision if precision
    param['size'] = size if size
    request(
        http_method: :get,
        endpoint: "symbols/book",
        params: params
    )
end
get_symbol_detail() click to toggle source

GET api-cloud.bitmart.com/spot/v1/symbols/details

# File lib/bitmart/api_spot.rb, line 40
def get_symbol_detail
    request(
        http_method: :get,
        endpoint: "symbols/details"
    )
end
get_symbol_kline(symbol, fromTime, toTime, step = 1) click to toggle source

GET api-cloud.bitmart.com/spot/v1/symbols/kline

# File lib/bitmart/api_spot.rb, line 73
def get_symbol_kline(symbol, fromTime, toTime, step = 1)
    params = {
        'symbol' => symbol,
        'from' => fromTime,
        'to' => toTime,
        'step' => step
    }
    request(
        http_method: :get,
        endpoint: "symboles/kline",
        params: params
    )
end
get_symbol_ticker(symbol) click to toggle source
# File lib/bitmart/api_spot.rb, line 55
def get_symbol_ticker(symbol)
    params = {'symbol' => symbol}
    request(
        http_method: :get,
        endpoint: "ticker",
        params: params
    )
end
get_symbol_trades(symbol) click to toggle source

GET api-cloud.bitmart.com/spot/v1/symbols/trades

# File lib/bitmart/api_spot.rb, line 102
def get_symbol_trades(symbol)
    params = {
        'symbol' => symbol
    }
    request(
        http_method: :get,
        endpoint: "symbols/trades",
        params: params
    )
end
get_symbols() click to toggle source

GET api-cloud.bitmart.com/spot/v1/symbols

# File lib/bitmart/api_spot.rb, line 32
def get_symbols
    request(
        http_method: :get,
        endpoint: "symbols"
    )
end
get_ticker() click to toggle source

GET api-cloud.bitmart.com/spot/v1/ticker

# File lib/bitmart/api_spot.rb, line 48
def get_ticker
    request(
        http_method: :get,
        endpoint: "ticker"
    )
end
get_user_order_detail(symbol, orderId) click to toggle source

GET api-cloud.bitmart.com/spot/v1/order_detail

# File lib/bitmart/api_spot.rb, line 209
def get_user_order_detail(symbol, orderId)
    params = {
        'order_id' => orderId,
        'symbol' => symbol,
    }
    request(
        http_method: :get,
        endpoint: "order_detail",
        params: params
    )
end
get_user_order_trades(symbol, orderId) click to toggle source

GET api-cloud.bitmart.com/spot/v1/trades

# File lib/bitmart/api_spot.rb, line 237
def get_user_order_trades(symbol, orderId)
    params = {
        'order_id' => orderId,
        'symbol' => symbol
    }
    request(
        http_method: :get,
        endpoint: "trades",
        params: params
    )
end
get_user_orders(symbol, offset, limit, status) click to toggle source

GET api-cloud.bitmart.com/spot/v1/orders

# File lib/bitmart/api_spot.rb, line 222
def get_user_orders(symbol, offset, limit, status)
    params = {
        'limit' => limit,
        'offset' => offset,
        'status' => status,
        'symbol' => symbol,
    }
    request(
        http_method: :get,
        endpoint: "orders",
        params: params
    )
end
get_user_trades(symbol, offset, limit) click to toggle source
# File lib/bitmart/api_spot.rb, line 249
def get_user_trades(symbol, offset, limit)
    params = {
        'limit' => limit,
        'offset' => offset,
        'symbol' => symbol,        
    }
    request(
        http_method: :get,
        endpoint: "trades",
        params: params
    )
end
get_wallet() click to toggle source

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

# File lib/bitmart/api_spot.rb, line 116
def get_wallet
    request(
        http_method: :get,
        endpoint: "wallet"
    )
end
post_cancel_order(symbol, orderId) click to toggle source

POST api-cloud.bitmart.com/spot/v2/cancel_order

# File lib/bitmart/api_spot.rb, line 183
def post_cancel_order(symbol, orderId)
    params = {
        'order_id' => orderId,
        'symbol' => symbol,
    }
    request(
        http_method: :post,
        endpoint: "cancel_order",
        params: params
    )
end
post_cancel_orders(symbol, side) click to toggle source

POST api-cloud.bitmart.com/spot/v1/cancel_orders

# File lib/bitmart/api_spot.rb, line 196
def post_cancel_orders(symbol, side)
    params = {
        'side' => side,
        'symbol' => symbol,
    }
    request(
        http_method: :post,
        endpoint: "cancel_orders",
        params: params
    )
end
post_submit_limit_buy_order(symbol, size='', price='') click to toggle source

POST api-cloud.bitmart.com/spot/v1/submit_order

# File lib/bitmart/api_spot.rb, line 124
def post_submit_limit_buy_order(symbol, size='', price='')
    params = {
        'price' => price,
        'side' => 'buy',
        'size' => size,
        'symbol' => symbol,
        'type' => 'limit',
    }
    request(
        http_method: :post,
        endpoint: "submit_order",
        params: params
    )
end
post_submit_limit_sell_order(symbol, size='', price='') click to toggle source
# File lib/bitmart/api_spot.rb, line 139
def post_submit_limit_sell_order(symbol, size='', price='')
    params = {
        'price' => price,
        'side' => 'sell',
        'size' => size,
        'symbol' => symbol,
        'type' => 'limit',
    }
    request(
        http_method: :post,
        endpoint: "submit_order",
        params: params
    )
end
post_submit_market_buy_order(symbol, notional='') click to toggle source
# File lib/bitmart/api_spot.rb, line 168
def post_submit_market_buy_order(symbol, notional='')
    params = {
        'notional' => notional,
        'side' => 'buy',
        'symbol' => symbol,
        'type' => 'market',
    }
    request(
        http_method: :post,
        endpoint: "submit_order",
        params: params
    )
end
post_submit_market_sell_order(symbol, size='') click to toggle source
# File lib/bitmart/api_spot.rb, line 154
def post_submit_market_sell_order(symbol, size='')
    params = {
        'side' => 'sell',
        'size' => size,
        'symbol' => symbol,
        'type' => 'market',
    }
    request(
        http_method: :post,
        endpoint: "submit_order",
        params: params
    )
end

Private Instance Methods

client() click to toggle source
# File lib/bitmart/api_spot.rb, line 264
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_spot.rb, line 275
def request(http_method:, endpoint:, params: {})
    puts http_method
    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