cryptomarket-sdk 1.0.0 → 3.0.0

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: 56104f24b0cf0227d1b07b004a96a0c7bb12f6c0144683fe5286ecf605e229e9
4
- data.tar.gz: 1bdebf110497fc4c99fa768ad5f01c4d5d7811f48b90c739b677e84b90d720fd
3
+ metadata.gz: 7b00c37cd577d6d79dd8e65c6333a5122d28728fa3023f24aa7ca0b13eab2bf6
4
+ data.tar.gz: a2523b57da4464aed4a0c655fe7316c4445b57cfa622d85425c583e70b424303
5
5
  SHA512:
6
- metadata.gz: b8db890022384ea30bfaf012af54b37e06eb2951874246aa7b363c603a3672a5d35f5a44b2ad6d02f006247818f04283b1327db62573c7374c3e7f6fdf054af5
7
- data.tar.gz: 467cd155cee84cb5e67dd57859eb3c1b5227f9549420d4c7e073e815355ce0842fd5b56d5dfb983f16f4c944b4adcc69aea302f923be3c4dc29126fa43681691
6
+ metadata.gz: f6f0bf8e26c38b44f686d36b5103ee56eeca2319ab30aa4552c180e8f4535a3aabd8d5b86b38b6c6e05d256cf85f4a9208d9e2877e04cd6ceaa9b42b97545d36
7
+ data.tar.gz: b859df27e046ecb43e678c4b2e9ca0b3dc03007dbc259c7d56ac23f79fa16b7850f6cfaa1ca7502aa7b477a9833974616b352e874a460d4c0f6c84a0b5da5f07
data/README.md CHANGED
@@ -1,131 +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
- To install Cryptomarket use pip
8
+
9
+ To install Cryptomarket use gem
10
+
9
11
  ```
10
- gem install cryptomarket
12
+ gem install cryptomarket-sdk
11
13
  ```
12
- # Documentation
13
14
 
14
- [The api documentation](https://api.exchange.cryptomkt.com/)
15
+ # Documentation
15
16
 
17
+ This sdk makes use of the [api version 3](https://api.exchange.cryptomkt.com/) of cryptomarket
16
18
 
17
19
  # Quick Start
18
20
 
19
21
  ## rest client
22
+
20
23
  ```ruby
21
- require "cryptomarket"
24
+ require "cryptomarket-sdk"
22
25
 
23
26
  # instance a client
24
27
  api_key='AB32B3201'
25
28
  api_secret='21b12401'
26
- client = Cryptomarket::Client.new apiKey:apiKey, apiSecret:apiSecret
29
+ client = Cryptomarket::Client.new api_key:api_key, api_secret:api_secret
27
30
 
28
31
  # get currencies
29
- currencies = client.getCurrencies()
32
+ currencies = client.get_currencies
30
33
 
31
34
  # get order books
32
- order_book = client.getOrderbook('EOSETH')
35
+ order_book = client.get_orderbooks symbols:['EOSETH']
33
36
 
34
37
  # get your account balances
35
- account_balance = client.getAccountBalance()
38
+ account_balance = client.get_wallet_balances
36
39
 
37
40
  # get your trading balances
38
- trading_balance = client.getTradingBalance()
41
+ trading_balance = client.get_spot_trading_balances
39
42
 
40
43
  # move balance from account bank to account trading
41
- 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
+ )
42
50
 
43
51
  # get your active orders
44
- orders = client.getActiveOrders('EOSETH')
52
+ orders = client.get_all_active_spot_orders('EOSETH')
45
53
 
46
54
  # create a new order
47
- 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
+ )
48
61
  ```
49
62
 
50
- ## websocket client
63
+ ## Websocket Clients
51
64
 
52
- 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.
53
66
 
54
- 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.
55
68
 
56
- There are three websocket clients, the PublicClient, the TradingClient and the AccountClient.
57
-
58
- ```ruby
59
- 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'
60
70
 
61
- # THE PUBLIC CLIENT
71
+ The documentation of a specific subscriptions explains with of this types of notification uses.
62
72
 
63
- wsclient = Cryptomarket::Websocket::PublicClient.new
73
+ ### Websocket Market Data Client
64
74
 
65
- wsclient.connect() # blocks until connected
75
+ There are no unsubscriptions methods for the `MarketDataClient`. To stop recieving messages is recomended to close the `MarketDataClient`.
66
76
 
67
- 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|
68
97
  if not err.nil?
69
- puts err # deal with error
70
- return
98
+ puts err
99
+ else
100
+ puts result
71
101
  end
72
- puts data
73
- }
74
-
75
- # get currencies
76
- wsclient.getCurrencies(my_callback)
77
-
78
-
79
- # get an order book feed,
80
- # feed_callback is for the subscription feed, with one argument
81
- # result_callback is for the subscription result (success or failure)
82
- feed_callback = Proc.new {|feed|
83
- puts feed
84
- }
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
+ ```
85
124
 
86
- wsclient.subscribeToOrderbook('EOSETH', feed_callback, my_callback)
125
+ ### Websocket Trading Client
87
126
 
88
- # THE TRADING CLIENT
127
+ Subscription callback to spot trading balances takes only one argument, a list of balances (see example below)
89
128
 
90
- 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)
91
174
 
92
- wsclient.connect() # blocks until connected and authenticated.
175
+ ```
93
176
 
94
- # get your trading balances
95
- wsclient.getTradingBalance(my_callback)
177
+ ### Websocket Wallet Management Client
96
178
 
97
- # get your active orders
98
- wsclient.getActinveOrders(my_callback)
179
+ Subscription callback to transactions takes only one argument, a transaction (see example below)
99
180
 
100
- # create a new order
101
- wsclient.create_order(
102
- clientOrderId:"123123",
103
- symbol:'EOSETH',
104
- side:'buy',
105
- quantity:"10",
106
- price:"10",
107
- 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
108
187
 
109
- # THE ACCONUT CLIENT
188
+ # subscribe to wallet transactions
189
+ def callback(transaction):
190
+ ->(transaction) { puts(transaction) }
110
191
 
111
- wsclient = Cryptomarket::Websocket::AccountClient apiKey:apiKey, apiSecret:apiSecret
192
+ client.subscribe_to_transactions(callback)
112
193
 
113
- 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
+ })
114
198
 
115
- wsclient.getAccountBalance(my_callback)
199
+ # get wallet balances
200
+ client.get_wallet_balances(->(balances){ puts balances})
116
201
  ```
117
202
 
118
-
119
203
  ## exception handling
204
+
120
205
  ```ruby
121
206
  require "cryptomarket-sdk"
122
207
 
123
- client = Cryptomarket::Client.new apiKey:apiKey, apiSecret:apiSecret
208
+ client = Cryptomarket::Client.new api_key:api_key, api_secret:api_secret
124
209
 
125
- # catch a wrong argument
210
+ # catch a wrong argument
126
211
  begin
127
- order = client.create_order(
128
- symbol='EOSETH',
212
+ order = client.create_spot_order(
213
+ symbol='EOSETH',
129
214
  side='selllll', # wrong
130
215
  quantity='3'
131
216
  )
@@ -135,18 +220,18 @@ end
135
220
 
136
221
  # catch a failed transaction
137
222
  begin
138
- order = client.create_order(
223
+ order = client.create_spot_order(
139
224
  symbol='eosehtt', # non existant symbol
140
225
  side='sell',
141
- quantity='10',
226
+ quantity='10',
142
227
  )
143
228
  rescue Cryptomarket::SDKException => e:
144
229
  puts e
145
230
  end
146
231
 
147
- wsclient = Cryptomarket::Websocket::TradingClient.new apiKey:apiKey, apiSecret:apiSecret
232
+ wsclient = Cryptomarket::Websocket::TradingClient.new api_key:api_key, api_secret:api_secret
148
233
 
149
- # 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
150
235
  my_callback = Proc.new {|err, data|
151
236
  if not err.nil?
152
237
  puts err # deal with error
@@ -155,23 +240,21 @@ my_callback = Proc.new {|err, data|
155
240
  puts data
156
241
  }
157
242
 
158
- wsclient.getTradingBalance(my_callback)
243
+ wsclient.get_spot_trading_balances(my_callback)
159
244
 
160
245
  # catch authorization error
161
246
  # to catch an authorization error on client connection, a on_error function must be defined on the client
162
- wsclient = TradingClient(apiKey, apiSecret)
247
+ wsclient = TradingClient(api_key, api_secret)
163
248
  wsclient.onerror = Proc.new {|error| puts "error", error}
164
249
  wsclient.connect
165
-
166
-
167
250
  ```
251
+
168
252
  # Checkout our other SDKs
169
- <!-- agregar links -->
170
253
 
171
- python sdk
254
+ [node sdk](https://github.com/cryptomkt/cryptomkt-node)
172
255
 
173
- node sdk
256
+ [java sdk](https://github.com/cryptomkt/cryptomkt-java)
174
257
 
175
- java sdk
258
+ [go sdk](https://github.com/cryptomkt/cryptomkt-go)
176
259
 
177
- go sdk
260
+ [python sdk](https://github.com/cryptomkt/cryptomkt-python)