Class: Bitmart::API::V1::Contract

Inherits:
Object
  • Object
show all
Defined in:
lib/bitmart/api_contract.rb

Constant Summary collapse

API_ENDPOINT =
'https://api-cloud.bitmart.com/contract/v1'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil, api_sign = nil, api_memo = nil) ⇒ Contract

Returns a new instance of Contract.



13
14
15
16
17
# 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

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



7
8
9
# File 'lib/bitmart/api_contract.rb', line 7

def api_key
  @api_key
end

#api_memoObject (readonly)

Returns the value of attribute api_memo.



9
10
11
# File 'lib/bitmart/api_contract.rb', line 9

def api_memo
  @api_memo
end

#api_signObject (readonly)

Returns the value of attribute api_sign.



8
9
10
# File 'lib/bitmart/api_contract.rb', line 8

def api_sign
  @api_sign
end

#signatureObject (readonly)

Returns the value of attribute signature.



11
12
13
# File 'lib/bitmart/api_contract.rb', line 11

def signature
  @signature
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



10
11
12
# File 'lib/bitmart/api_contract.rb', line 10

def timestamp
  @timestamp
end

Instance Method Details

#get_accounts(coinCode) ⇒ Object



209
210
211
212
213
214
215
216
# 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_contractsObject



20
21
22
23
24
25
26
27
# 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_depth(contractId, count = nil) ⇒ Object



102
103
104
105
106
107
108
109
110
# 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_funding_rate(contractId) ⇒ Object



113
114
115
116
117
118
119
120
# 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_index_quote(indexId, startTime, endTime, unit, resolution) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# 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_indexesObject



40
41
42
43
44
45
46
# File 'lib/bitmart/api_contract.rb', line 40

def get_indexes
    request(
        http_method: :get,
        endpoint: "ifcontract/indexes",
        params: params
    )
end

#get_order_trades(contractId, orderId) ⇒ Object



199
200
201
202
203
204
205
206
# 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_pnls(contractId) ⇒ Object



30
31
32
33
34
35
36
37
# 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_position_fee(contractId, positionId) ⇒ Object



242
243
244
245
246
247
248
249
250
251
252
# 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_quote(contractId, startTime, endTime, unit, resolution) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 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_tickers(contractId = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
# 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_trades(contractId) ⇒ Object



92
93
94
95
96
97
98
99
# 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_user_liq_records(contractId, orderId) ⇒ Object



229
230
231
232
233
234
235
236
237
238
239
# 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_user_order_info(contractId, orderId) ⇒ Object



138
139
140
141
142
143
144
145
# 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

#get_user_orders(contractId, status, offset = nil, size = nil) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
# 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_user_positions(contractId) ⇒ Object



219
220
221
222
223
224
225
226
# 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_user_trades(contractId, offset = nil, size = nil) ⇒ Object



187
188
189
190
191
192
193
194
195
196
# 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_cancel_order(contractId, orders) ⇒ Object



177
178
179
180
181
182
183
184
# 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_margin_oper(contractId, positionId, vol, operType) ⇒ Object



255
256
257
258
259
260
261
262
263
264
265
266
267
# 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_submit_batch_order(orders) ⇒ Object



167
168
169
170
171
172
173
174
# 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_submit_order(contractId, category, way, openType, leverage, customId, price, vol) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# 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