max_exchange_api 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +482 -3
- data/lib/max_exchange_api.rb +1 -0
- data/lib/max_exchange_api/base_api.rb +4 -3
- data/lib/max_exchange_api/config.rb +6 -4
- data/lib/max_exchange_api/helper.rb +21 -0
- data/lib/max_exchange_api/private_api.rb +225 -0
- data/lib/max_exchange_api/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29e67831c545b85f3e39db7cdab7dcbf293c8d2958a5fed7affa29b2617d4a79
|
4
|
+
data.tar.gz: '08ba7fe4b157b1abcd9611e47c170c406975dcea7497cc9be6490ec7bd3985f3'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c10c08e3462a21a8ea9cb5be83327d06bdc8e406757895004ef31ed38df4606903337edbf7c07e0c5944ca88f8817c203abd7319369cbe763fed74785d3a788a
|
7
|
+
data.tar.gz: dd2bc0c74f8ae55bb1df54cfed702c6c908678ebca08f10c4181adc26162b23401ecaaddbbe9ff2698a9a96fb0662a041431044b2f6327d26285dba12b62c10a
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
## Change Log
|
2
2
|
|
3
|
+
### [v0.1.0](https://github.com/khiav223577/max_exchange_api/compare/v0.0.1...v0.1.0) 2021/06/26
|
4
|
+
- [#3](https://github.com/khiav223577/max_exchange_api/pull/3) Add default_timeout config (@khiav223577)
|
5
|
+
- [#2](https://github.com/khiav223577/max_exchange_api/pull/2) Implement all v2 public APIs (@khiav223577)
|
6
|
+
|
3
7
|
### v0.0.1 2021/06/23
|
4
8
|
- [#1](https://github.com/khiav223577/max_exchange_api/pull/1) Implement `/depth` API (@khiav223577)
|
data/README.md
CHANGED
@@ -35,12 +35,21 @@ Or install it yourself as:
|
|
35
35
|
|
36
36
|
$ gem install max_exchange_api
|
37
37
|
|
38
|
-
##
|
38
|
+
## Configuration
|
39
39
|
|
40
|
-
|
40
|
+
### Api timeout time
|
41
41
|
|
42
42
|
```rb
|
43
|
-
MaxExchangeApi.
|
43
|
+
MaxExchangeApi.default_config.timeout = 3 # seconds
|
44
|
+
```
|
45
|
+
|
46
|
+
### Api logging
|
47
|
+
|
48
|
+
```rb
|
49
|
+
require 'logger'
|
50
|
+
|
51
|
+
MaxExchangeApi.default_config.logger = Logger.new(STDOUT) # print log to stdand output
|
52
|
+
MaxExchangeApi.default_config.logger = Logger.new('log/api.log')
|
44
53
|
```
|
45
54
|
|
46
55
|
## Usage
|
@@ -205,6 +214,476 @@ MaxExchangeApi.config.default_timeout = 3
|
|
205
214
|
```
|
206
215
|
</details>
|
207
216
|
|
217
|
+
### Private Api Examples
|
218
|
+
|
219
|
+
```rb
|
220
|
+
access_key = 'YOUR_ACCESS_KEY'
|
221
|
+
secret_key = 'YOUR_SECRET_KEY'
|
222
|
+
|
223
|
+
@api = MaxExchangeApi::PrivateApi.new(access_key, secret_key)
|
224
|
+
```
|
225
|
+
|
226
|
+
### Trade
|
227
|
+
#### [GET /api/v2/trades/my/of_order](https://max.maicoin.com/documents/api_list#!/private/getApiV2TradesMyOfOrder)
|
228
|
+
|
229
|
+
> get your executed trades related to a order
|
230
|
+
|
231
|
+
<details>
|
232
|
+
<summary>Show code</summary>
|
233
|
+
|
234
|
+
```rb
|
235
|
+
# use max unique order id
|
236
|
+
@api.my_trades_of_order(123456)
|
237
|
+
|
238
|
+
# use user specified order id
|
239
|
+
@api.my_trades_of_order('MY_ORDER_123456', use_client_id: true)
|
240
|
+
```
|
241
|
+
</details>
|
242
|
+
|
243
|
+
#### [GET /api/v2/trades/my](https://max.maicoin.com/documents/api_list#!/private/getApiV2TradesMy)
|
244
|
+
|
245
|
+
> get your executed trades, sorted in reverse creation order
|
246
|
+
|
247
|
+
<details>
|
248
|
+
<summary>Show code</summary>
|
249
|
+
|
250
|
+
```rb
|
251
|
+
# use default parameters
|
252
|
+
@api.my_trades('btctwd')
|
253
|
+
|
254
|
+
# provide all possible parameters
|
255
|
+
@api.my_trades(
|
256
|
+
'maxtwd',
|
257
|
+
timestamp: 1624705402,
|
258
|
+
from: 68444,
|
259
|
+
to: 69444,
|
260
|
+
order_by: 'asc',
|
261
|
+
pagination: true,
|
262
|
+
page: 3,
|
263
|
+
limit: 15,
|
264
|
+
offset: 5,
|
265
|
+
)
|
266
|
+
```
|
267
|
+
</details>
|
268
|
+
|
269
|
+
### Withdrawal
|
270
|
+
#### [GET /api/v2/withdrawals](https://max.maicoin.com/documents/api_list#!/private/getApiV2Withdrawals)
|
271
|
+
|
272
|
+
> get your external withdrawals history
|
273
|
+
|
274
|
+
<details>
|
275
|
+
<summary>Show code</summary>
|
276
|
+
|
277
|
+
```rb
|
278
|
+
# use default parameters
|
279
|
+
@api.withdrawals('max')
|
280
|
+
|
281
|
+
# provide all possible parameters
|
282
|
+
@api.withdrawals(
|
283
|
+
'max',
|
284
|
+
'confirmed',
|
285
|
+
from: 68444,
|
286
|
+
to: 69444,
|
287
|
+
state: 'confirmed',
|
288
|
+
pagination: true,
|
289
|
+
page: 3,
|
290
|
+
limit: 15,
|
291
|
+
offset: 5,
|
292
|
+
)
|
293
|
+
```
|
294
|
+
</details>
|
295
|
+
|
296
|
+
#### [GET /api/v2/withdrawal](https://max.maicoin.com/documents/api_list#!/private/getApiV2Withdrawal)
|
297
|
+
|
298
|
+
> get details of a specific external withdraw
|
299
|
+
|
300
|
+
<details>
|
301
|
+
<summary>Show code</summary>
|
302
|
+
|
303
|
+
```rb
|
304
|
+
@api.withdrawal('withdraw_id')
|
305
|
+
```
|
306
|
+
</details>
|
307
|
+
|
308
|
+
#### [POST /api/v2/withdrawal](https://max.maicoin.com/documents/api_list#!/private/postApiV2Withdrawal)
|
309
|
+
|
310
|
+
> submit a withdrawal. IP whitelist for api token is required.
|
311
|
+
|
312
|
+
<details>
|
313
|
+
<summary>Show code</summary>
|
314
|
+
|
315
|
+
```rb
|
316
|
+
@api.create_withdrawal!('twd', 'withdraw_address_id', 100000)
|
317
|
+
```
|
318
|
+
</details>
|
319
|
+
|
320
|
+
### Profile
|
321
|
+
#### [GET /api/v2/members/profile](https://max.maicoin.com/documents/api_list#!/private/getApiV2MembersProfile)
|
322
|
+
|
323
|
+
> get personal profile information
|
324
|
+
|
325
|
+
<details>
|
326
|
+
<summary>Show code</summary>
|
327
|
+
|
328
|
+
```rb
|
329
|
+
@api.member_profile
|
330
|
+
```
|
331
|
+
</details>
|
332
|
+
|
333
|
+
#### [GET /api/v2/members/me](https://max.maicoin.com/documents/api_list#!/private/getApiV2MembersMe)
|
334
|
+
|
335
|
+
> get your profile and accounts information
|
336
|
+
|
337
|
+
<details>
|
338
|
+
<summary>Show code</summary>
|
339
|
+
|
340
|
+
```rb
|
341
|
+
@api.me
|
342
|
+
```
|
343
|
+
</details>
|
344
|
+
|
345
|
+
#### [GET /api/v2/members/vip_level](https://max.maicoin.com/documents/api_list#!/private/getApiV2MembersVipLevel)
|
346
|
+
|
347
|
+
> get VIP level info
|
348
|
+
|
349
|
+
<details>
|
350
|
+
<summary>Show code</summary>
|
351
|
+
|
352
|
+
```rb
|
353
|
+
@api.vip_level
|
354
|
+
```
|
355
|
+
</details>
|
356
|
+
|
357
|
+
### Account
|
358
|
+
#### [GET /api/v2/members/accounts](https://max.maicoin.com/documents/api_list#!/private/getApiV2MembersAccounts)
|
359
|
+
|
360
|
+
> get personal accounts information
|
361
|
+
|
362
|
+
<details>
|
363
|
+
<summary>Show code</summary>
|
364
|
+
|
365
|
+
```rb
|
366
|
+
@api.accounts
|
367
|
+
```
|
368
|
+
</details>
|
369
|
+
|
370
|
+
#### [GET /api/v2/members/accounts/{path_currency}](https://max.maicoin.com/documents/api_list#!/private/getApiV2MembersAccountsPathCurrency)
|
371
|
+
|
372
|
+
> get personal accounts information of a currency
|
373
|
+
|
374
|
+
<details>
|
375
|
+
<summary>Show code</summary>
|
376
|
+
|
377
|
+
```rb
|
378
|
+
@api.account(currnecy)
|
379
|
+
```
|
380
|
+
</details>
|
381
|
+
|
382
|
+
### Deposit
|
383
|
+
#### [GET /api/v2/deposits](https://max.maicoin.com/documents/api_list#!/private/getApiV2Deposits)
|
384
|
+
|
385
|
+
> get your deposits history
|
386
|
+
|
387
|
+
<details>
|
388
|
+
<summary>Show code</summary>
|
389
|
+
|
390
|
+
```rb
|
391
|
+
# use default parameters
|
392
|
+
@api.deposits('max')
|
393
|
+
|
394
|
+
# provide all possible parameters
|
395
|
+
@api.deposits(
|
396
|
+
'max',
|
397
|
+
'confirmed',
|
398
|
+
from: 68444,
|
399
|
+
to: 69444,
|
400
|
+
state: 'accepted',
|
401
|
+
pagination: true,
|
402
|
+
page: 3,
|
403
|
+
limit: 15,
|
404
|
+
offset: 5,
|
405
|
+
)
|
406
|
+
```
|
407
|
+
</details>
|
408
|
+
|
409
|
+
#### [GET /api/v2/deposit](https://max.maicoin.com/documents/api_list#!/private/getApiV2Deposit)
|
410
|
+
|
411
|
+
> get details of a specific deposit
|
412
|
+
|
413
|
+
<details>
|
414
|
+
<summary>Show code</summary>
|
415
|
+
|
416
|
+
```rb
|
417
|
+
@api.deposit('transaction_id')
|
418
|
+
```
|
419
|
+
</details>
|
420
|
+
|
421
|
+
### Address
|
422
|
+
#### [GET /api/v2/deposit_addresses](https://max.maicoin.com/documents/api_list#!/private/getApiV2DepositAddresses)
|
423
|
+
|
424
|
+
> The addresses could be empty before generated, please call POST /deposit_addresses in that case
|
425
|
+
|
426
|
+
<details>
|
427
|
+
<summary>Show code</summary>
|
428
|
+
|
429
|
+
```rb
|
430
|
+
# use default parameters
|
431
|
+
@api.deposit_addresses
|
432
|
+
|
433
|
+
# provide all possible parameters
|
434
|
+
@api.deposit_addresses(currency: 'twd', pagination: true, page: 3, limit: 15, offset: 5)
|
435
|
+
```
|
436
|
+
</details>
|
437
|
+
|
438
|
+
#### [POST /api/v2/deposit_addresses](https://max.maicoin.com/documents/api_list#!/private/postApiV2DepositAddresses)
|
439
|
+
|
440
|
+
> Address creation is asynchronous, please call GET /deposit_addresses later to get generated addresses
|
441
|
+
|
442
|
+
<details>
|
443
|
+
<summary>Show code</summary>
|
444
|
+
|
445
|
+
```rb
|
446
|
+
@api.create_deposit_addresses!('twd')
|
447
|
+
```
|
448
|
+
</details>
|
449
|
+
|
450
|
+
#### [GET /api/v2/withdraw_addresses](https://max.maicoin.com/documents/api_list#!/private/getApiV2WithdrawAddresses)
|
451
|
+
|
452
|
+
> get withdraw addresses
|
453
|
+
|
454
|
+
<details>
|
455
|
+
<summary>Show code</summary>
|
456
|
+
|
457
|
+
```rb
|
458
|
+
# use default parameters
|
459
|
+
@api.withdraw_addresses('twd')
|
460
|
+
|
461
|
+
# provide all possible parameters
|
462
|
+
@api.withdraw_addresses('usdt', pagination: true, page: 3, limit: 15, offset: 5)
|
463
|
+
```
|
464
|
+
</details>
|
465
|
+
|
466
|
+
### Internal Transfer
|
467
|
+
#### [GET /api/v2/internal_transfers](https://max.maicoin.com/documents/api_list#!/private/getApiV2InternalTransfers)
|
468
|
+
|
469
|
+
> get internal transfers history
|
470
|
+
|
471
|
+
<details>
|
472
|
+
<summary>Show code</summary>
|
473
|
+
|
474
|
+
```rb
|
475
|
+
# use default parameters
|
476
|
+
@api.internal_transfers
|
477
|
+
|
478
|
+
# provide all possible parameters
|
479
|
+
@api.internal_transfers(
|
480
|
+
currency: 'btc',
|
481
|
+
side: 'in',
|
482
|
+
from: 68444,
|
483
|
+
to: 69444,
|
484
|
+
pagination: true,
|
485
|
+
page: 3,
|
486
|
+
limit: 15,
|
487
|
+
offset: 5,
|
488
|
+
)
|
489
|
+
```
|
490
|
+
</details>
|
491
|
+
|
492
|
+
#### [GET /api/v2/internal_transfer](https://max.maicoin.com/documents/api_list#!/private/getApiV2InternalTransfer)
|
493
|
+
|
494
|
+
> get details of a specific internal transfer
|
495
|
+
|
496
|
+
<details>
|
497
|
+
<summary>Show code</summary>
|
498
|
+
|
499
|
+
```rb
|
500
|
+
@api.internal_transfer('internal_transfer_id')
|
501
|
+
```
|
502
|
+
</details>
|
503
|
+
|
504
|
+
### Reward
|
505
|
+
#### [GET /api/v2/rewards](https://max.maicoin.com/documents/api_list#!/private/getApiV2Rewards)
|
506
|
+
|
507
|
+
> get rewards history
|
508
|
+
|
509
|
+
<details>
|
510
|
+
<summary>Show code</summary>
|
511
|
+
|
512
|
+
```rb
|
513
|
+
# use default parameters
|
514
|
+
@api.rewards
|
515
|
+
|
516
|
+
# provide all possible parameters
|
517
|
+
@api.rewards(
|
518
|
+
currency: 'btc',
|
519
|
+
from: 68444,
|
520
|
+
to: 69444,
|
521
|
+
pagination: true,
|
522
|
+
page: 3,
|
523
|
+
limit: 15,
|
524
|
+
offset: 5,
|
525
|
+
)
|
526
|
+
```
|
527
|
+
</details>
|
528
|
+
|
529
|
+
#### [GET /api/v2/rewards/{path_reward_type}](https://max.maicoin.com/documents/api_list#!/private/getApiV2RewardsPathRewardType)
|
530
|
+
|
531
|
+
> get specific rewards history
|
532
|
+
|
533
|
+
<details>
|
534
|
+
<summary>Show code</summary>
|
535
|
+
|
536
|
+
```rb
|
537
|
+
# use default parameters
|
538
|
+
@api.rewards(reward_type: 'airdrop_rewards')
|
539
|
+
|
540
|
+
# provide all possible parameters
|
541
|
+
@api.rewards(
|
542
|
+
reward_type: 'airdrop_rewards',
|
543
|
+
currency: 'btc',
|
544
|
+
from: 68444,
|
545
|
+
to: 69444,
|
546
|
+
pagination: true,
|
547
|
+
page: 3,
|
548
|
+
limit: 15,
|
549
|
+
offset: 5,
|
550
|
+
)
|
551
|
+
```
|
552
|
+
</details>
|
553
|
+
|
554
|
+
#### [GET /api/v2/max_rewards/yesterday](https://max.maicoin.com/documents/api_list#!/private/getApiV2MaxRewardsYesterday)
|
555
|
+
|
556
|
+
> get max rewards yesterday
|
557
|
+
|
558
|
+
<details>
|
559
|
+
<summary>Show code</summary>
|
560
|
+
|
561
|
+
```rb
|
562
|
+
@api.max_rewards_yesterday
|
563
|
+
```
|
564
|
+
</details>
|
565
|
+
|
566
|
+
### Order
|
567
|
+
#### [GET /api/v2/orders](https://max.maicoin.com/documents/api_list#!/private/getApiV2Orders)
|
568
|
+
|
569
|
+
> get your orders, results is paginated.
|
570
|
+
|
571
|
+
<details>
|
572
|
+
<summary>Show code</summary>
|
573
|
+
|
574
|
+
```rb
|
575
|
+
# use default parameters
|
576
|
+
@api.orders('maxtwd')
|
577
|
+
|
578
|
+
# provide all possible parameters
|
579
|
+
@api.orders(
|
580
|
+
'maxtwd',
|
581
|
+
state: 'done',
|
582
|
+
order_by: 'desc',
|
583
|
+
group_id: 12345,
|
584
|
+
pagination: true,
|
585
|
+
page: 3,
|
586
|
+
limit: 15,
|
587
|
+
offset: 5,
|
588
|
+
)
|
589
|
+
```
|
590
|
+
</details>
|
591
|
+
|
592
|
+
#### [GET /api/v2/order](https://max.maicoin.com/documents/api_list#!/private/getApiV2Order)
|
593
|
+
|
594
|
+
> get a specific order.
|
595
|
+
|
596
|
+
<details>
|
597
|
+
<summary>Show code</summary>
|
598
|
+
|
599
|
+
```rb
|
600
|
+
# use max unique order id
|
601
|
+
@api.order(123456)
|
602
|
+
|
603
|
+
# use user specified order id
|
604
|
+
@api.order('MY_ORDER_123456', use_client_id: true)
|
605
|
+
```
|
606
|
+
</details>
|
607
|
+
|
608
|
+
#### [POST /api/v2/orders/clear](https://max.maicoin.com/documents/api_list#!/private/postApiV2OrdersClear)
|
609
|
+
|
610
|
+
> cancel all your orders with given market and side
|
611
|
+
|
612
|
+
<details>
|
613
|
+
<summary>Show code</summary>
|
614
|
+
|
615
|
+
```rb
|
616
|
+
# use default parameters
|
617
|
+
@api.cancel_orders!
|
618
|
+
|
619
|
+
# provide all possible parameters
|
620
|
+
@api.cancel_orders!(market: 'maxtwd', side: 'sell', group_id: '123456')
|
621
|
+
```
|
622
|
+
</details>
|
623
|
+
|
624
|
+
#### [POST /api/v2/order/delete](https://max.maicoin.com/documents/api_list#!/private/postApiV2OrderDelete)
|
625
|
+
|
626
|
+
> cancel an order
|
627
|
+
|
628
|
+
<details>
|
629
|
+
<summary>Show code</summary>
|
630
|
+
|
631
|
+
```rb
|
632
|
+
# use max unique order id
|
633
|
+
@api.cancel_order!(123456)
|
634
|
+
|
635
|
+
# use user specified order id
|
636
|
+
@api.cancel_order!('MY_ORDER_123456', use_client_id: true)
|
637
|
+
```
|
638
|
+
</details>
|
639
|
+
|
640
|
+
#### [POST /api/v2/orders](https://max.maicoin.com/documents/api_list#!/private/postApiV2Orders)
|
641
|
+
|
642
|
+
> create a sell/buy order
|
643
|
+
|
644
|
+
<details>
|
645
|
+
<summary>Show code</summary>
|
646
|
+
|
647
|
+
```rb
|
648
|
+
# use default parameters
|
649
|
+
@api.create_order!('maxtwd', 'buy', 1000, price: 7.5)
|
650
|
+
|
651
|
+
# provide all possible parameters
|
652
|
+
@api.create_order!(
|
653
|
+
'maxtwd',
|
654
|
+
'buy',
|
655
|
+
1000,
|
656
|
+
price: 7.5,
|
657
|
+
client_oid: 'MY_ORDER_ID_12345',
|
658
|
+
stop_price: 8,
|
659
|
+
ord_type: 'limit',
|
660
|
+
group_id: 12345678,
|
661
|
+
)
|
662
|
+
```
|
663
|
+
</details>
|
664
|
+
|
665
|
+
#### [POST /api/v2/orders/multi/onebyone](https://max.maicoin.com/documents/api_list#!/private/postApiV2OrdersMultiOnebyone)
|
666
|
+
|
667
|
+
> Create multiple sell/buy orders, orders may be partially accepted, please put your orders as an array in json body.
|
668
|
+
|
669
|
+
<details>
|
670
|
+
<summary>Show code</summary>
|
671
|
+
|
672
|
+
```rb
|
673
|
+
# use default parameters
|
674
|
+
@api.create_orders!('maxtwd', [
|
675
|
+
{ side: 'buy', volume: '1000', price: 7.5 },
|
676
|
+
{ side: 'buy', volume: '1500', price: 7.2 },
|
677
|
+
])
|
678
|
+
|
679
|
+
# provide all possible parameters
|
680
|
+
@api.create_orders!('maxtwd', [
|
681
|
+
{ side: 'buy', volume: '1000', price: 7.5, client_oid: 'MY_ORDER_ID_12345', stop_price: 8, ord_type: 'limit' },
|
682
|
+
{ side: 'buy', volume: '1500', price: 7.2, client_oid: 'MY_ORDER_ID_12346', stop_price: 8, ord_type: 'limit' },
|
683
|
+
], group_id: 12345)
|
684
|
+
```
|
685
|
+
</details>
|
686
|
+
|
208
687
|
## Development
|
209
688
|
|
210
689
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/max_exchange_api.rb
CHANGED
@@ -19,7 +19,7 @@ module MaxExchangeApi
|
|
19
19
|
path,
|
20
20
|
headers: headers,
|
21
21
|
query: query,
|
22
|
-
timeout: MaxExchangeApi.
|
22
|
+
timeout: MaxExchangeApi.default_config.timeout,
|
23
23
|
).parsed_response
|
24
24
|
|
25
25
|
print_log(:info, "[API] #{uuid} response #{response}")
|
@@ -32,8 +32,9 @@ module MaxExchangeApi
|
|
32
32
|
|
33
33
|
private
|
34
34
|
|
35
|
-
def print_log(
|
36
|
-
|
35
|
+
def print_log(method, message)
|
36
|
+
logger = MaxExchangeApi.default_config.logger
|
37
|
+
logger.send(method, message) if logger
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
@@ -2,16 +2,18 @@
|
|
2
2
|
|
3
3
|
module MaxExchangeApi
|
4
4
|
class Config
|
5
|
-
attr_accessor :
|
5
|
+
attr_accessor :timeout
|
6
|
+
attr_accessor :logger
|
6
7
|
|
7
8
|
def initialize
|
8
|
-
@
|
9
|
+
@timeout = 3
|
10
|
+
@logger = nil
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
12
|
-
@
|
14
|
+
@default_config = Config.new
|
13
15
|
|
14
16
|
class << self
|
15
|
-
attr_reader :
|
17
|
+
attr_reader :default_config
|
16
18
|
end
|
17
19
|
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)
|
10
|
+
super()
|
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' : "/rewards/#{reward_type}"
|
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
|
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:
|
4
|
+
version: 1.0.0
|
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-
|
11
|
+
date: 2021-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- lib/max_exchange_api/base_api.rb
|
109
109
|
- lib/max_exchange_api/config.rb
|
110
110
|
- lib/max_exchange_api/helper.rb
|
111
|
+
- lib/max_exchange_api/private_api.rb
|
111
112
|
- lib/max_exchange_api/public_api.rb
|
112
113
|
- lib/max_exchange_api/version.rb
|
113
114
|
- max_exchange_api.gemspec
|