cryptomarket-sdk 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -10
- data/lib/cryptomarket/HttpManager.rb +7 -3
- data/lib/cryptomarket/client.rb +2 -2
- data/lib/cryptomarket/websocket/accountClient.rb +42 -2
- data/lib/cryptomarket/websocket/authClient.rb +2 -2
- data/lib/cryptomarket/websocket/publicClient.rb +40 -4
- data/lib/cryptomarket/websocket/tradingClient.rb +12 -1
- data/lib/cryptomarket/websocket/wsClientBase.rb +6 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62756eac34a0cac0bff07eb60b27f57d35688de29c77db8b9c395bb00d48af2b
|
4
|
+
data.tar.gz: c6326c7df54dbc1069fec07be675f06fc95e8aafa71ac5ed47b6e9a1b97236f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d64312e26d144291661b081b8dfde90ea2d65d909392bafc310a4fc3720e8f21a356f47521a70e274ad515558a2c41b75f8a2bcad86d4540f2bb163ece8fb016
|
7
|
+
data.tar.gz: cf5e559cdf9bd29fc578c04387ae837a4fb3f46c15eb5bf502ded24f2f2c41461ee7beceeda536ba03dc9a4a92737147106a717df319da1cb8fd5375c470b164
|
data/README.md
CHANGED
@@ -5,14 +5,12 @@
|
|
5
5
|
[sign up in CryptoMarket](https://www.cryptomkt.com/account/register).
|
6
6
|
|
7
7
|
# Installation
|
8
|
-
To install Cryptomarket use
|
8
|
+
To install Cryptomarket use gem
|
9
9
|
```
|
10
|
-
gem install cryptomarket
|
10
|
+
gem install cryptomarket-sdk
|
11
11
|
```
|
12
12
|
# Documentation
|
13
|
-
|
14
|
-
[The api documentation](https://api.exchange.cryptomkt.com/)
|
15
|
-
|
13
|
+
This sdk makes use of the [api version 2](https://api.exchange.cryptomkt.com/v2) of cryptomarket
|
16
14
|
|
17
15
|
# Quick Start
|
18
16
|
|
@@ -166,12 +164,11 @@ wsclient.connect
|
|
166
164
|
|
167
165
|
```
|
168
166
|
# Checkout our other SDKs
|
169
|
-
<!-- agregar links -->
|
170
167
|
|
171
|
-
|
168
|
+
[node sdk](https://github.com/cryptomkt/cryptomkt-node)
|
172
169
|
|
173
|
-
|
170
|
+
[java sdk](https://github.com/cryptomkt/cryptomkt-java)
|
174
171
|
|
175
|
-
|
172
|
+
[go sdk](https://github.com/cryptomkt/cryptomkt-go)
|
176
173
|
|
177
|
-
|
174
|
+
[python sdk](https://github.com/cryptomkt/cryptomkt-python)
|
@@ -3,6 +3,7 @@ require 'uri'
|
|
3
3
|
require 'json'
|
4
4
|
require 'base64'
|
5
5
|
require 'rest-client'
|
6
|
+
require_relative 'exceptions'
|
6
7
|
|
7
8
|
module Cryptomarket
|
8
9
|
class HttpManager
|
@@ -19,7 +20,7 @@ module Cryptomarket
|
|
19
20
|
timestamp = Time.now.to_i.to_s
|
20
21
|
msg = httpMethod + timestamp + @@apiVersion + method
|
21
22
|
if not params.nil? and params.keys.any?
|
22
|
-
if httpMethod == 'GET'
|
23
|
+
if httpMethod.upcase == 'GET' or httpMethod.upcase == 'PUT'
|
23
24
|
msg += '?'
|
24
25
|
end
|
25
26
|
msg += URI.encode_www_form params
|
@@ -32,11 +33,14 @@ module Cryptomarket
|
|
32
33
|
|
33
34
|
def makeRequest(method:, endpoint:, params:nil, public:false)
|
34
35
|
uri = URI(@@apiUrl + @@apiVersion + endpoint)
|
36
|
+
if not params.nil?
|
37
|
+
params = Hash[params.sort_by {|key, val| key.to_s }]
|
38
|
+
end
|
35
39
|
headers = Hash.new
|
36
40
|
if not public
|
37
41
|
headers['Authorization'] = getCredential(method.upcase, endpoint, params)
|
38
42
|
end
|
39
|
-
if method.upcase == 'GET' and not params.nil?
|
43
|
+
if (method.upcase == 'GET' or method.upcase =='PUT') and not params.nil?
|
40
44
|
uri.query = URI.encode_www_form params
|
41
45
|
params = nil
|
42
46
|
end
|
@@ -68,4 +72,4 @@ module Cryptomarket
|
|
68
72
|
return parsed_result
|
69
73
|
end
|
70
74
|
end
|
71
|
-
end
|
75
|
+
end
|
data/lib/cryptomarket/client.rb
CHANGED
@@ -630,8 +630,8 @@ module Cryptomarket
|
|
630
630
|
# +String+ +currency+:: the currency code for withdraw
|
631
631
|
# +Integer+ +amount+:: the expected withdraw amount
|
632
632
|
|
633
|
-
def
|
634
|
-
params = {
|
633
|
+
def getEstimateWithdrawFee(currency, amount)
|
634
|
+
params = {amount:amount, currency:currency}
|
635
635
|
return get('account/crypto/estimate-withdraw', params)
|
636
636
|
end
|
637
637
|
|
@@ -3,7 +3,7 @@ require_relative"../utils"
|
|
3
3
|
|
4
4
|
module Cryptomarket
|
5
5
|
module Websocket
|
6
|
-
|
6
|
+
|
7
7
|
# AccountClient connects via websocket to cryptomarket to get account information of the user. uses SHA256 as auth method and authenticates automatically.
|
8
8
|
#
|
9
9
|
# +string+ +apiKey+:: the user api key
|
@@ -12,9 +12,24 @@ module Cryptomarket
|
|
12
12
|
|
13
13
|
class AccountClient < AuthClient
|
14
14
|
include Utils
|
15
|
+
|
15
16
|
# Creates a new client and authenticates it to the server
|
16
17
|
def initialize(apiKey:, apiSecret:)
|
17
|
-
|
18
|
+
transaction = "transaction"
|
19
|
+
balance = "balance"
|
20
|
+
super(
|
21
|
+
url:"wss://api.exchange.cryptomkt.com/api/2/ws/account",
|
22
|
+
apiKey:apiKey,
|
23
|
+
apiSecret:apiSecret,
|
24
|
+
subscriptionKeys:{
|
25
|
+
"unsubscribeTransactions" => transaction,
|
26
|
+
"subscribeTransactions" => transaction,
|
27
|
+
"updateTransaction" => transaction,
|
28
|
+
|
29
|
+
"unsubscribeBalance" => balance,
|
30
|
+
"subscribeBalance" => balance,
|
31
|
+
"balance" => balance,
|
32
|
+
})
|
18
33
|
end
|
19
34
|
|
20
35
|
# get the account balance as a list of balances. non-zero balances only
|
@@ -105,6 +120,31 @@ module Cryptomarket
|
|
105
120
|
def unsubscribeToTransactions(callback:nil)
|
106
121
|
sendUnsubscription('unsubscribeTransactions', callback, {})
|
107
122
|
end
|
123
|
+
|
124
|
+
# subscribes to a feed of balances
|
125
|
+
#
|
126
|
+
# This subscription aims to provide an easy way to be informed of the current balance state.
|
127
|
+
# If the state has been changed or potentially changed the "balance" event will come with the actual state.
|
128
|
+
# Please be aware that only non-zero values present.
|
129
|
+
#
|
130
|
+
# https://api.exchange.cryptomkt.com/#subscription-to-the-balance
|
131
|
+
#
|
132
|
+
# +Proc+ +callback+:: A +Proc+ to call with the result data. It takes one argument. a feed of balances
|
133
|
+
# +Proc+ +resultCallback+:: Optional. A +Proc+ to call with the result data. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: Proc.new {|err, result| ...}
|
134
|
+
|
135
|
+
def subscribeToBalance(callback, resultCallback:nil)
|
136
|
+
sendSubscription('subscribeBalance', callback, {}, resultCallback)
|
137
|
+
end
|
138
|
+
|
139
|
+
# unsubscribe to the balance feed.
|
140
|
+
#
|
141
|
+
# https://api.exchange.cryptomkt.com/#subscription-to-the-balance
|
142
|
+
#
|
143
|
+
# +Proc+ +callback+:: Optional. A +Proc+ to call with the result data. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: Proc.new {|err, result| ...}
|
144
|
+
|
145
|
+
def unsubscribeToBalance(callback:nil)
|
146
|
+
sendUnsubscription('unsubscribeBalance', callback, {})
|
147
|
+
end
|
108
148
|
end
|
109
149
|
end
|
110
150
|
end
|
@@ -5,10 +5,10 @@ module Cryptomarket
|
|
5
5
|
module Websocket
|
6
6
|
class AuthClient < ClientBase
|
7
7
|
# Creates a new client
|
8
|
-
def initialize(url:, apiKey:, apiSecret:)
|
8
|
+
def initialize(url:, apiKey:, apiSecret:, subscriptionKeys:)
|
9
9
|
@apiKey = apiKey
|
10
10
|
@apiSecret = apiSecret
|
11
|
-
super url:url
|
11
|
+
super url:url, subscriptionKeys:subscriptionKeys
|
12
12
|
@authed = false
|
13
13
|
end
|
14
14
|
|
@@ -2,7 +2,6 @@ require "securerandom"
|
|
2
2
|
|
3
3
|
require_relative "wsClientBase"
|
4
4
|
require_relative"../utils"
|
5
|
-
require_relative "methods"
|
6
5
|
|
7
6
|
|
8
7
|
|
@@ -15,11 +14,35 @@ module Cryptomarket
|
|
15
14
|
|
16
15
|
class PublicClient < ClientBase
|
17
16
|
include Utils
|
18
|
-
include Methods
|
19
17
|
|
20
18
|
def initialize()
|
19
|
+
orderbook = "orderbook"
|
20
|
+
tickers = "tickers"
|
21
|
+
trades = "trades"
|
22
|
+
candles = "candles"
|
23
|
+
super(
|
24
|
+
url:"wss://api.exchange.cryptomkt.com/api/2/ws/public",
|
25
|
+
subscriptionKeys:{
|
26
|
+
"subscribeTicker" => tickers,
|
27
|
+
"unsubscribeTicker" => tickers,
|
28
|
+
"ticker" => tickers,
|
29
|
+
|
30
|
+
"subscribeOrderbook" => orderbook,
|
31
|
+
"unsubscribeOrderbook" => orderbook,
|
32
|
+
"snapshotOrderbook" => orderbook,
|
33
|
+
"updateOrderbook" => orderbook,
|
34
|
+
|
35
|
+
"subscribeTrades" => trades,
|
36
|
+
"unsubscribeTrades" => trades,
|
37
|
+
"snapshotTrades" => trades,
|
38
|
+
"updateTrades" => trades,
|
39
|
+
|
40
|
+
"subscribeCandles" => candles,
|
41
|
+
"unsubscribeCandles" => candles,
|
42
|
+
"snapshotCandles" => candles,
|
43
|
+
"updateCandles" => candles
|
44
|
+
})
|
21
45
|
@OBCache = OrderbookCache.new
|
22
|
-
super url:"wss://api.exchange.cryptomkt.com/api/2/ws/public"
|
23
46
|
end
|
24
47
|
|
25
48
|
def handleNotification(notification)
|
@@ -49,7 +72,7 @@ module Cryptomarket
|
|
49
72
|
end
|
50
73
|
|
51
74
|
def buildKey(method, params)
|
52
|
-
methodKey =
|
75
|
+
methodKey = @subscriptionKeys[method]
|
53
76
|
|
54
77
|
symbol = ''
|
55
78
|
if params.has_key? 'symbol'
|
@@ -63,6 +86,19 @@ module Cryptomarket
|
|
63
86
|
return key.upcase
|
64
87
|
end
|
65
88
|
|
89
|
+
def orderbookFeed(method)
|
90
|
+
return @subscriptionKeys[method] == "orderbook"
|
91
|
+
end
|
92
|
+
|
93
|
+
def tradesFeed(method)
|
94
|
+
return @subscriptionKeys[method] == "trades"
|
95
|
+
end
|
96
|
+
|
97
|
+
def candlesFeed(method)
|
98
|
+
return @subscriptionKeys[method] == "candles"
|
99
|
+
end
|
100
|
+
|
101
|
+
|
66
102
|
# Get a list all available currencies on the exchange
|
67
103
|
#
|
68
104
|
# https://api.exchange.cryptomkt.com/#get-currencies
|
@@ -13,8 +13,19 @@ module Cryptomarket
|
|
13
13
|
class TradingClient < AuthClient
|
14
14
|
include Utils
|
15
15
|
# Creates a new client
|
16
|
+
|
16
17
|
def initialize(apiKey:, apiSecret:)
|
17
|
-
|
18
|
+
reports = "reports"
|
19
|
+
super(
|
20
|
+
url:"wss://api.exchange.cryptomkt.com/api/2/ws/trading",
|
21
|
+
apiKey:apiKey,
|
22
|
+
apiSecret:apiSecret,
|
23
|
+
subscriptionKeys:{
|
24
|
+
"subscribeReports" => reports,
|
25
|
+
"unsubscribeReports" => reports,
|
26
|
+
"activeOrders" => reports,
|
27
|
+
"report" => reports,
|
28
|
+
})
|
18
29
|
end
|
19
30
|
|
20
31
|
# Subscribe to a feed of trading events of the account
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative "callbackCache"
|
2
|
-
require_relative "methods"
|
3
2
|
require_relative "orderbookCache"
|
4
3
|
require_relative "wsManager"
|
5
4
|
require_relative '../exceptions'
|
@@ -7,9 +6,8 @@ require_relative '../exceptions'
|
|
7
6
|
module Cryptomarket
|
8
7
|
module Websocket
|
9
8
|
class ClientBase
|
10
|
-
|
11
|
-
|
12
|
-
def initialize(url:)
|
9
|
+
def initialize(url:, subscriptionKeys:)
|
10
|
+
@subscriptionKeys = subscriptionKeys
|
13
11
|
@callbackCache = CallbackCache.new
|
14
12
|
@wsmanager = WSManager.new self, url:url
|
15
13
|
@onconnect = ->{}
|
@@ -98,7 +96,7 @@ module Cryptomarket
|
|
98
96
|
end
|
99
97
|
|
100
98
|
def handleNotification(notification)
|
101
|
-
key = "
|
99
|
+
key = buildKey(notification["method"])
|
102
100
|
callback = @callbackCache.getSubscriptionCallback(key)
|
103
101
|
if callback.nil?
|
104
102
|
return
|
@@ -107,6 +105,9 @@ module Cryptomarket
|
|
107
105
|
end
|
108
106
|
|
109
107
|
def buildKey(method=nil, params=nil)
|
108
|
+
if @subscriptionKeys.key? method
|
109
|
+
return @subscriptionKeys[method]
|
110
|
+
end
|
110
111
|
return "subscription"
|
111
112
|
end
|
112
113
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cryptomarket-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- T. Ismael Verdugo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|