max_exchange_api 0.0.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2850870981b0e9f2735fdc35f3e651451f8f9098894bbf5a6143e85e3c66c0b2
4
- data.tar.gz: 23d415aae12408c224d3666d95b9b28a24065c92a4bd090ea74bbe20c021510d
3
+ metadata.gz: f8bceace151d12c20233b2cf113dc1ffaa07966ade671c8bdb368bfe93c32854
4
+ data.tar.gz: 4edcb0c3c6ffce922b56eeb75b7224b2640366a6068af71039a66fb33025c3d4
5
5
  SHA512:
6
- metadata.gz: c6be2e2a38315742f6b0cba88399539414e48188b66a71634358eacf312c9fbaf7e35ba65c940defb600a8c998f72a01cb2fa5b8e99d41ffb8cedd8662fc28e7
7
- data.tar.gz: 8f2b9a09f71b0f30a3ecc5785851ca6d759751b83ed98d90685f84305b420557f322872bb73b62cd3226a0466e0f81f8386d87d73cbbb027073a6675cd1c923c
6
+ metadata.gz: c1ee9f002c63318a0bf5653c7d372193ca7566fcef4b7da7b270b657a003bfcc35a91ff0e6b97acdaa952d77fe264d62f75daa972fd0cd2ba32d3ed5fd7242cc
7
+ data.tar.gz: 7cb308ff8fe60215816272108cbb0d3a4c0f29f1804648f42832d8699194c764c162326291314675bbb8d46a81d8863ed97368f4c54ddd3b11d3913c11a0b9e3
data/.rubocop.yml CHANGED
@@ -243,7 +243,7 @@ Metrics/ModuleLength:
243
243
  Metrics/ParameterLists:
244
244
  Description: 'Avoid parameter lists longer than three or four parameters.'
245
245
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#too-many-params'
246
- Enabled: true
246
+ Enabled: false
247
247
 
248
248
  Metrics/PerceivedComplexity:
249
249
  Description: >-
@@ -337,7 +337,7 @@ Rails/HasAndBelongsToMany:
337
337
 
338
338
  Rails/Output:
339
339
  Description: 'Checks for calls to puts, print, etc.'
340
- Enabled: true
340
+ Enabled: false
341
341
 
342
342
  Rails/ReadWriteAttribute:
343
343
  Description: >-
@@ -812,7 +812,7 @@ Style/NumericLiterals:
812
812
  Add underscores to large numeric literals to improve their
813
813
  readability.
814
814
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscores-in-numerics'
815
- Enabled: true
815
+ Enabled: false
816
816
 
817
817
  Style/OneLineConditional:
818
818
  Description: >-
data/CHANGELOG.md CHANGED
@@ -1 +1,15 @@
1
- ## Change Log
1
+ ## Change Log
2
+
3
+ ### [v1.1.0](https://github.com/khiav223577/max_exchange_api/compare/v1.0.0...v1.1.0) 2021/06/27
4
+ - [#6](https://github.com/khiav223577/max_exchange_api/pull/6) Allow every api instance to have custom config (@khiav223577)
5
+
6
+ ### [v1.0.0](https://github.com/khiav223577/max_exchange_api/compare/v0.1.0...v1.0.0) 2021/06/27
7
+ - [#5](https://github.com/khiav223577/max_exchange_api/pull/5) Implement all v2 private APIs (@khiav223577)
8
+ - [#4](https://github.com/khiav223577/max_exchange_api/pull/4) Add logger config (@khiav223577)
9
+
10
+ ### [v0.1.0](https://github.com/khiav223577/max_exchange_api/compare/v0.0.1...v0.1.0) 2021/06/26
11
+ - [#3](https://github.com/khiav223577/max_exchange_api/pull/3) Add default_timeout config (@khiav223577)
12
+ - [#2](https://github.com/khiav223577/max_exchange_api/pull/2) Implement all v2 public APIs (@khiav223577)
13
+
14
+ ### v0.0.1 2021/06/23
15
+ - [#1](https://github.com/khiav223577/max_exchange_api/pull/1) Implement `/depth` API (@khiav223577)
data/README.md CHANGED
@@ -35,16 +35,100 @@ Or install it yourself as:
35
35
 
36
36
  $ gem install max_exchange_api
37
37
 
38
+ ## Configuration
39
+
40
+ ### Set timeout time
41
+
42
+ ```rb
43
+ # default config
44
+ MaxExchangeApi.default_config.timeout = 3 # seconds
45
+
46
+ # custom config
47
+ MaxExchangeApi::PublicApi.new(config: { timeout: 12 })
48
+ MaxExchangeApi::PrivateApi.new(access_key, secret_key, config: { timeout: 12 })
49
+ ```
50
+
51
+ ### Logging
52
+
53
+ ```rb
54
+ require 'logger'
55
+
56
+ # default config
57
+ MaxExchangeApi.default_config.logger = Logger.new(STDOUT) # print log to stdand output
58
+ MaxExchangeApi.default_config.logger = Logger.new('log/api.log')
59
+
60
+ # custom config
61
+ MaxExchangeApi::PublicApi.new(config: { logger: Logger.new(STDOUT) })
62
+ MaxExchangeApi::PrivateApi.new(access_key, secret_key, config: { logger: Logger.new(STDOUT) })
63
+ ```
64
+
38
65
  ## Usage
39
66
 
40
- ### Public Apis
67
+ ### Public Api Examples
41
68
 
42
69
  ```rb
43
70
  @api = MaxExchangeApi::PublicApi.new
44
71
  ```
45
72
 
73
+ #### [GET GET /api/v2/vip_levels](https://max.maicoin.com/documents/api_list#!/public/getApiV2VipLevels)
74
+
75
+ > Get all VIP level fees.
76
+
77
+ <details>
78
+ <summary>Show code</summary>
79
+
80
+ ```rb
81
+ @api.vip_levels
82
+ ```
83
+ </details>
84
+
85
+ #### [GET /api/v2/vip_levels/{level}](https://max.maicoin.com/documents/api_list#!/public/getApiV2VipLevelsLevel)
86
+
87
+ > Get VIP level fee by level.
88
+
89
+ <details>
90
+ <summary>Show code</summary>
91
+
92
+ ```rb
93
+ @api.vip_levels(2)
94
+ ```
95
+ </details>
96
+
97
+ #### [GET /api/v2/currencies](https://max.maicoin.com/documents/api_list#!/public/getApiV2Currencies)
98
+
99
+ > Get all available currencies.
100
+
101
+ <details>
102
+ <summary>Show code</summary>
103
+
104
+ ```rb
105
+ @api.currencies
106
+ ```
107
+ </details>
108
+
109
+ #### [GET /api/v2/k](https://max.maicoin.com/documents/api_list#!/public/getApiV2K)
110
+
111
+ > Get OHLC(k line) of a specific market.
112
+
113
+ <details>
114
+ <summary>Show code</summary>
115
+
116
+ ```rb
117
+ # use default parameters
118
+ @api.k('btctwd')
119
+
120
+ # provide all possible parameters
121
+ @api.k('btctwd', limit: 30, period: 1, timestamp: 1624705402)
122
+ ```
123
+ </details>
124
+
46
125
  #### [GET /api/v2/depth](https://max.maicoin.com/documents/api_list#!/public/getApiV2Depth)
47
126
 
127
+ > Get depth of a specified market.
128
+
129
+ <details>
130
+ <summary>Show code</summary>
131
+
48
132
  ```rb
49
133
  # use default parameters
50
134
  @api.depth('maxtwd')
@@ -52,6 +136,563 @@ Or install it yourself as:
52
136
  # provide all possible parameters
53
137
  @api.depth('maxtwd', limit: 10, sort_by_price: true)
54
138
  ```
139
+ </details>
140
+
141
+ #### [GET /api/v2/trades](https://max.maicoin.com/documents/api_list#!/public/getApiV2Trades)
142
+
143
+ > Get recent trades on market, sorted in reverse creation order.
144
+
145
+ <details>
146
+ <summary>Show code</summary>
147
+
148
+ ```rb
149
+ # use default parameters
150
+ @api.trades('btctwd')
151
+
152
+ # provide all possible parameters
153
+ @api.trades(
154
+ 'maxtwd',
155
+ timestamp: 1624705402,
156
+ from: 68444,
157
+ to: 69444,
158
+ order_by: 'asc',
159
+ pagination: true,
160
+ page: 3,
161
+ limit: 15,
162
+ offset: 5,
163
+ )
164
+ ```
165
+ </details>
166
+
167
+ #### [GET /api/v2/markets](https://max.maicoin.com/documents/api_list#!/public/getApiV2Markets)
168
+
169
+ > Get all available markets.
170
+
171
+ <details>
172
+ <summary>Show code</summary>
173
+
174
+ ```rb
175
+ @api.markets
176
+ ```
177
+ </details>
178
+
179
+ #### [GET /api/v2/summary](https://max.maicoin.com/documents/api_list#!/public/getApiV2Summary)
180
+
181
+ > Overview of market data for all tickers.
182
+
183
+ <details>
184
+ <summary>Show code</summary>
185
+
186
+ ```rb
187
+ @api.summary
188
+ ```
189
+ </details>
190
+
191
+ #### [GET /api/v2/tickers/{path_market}](https://max.maicoin.com/documents/api_list#!/public/getApiV2TickersPathMarket)
192
+
193
+ > Get ticker of specific market.
194
+
195
+ <details>
196
+ <summary>Show code</summary>
197
+
198
+ ```rb
199
+ @api.tickers('btctwd')
200
+ ```
201
+ </details>
202
+
203
+ #### [GET /api/v2/tickers](https://max.maicoin.com/documents/api_list#!/public/getApiV2Tickers)
204
+
205
+ > Get ticker of all markets.
206
+
207
+ <details>
208
+ <summary>Show code</summary>
209
+
210
+ ```rb
211
+ @api.tickers
212
+ ```
213
+ </details>
214
+
215
+ #### [GET /api/v2/timestamp](https://max.maicoin.com/documents/api_list#!/public/getApiV2Timestamp)
216
+
217
+ > Get server current time, in seconds since Unix epoch.
218
+
219
+ <details>
220
+ <summary>Show code</summary>
221
+
222
+ ```rb
223
+ @api.timestamp
224
+ ```
225
+ </details>
226
+
227
+ ### Private Api Examples
228
+
229
+ ```rb
230
+ access_key = 'YOUR_ACCESS_KEY'
231
+ secret_key = 'YOUR_SECRET_KEY'
232
+
233
+ @api = MaxExchangeApi::PrivateApi.new(access_key, secret_key)
234
+ ```
235
+
236
+ ### Trade
237
+ #### [GET /api/v2/trades/my/of_order](https://max.maicoin.com/documents/api_list#!/private/getApiV2TradesMyOfOrder)
238
+
239
+ > get your executed trades related to a order
240
+
241
+ <details>
242
+ <summary>Show code</summary>
243
+
244
+ ```rb
245
+ # use max unique order id
246
+ @api.my_trades_of_order(123456)
247
+
248
+ # use user specified order id
249
+ @api.my_trades_of_order('MY_ORDER_123456', use_client_id: true)
250
+ ```
251
+ </details>
252
+
253
+ #### [GET /api/v2/trades/my](https://max.maicoin.com/documents/api_list#!/private/getApiV2TradesMy)
254
+
255
+ > get your executed trades, sorted in reverse creation order
256
+
257
+ <details>
258
+ <summary>Show code</summary>
259
+
260
+ ```rb
261
+ # use default parameters
262
+ @api.my_trades('btctwd')
263
+
264
+ # provide all possible parameters
265
+ @api.my_trades(
266
+ 'maxtwd',
267
+ timestamp: 1624705402,
268
+ from: 68444,
269
+ to: 69444,
270
+ order_by: 'asc',
271
+ pagination: true,
272
+ page: 3,
273
+ limit: 15,
274
+ offset: 5,
275
+ )
276
+ ```
277
+ </details>
278
+
279
+ ### Withdrawal
280
+ #### [GET /api/v2/withdrawals](https://max.maicoin.com/documents/api_list#!/private/getApiV2Withdrawals)
281
+
282
+ > get your external withdrawals history
283
+
284
+ <details>
285
+ <summary>Show code</summary>
286
+
287
+ ```rb
288
+ # use default parameters
289
+ @api.withdrawals('max')
290
+
291
+ # provide all possible parameters
292
+ @api.withdrawals(
293
+ 'max',
294
+ 'confirmed',
295
+ from: 68444,
296
+ to: 69444,
297
+ state: 'confirmed',
298
+ pagination: true,
299
+ page: 3,
300
+ limit: 15,
301
+ offset: 5,
302
+ )
303
+ ```
304
+ </details>
305
+
306
+ #### [GET /api/v2/withdrawal](https://max.maicoin.com/documents/api_list#!/private/getApiV2Withdrawal)
307
+
308
+ > get details of a specific external withdraw
309
+
310
+ <details>
311
+ <summary>Show code</summary>
312
+
313
+ ```rb
314
+ @api.withdrawal('withdraw_id')
315
+ ```
316
+ </details>
317
+
318
+ #### [POST /api/v2/withdrawal](https://max.maicoin.com/documents/api_list#!/private/postApiV2Withdrawal)
319
+
320
+ > submit a withdrawal. IP whitelist for api token is required.
321
+
322
+ <details>
323
+ <summary>Show code</summary>
324
+
325
+ ```rb
326
+ @api.create_withdrawal!('twd', 'withdraw_address_id', 100000)
327
+ ```
328
+ </details>
329
+
330
+ ### Profile
331
+ #### [GET /api/v2/members/profile](https://max.maicoin.com/documents/api_list#!/private/getApiV2MembersProfile)
332
+
333
+ > get personal profile information
334
+
335
+ <details>
336
+ <summary>Show code</summary>
337
+
338
+ ```rb
339
+ @api.member_profile
340
+ ```
341
+ </details>
342
+
343
+ #### [GET /api/v2/members/me](https://max.maicoin.com/documents/api_list#!/private/getApiV2MembersMe)
344
+
345
+ > get your profile and accounts information
346
+
347
+ <details>
348
+ <summary>Show code</summary>
349
+
350
+ ```rb
351
+ @api.me
352
+ ```
353
+ </details>
354
+
355
+ #### [GET /api/v2/members/vip_level](https://max.maicoin.com/documents/api_list#!/private/getApiV2MembersVipLevel)
356
+
357
+ > get VIP level info
358
+
359
+ <details>
360
+ <summary>Show code</summary>
361
+
362
+ ```rb
363
+ @api.vip_level
364
+ ```
365
+ </details>
366
+
367
+ ### Account
368
+ #### [GET /api/v2/members/accounts](https://max.maicoin.com/documents/api_list#!/private/getApiV2MembersAccounts)
369
+
370
+ > get personal accounts information
371
+
372
+ <details>
373
+ <summary>Show code</summary>
374
+
375
+ ```rb
376
+ @api.accounts
377
+ ```
378
+ </details>
379
+
380
+ #### [GET /api/v2/members/accounts/{path_currency}](https://max.maicoin.com/documents/api_list#!/private/getApiV2MembersAccountsPathCurrency)
381
+
382
+ > get personal accounts information of a currency
383
+
384
+ <details>
385
+ <summary>Show code</summary>
386
+
387
+ ```rb
388
+ @api.account(currnecy)
389
+ ```
390
+ </details>
391
+
392
+ ### Deposit
393
+ #### [GET /api/v2/deposits](https://max.maicoin.com/documents/api_list#!/private/getApiV2Deposits)
394
+
395
+ > get your deposits history
396
+
397
+ <details>
398
+ <summary>Show code</summary>
399
+
400
+ ```rb
401
+ # use default parameters
402
+ @api.deposits('max')
403
+
404
+ # provide all possible parameters
405
+ @api.deposits(
406
+ 'max',
407
+ 'confirmed',
408
+ from: 68444,
409
+ to: 69444,
410
+ state: 'accepted',
411
+ pagination: true,
412
+ page: 3,
413
+ limit: 15,
414
+ offset: 5,
415
+ )
416
+ ```
417
+ </details>
418
+
419
+ #### [GET /api/v2/deposit](https://max.maicoin.com/documents/api_list#!/private/getApiV2Deposit)
420
+
421
+ > get details of a specific deposit
422
+
423
+ <details>
424
+ <summary>Show code</summary>
425
+
426
+ ```rb
427
+ @api.deposit('transaction_id')
428
+ ```
429
+ </details>
430
+
431
+ ### Address
432
+ #### [GET /api/v2/deposit_addresses](https://max.maicoin.com/documents/api_list#!/private/getApiV2DepositAddresses)
433
+
434
+ > The addresses could be empty before generated, please call POST /deposit_addresses in that case
435
+
436
+ <details>
437
+ <summary>Show code</summary>
438
+
439
+ ```rb
440
+ # use default parameters
441
+ @api.deposit_addresses
442
+
443
+ # provide all possible parameters
444
+ @api.deposit_addresses(currency: 'twd', pagination: true, page: 3, limit: 15, offset: 5)
445
+ ```
446
+ </details>
447
+
448
+ #### [POST /api/v2/deposit_addresses](https://max.maicoin.com/documents/api_list#!/private/postApiV2DepositAddresses)
449
+
450
+ > Address creation is asynchronous, please call GET /deposit_addresses later to get generated addresses
451
+
452
+ <details>
453
+ <summary>Show code</summary>
454
+
455
+ ```rb
456
+ @api.create_deposit_addresses!('twd')
457
+ ```
458
+ </details>
459
+
460
+ #### [GET /api/v2/withdraw_addresses](https://max.maicoin.com/documents/api_list#!/private/getApiV2WithdrawAddresses)
461
+
462
+ > get withdraw addresses
463
+
464
+ <details>
465
+ <summary>Show code</summary>
466
+
467
+ ```rb
468
+ # use default parameters
469
+ @api.withdraw_addresses('twd')
470
+
471
+ # provide all possible parameters
472
+ @api.withdraw_addresses('usdt', pagination: true, page: 3, limit: 15, offset: 5)
473
+ ```
474
+ </details>
475
+
476
+ ### Internal Transfer
477
+ #### [GET /api/v2/internal_transfers](https://max.maicoin.com/documents/api_list#!/private/getApiV2InternalTransfers)
478
+
479
+ > get internal transfers history
480
+
481
+ <details>
482
+ <summary>Show code</summary>
483
+
484
+ ```rb
485
+ # use default parameters
486
+ @api.internal_transfers
487
+
488
+ # provide all possible parameters
489
+ @api.internal_transfers(
490
+ currency: 'btc',
491
+ side: 'in',
492
+ from: 68444,
493
+ to: 69444,
494
+ pagination: true,
495
+ page: 3,
496
+ limit: 15,
497
+ offset: 5,
498
+ )
499
+ ```
500
+ </details>
501
+
502
+ #### [GET /api/v2/internal_transfer](https://max.maicoin.com/documents/api_list#!/private/getApiV2InternalTransfer)
503
+
504
+ > get details of a specific internal transfer
505
+
506
+ <details>
507
+ <summary>Show code</summary>
508
+
509
+ ```rb
510
+ @api.internal_transfer('internal_transfer_id')
511
+ ```
512
+ </details>
513
+
514
+ ### Reward
515
+ #### [GET /api/v2/rewards](https://max.maicoin.com/documents/api_list#!/private/getApiV2Rewards)
516
+
517
+ > get rewards history
518
+
519
+ <details>
520
+ <summary>Show code</summary>
521
+
522
+ ```rb
523
+ # use default parameters
524
+ @api.rewards
525
+
526
+ # provide all possible parameters
527
+ @api.rewards(
528
+ currency: 'btc',
529
+ from: 68444,
530
+ to: 69444,
531
+ pagination: true,
532
+ page: 3,
533
+ limit: 15,
534
+ offset: 5,
535
+ )
536
+ ```
537
+ </details>
538
+
539
+ #### [GET /api/v2/rewards/{path_reward_type}](https://max.maicoin.com/documents/api_list#!/private/getApiV2RewardsPathRewardType)
540
+
541
+ > get specific rewards history
542
+
543
+ <details>
544
+ <summary>Show code</summary>
545
+
546
+ ```rb
547
+ # use default parameters
548
+ @api.rewards(reward_type: 'airdrop_rewards')
549
+
550
+ # provide all possible parameters
551
+ @api.rewards(
552
+ reward_type: 'airdrop_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
+ </details>
563
+
564
+ #### [GET /api/v2/max_rewards/yesterday](https://max.maicoin.com/documents/api_list#!/private/getApiV2MaxRewardsYesterday)
565
+
566
+ > get max rewards yesterday
567
+
568
+ <details>
569
+ <summary>Show code</summary>
570
+
571
+ ```rb
572
+ @api.max_rewards_yesterday
573
+ ```
574
+ </details>
575
+
576
+ ### Order
577
+ #### [GET /api/v2/orders](https://max.maicoin.com/documents/api_list#!/private/getApiV2Orders)
578
+
579
+ > get your orders, results is paginated.
580
+
581
+ <details>
582
+ <summary>Show code</summary>
583
+
584
+ ```rb
585
+ # use default parameters
586
+ @api.orders('maxtwd')
587
+
588
+ # provide all possible parameters
589
+ @api.orders(
590
+ 'maxtwd',
591
+ state: 'done',
592
+ order_by: 'desc',
593
+ group_id: 12345,
594
+ pagination: true,
595
+ page: 3,
596
+ limit: 15,
597
+ offset: 5,
598
+ )
599
+ ```
600
+ </details>
601
+
602
+ #### [GET /api/v2/order](https://max.maicoin.com/documents/api_list#!/private/getApiV2Order)
603
+
604
+ > get a specific order.
605
+
606
+ <details>
607
+ <summary>Show code</summary>
608
+
609
+ ```rb
610
+ # use max unique order id
611
+ @api.order(123456)
612
+
613
+ # use user specified order id
614
+ @api.order('MY_ORDER_123456', use_client_id: true)
615
+ ```
616
+ </details>
617
+
618
+ #### [POST /api/v2/orders/clear](https://max.maicoin.com/documents/api_list#!/private/postApiV2OrdersClear)
619
+
620
+ > cancel all your orders with given market and side
621
+
622
+ <details>
623
+ <summary>Show code</summary>
624
+
625
+ ```rb
626
+ # use default parameters
627
+ @api.cancel_orders!
628
+
629
+ # provide all possible parameters
630
+ @api.cancel_orders!(market: 'maxtwd', side: 'sell', group_id: '123456')
631
+ ```
632
+ </details>
633
+
634
+ #### [POST /api/v2/order/delete](https://max.maicoin.com/documents/api_list#!/private/postApiV2OrderDelete)
635
+
636
+ > cancel an order
637
+
638
+ <details>
639
+ <summary>Show code</summary>
640
+
641
+ ```rb
642
+ # use max unique order id
643
+ @api.cancel_order!(123456)
644
+
645
+ # use user specified order id
646
+ @api.cancel_order!('MY_ORDER_123456', use_client_id: true)
647
+ ```
648
+ </details>
649
+
650
+ #### [POST /api/v2/orders](https://max.maicoin.com/documents/api_list#!/private/postApiV2Orders)
651
+
652
+ > create a sell/buy order
653
+
654
+ <details>
655
+ <summary>Show code</summary>
656
+
657
+ ```rb
658
+ # use default parameters
659
+ @api.create_order!('maxtwd', 'buy', 1000, price: 7.5)
660
+
661
+ # provide all possible parameters
662
+ @api.create_order!(
663
+ 'maxtwd',
664
+ 'buy',
665
+ 1000,
666
+ price: 7.5,
667
+ client_oid: 'MY_ORDER_ID_12345',
668
+ stop_price: 8,
669
+ ord_type: 'limit',
670
+ group_id: 12345678,
671
+ )
672
+ ```
673
+ </details>
674
+
675
+ #### [POST /api/v2/orders/multi/onebyone](https://max.maicoin.com/documents/api_list#!/private/postApiV2OrdersMultiOnebyone)
676
+
677
+ > Create multiple sell/buy orders, orders may be partially accepted, please put your orders as an array in json body.
678
+
679
+ <details>
680
+ <summary>Show code</summary>
681
+
682
+ ```rb
683
+ # use default parameters
684
+ @api.create_orders!('maxtwd', [
685
+ { side: 'buy', volume: '1000', price: 7.5 },
686
+ { side: 'buy', volume: '1500', price: 7.2 },
687
+ ])
688
+
689
+ # provide all possible parameters
690
+ @api.create_orders!('maxtwd', [
691
+ { side: 'buy', volume: '1000', price: 7.5, client_oid: 'MY_ORDER_ID_12345', stop_price: 8, ord_type: 'limit' },
692
+ { side: 'buy', volume: '1500', price: 7.2, client_oid: 'MY_ORDER_ID_12346', stop_price: 8, ord_type: 'limit' },
693
+ ], group_id: 12345)
694
+ ```
695
+ </details>
55
696
 
56
697
  ## Development
57
698
 
@@ -1,2 +1,4 @@
1
1
  require 'max_exchange_api/version'
2
+ require 'max_exchange_api/config'
2
3
  require 'max_exchange_api/public_api'
4
+ require 'max_exchange_api/private_api'
@@ -7,6 +7,13 @@ module MaxExchangeApi
7
7
  class BaseApi
8
8
  include HTTParty
9
9
 
10
+ attr_reader :config
11
+
12
+ def initialize(config: nil)
13
+ @config = Config.new(config)
14
+ @config.reverse_merge!(MaxExchangeApi.default_config)
15
+ end
16
+
10
17
  protected
11
18
 
12
19
  def send_request(method, path, headers, query)
@@ -19,7 +26,7 @@ module MaxExchangeApi
19
26
  path,
20
27
  headers: headers,
21
28
  query: query,
22
- timeout: 3,
29
+ timeout: @config.timeout,
23
30
  ).parsed_response
24
31
 
25
32
  print_log(:info, "[API] #{uuid} response #{response}")
@@ -32,8 +39,9 @@ module MaxExchangeApi
32
39
 
33
40
  private
34
41
 
35
- def print_log(_method, message)
36
- puts message
42
+ def print_log(method, message)
43
+ logger = @config.logger
44
+ logger.send(method, message) if logger
37
45
  end
38
46
  end
39
47
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MaxExchangeApi
4
+ class Config
5
+ attr_accessor :timeout
6
+ attr_accessor :logger
7
+
8
+ def initialize(data = nil)
9
+ data ||= {}
10
+ @timeout = data[:timeout]
11
+ @logger = data[:logger]
12
+ end
13
+
14
+ def reverse_merge!(other)
15
+ @timeout ||= other.timeout
16
+ @logger ||= other.logger
17
+ end
18
+ end
19
+
20
+ @default_config = Config.new
21
+ @default_config.timeout = 3
22
+
23
+ class << self
24
+ attr_reader :default_config
25
+ end
26
+ end
@@ -2,5 +2,26 @@
2
2
 
3
3
  module MaxExchangeApi
4
4
  module Helper
5
+ class << self
6
+ def gen_headers(payload, access_key, secret_key)
7
+ encoded_payload = encode(payload)
8
+
9
+ return {
10
+ 'X-MAX-ACCESSKEY' => access_key,
11
+ 'X-MAX-PAYLOAD' => encoded_payload,
12
+ 'X-MAX-SIGNATURE' => encrypt(encoded_payload, secret_key),
13
+ }
14
+ end
15
+
16
+ private
17
+
18
+ def encode(data)
19
+ Base64.strict_encode64(data.to_json)
20
+ end
21
+
22
+ def encrypt(data, key)
23
+ OpenSSL::HMAC.digest('sha256', key, data).unpack('H*')[0]
24
+ end
25
+ end
5
26
  end
6
27
  end
@@ -0,0 +1,225 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'max_exchange_api/base_api'
4
+
5
+ module MaxExchangeApi
6
+ class PrivateApi < BaseApi
7
+ base_uri 'https://max-api.maicoin.com/api/v2'
8
+
9
+ def initialize(access_key, secret_key, config: nil)
10
+ super(config: config)
11
+
12
+ @access_key = access_key
13
+ @secret_key = secret_key
14
+ end
15
+
16
+ def my_trades_of_order(order_id, use_client_id: false)
17
+ id_params_key = use_client_id ? :client_oid : :id
18
+ send_request(:get, '/trades/my/of_order', id_params_key => order_id)
19
+ end
20
+
21
+ def my_trades(market, timestamp: nil, from: nil, to: nil, order_by: 'desc', pagination: true, page: 1, limit: 50,
22
+ offset: 0)
23
+ send_request(
24
+ :get,
25
+ '/trades/my',
26
+ market: market,
27
+ timestamp: timestamp,
28
+ from: from,
29
+ to: to,
30
+ order_by: order_by,
31
+ pagination: pagination,
32
+ page: page,
33
+ limit: limit,
34
+ offset: offset,
35
+ )
36
+ end
37
+
38
+ def member_profile
39
+ send_request(:get, '/members/profile', {})
40
+ end
41
+
42
+ def me
43
+ send_request(:get, '/members/me', {})
44
+ end
45
+
46
+ def vip_level
47
+ send_request(:get, '/members/vip_level', {})
48
+ end
49
+
50
+ def accounts
51
+ send_request(:get, '/members/accounts', {})
52
+ end
53
+
54
+ def account(currency)
55
+ send_request(:get, "/members/accounts/#{currency}", {})
56
+ end
57
+
58
+ def deposits(currency, from: nil, to: nil, state: nil, pagination: nil, page: 1, limit: 50,
59
+ offset: 0)
60
+ send_request(
61
+ :get,
62
+ '/deposits',
63
+ currency: currency,
64
+ from: from,
65
+ to: to,
66
+ state: state,
67
+ pagination: pagination,
68
+ page: page,
69
+ limit: limit,
70
+ offset: offset,
71
+ )
72
+ end
73
+
74
+ def deposit(transaction_id)
75
+ send_request(:get, '/deposit', txid: transaction_id)
76
+ end
77
+
78
+ def deposit_addresses(currency: nil, pagination: nil, page: 1, limit: 50, offset: 0)
79
+ send_request(
80
+ :get,
81
+ '/deposit_addresses',
82
+ currency: currency,
83
+ pagination: pagination,
84
+ page: page,
85
+ limit: limit,
86
+ offset: offset,
87
+ )
88
+ end
89
+
90
+ def create_deposit_addresses!(currency)
91
+ send_request(:post, '/deposit_addresses', currency: currency)
92
+ end
93
+
94
+ def withdraw_addresses(currency, pagination: nil, page: 1, limit: 50, offset: 0)
95
+ send_request(
96
+ :get,
97
+ '/withdraw_addresses',
98
+ currency: currency,
99
+ pagination: pagination,
100
+ page: page,
101
+ limit: limit,
102
+ offset: offset,
103
+ )
104
+ end
105
+
106
+ def withdrawal(withdraw_id)
107
+ send_request(:get, '/withdrawal', uuid: withdraw_id)
108
+ end
109
+
110
+ def withdrawals(currency, from: nil, to: nil, state: nil, pagination: nil, page: 1, limit: 50,
111
+ offset: 0)
112
+ send_request(
113
+ :get,
114
+ '/withdrawals',
115
+ currency: currency,
116
+ from: from,
117
+ to: to,
118
+ state: state,
119
+ pagination: pagination,
120
+ page: page,
121
+ limit: limit,
122
+ offset: offset,
123
+ )
124
+ end
125
+
126
+ def create_withdrawal!(currency, withdraw_address_id, amount)
127
+ send_request(:post, '/withdrawal', currency: currency, withdraw_address_uuid: withdraw_address_id, amount: amount)
128
+ end
129
+
130
+ def internal_transfers(currency: nil, side: 'in', from: nil, to: nil, pagination: nil, page: 1, limit: 50,
131
+ offset: 0)
132
+ send_request(
133
+ :get,
134
+ '/internal_transfers',
135
+ currency: currency,
136
+ side: side,
137
+ from: from,
138
+ to: to,
139
+ pagination: pagination,
140
+ page: page,
141
+ limit: limit,
142
+ offset: offset,
143
+ )
144
+ end
145
+
146
+ def internal_transfer(internal_transfer_id)
147
+ send_request(:get, '/internal_transfer', uuid: internal_transfer_id)
148
+ end
149
+
150
+ def rewards(reward_type: nil, currency: nil, from: nil, to: nil, pagination: nil, page: 1, limit: 50, offset: 0)
151
+ path = reward_type ? "/rewards/#{reward_type}" : '/rewards'
152
+ send_request(
153
+ :get,
154
+ path,
155
+ currency: currency,
156
+ from: from,
157
+ to: to,
158
+ pagination: pagination,
159
+ page: page,
160
+ limit: limit,
161
+ offset: offset,
162
+ )
163
+ end
164
+
165
+ def max_rewards_yesterday
166
+ send_request(:get, '/max_rewards/yesterday', {})
167
+ end
168
+
169
+ def orders(market, state: nil, order_by: 'asc', group_id: nil, pagination: nil, page: 1, limit: 50, offset: 0)
170
+ send_request(
171
+ :get,
172
+ '/orders',
173
+ market: market,
174
+ state: state,
175
+ order_by: order_by,
176
+ group_id: group_id,
177
+ pagination: pagination,
178
+ page: page,
179
+ limit: limit,
180
+ offset: offset,
181
+ )
182
+ end
183
+
184
+ def order(order_id, use_client_id: false)
185
+ id_params_key = use_client_id ? :client_oid : :id
186
+ send_request(:get, '/order', id_params_key => order_id)
187
+ end
188
+
189
+ def cancel_orders!(market: nil, side: nil, group_id: nil)
190
+ send_request(:post, '/orders/clear', market: market, side: side, group_id: group_id)
191
+ end
192
+
193
+ def cancel_order!(order_id, use_client_id: false)
194
+ id_params_key = use_client_id ? :client_oid : :id
195
+ send_request(:post, '/order/delete', id_params_key => order_id)
196
+ end
197
+
198
+ def create_order!(market, side, volume, price: nil, client_oid: nil, stop_price: nil, ord_type: nil, group_id: nil)
199
+ send_request(
200
+ :post,
201
+ '/orders',
202
+ market: market,
203
+ side: side,
204
+ volume: volume,
205
+ price: price,
206
+ client_oid: client_oid,
207
+ stop_price: stop_price,
208
+ ord_type: ord_type,
209
+ group_id: group_id,
210
+ )
211
+ end
212
+
213
+ def create_orders!(market, orders, group_id: nil)
214
+ send_request(:post, '/orders/multi/onebyone', market: market, orders: orders, group_id: group_id)
215
+ end
216
+
217
+ protected
218
+
219
+ def send_request(method, path, query)
220
+ query = query.compact
221
+ query.merge!(path: "/api/v2#{path}", nonce: (Time.now.to_f * 1000).to_i)
222
+ return super(method, path, Helper.gen_headers(query, @access_key, @secret_key), query)
223
+ end
224
+ end
225
+ end
@@ -6,10 +6,63 @@ module MaxExchangeApi
6
6
  class PublicApi < BaseApi
7
7
  base_uri 'https://max-api.maicoin.com/api/v2'
8
8
 
9
+ def vip_levels(level = nil)
10
+ if level
11
+ send_request(:get, "/vip_levels/#{level}", {})
12
+ else
13
+ send_request(:get, '/vip_levels', {})
14
+ end
15
+ end
16
+
17
+ def currencies
18
+ send_request(:get, '/currencies', {})
19
+ end
20
+
21
+ def k(market, limit: 30, period: 1, timestamp: nil)
22
+ send_request(:get, '/k', market: market, limit: limit, period: period, timestamp: timestamp)
23
+ end
24
+
9
25
  def depth(market, limit: 10, sort_by_price: true)
10
26
  send_request(:get, '/depth', market: market, limit: limit, sort_by_price: sort_by_price)
11
27
  end
12
28
 
29
+ def trades(market, timestamp: nil, from: nil, to: nil, order_by: 'desc', pagination: true, page: 1, limit: 50,
30
+ offset: 0)
31
+ send_request(
32
+ :get,
33
+ '/trades',
34
+ market: market,
35
+ timestamp: timestamp,
36
+ from: from,
37
+ to: to,
38
+ order_by: order_by,
39
+ pagination: pagination,
40
+ page: page,
41
+ limit: limit,
42
+ offset: offset,
43
+ )
44
+ end
45
+
46
+ def markets
47
+ send_request(:get, '/markets', {})
48
+ end
49
+
50
+ def summary
51
+ send_request(:get, '/summary', {})
52
+ end
53
+
54
+ def tickers(market = nil)
55
+ if market
56
+ send_request(:get, "/tickers/#{market}", {})
57
+ else
58
+ send_request(:get, '/tickers', {})
59
+ end
60
+ end
61
+
62
+ def timestamp
63
+ send_request(:get, '/timestamp', {})
64
+ end
65
+
13
66
  protected
14
67
 
15
68
  def send_request(method, path, query)
@@ -1,3 +1,3 @@
1
1
  module MaxExchangeApi
2
- VERSION = '0.0.1'
2
+ VERSION = '1.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: max_exchange_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - khiav reoy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-23 00:00:00.000000000 Z
11
+ date: 2021-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -106,7 +106,9 @@ files:
106
106
  - gemfiles/Gemfile
107
107
  - lib/max_exchange_api.rb
108
108
  - lib/max_exchange_api/base_api.rb
109
+ - lib/max_exchange_api/config.rb
109
110
  - lib/max_exchange_api/helper.rb
111
+ - lib/max_exchange_api/private_api.rb
110
112
  - lib/max_exchange_api/public_api.rb
111
113
  - lib/max_exchange_api/version.rb
112
114
  - max_exchange_api.gemspec