class Bitmart::API::V1::Contract
Constants
- API_ENDPOINT
Attributes
Public Class Methods
# File lib/bitmart/api_contract.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 api-cloud.bitmart.com/contract/v1/ifcontract/accounts
# File lib/bitmart/api_contract.rb, line 209 def get_accounts(coinCode) params = {'coinCode': coinCode} request( http_method: :get, endpoint: "ifcontract/userOrders", params: params ) end
GET api-cloud.bitmart.com/contract/v1/ifcontract/contracts
# File lib/bitmart/api_contract.rb, line 20 def get_contracts params = {'exchange': 'bitmart'} request( http_method: :get, endpoint: "ifcontract/contracts", params: params ) end
GET api-cloud.bitmart.com/contract/v1/ifcontract/depth
# File lib/bitmart/api_contract.rb, line 102 def get_depth(contractId, count = nil) params = {'contractID': contractId} param['count'] = count if count request( http_method: :get, endpoint: "ifcontract/depth", params: params ) end
GET api-cloud.bitmart.com/contract/v1/ifcontract/fundingrate
# File lib/bitmart/api_contract.rb, line 113 def get_funding_rate(contractId) params = {'contractID': contractId} request( http_method: :get, endpoint: "ifcontract/fundingrate", params: params ) end
GET api-cloud.bitmart.com/contract/v1/ifcontract/indexquote
# File lib/bitmart/api_contract.rb, line 76 def get_index_quote(indexId, startTime, endTime, unit, resolution) params = { 'endTime': endTime, 'indexID': indexId, 'resolution': resolution, 'startTime': startTime, 'unit': unit, } request( http_method: :get, endpoint: "ifcontract/indexquote", params: params ) end
GET api-cloud.bitmart.com/contract/v1/ifcontract/indexes
# File lib/bitmart/api_contract.rb, line 40 def get_indexes request( http_method: :get, endpoint: "ifcontract/indexes", params: params ) end
GET api-cloud.bitmart.com/contract/v1/ifcontract/orderTrades
# File lib/bitmart/api_contract.rb, line 199 def get_order_trades(contractId, orderId) params = {'contractID': contractId, 'orderID': orderId} request( http_method: :get, endpoint: "ifcontract/orderTrades", params: params ) end
GET api-cloud.bitmart.com/contract/v1/ifcontract/pnls
# File lib/bitmart/api_contract.rb, line 30 def get_pnls(contractId) params = {'contractID': contractId} request( http_method: :get, endpoint: "ifcontract/pnls", params: params ) end
GET api-cloud.bitmart.com/contract/v1/ifcontract/positionFee
# File lib/bitmart/api_contract.rb, line 242 def get_position_fee(contractId, positionId) params = { 'contractID': contractId, 'positionID': positionId } request( http_method: :get, endpoint: "ifcontract/positionFee", params: params ) end
GET api-cloud.bitmart.com/contract/v1/ifcontract/quote
# File lib/bitmart/api_contract.rb, line 60 def get_quote(contractId, startTime, endTime, unit, resolution) params = { 'contractID': contractId, 'endTime': endTime, 'resolution': resolution, 'startTime': startTime, 'unit': unit, } request( http_method: :get, endpoint: "ifcontract/quote", params: params ) end
GET api-cloud.bitmart.com/contract/v1/ifcontract/tickers
# File lib/bitmart/api_contract.rb, line 49 def get_tickers(contractId = nil) params = {} params = {'contractID': contractId} if contractId request( http_method: :get, endpoint: "ifcontract/tickers", params: params ) end
GET api-cloud.bitmart.com/contract/v1/ifcontract/trades
# File lib/bitmart/api_contract.rb, line 92 def get_trades(contractId) params = {'contractID': contractId} request( http_method: :get, endpoint: "ifcontract/trades", params: params ) end
GET api-cloud.bitmart.com/contract/v1/ifcontract/userLiqRecords
# File lib/bitmart/api_contract.rb, line 229 def get_user_liq_records(contractId, orderId) params = { 'contractID': contractId, 'orderID': orderId } request( http_method: :get, endpoint: "ifcontract/userLiqRecords", params: params ) end
GET api-cloud.bitmart.com/contract/v1/ifcontract/userOrderInfo
# File lib/bitmart/api_contract.rb, line 138 def get_user_order_info(contractId, orderId) params = {'contractID': contractId, 'orderID': orderId} request( http_method: :get, endpoint: "ifcontract/userOrderInfo", params: params ) end
Order API
GET api-cloud.bitmart.com/contract/v1/ifcontract/userOrders
# File lib/bitmart/api_contract.rb, line 124 def get_user_orders(contractId, status, offset = nil, size = nil) params = {'contractID': contractId, 'status': status} if offset && size params['offset'] = offset params['size'] = size end request( http_method: :get, endpoint: "ifcontract/userOrders", params: params ) end
GET api-cloud.bitmart.com/contract/v1/ifcontract/userPositions
# File lib/bitmart/api_contract.rb, line 219 def get_user_positions(contractId) params = {'contractID': contractId} request( http_method: :get, endpoint: "ifcontract/userPositions", params: params ) end
GET api-cloud.bitmart.com/contract/v1/ifcontract/userTrades
# File lib/bitmart/api_contract.rb, line 187 def get_user_trades(contractId, offset = nil, size = nil) params = {'contractID': contractId} params['offset'] = offset if offset params['size'] = size if size request( http_method: :get, endpoint: "ifcontract/userTrades", params: params ) end
POST api-cloud.bitmart.com/contract/v1/ifcontract/cancelOrders
# File lib/bitmart/api_contract.rb, line 177 def post_cancel_order(contractId, orders) params = {'contractID': contractId, 'orders': orders} request( http_method: :get, endpoint: "ifcontract/cancelOrders", params: params ) end
POST api-cloud.bitmart.com/contract/v1/ifcontract/marginOper
# File lib/bitmart/api_contract.rb, line 255 def post_margin_oper(contractId, positionId, vol, operType) params = { 'contract_id': contractId, 'oper_type': operType, 'position_id': positionId, 'vol': vol, } request( http_method: :post, endpoint: "ifcontract/marginOper", params: params ) end
POST api-cloud.bitmart.com/contract/v1/ifcontract/batchOrders
# File lib/bitmart/api_contract.rb, line 167 def post_submit_batch_order(orders) params = {'orders': orders} request( http_method: :get, endpoint: "ifcontract/batchOrders", params: params ) end
POST api-cloud.bitmart.com/contract/v1/ifcontract/submitOrder
# File lib/bitmart/api_contract.rb, line 148 def post_submit_order(contractId, category, way, openType, leverage, customId, price, vol) params = { 'category': category, 'contract_id': contractId, 'custom_id': customId, 'leverage': leverage, 'open_type': openType, 'price': price, 'vol': vol, 'way': way, } request( http_method: :post, endpoint: "ifcontract/submitOrder", params: params ) end
Private Instance Methods
# File lib/bitmart/api_contract.rb, line 271 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
# File lib/bitmart/api_contract.rb, line 282 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