cobinhood 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +265 -0
- data/Rakefile +6 -0
- data/lib/cobinhood.rb +5 -0
- data/lib/cobinhood/client/rest.rb +154 -0
- data/lib/cobinhood/client/rest/api_endpoints.rb +46 -0
- data/lib/cobinhood/client/rest/auth_request_middleware.rb +14 -0
- data/lib/cobinhood/client/rest/chart_api.rb +21 -0
- data/lib/cobinhood/client/rest/market_api.rb +43 -0
- data/lib/cobinhood/client/rest/nonce_request_middleware.rb +10 -0
- data/lib/cobinhood/client/rest/system_api.rb +19 -0
- data/lib/cobinhood/client/rest/trading_api.rb +71 -0
- data/lib/cobinhood/client/rest/wallet_api.rb +49 -0
- data/lib/cobinhood/version.rb +3 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: eb26b0d6d0be6237f3973bb89693d6eebb5c600f33e5b0b383e20495ea6a5308
|
4
|
+
data.tar.gz: 31cb040867b0e5433942268c607433366e17d8bf4da25b59ac8a918d53927e54
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 856cf4554b437e3e08de2eb2210931c3c43b1057fac494cf386604f09fd9f454ed43588be47f3f278b2e59ea2105d2777262bff164664f5063c2dbbc23072993
|
7
|
+
data.tar.gz: 627f64273a4ff84f24a4e380794f96c6748057b77edb0128c1aba737ffb89cdea8175d2976aa9cc28888572f2186598ef2677cb0bd85dd631612da986d598164
|
data/README.md
ADDED
@@ -0,0 +1,265 @@
|
|
1
|
+
# Cobinhood
|
2
|
+
|
3
|
+
This is an unofficial Ruby wrapper for the Cobinhood exchange REST and WebSocket APIs.
|
4
|
+
|
5
|
+
##### Notice
|
6
|
+
|
7
|
+
* This is Alpha software. All issues should be aggressively reported for quick resolution!
|
8
|
+
* RESTful interface is fully implemented.
|
9
|
+
* Websocket is *not* done.
|
10
|
+
* Pull Requests are very welcome!
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'cobinhood'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install cobinhood
|
27
|
+
|
28
|
+
## Features
|
29
|
+
|
30
|
+
#### Current
|
31
|
+
|
32
|
+
* Basic implementation of REST API
|
33
|
+
* Easy to use authentication
|
34
|
+
* Methods return parsed JSON
|
35
|
+
* No need to generate timestamps
|
36
|
+
* No need to generate signatures
|
37
|
+
|
38
|
+
#### Planned
|
39
|
+
|
40
|
+
* Basic implementation of WebSocket API
|
41
|
+
* Pass procs or lambdas to event handlers
|
42
|
+
* Single and multiple streams supported
|
43
|
+
* Runs on EventMachine
|
44
|
+
|
45
|
+
* Exception handling with responses
|
46
|
+
* High level abstraction
|
47
|
+
|
48
|
+
## Getting Started
|
49
|
+
|
50
|
+
#### REST Client
|
51
|
+
|
52
|
+
Require Cobinhood:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
require 'cobinhood'
|
56
|
+
```
|
57
|
+
|
58
|
+
Create a new instance of the REST Client:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
# If you only plan on touching public API endpoints, you can forgo any arguments
|
62
|
+
client = Cobinhood::Client::REST.new
|
63
|
+
|
64
|
+
# Otherwise provide an api_key as keyword arguments
|
65
|
+
client = Cobinhood::Client::REST.new api_key: 'x'
|
66
|
+
```
|
67
|
+
|
68
|
+
ALTERNATIVELY, set your API key in exported environment variable:
|
69
|
+
|
70
|
+
```bash
|
71
|
+
export COBINHOOD_API_KEY=your.api_key
|
72
|
+
```
|
73
|
+
|
74
|
+
Then you can instantiate client without parameters as in first variation above.
|
75
|
+
|
76
|
+
Create various requests:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
# Ping the server
|
80
|
+
client.time
|
81
|
+
# => {"time"=>1527470756975}
|
82
|
+
|
83
|
+
# Get candle data
|
84
|
+
client.candles "ABT-BTC", timeframe: '1m'
|
85
|
+
# => {"candles"=>[
|
86
|
+
# {"timeframe"=>"1m", "trading_pair_id"=>"ABT-BTC", "timestamp"=>1527384360000, "volume"=>"0",
|
87
|
+
# "open"=>"0.00012873", "close"=>"0.00012873", "high"=>"0.00012873", "low"=>"0.00012873"
|
88
|
+
# },
|
89
|
+
# {"timeframe"=>"1m", "trading_pair_id"=>"ABT-BTC", "timestamp"=>1527384420000, "volume"=>"0",
|
90
|
+
# "open"=>"0.00012873", "close"=>"0.00012873", "high"=>"0.00012873", "low"=>"0.00012873"
|
91
|
+
# },
|
92
|
+
# {"timeframe"=>"1m", "trading_pair_id"=>"ABT-BTC", ...
|
93
|
+
|
94
|
+
|
95
|
+
# Place an order
|
96
|
+
client.place_order 'ABT-BTC', side: :ask, type: :limit, price: 0.000127, size: 22
|
97
|
+
# => {
|
98
|
+
# "order"=>{
|
99
|
+
# "id"=>"298e5465-7282-47ca-9a1f-377c56487f5f",
|
100
|
+
# "trading_pair_id"=>"ABT-BTC",
|
101
|
+
# "side"=>"ask",
|
102
|
+
# "type"=>"limit",
|
103
|
+
# "price"=>"0.000127",
|
104
|
+
# "size"=>"22",
|
105
|
+
# "filled"=>"0",
|
106
|
+
# "state"=>"queued",
|
107
|
+
# "timestamp"=>1527471152779,
|
108
|
+
# "eq_price"=>"0",
|
109
|
+
# "completed_at"=>nil,
|
110
|
+
# "source"=>"exchange"
|
111
|
+
# }
|
112
|
+
# }
|
113
|
+
|
114
|
+
|
115
|
+
# Get deposit address
|
116
|
+
client.get_deposit_addresses
|
117
|
+
=> { "deposit_addresses"=>[
|
118
|
+
{ "address"=>"0x8bdFCC26CaA363234528288471107D90525d6BF923",
|
119
|
+
"blockchain_id"=>"ethereum",
|
120
|
+
"created_at"=>1527263083623,
|
121
|
+
"currency"=>"FXT",
|
122
|
+
"type"=>"exchange"
|
123
|
+
},
|
124
|
+
...
|
125
|
+
```
|
126
|
+
|
127
|
+
Required and optional parameters, as well as enum values, can currently be found on the [Cobinhood GitHub Page](https://cobinhood.github.io/api-public). Parameters should always be passed to client methods as keyword arguments in snake_case form. trading_pair_id, when a required parameter is simply passed as first parameter for most API calls.
|
128
|
+
|
129
|
+
### REST Endpoints
|
130
|
+
|
131
|
+
REST endpoints are in order as documented on the Cobinhood Github page (linked above). The following lists only the method
|
132
|
+
names, aliases (if any) and parameters of the methods to access endpoints. For the most part, method names follow naming
|
133
|
+
of the endpoint's URL and alias method follows the title/name given in Cobinhood API documentation. There were some deviations
|
134
|
+
where there would otherwise be name clashes/overloading.
|
135
|
+
|
136
|
+
#### System Endpoints
|
137
|
+
|
138
|
+
name: time
|
139
|
+
* required params: none
|
140
|
+
|
141
|
+
name: info
|
142
|
+
* required params: none
|
143
|
+
|
144
|
+
#### Market Endpoints
|
145
|
+
|
146
|
+
name: currencies
|
147
|
+
alias: get_all_currencies
|
148
|
+
* required params: none
|
149
|
+
|
150
|
+
name: trading_pairs
|
151
|
+
alias: get_all_trading_pairs
|
152
|
+
* required params: none
|
153
|
+
|
154
|
+
name: order_book trading_pair_id
|
155
|
+
alias: get_order_book
|
156
|
+
* required params: trading_pair_id
|
157
|
+
|
158
|
+
name: precisions trading_pair_id
|
159
|
+
alias: get_order_book_precisions
|
160
|
+
* required params: trading_pair_id
|
161
|
+
|
162
|
+
name: stats
|
163
|
+
* required params: none
|
164
|
+
|
165
|
+
name: tickers trading_pair_id
|
166
|
+
alias: get_ticker
|
167
|
+
* required params: none
|
168
|
+
|
169
|
+
alias : :market_trades
|
170
|
+
name: market_trades trading_pair_id
|
171
|
+
alias: get_recent_trades
|
172
|
+
* required params: none
|
173
|
+
|
174
|
+
#### Chart Endpoints
|
175
|
+
|
176
|
+
name: candles trading_pair_id, options={}
|
177
|
+
* required params: trading_pair_id, timeframe
|
178
|
+
|
179
|
+
#### Trading Endpoints
|
180
|
+
|
181
|
+
name: order order_id
|
182
|
+
alias: get_order
|
183
|
+
* required params: order_id
|
184
|
+
|
185
|
+
name: order_trades order_id
|
186
|
+
alias: get_trades_of_an_order
|
187
|
+
* required params: order_id
|
188
|
+
|
189
|
+
name: orders
|
190
|
+
alias: get_all_orders
|
191
|
+
* required params: none
|
192
|
+
|
193
|
+
name: place_order trading_pair_id, options={}
|
194
|
+
* required params: side, type, size, price (except market orders)
|
195
|
+
|
196
|
+
name: modify_order order_id, options={}
|
197
|
+
* required params: order_id, size, price
|
198
|
+
|
199
|
+
name: cancel_order order_id
|
200
|
+
* required params: order_id
|
201
|
+
|
202
|
+
name: order_history trading_pair_id=nil, options={}
|
203
|
+
alias: get_order_history
|
204
|
+
* required params: none
|
205
|
+
|
206
|
+
name: get_trade trade_id
|
207
|
+
alias: trade
|
208
|
+
* required params: trade_id
|
209
|
+
|
210
|
+
name: trades trading_pair_id, options={}
|
211
|
+
* required params: trading_pair_id
|
212
|
+
|
213
|
+
#### Wallet Endpoints
|
214
|
+
|
215
|
+
name: balances
|
216
|
+
alias: get_wallet_balances
|
217
|
+
* required params: none
|
218
|
+
|
219
|
+
name: ledger
|
220
|
+
alias: get_ledger_entries
|
221
|
+
* required params: none
|
222
|
+
|
223
|
+
name: deposit_addresses
|
224
|
+
alias: get_deposit_addresses
|
225
|
+
* required params: none
|
226
|
+
|
227
|
+
name: withdrawal_addresses
|
228
|
+
alias: get_withdrawal_addresses
|
229
|
+
* required params: none
|
230
|
+
|
231
|
+
name: withdrawal withdrawal_id
|
232
|
+
alias: get_withdrawal
|
233
|
+
* required params: withdrawal_id
|
234
|
+
|
235
|
+
name: withdrawals
|
236
|
+
alias: get_all_withdrawals
|
237
|
+
* required params: none
|
238
|
+
|
239
|
+
name: deposit deposit_id
|
240
|
+
alias: get_deposit
|
241
|
+
* required params: deposit_id
|
242
|
+
|
243
|
+
name: deposits
|
244
|
+
alias: get_all_deposits
|
245
|
+
* required params: none
|
246
|
+
|
247
|
+
#### WebSocket Client
|
248
|
+
|
249
|
+
* COMING SOON!
|
250
|
+
|
251
|
+
## Development
|
252
|
+
|
253
|
+
* RSPECs coming soon!
|
254
|
+
|
255
|
+
## Contributing
|
256
|
+
|
257
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mwlang/cobinhood.
|
258
|
+
|
259
|
+
## Inspiration
|
260
|
+
|
261
|
+
The inspiration for architectural layout of this gem comes nearly one-for-one from the [Binance gem](https://github.com/craysiii/binance) by craysiii.
|
262
|
+
|
263
|
+
## License
|
264
|
+
|
265
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/lib/cobinhood.rb
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
require_relative 'rest/api_endpoints'
|
2
|
+
require_relative 'rest/nonce_request_middleware'
|
3
|
+
require_relative 'rest/auth_request_middleware'
|
4
|
+
|
5
|
+
require_relative 'rest/system_api'
|
6
|
+
require_relative 'rest/market_api'
|
7
|
+
require_relative 'rest/chart_api'
|
8
|
+
require_relative 'rest/trading_api'
|
9
|
+
require_relative 'rest/wallet_api'
|
10
|
+
|
11
|
+
module Cobinhood
|
12
|
+
MissingParamError = Class.new(Exception)
|
13
|
+
InvalidParamError = Class.new(Exception)
|
14
|
+
MissingApiKeyError = Class.new(Exception)
|
15
|
+
ClientError = Class.new(Exception)
|
16
|
+
|
17
|
+
module Client
|
18
|
+
# Public: Client with methods mirroring the Cobinhood REST APIs
|
19
|
+
class REST
|
20
|
+
# Public: String base url for REST client to use
|
21
|
+
BASE_URL = "https://api.cobinhood.com".freeze
|
22
|
+
|
23
|
+
include SystemAPI
|
24
|
+
include MarketAPI
|
25
|
+
include ChartAPI
|
26
|
+
include TradingAPI
|
27
|
+
include WalletAPI
|
28
|
+
|
29
|
+
def default_api_key
|
30
|
+
ENV["COBINHOOD_API_KEY"].to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
# Public: Initialize a REST Client
|
34
|
+
#
|
35
|
+
# :api_key - The String API key to authenticate (Default = '').
|
36
|
+
#
|
37
|
+
# :adapter - The Faraday::Adapter to be used for the client
|
38
|
+
# (Default = Faraday.default_adapter).
|
39
|
+
def initialize api_key: default_api_key, adapter: Faraday.default_adapter
|
40
|
+
|
41
|
+
@library = {
|
42
|
+
system: public_client(adapter),
|
43
|
+
market: public_client(adapter),
|
44
|
+
chart: public_client(adapter),
|
45
|
+
trading: auth_client(api_key, adapter),
|
46
|
+
wallet: auth_client(api_key, adapter),
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def assert_required_param options, param, valid_values=nil
|
51
|
+
raise Cobinhood::MissingParamError.new("#{param} is required") unless options.has_key?(param)
|
52
|
+
assert_param_is_one_of options, param, valid_values if valid_values
|
53
|
+
end
|
54
|
+
|
55
|
+
def assert_param_is_one_of options, param, valid_values
|
56
|
+
return if valid_values.include? options[param].to_s
|
57
|
+
raise Cobinhood::InvalidParamError.new("#{param} must be one of #{valid_values.inspect}")
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def public_client adapter
|
63
|
+
Faraday.new(url: BASE_URL) do |conn|
|
64
|
+
conn.request :json
|
65
|
+
conn.response :json, content_type: /\bjson$/
|
66
|
+
conn.use NonceRequestMiddleware
|
67
|
+
conn.adapter adapter
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def auth_client api_key, adapter
|
72
|
+
Faraday.new(url: BASE_URL) do |conn|
|
73
|
+
conn.request :json
|
74
|
+
conn.response :json, content_type: /\bjson$/
|
75
|
+
conn.use NonceRequestMiddleware
|
76
|
+
conn.use AuthRequestMiddleware, api_key
|
77
|
+
conn.adapter adapter
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Internal: Create a request that hits one of the REST APIs
|
82
|
+
#
|
83
|
+
# api - The Symbol that represents which API to use.
|
84
|
+
#
|
85
|
+
# method - The Symbol that represents which HTTP method to use.
|
86
|
+
#
|
87
|
+
# endpoint - The String that represents which API endpoint to request
|
88
|
+
# from.
|
89
|
+
#
|
90
|
+
# options - The Hash which hosts various REST query params. (Default = {})
|
91
|
+
# Each endpoint will have their own required and optional
|
92
|
+
# params.
|
93
|
+
def request api, method, endpoint, options = {}
|
94
|
+
response = @library[api].send(method) do |req|
|
95
|
+
|
96
|
+
# substitute path parameters and remove from options hash
|
97
|
+
endpoint_url = API_ENDPOINTS[api][endpoint].dup
|
98
|
+
options.each do |option, value|
|
99
|
+
path_param = Regexp.new(":#{option}")
|
100
|
+
if endpoint_url =~ path_param
|
101
|
+
options.delete(option)
|
102
|
+
endpoint_url.gsub!(path_param, value)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Cobinhood wants certain parameters a certain way.
|
107
|
+
adapt_price_param options
|
108
|
+
adapt_size_param options
|
109
|
+
[:start_time, :end_time].each{|key| adapt_timestamp_param key, options}
|
110
|
+
|
111
|
+
req.url endpoint_url
|
112
|
+
|
113
|
+
# parameters go into request body, not headers on POSTs
|
114
|
+
if method == :post
|
115
|
+
req.body = options.to_json
|
116
|
+
else
|
117
|
+
req.params.merge!(options)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
success_or_error response
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
def success_or_error response
|
126
|
+
return response.body["result"] if response.body.is_a?(Hash) && response.body["success"]
|
127
|
+
json = JSON.parse(response.body)
|
128
|
+
raise Cobinhood::ClientError.new("Cobinhood Error: " + json["error"]["error_code"] + " for REQUEST ID: #{json["request_id"]}")
|
129
|
+
rescue
|
130
|
+
raise Cobinhood::ClientError.new("Cobinhood Error: " + response.body)
|
131
|
+
end
|
132
|
+
|
133
|
+
# TODO: This needs more testing! I'm not sure about precision of the epoche nor if
|
134
|
+
# adjustments are needed to account for timezone differences.
|
135
|
+
# Currently only used for params of Cobinhood::Client::REST.candles
|
136
|
+
def adapt_timestamp_param key, params
|
137
|
+
return unless params.has_key? key
|
138
|
+
return if params[key].is_a?(Integer)
|
139
|
+
params[key] = (params[key].to_time.to_f * 1000).ceil
|
140
|
+
end
|
141
|
+
|
142
|
+
def adapt_price_param params
|
143
|
+
return unless params.has_key? :price
|
144
|
+
params[:price] = '%0.8f' % params[:price].to_f
|
145
|
+
end
|
146
|
+
|
147
|
+
def adapt_size_param params
|
148
|
+
return unless params.has_key? :size
|
149
|
+
params[:size] = params[:size].to_s
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Cobinhood
|
2
|
+
module Client
|
3
|
+
class REST
|
4
|
+
API_ENDPOINTS = {
|
5
|
+
system: {
|
6
|
+
time: 'v1/system/time',
|
7
|
+
info: 'v1/system/info',
|
8
|
+
},
|
9
|
+
|
10
|
+
market: {
|
11
|
+
currencies: '/v1/market/currencies',
|
12
|
+
trading_pairs: '/v1/market/trading_pairs',
|
13
|
+
order_book: '/v1/market/orderbooks/:trading_pair_id',
|
14
|
+
precisions: '/v1/market/orderbook/precisions/:trading_pair_id',
|
15
|
+
stats: '/v1/market/stats',
|
16
|
+
tickers: '/v1/market/tickers/:trading_pair_id',
|
17
|
+
trades: '/v1/market/trades/:trading_pair_id',
|
18
|
+
},
|
19
|
+
|
20
|
+
chart: {
|
21
|
+
candles: '/v1/chart/candles/:trading_pair_id',
|
22
|
+
},
|
23
|
+
|
24
|
+
trading: {
|
25
|
+
order: '/v1/trading/orders/:order_id',
|
26
|
+
order_trades: '/v1/trading/orders/:order_id/trades',
|
27
|
+
orders: '/v1/trading/orders',
|
28
|
+
order_history: '/v1/trading/order_history',
|
29
|
+
get_trade: '/v1/trading/trades/:trade_id',
|
30
|
+
trades: '/v1/trading/trades',
|
31
|
+
},
|
32
|
+
|
33
|
+
wallet: {
|
34
|
+
balances: '/v1/wallet/balances',
|
35
|
+
ledger: '/v1/wallet/ledger',
|
36
|
+
deposit_addresses: '/v1/wallet/deposit_addresses',
|
37
|
+
withdrawal_addresses: '/v1/wallet/withdrawal_addresses',
|
38
|
+
withdrawal: '/v1/wallet/withdrawals/:withdrawal_id',
|
39
|
+
withdrawals: '/v1/wallet/withdrawals',
|
40
|
+
deposit: '/v1/wallet/deposits/:deposit_id',
|
41
|
+
deposits: '/v1/wallet/deposits',
|
42
|
+
},
|
43
|
+
}.freeze
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Cobinhood
|
2
|
+
class AuthRequestMiddleware < Faraday::Middleware
|
3
|
+
def initialize app, api_key
|
4
|
+
super(app)
|
5
|
+
@api_key = api_key
|
6
|
+
end
|
7
|
+
|
8
|
+
def call env
|
9
|
+
raise Cobinhood::MissingApiKeyError.new('API KEY not provided') if @api_key.to_s == ''
|
10
|
+
env[:request_headers]["authorization"] = @api_key
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Cobinhood
|
2
|
+
module Client
|
3
|
+
class REST
|
4
|
+
# Public: A Module containing all of the Public API endpoints
|
5
|
+
module ChartAPI
|
6
|
+
|
7
|
+
def candles trading_pair_id, options={}
|
8
|
+
assert_required_param options, :timeframe, timeframes
|
9
|
+
request :chart, :get, :candles, options.merge!(trading_pair_id: trading_pair_id)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def timeframes
|
15
|
+
%w{1m 5m 15m 30m 1h 3h 6h 12h 1D 7D 14D 1M}
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Cobinhood
|
2
|
+
module Client
|
3
|
+
class REST
|
4
|
+
# Public: A Module containing all of the Public API endpoints
|
5
|
+
module MarketAPI
|
6
|
+
|
7
|
+
def currencies
|
8
|
+
request :market, :get, :currencies
|
9
|
+
end
|
10
|
+
alias :get_all_currencies :currencies
|
11
|
+
|
12
|
+
def trading_pairs
|
13
|
+
request :market, :get, :trading_pairs
|
14
|
+
end
|
15
|
+
alias :get_all_trading_pairs :trading_pairs
|
16
|
+
|
17
|
+
def order_book trading_pair_id
|
18
|
+
request :market, :get, :order_book, trading_pair_id: trading_pair_id
|
19
|
+
end
|
20
|
+
alias :get_order_book :order_book
|
21
|
+
|
22
|
+
def precisions trading_pair_id
|
23
|
+
request :market, :get, :precisions, trading_pair_id: trading_pair_id
|
24
|
+
end
|
25
|
+
alias :get_order_book_precisions :precisions
|
26
|
+
|
27
|
+
def stats
|
28
|
+
request :market, :get, :stats
|
29
|
+
end
|
30
|
+
|
31
|
+
def tickers trading_pair_id
|
32
|
+
request :market, :get, :tickers, trading_pair_id: trading_pair_id
|
33
|
+
end
|
34
|
+
alias :get_ticker :tickers
|
35
|
+
|
36
|
+
def market_trades trading_pair_id
|
37
|
+
request :market, :get, :trades, trading_pair_id: trading_pair_id
|
38
|
+
end
|
39
|
+
alias :get_recent_trades :market_trades
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Cobinhood
|
2
|
+
module Client
|
3
|
+
class REST
|
4
|
+
module SystemAPI
|
5
|
+
def time
|
6
|
+
request :system, :get, :time
|
7
|
+
end
|
8
|
+
|
9
|
+
def localtime
|
10
|
+
Time.at time["result"]["time"] / 1000.0
|
11
|
+
end
|
12
|
+
|
13
|
+
def info
|
14
|
+
request :system, :get, :info
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Cobinhood
|
2
|
+
module Client
|
3
|
+
class REST
|
4
|
+
# Public: A Module containing all of the Public API endpoints
|
5
|
+
module TradingAPI
|
6
|
+
|
7
|
+
def order order_id
|
8
|
+
request :trading, :get, :order, order_id: order_id
|
9
|
+
end
|
10
|
+
alias :get_order :order
|
11
|
+
|
12
|
+
def order_trades order_id
|
13
|
+
request :trading, :get, :order_trades, order_id: order_id
|
14
|
+
end
|
15
|
+
alias :get_trades_of_an_order :order_trades
|
16
|
+
|
17
|
+
def orders
|
18
|
+
request :trading, :get, :orders
|
19
|
+
end
|
20
|
+
alias :get_all_orders :orders
|
21
|
+
|
22
|
+
def place_order trading_pair_id, options={}
|
23
|
+
assert_required_param options, :side, sides
|
24
|
+
assert_required_param options, :type, order_types
|
25
|
+
assert_required_param options, :size
|
26
|
+
assert_required_param options, :price unless market_order?(options)
|
27
|
+
request :trading, :post, :orders, options.merge(trading_pair_id: trading_pair_id)
|
28
|
+
end
|
29
|
+
|
30
|
+
def modify_order order_id, options={}
|
31
|
+
assert_required_param options, :size
|
32
|
+
assert_required_param options, :price
|
33
|
+
request :trading, :put, :orders, options.merge(order_id: order_id)
|
34
|
+
end
|
35
|
+
|
36
|
+
def cancel_order order_id
|
37
|
+
request :trading, :delete, :order, order_id: order_id
|
38
|
+
end
|
39
|
+
|
40
|
+
def order_history trading_pair_id=nil, options={}
|
41
|
+
options.merge!(trading_pair_id: trading_pair_id) unless trading_pair_id.nil?
|
42
|
+
request :trading, :get, :order_history, options
|
43
|
+
end
|
44
|
+
alias :get_order_history :order_history
|
45
|
+
|
46
|
+
def get_trade trade_id
|
47
|
+
request :trading, :get, :get_trade, options.merge(trade_id: trade_id)
|
48
|
+
end
|
49
|
+
alias :trade :get_trade
|
50
|
+
|
51
|
+
def trades trading_pair_id, options={}
|
52
|
+
request :trading, :get, :trades, options.merge(trading_pair_id: trading_pair_id)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def market_order? options
|
58
|
+
options[:type].to_s == "market"
|
59
|
+
end
|
60
|
+
|
61
|
+
def order_types
|
62
|
+
%w{market limit stop stop_limit}
|
63
|
+
end
|
64
|
+
|
65
|
+
def sides
|
66
|
+
%w{bid ask}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Cobinhood
|
2
|
+
module Client
|
3
|
+
class REST
|
4
|
+
# Public: A Module containing all of the Public API endpoints
|
5
|
+
module WalletAPI
|
6
|
+
|
7
|
+
def balances
|
8
|
+
request :wallet, :get, :balances
|
9
|
+
end
|
10
|
+
alias :get_wallet_balances :balances
|
11
|
+
|
12
|
+
def ledger
|
13
|
+
request :wallet, :get, :ledger
|
14
|
+
end
|
15
|
+
alias :get_ledger_entries :ledger
|
16
|
+
|
17
|
+
def deposit_addresses
|
18
|
+
request :wallet, :get, :deposit_addresses
|
19
|
+
end
|
20
|
+
alias :get_deposit_addresses :deposit_addresses
|
21
|
+
|
22
|
+
def withdrawal_addresses
|
23
|
+
request :wallet, :get, :withdrawal_addresses
|
24
|
+
end
|
25
|
+
alias :get_withdrawal_addresses :withdrawal_addresses
|
26
|
+
|
27
|
+
def withdrawal withdrawal_id
|
28
|
+
request :wallet, :get, :withdrawal, withdrawal_id: withdrawal_id
|
29
|
+
end
|
30
|
+
alias :get_withdrawal :withdrawal
|
31
|
+
|
32
|
+
def withdrawals
|
33
|
+
request :wallet, :get, :withdrawals
|
34
|
+
end
|
35
|
+
alias :get_all_withdrawals :withdrawals
|
36
|
+
|
37
|
+
def deposit deposit_id
|
38
|
+
request :wallet, :get, :deposit, deposit_id: deposit_id
|
39
|
+
end
|
40
|
+
alias :get_deposit :deposit
|
41
|
+
|
42
|
+
def deposits
|
43
|
+
request :wallet, :get, :deposits
|
44
|
+
end
|
45
|
+
alias :get_all_deposits :deposits
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cobinhood
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Lang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.12'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday_middleware
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.12'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.12'
|
83
|
+
description: Implements Cobinhood API
|
84
|
+
email:
|
85
|
+
- mwlang@cybrains.net
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- lib/cobinhood.rb
|
93
|
+
- lib/cobinhood/client/rest.rb
|
94
|
+
- lib/cobinhood/client/rest/api_endpoints.rb
|
95
|
+
- lib/cobinhood/client/rest/auth_request_middleware.rb
|
96
|
+
- lib/cobinhood/client/rest/chart_api.rb
|
97
|
+
- lib/cobinhood/client/rest/market_api.rb
|
98
|
+
- lib/cobinhood/client/rest/nonce_request_middleware.rb
|
99
|
+
- lib/cobinhood/client/rest/system_api.rb
|
100
|
+
- lib/cobinhood/client/rest/trading_api.rb
|
101
|
+
- lib/cobinhood/client/rest/wallet_api.rb
|
102
|
+
- lib/cobinhood/version.rb
|
103
|
+
homepage: https://github.com/mwlang/cobinhood
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.7.6
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Implements Cobinhood API
|
127
|
+
test_files: []
|