max_exchange_api 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,610 @@
1
+ ## Documentations
2
+
3
+ * [REST API Introduction](https://max.maicoin.com/documents/api_v2)
4
+ * [WebSocket API Documentation](https://maicoin.github.io/max-websocket-docs/)
5
+
6
+ ## Table of contents
7
+
8
+ <!-- TOC -->
9
+ * [Documentations](#documentations)
10
+ * [Table of contents](#table-of-contents)
11
+ * [Usage](#usage)
12
+ * [Configuration](#configuration)
13
+ * [Set timeout time](#set-timeout-time)
14
+ * [Logging](#logging)
15
+ * [Switch Sub-Account](#switch-sub-account)
16
+ * [Public V2 Api Examples](#public-v2-api-examples)
17
+ * [GET /api/v2/vip_levels](#get-apiv2vip_levels)
18
+ * [GET /api/v2/vip_levels/{level}](#get-apiv2vip_levelslevel)
19
+ * [GET /api/v2/currencies](#get-apiv2currencies)
20
+ * [GET /api/v2/k](#get-apiv2k)
21
+ * [GET /api/v2/depth](#get-apiv2depth)
22
+ * [GET /api/v2/trades](#get-apiv2trades)
23
+ * [GET /api/v2/markets](#get-apiv2markets)
24
+ * [GET /api/v2/summary](#get-apiv2summary)
25
+ * [GET /api/v2/tickers/{path_market}](#get-apiv2tickerspath_market)
26
+ * [GET /api/v2/tickers](#get-apiv2tickers)
27
+ * [GET /api/v2/timestamp](#get-apiv2timestamp)
28
+ * [Private V2 Api Examples](#private-v2-api-examples)
29
+ * [User](#user)
30
+ * [GET /api/v2/members/profile](#get-apiv2membersprofile)
31
+ * [GET /api/v2/members/me](#get-apiv2membersme)
32
+ * [GET /api/v2/members/vip_level](#get-apiv2membersvip_level)
33
+ * [Account](#account)
34
+ * [GET /api/v2/members/accounts](#get-apiv2membersaccounts)
35
+ * [GET /api/v2/members/accounts/{path_currency}](#get-apiv2membersaccountspath_currency)
36
+ * [Order](#order)
37
+ * [GET /api/v2/orders](#get-apiv2orders)
38
+ * [GET /api/v2/order](#get-apiv2order)
39
+ * [POST /api/v2/orders/clear](#post-apiv2ordersclear)
40
+ * [POST /api/v2/order/delete](#post-apiv2orderdelete)
41
+ * [POST /api/v2/orders](#post-apiv2orders)
42
+ * [POST /api/v2/orders/multi/onebyone](#post-apiv2ordersmultionebyone)
43
+ * [Trade](#trade)
44
+ * [GET /api/v2/trades/my/of_order](#get-apiv2tradesmyof_order)
45
+ * [GET /api/v2/trades/my](#get-apiv2tradesmy)
46
+ * [Deposit](#deposit)
47
+ * [GET /api/v2/deposits](#get-apiv2deposits)
48
+ * [GET /api/v2/deposit](#get-apiv2deposit)
49
+ * [GET /api/v2/deposit_addresses](#get-apiv2deposit_addresses)
50
+ * [POST /api/v2/deposit_addresses](#post-apiv2deposit_addresses)
51
+ * [Withdrawal](#withdrawal)
52
+ * [GET /api/v2/withdrawals](#get-apiv2withdrawals)
53
+ * [GET /api/v2/withdrawal](#get-apiv2withdrawal)
54
+ * [POST /api/v2/withdrawal](#post-apiv2withdrawal)
55
+ * [GET /api/v2/withdraw_addresses](#get-apiv2withdraw_addresses)
56
+ * [Internal Transfer](#internal-transfer)
57
+ * [GET /api/v2/internal_transfers](#get-apiv2internal_transfers)
58
+ * [GET /api/v2/internal_transfer](#get-apiv2internal_transfer)
59
+ * [Reward](#reward)
60
+ * [GET /api/v2/rewards](#get-apiv2rewards)
61
+ * [GET /api/v2/rewards/{path_reward_type}](#get-apiv2rewardspath_reward_type)
62
+ * [GET /api/v2/max_rewards/yesterday](#get-apiv2max_rewardsyesterday)
63
+ * [GET /api/v2/yields](#get-apiv2yields)
64
+ <!-- TOC -->
65
+
66
+ ## Usage
67
+
68
+ ```rb
69
+ @public_v2_api = MaxExchangeApi::PublicV2Api.new
70
+ @public_v2_api.depth('usdttwd')
71
+
72
+ access_key, secret_key = File.read('secret').split(',')
73
+ @private_v2_api = MaxExchangeApi::PrivateV2Api.new(access_key, secret_key)
74
+ @private_v2_api.create_order!('usdttwd', 'sell', 1000, price: 31.35)
75
+ @private_v2_api.create_order!('usdttwd', 'buy', 1000, price: 31.15)
76
+ ```
77
+
78
+ ## Configuration
79
+
80
+ ### Set timeout time
81
+
82
+ ```rb
83
+ # Set default timeout time
84
+ MaxExchangeApi.default_config.timeout = 3 # seconds
85
+
86
+ # Create an api instance with custom timeout time
87
+ api = MaxExchangeApi::PublicV2Api.new(config: { timeout: 12 })
88
+ api = MaxExchangeApi::PrivateV2Api.new(access_key, secret_key, config: { timeout: 12 })
89
+ ```
90
+
91
+ ### Logging
92
+
93
+ ```rb
94
+ require 'logger'
95
+
96
+ # Print log to standard output
97
+ MaxExchangeApi.default_config.logger = Logger.new(STDOUT)
98
+
99
+ # Print log to file
100
+ MaxExchangeApi.default_config.logger = Logger.new('log/api.log')
101
+
102
+ # Create an api instance with custom logger
103
+ api = MaxExchangeApi::PublicV2Api.new(config: { logger: Logger.new(STDOUT) })
104
+ api = MaxExchangeApi::PrivateV2Api.new(access_key, secret_key, config: { logger: Logger.new(STDOUT) })
105
+ ```
106
+
107
+ ### Switch Sub-Account
108
+
109
+ Not supported in V2 API
110
+
111
+ ## Public V2 Api Examples
112
+
113
+ ```rb
114
+ @public_v2_api = MaxExchangeApi::PublicV2Api.new
115
+ ```
116
+
117
+ #### [GET /api/v2/vip_levels](https://max-api.maicoin.com/doc/v2.html#tag/public/operation/getApiV2VipLevels)
118
+
119
+ > Get all VIP level fees.
120
+
121
+ ```rb
122
+ @public_v2_api.vip_levels
123
+ ```
124
+
125
+ #### [GET /api/v2/vip_levels/{level}](https://max-api.maicoin.com/doc/v2.html#tag/public/operation/getApiV2VipLevelsLevel)
126
+
127
+ > Get VIP level fee by level.
128
+
129
+ ```rb
130
+ @public_v2_api.vip_levels(2)
131
+ ```
132
+
133
+ #### [GET /api/v2/currencies](https://max-api.maicoin.com/doc/v2.html#tag/public/operation/getApiV2Currencies)
134
+
135
+ > Get all available currencies.
136
+
137
+ ```rb
138
+ @public_v2_api.currencies
139
+ ```
140
+
141
+ #### [GET /api/v2/k](https://max-api.maicoin.com/doc/v2.html#tag/public/operation/getApiV2K)
142
+
143
+ > Get OHLC(k line) of a specific market.
144
+
145
+ ```rb
146
+ # use default parameters
147
+ @public_v2_api.k('btctwd')
148
+
149
+ # provide all possible parameters
150
+ @public_v2_api.k('btctwd', limit: 30, period: 1, timestamp: 1624705402)
151
+ ```
152
+
153
+ #### [GET /api/v2/depth](https://max-api.maicoin.com/doc/v2.html#tag/public/operation/getApiV2Depth)
154
+
155
+ > Get depth of a specified market.
156
+
157
+ ```rb
158
+ # use default parameters
159
+ @public_v2_api.depth('maxtwd')
160
+
161
+ # provide all possible parameters
162
+ @public_v2_api.depth('maxtwd', limit: 10, sort_by_price: true)
163
+ ```
164
+
165
+ #### [GET /api/v2/trades](https://max-api.maicoin.com/doc/v2.html#tag/public/operation/getApiV2Trades)
166
+
167
+ > Get recent trades on market, sorted in reverse creation order.
168
+
169
+ ```rb
170
+ # use default parameters
171
+ @public_v2_api.trades('btctwd')
172
+
173
+ # provide all possible parameters
174
+ @public_v2_api.trades(
175
+ 'maxtwd',
176
+ timestamp: 1624705402,
177
+ from: 68444,
178
+ to: 69444,
179
+ order_by: 'asc',
180
+ pagination: true,
181
+ page: 3,
182
+ limit: 15,
183
+ offset: 5,
184
+ )
185
+ ```
186
+
187
+ #### [GET /api/v2/markets](https://max-api.maicoin.com/doc/v2.html#tag/public/operation/getApiV2Markets)
188
+
189
+ > Get all available markets.
190
+
191
+ ```rb
192
+ @public_v2_api.markets
193
+ ```
194
+
195
+ #### [GET /api/v2/summary](https://max-api.maicoin.com/doc/v2.html#tag/public/operation/getApiV2Summary)
196
+
197
+ > Overview of market data for all tickers.
198
+
199
+ ```rb
200
+ @public_v2_api.summary
201
+ ```
202
+
203
+ #### [GET /api/v2/tickers/{path_market}](https://max-api.maicoin.com/doc/v2.html#tag/public/operation/getApiV2TickersPathMarket)
204
+
205
+ > Get ticker of specific market.
206
+
207
+ ```rb
208
+ @public_v2_api.tickers('btctwd')
209
+ ```
210
+
211
+ #### [GET /api/v2/tickers](https://max-api.maicoin.com/doc/v2.html#tag/public/operation/getApiV2Tickers)
212
+
213
+ > Get ticker of all markets.
214
+
215
+ ```rb
216
+ @public_v2_api.tickers
217
+ ```
218
+
219
+ #### [GET /api/v2/timestamp](https://max-api.maicoin.com/doc/v2.html#tag/public/operation/getApiV2Timestamp)
220
+
221
+ > Get server current time, in seconds since Unix epoch.
222
+
223
+ ```rb
224
+ @public_v2_api.timestamp
225
+ ```
226
+
227
+ ## Private V2 Api Examples
228
+
229
+ ```rb
230
+ access_key = 'YOUR_ACCESS_KEY'
231
+ secret_key = 'YOUR_SECRET_KEY'
232
+
233
+ @private_v2_api = MaxExchangeApi::PrivateV2Api.new(access_key, secret_key)
234
+ ```
235
+
236
+ ### User
237
+ #### [GET /api/v2/members/profile](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2MembersProfile)
238
+
239
+ > get personal profile information
240
+
241
+ ```rb
242
+ @private_v2_api.member_profile
243
+ ```
244
+
245
+ #### [GET /api/v2/members/me](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2MembersMe)
246
+
247
+ > get your profile and accounts information
248
+
249
+ ```rb
250
+ @private_v2_api.me
251
+ ```
252
+
253
+ #### [GET /api/v2/members/vip_level](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2MembersVipLevel)
254
+
255
+ > get VIP level info
256
+
257
+ ```rb
258
+ @private_v2_api.vip_level
259
+ ```
260
+
261
+ ### Account
262
+ #### [GET /api/v2/members/accounts](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2MembersAccounts)
263
+
264
+ > get personal accounts information
265
+
266
+ ```rb
267
+ @private_v2_api.accounts
268
+ ```
269
+
270
+ #### [GET /api/v2/members/accounts/{path_currency}](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2MembersAccountsPathCurrency)
271
+
272
+ > get personal accounts information of a currency
273
+
274
+ ```rb
275
+ @private_v2_api.account(currnecy)
276
+ ```
277
+
278
+ ### Order
279
+ #### [GET /api/v2/orders](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2Orders)
280
+
281
+ > get your orders, results is paginated.
282
+
283
+ ```rb
284
+ # use default parameters
285
+ @private_v2_api.orders('maxtwd')
286
+
287
+ # provide all possible parameters
288
+ @api.orders(
289
+ 'maxtwd',
290
+ state: 'done',
291
+ order_by: 'desc',
292
+ group_id: 12345,
293
+ pagination: true,
294
+ page: 3,
295
+ limit: 15,
296
+ offset: 5,
297
+ )
298
+ ```
299
+
300
+ #### [GET /api/v2/order](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2Order)
301
+
302
+ > get a specific order.
303
+
304
+ ```rb
305
+ # use max unique order id
306
+ @api.order(123456)
307
+
308
+ # use user specified order id
309
+ @api.order('MY_ORDER_123456', use_client_id: true)
310
+ ```
311
+
312
+ #### [POST /api/v2/orders/clear](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/postApiV2OrdersClear)
313
+
314
+ > cancel all your orders with given market and side
315
+
316
+ ```rb
317
+ # use default parameters
318
+ @api.cancel_orders!
319
+
320
+ # provide all possible parameters
321
+ @api.cancel_orders!(market: 'maxtwd', side: 'sell', group_id: '123456')
322
+ ```
323
+
324
+ #### [POST /api/v2/order/delete](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/postApiV2OrderDelete)
325
+
326
+ > cancel an order
327
+
328
+ ```rb
329
+ # use max unique order id
330
+ @api.cancel_order!(123456)
331
+
332
+ # use user specified order id
333
+ @api.cancel_order!('MY_ORDER_123456', use_client_id: true)
334
+ ```
335
+
336
+ #### [POST /api/v2/orders](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/postApiV2Orders)
337
+
338
+ > create a sell/buy order
339
+
340
+ ```rb
341
+ # use default parameters
342
+ @api.create_order!('maxtwd', 'buy', 1000, price: 7.5)
343
+
344
+ # provide all possible parameters
345
+ @api.create_order!(
346
+ 'maxtwd',
347
+ 'buy',
348
+ 1000,
349
+ price: 7.5,
350
+ client_oid: 'MY_ORDER_ID_12345',
351
+ stop_price: 8,
352
+ ord_type: 'limit',
353
+ group_id: 12345678,
354
+ )
355
+ ```
356
+
357
+ #### [POST /api/v2/orders/multi/onebyone](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/postApiV2OrdersMultiOnebyone)
358
+
359
+ > Create multiple sell/buy orders, orders may be partially accepted, please put your orders as an array in json body.
360
+
361
+ ```rb
362
+ # use default parameters
363
+ @api.create_orders!('maxtwd', [
364
+ { side: 'buy', volume: '1000', price: '7.5' },
365
+ { side: 'buy', volume: '1500', price: '7.2' },
366
+ ])
367
+
368
+ # provide all possible parameters
369
+ @api.create_orders!('maxtwd', [
370
+ { side: 'buy', volume: '1000', price: '7.5', client_oid: 'MY_ORDER_ID_12345', stop_price: '8', ord_type: 'limit' },
371
+ { side: 'buy', volume: '1500', price: '7.2', client_oid: 'MY_ORDER_ID_12346', stop_price: '8', ord_type: 'limit' },
372
+ ], group_id: 12345)
373
+ ```
374
+
375
+ ### Trade
376
+ #### [GET /api/v2/trades/my/of_order](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2TradesMyOfOrder)
377
+
378
+ > get your executed trades related to a order
379
+
380
+ ```rb
381
+ # use max unique order id
382
+ @private_v2_api.my_trades_of_order(123456)
383
+
384
+ # use user specified order id
385
+ @private_v2_api.my_trades_of_order('MY_ORDER_123456', use_client_id: true)
386
+ ```
387
+
388
+ #### [GET /api/v2/trades/my](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2TradesMy)
389
+
390
+ > get your executed trades, sorted in reverse creation order
391
+
392
+ ```rb
393
+ # use default parameters
394
+ @private_v2_api.my_trades('btctwd')
395
+
396
+ # provide all possible parameters
397
+ @private_v2_api.my_trades(
398
+ 'maxtwd',
399
+ timestamp: 1624705402,
400
+ from: 68444,
401
+ to: 69444,
402
+ order_by: 'asc',
403
+ pagination: true,
404
+ page: 3,
405
+ limit: 15,
406
+ offset: 5,
407
+ )
408
+ ```
409
+
410
+ ### Deposit
411
+ #### [GET /api/v2/deposits](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2Deposits)
412
+
413
+ > get your deposits history
414
+
415
+ ```rb
416
+ # use default parameters
417
+ @private_v2_api.deposits('max')
418
+
419
+ # provide all possible parameters
420
+ @private_v2_api.deposits(
421
+ 'max',
422
+ 'confirmed',
423
+ from: 68444,
424
+ to: 69444,
425
+ state: 'accepted',
426
+ pagination: true,
427
+ page: 3,
428
+ limit: 15,
429
+ offset: 5,
430
+ )
431
+ ```
432
+
433
+ #### [GET /api/v2/deposit](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2Deposit)
434
+
435
+ > get details of a specific deposit
436
+
437
+ ```rb
438
+ @private_v2_api.deposit('transaction_id')
439
+ ```
440
+
441
+ #### [GET /api/v2/deposit_addresses](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2DepositAddresses)
442
+
443
+ > The addresses could be empty before generated, please call POST /deposit_addresses in that case
444
+
445
+ ```rb
446
+ # use default parameters
447
+ @private_v2_api.deposit_addresses
448
+
449
+ # provide all possible parameters
450
+ @private_v2_api.deposit_addresses(currency: 'twd', pagination: true, page: 3, limit: 15, offset: 5)
451
+ ```
452
+
453
+ #### [POST /api/v2/deposit_addresses](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/postApiV2DepositAddresses)
454
+
455
+ > Address creation is asynchronous, please call GET /deposit_addresses later to get generated addresses
456
+
457
+ ```rb
458
+ @private_v2_api.create_deposit_addresses!('twd')
459
+ ```
460
+
461
+ ### Withdrawal
462
+ #### [GET /api/v2/withdrawals](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2Withdrawals)
463
+
464
+ > get your external withdrawals history
465
+
466
+ ```rb
467
+ # use default parameters
468
+ @private_v2_api.withdrawals('max')
469
+
470
+ # provide all possible parameters
471
+ @private_v2_api.withdrawals(
472
+ 'max',
473
+ 'confirmed',
474
+ from: 68444,
475
+ to: 69444,
476
+ state: 'confirmed',
477
+ pagination: true,
478
+ page: 3,
479
+ limit: 15,
480
+ offset: 5,
481
+ )
482
+ ```
483
+
484
+ #### [GET /api/v2/withdrawal](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2Withdrawal)
485
+
486
+ > get details of a specific external withdraw
487
+
488
+ ```rb
489
+ @private_v2_api.withdrawal('withdraw_id')
490
+ ```
491
+
492
+ #### [POST /api/v2/withdrawal](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/postApiV2Withdrawal)
493
+
494
+ > submit a withdrawal. IP whitelist for api token is required.
495
+
496
+ ```rb
497
+ @private_v2_api.create_withdrawal!('twd', 'withdraw_address_id', 100000)
498
+ ```
499
+
500
+ #### [GET /api/v2/withdraw_addresses](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2WithdrawAddresses)
501
+
502
+ > get withdraw addresses
503
+
504
+ ```rb
505
+ # use default parameters
506
+ @private_v2_api.withdraw_addresses('twd')
507
+
508
+ # provide all possible parameters
509
+ @private_v2_api.withdraw_addresses('usdt', pagination: true, page: 3, limit: 15, offset: 5)
510
+ ```
511
+
512
+ ### Internal Transfer
513
+ #### [GET /api/v2/internal_transfers](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2InternalTransfers)
514
+
515
+ > get internal transfers history
516
+
517
+ ```rb
518
+ # use default parameters
519
+ @private_v2_api.internal_transfers
520
+
521
+ # provide all possible parameters
522
+ @private_v2_api.internal_transfers(
523
+ currency: 'btc',
524
+ side: 'in',
525
+ from: 68444,
526
+ to: 69444,
527
+ pagination: true,
528
+ page: 3,
529
+ limit: 15,
530
+ offset: 5,
531
+ )
532
+ ```
533
+
534
+ #### [GET /api/v2/internal_transfer](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2InternalTransfer)
535
+
536
+ > get details of a specific internal transfer
537
+
538
+ ```rb
539
+ @private_v2_api.internal_transfer('internal_transfer_id')
540
+ ```
541
+
542
+ ### Reward
543
+ #### [GET /api/v2/rewards](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2Rewards)
544
+
545
+ > get rewards history
546
+
547
+ ```rb
548
+ # use default parameters
549
+ @private_v2_api.rewards
550
+
551
+ # provide all possible parameters
552
+ @private_v2_api.rewards(
553
+ currency: 'btc',
554
+ from: 68444,
555
+ to: 69444,
556
+ pagination: true,
557
+ page: 3,
558
+ limit: 15,
559
+ offset: 5,
560
+ )
561
+ ```
562
+
563
+ #### [GET /api/v2/rewards/{path_reward_type}](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2RewardsPathRewardType)
564
+
565
+ > get specific rewards history
566
+
567
+ ```rb
568
+ # use default parameters
569
+ @private_v2_api.rewards(reward_type: 'airdrop_rewards')
570
+
571
+ # provide all possible parameters
572
+ @private_v2_api.rewards(
573
+ reward_type: 'airdrop_rewards',
574
+ currency: 'btc',
575
+ from: 68444,
576
+ to: 69444,
577
+ pagination: true,
578
+ page: 3,
579
+ limit: 15,
580
+ offset: 5,
581
+ )
582
+ ```
583
+
584
+ #### [GET /api/v2/max_rewards/yesterday](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2MaxRewardsYesterday)
585
+
586
+ > get max rewards yesterday
587
+
588
+ ```rb
589
+ @private_v2_api.max_rewards_yesterday
590
+ ```
591
+
592
+ #### [GET /api/v2/yields](https://max-api.maicoin.com/doc/v2.html#tag/private/operation/getApiV2Yields)
593
+
594
+ > get yields history
595
+
596
+ ```rb
597
+ # use default parameters
598
+ @private_v2_api.yields
599
+
600
+ # provide all possible parameters
601
+ @private_v2_api.yields(
602
+ currency: 'usdt',
603
+ from: 68444,
604
+ to: 69444,
605
+ pagination: true,
606
+ page: 3,
607
+ limit: 15,
608
+ offset: 5,
609
+ )
610
+ ```