cryptomarket-sdk 1.0.1 → 3.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62756eac34a0cac0bff07eb60b27f57d35688de29c77db8b9c395bb00d48af2b
4
- data.tar.gz: c6326c7df54dbc1069fec07be675f06fc95e8aafa71ac5ed47b6e9a1b97236f4
3
+ metadata.gz: 7b00c37cd577d6d79dd8e65c6333a5122d28728fa3023f24aa7ca0b13eab2bf6
4
+ data.tar.gz: a2523b57da4464aed4a0c655fe7316c4445b57cfa622d85425c583e70b424303
5
5
  SHA512:
6
- metadata.gz: d64312e26d144291661b081b8dfde90ea2d65d909392bafc310a4fc3720e8f21a356f47521a70e274ad515558a2c41b75f8a2bcad86d4540f2bb163ece8fb016
7
- data.tar.gz: cf5e559cdf9bd29fc578c04387ae837a4fb3f46c15eb5bf502ded24f2f2c41461ee7beceeda536ba03dc9a4a92737147106a717df319da1cb8fd5375c470b164
6
+ metadata.gz: f6f0bf8e26c38b44f686d36b5103ee56eeca2319ab30aa4552c180e8f4535a3aabd8d5b86b38b6c6e05d256cf85f4a9208d9e2877e04cd6ceaa9b42b97545d36
7
+ data.tar.gz: b859df27e046ecb43e678c4b2e9ca0b3dc03007dbc259c7d56ac23f79fa16b7850f6cfaa1ca7502aa7b477a9833974616b352e874a460d4c0f6c84a0b5da5f07
data/README.md CHANGED
@@ -1,129 +1,216 @@
1
1
  # CryptoMarket-Ruby
2
- [main page](https://www.cryptomkt.com/)
3
2
 
3
+ [main page](https://www.cryptomkt.com/)
4
4
 
5
5
  [sign up in CryptoMarket](https://www.cryptomkt.com/account/register).
6
6
 
7
7
  # Installation
8
+
8
9
  To install Cryptomarket use gem
10
+
9
11
  ```
10
12
  gem install cryptomarket-sdk
11
13
  ```
14
+
12
15
  # Documentation
13
- This sdk makes use of the [api version 2](https://api.exchange.cryptomkt.com/v2) of cryptomarket
16
+
17
+ This sdk makes use of the [api version 3](https://api.exchange.cryptomkt.com/) of cryptomarket
14
18
 
15
19
  # Quick Start
16
20
 
17
21
  ## rest client
22
+
18
23
  ```ruby
19
- require "cryptomarket"
24
+ require "cryptomarket-sdk"
20
25
 
21
26
  # instance a client
22
27
  api_key='AB32B3201'
23
28
  api_secret='21b12401'
24
- client = Cryptomarket::Client.new apiKey:apiKey, apiSecret:apiSecret
29
+ client = Cryptomarket::Client.new api_key:api_key, api_secret:api_secret
25
30
 
26
31
  # get currencies
27
- currencies = client.getCurrencies()
32
+ currencies = client.get_currencies
28
33
 
29
34
  # get order books
30
- order_book = client.getOrderbook('EOSETH')
35
+ order_book = client.get_orderbooks symbols:['EOSETH']
31
36
 
32
37
  # get your account balances
33
- account_balance = client.getAccountBalance()
38
+ account_balance = client.get_wallet_balances
34
39
 
35
40
  # get your trading balances
36
- trading_balance = client.getTradingBalance()
41
+ trading_balance = client.get_spot_trading_balances
37
42
 
38
43
  # move balance from account bank to account trading
39
- result = client.transferMoneyFromBankToExchange('ETH', '3.2')
44
+ result = @client.transfer_between_wallet_and_exchange(
45
+ currency: "CRO",
46
+ amount: "0.1",
47
+ source:"wallet",
48
+ destination:"spot",
49
+ )
40
50
 
41
51
  # get your active orders
42
- orders = client.getActiveOrders('EOSETH')
52
+ orders = client.get_all_active_spot_orders('EOSETH')
43
53
 
44
54
  # create a new order
45
- order = client.createOrder('EOSETH', 'buy', '10', order_type=args.ORDER_TYPE.MARKET)
55
+ order = client.create_spot_order(
56
+ symbol:'EOSETH',
57
+ side:'buy',
58
+ quantity:'10',
59
+ order_type:args.ORDER_TYPE.MARKET
60
+ )
46
61
  ```
47
62
 
48
- ## websocket client
63
+ ## Websocket Clients
49
64
 
50
- All websocket calls work with callbacks, subscriptions also use a callback with one argument for the subscription feed. All the other callbacks takes two arguments, err and result: callback(err, result). If the transaction is successful err is None and the result is in result. If the transaction fails, result is None and the error is in err.
65
+ Ahere are three websocket clients, the `MarketDataClient`, the `TradingClient` and the `WalletClient`. The `MarketDataClient` is public, while the others require authentication to be used.
51
66
 
52
- callbacks are callables like Procs
67
+ All websocket methods take Procs for their callbacks. These procs take two argument, the first is a possible error in the call (such as missing arguments), and the result data of the method.
53
68
 
54
- There are three websocket clients, the PublicClient, the TradingClient and the AccountClient.
55
-
56
- ```ruby
57
- require "cryptomarket-sdk"
69
+ Subscriptions also take in a Proc of two parameters, the notification data, and the notification type. The notification type is of type Args::NotificationType, and is either SNAPSHOT, NOTIFICATION or DATA, corresponding to the strings 'snapshot', 'update' and 'data'
58
70
 
59
- # THE PUBLIC CLIENT
71
+ The documentation of a specific subscriptions explains with of this types of notification uses.
60
72
 
61
- wsclient = Cryptomarket::Websocket::PublicClient.new
73
+ ### Websocket Market Data Client
62
74
 
63
- wsclient.connect() # blocks until connected
75
+ There are no unsubscriptions methods for the `MarketDataClient`. To stop recieving messages is recomended to close the `MarketDataClient`.
64
76
 
65
- my_callback = Proc.new {|err, data|
77
+ ```ruby
78
+ # instance a client
79
+ client = Cryptomarket::Websocket::MarketDataClient.new
80
+ client.connect
81
+ # close the client
82
+ client.close
83
+ # subscribe to public trades
84
+ client.subscribe_to_trades(
85
+ callback:Proc.new {|notification, type|
86
+ if type == Args::NotificationType::UPDATE
87
+ puts "an update"
88
+ end
89
+ if type == Args::NotificationType::SNAPSHOT
90
+ puts "a snapshot"
91
+ end
92
+ puts notification
93
+ },
94
+ symbols:['eoseth', 'ethbtc'],
95
+ limit:2,
96
+ result_callback:Proc.new {|err, result|
66
97
  if not err.nil?
67
- puts err # deal with error
68
- return
98
+ puts err
99
+ else
100
+ puts result
69
101
  end
70
- puts data
71
- }
72
-
73
- # get currencies
74
- wsclient.getCurrencies(my_callback)
75
-
76
-
77
- # get an order book feed,
78
- # feed_callback is for the subscription feed, with one argument
79
- # result_callback is for the subscription result (success or failure)
80
- feed_callback = Proc.new {|feed|
81
- puts feed
82
- }
102
+ }
103
+ )
104
+
105
+ # subscribe to symbol tickers
106
+ client.subscribe_to_ticker(
107
+ speed:"1s",
108
+ callback:Proc.new {|notificatoin, type|
109
+ if type == Args::NotificationType::DATA
110
+ puts "is always data"
111
+ end
112
+ puts notification
113
+ },
114
+ symbols:['eoseth', 'ethbtc'],
115
+ result_callback:Proc.new {|err, result|
116
+ if not err.nil?
117
+ puts err
118
+ else
119
+ puts result
120
+ end
121
+ }
122
+ )
123
+ ```
83
124
 
84
- wsclient.subscribeToOrderbook('EOSETH', feed_callback, my_callback)
125
+ ### Websocket Trading Client
85
126
 
86
- # THE TRADING CLIENT
127
+ Subscription callback to spot trading balances takes only one argument, a list of balances (see example below)
87
128
 
88
- wsclient = Cryptomarket::Websocket::TradingClient.new apiKey:apiKey, apiSecret:apiSecret
129
+ ```ruby
130
+ # instance a client with a 15 seconds window
131
+ client = Cryptomarket::Websocket::TradingClient.new(
132
+ api_key:Keyloader.api_key,
133
+ api_secret:Keyloader.api_secret,
134
+ window:15_000
135
+ )
136
+ client.connect
137
+ # close the client
138
+ client.close
139
+
140
+ # subscribe to order reports
141
+ client.subscribe_to_reports(
142
+ callback:Proc.new {|notification, type|
143
+ if type == Args::NotificationType::UPDATE
144
+ puts "a lonely report in a list"
145
+ end
146
+ if type == 'snapshot' # same as Args::NotificationType::SNAPSHOT
147
+ puts "reports of active orders"
148
+ end
149
+ puts notification
150
+ }
151
+ )
152
+ # unsubscribe from order reports
153
+ client.unsubscribe_to_reports
154
+
155
+ @wsclient.subscribe_to_spot_balance(
156
+ callback: ->(balances) {puts balances},
157
+ result_callback: ->(_) {},
158
+ mode: 'updates'
159
+ )
160
+
161
+ client_order_id = Time.now.to_i.to_s
162
+
163
+ # create an order
164
+ client.create_spot_order(
165
+ symbol: symbol,
166
+ price:'10000',
167
+ quantity:'0.01',
168
+ side:'sell',
169
+ clientOrderId:client_order_id
170
+ )
171
+
172
+ # candel an order
173
+ client.cancel_spot_order(client_order_id)
89
174
 
90
- wsclient.connect() # blocks until connected and authenticated.
175
+ ```
91
176
 
92
- # get your trading balances
93
- wsclient.getTradingBalance(my_callback)
177
+ ### Websocket Wallet Management Client
94
178
 
95
- # get your active orders
96
- wsclient.getActinveOrders(my_callback)
179
+ Subscription callback to transactions takes only one argument, a transaction (see example below)
97
180
 
98
- # create a new order
99
- wsclient.create_order(
100
- clientOrderId:"123123",
101
- symbol:'EOSETH',
102
- side:'buy',
103
- quantity:"10",
104
- price:"10",
105
- callback:my_callback)
181
+ ```ruby
182
+ # instance a client with a default window of 10 seconds
183
+ client = Cryptomarket::Websocket::WalletClient.new api_key:Keyloader.api_key, api_secret:Keyloader.api_secret
184
+ client.connect
185
+ # close the client
186
+ defer client.close
106
187
 
107
- # THE ACCONUT CLIENT
188
+ # subscribe to wallet transactions
189
+ def callback(transaction):
190
+ ->(transaction) { puts(transaction) }
108
191
 
109
- wsclient = Cryptomarket::Websocket::AccountClient apiKey:apiKey, apiSecret:apiSecret
192
+ client.subscribe_to_transactions(callback)
110
193
 
111
- wsclient.connect() # blocks until connected
194
+ # unsubscribe from wallet transactions
195
+ client.unsubscribe_to_transactions(lambda { |is_success|
196
+ puts('successful unsubscription') if is_success
197
+ })
112
198
 
113
- wsclient.getAccountBalance(my_callback)
199
+ # get wallet balances
200
+ client.get_wallet_balances(->(balances){ puts balances})
114
201
  ```
115
202
 
116
-
117
203
  ## exception handling
204
+
118
205
  ```ruby
119
206
  require "cryptomarket-sdk"
120
207
 
121
- client = Cryptomarket::Client.new apiKey:apiKey, apiSecret:apiSecret
208
+ client = Cryptomarket::Client.new api_key:api_key, api_secret:api_secret
122
209
 
123
- # catch a wrong argument
210
+ # catch a wrong argument
124
211
  begin
125
- order = client.create_order(
126
- symbol='EOSETH',
212
+ order = client.create_spot_order(
213
+ symbol='EOSETH',
127
214
  side='selllll', # wrong
128
215
  quantity='3'
129
216
  )
@@ -133,18 +220,18 @@ end
133
220
 
134
221
  # catch a failed transaction
135
222
  begin
136
- order = client.create_order(
223
+ order = client.create_spot_order(
137
224
  symbol='eosehtt', # non existant symbol
138
225
  side='sell',
139
- quantity='10',
226
+ quantity='10',
140
227
  )
141
228
  rescue Cryptomarket::SDKException => e:
142
229
  puts e
143
230
  end
144
231
 
145
- wsclient = Cryptomarket::Websocket::TradingClient.new apiKey:apiKey, apiSecret:apiSecret
232
+ wsclient = Cryptomarket::Websocket::TradingClient.new api_key:api_key, api_secret:api_secret
146
233
 
147
- # websocket errors are passed as the first argument to the callback
234
+ # websocket errors are passed as the first argument to the callback. valid for all non subscription methods
148
235
  my_callback = Proc.new {|err, data|
149
236
  if not err.nil?
150
237
  puts err # deal with error
@@ -153,16 +240,15 @@ my_callback = Proc.new {|err, data|
153
240
  puts data
154
241
  }
155
242
 
156
- wsclient.getTradingBalance(my_callback)
243
+ wsclient.get_spot_trading_balances(my_callback)
157
244
 
158
245
  # catch authorization error
159
246
  # to catch an authorization error on client connection, a on_error function must be defined on the client
160
- wsclient = TradingClient(apiKey, apiSecret)
247
+ wsclient = TradingClient(api_key, api_secret)
161
248
  wsclient.onerror = Proc.new {|error| puts "error", error}
162
249
  wsclient.connect
163
-
164
-
165
250
  ```
251
+
166
252
  # Checkout our other SDKs
167
253
 
168
254
  [node sdk](https://github.com/cryptomkt/cryptomkt-node)