stocks_exchange_api_client 2.0.0 → 2.2.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 +18 -87
- data/lib/stocks_exchange_api_client.rb +85 -84
- data/lib/stocks_exchange_api_client/configuration.rb +15 -9
- data/lib/stocks_exchange_api_client/errors/configuration_error.rb +1 -1
- data/lib/stocks_exchange_api_client/private_v3.rb +1 -1
- data/lib/stocks_exchange_api_client/public_v3.rb +53 -11
- data/lib/stocks_exchange_api_client/version.rb +1 -1
- data/stocks_exchange_api_client.gemspec +5 -5
- metadata +18 -21
- data/lib/stocks_exchange_api_client/private.rb +0 -157
- data/lib/stocks_exchange_api_client/public.rb +0 -65
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f498126ccbb261c38052f090e97ac6b099aec7e61c3b3547f6c804cb9884bf9
|
4
|
+
data.tar.gz: 9c35c1441f17d199311323a8a2cdf2af1fd5febcd7938680bf1aafe21004eb60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5881fc72bc145657816ba97592099f2708566d57bacd39e3424ff708d2c11112fa62522bb97a69992093e4d53c56cc44070bf1a5fc2da1b8df804b5090918a5
|
7
|
+
data.tar.gz: 8ab84c9a7c7390c5c18a2be36a2743155fc21e8d012f385b33239a3535cd1ecf430c057fda4ce7434f86b1807100b8b76b2e3ccbabcc4812fb0b35a547347337
|
data/README.md
CHANGED
@@ -12,14 +12,12 @@ STEX (former Stocks.Exchange) provides all the core exchange functionality, and
|
|
12
12
|
## General
|
13
13
|
The base URL for all the requests other than public methods is
|
14
14
|
```
|
15
|
-
https://app.stocks.exchange/api2
|
16
|
-
https://app.stex.com/api2
|
17
15
|
https://api3.stex.com
|
18
16
|
```
|
19
17
|
|
20
18
|
## Getting started
|
21
19
|
- [Documentation](http://help.stex.com/api-integration).
|
22
|
-
- [Sandbox API
|
20
|
+
- [Sandbox API](https://apidocs.stex.com).
|
23
21
|
|
24
22
|
To get started with the Ruby API client, here's a snippet for creating a client with existing credentials:
|
25
23
|
> In order to use the API functions, you must have an API key and API secret, which is generated in the user profile.
|
@@ -31,92 +29,10 @@ gem install stocks_exchange_api_client
|
|
31
29
|
|
32
30
|
After install use for example this code!
|
33
31
|
|
34
|
-
### Example
|
35
|
-
```ruby
|
36
|
-
require 'stocks_exchange_api_client'
|
37
|
-
|
38
|
-
StocksExchangeApiClient.configure do |conf|
|
39
|
-
conf.url = 'https://app.stocks.exchange/api2'
|
40
|
-
conf.api_key = '' # Your Api Key
|
41
|
-
conf.api_secret = '' # Your Api Secret
|
42
|
-
end
|
43
|
-
# Get information about your account
|
44
|
-
puts StocksExchangeApiClient::Private.get_info
|
45
|
-
|
46
|
-
# Get information about active orders.
|
47
|
-
# Params: pair, count, order, type, owner, since, end
|
48
|
-
puts StocksExchangeApiClient::Private.active_order
|
49
|
-
|
50
|
-
# Create orders for the purchase and sale.
|
51
|
-
# Params: type, pair, amount, rate
|
52
|
-
puts StocksExchangeApiClient::Private.trade('BUY', 'LTC_BTC', 0.1, 0.00002)
|
53
|
-
|
54
|
-
# Cancel selected order.
|
55
|
-
# Params: order_id
|
56
|
-
puts StocksExchangeApiClient::Private.cancel_order(2761025)
|
57
|
-
|
58
|
-
# Get information about all orders.
|
59
|
-
# Params: pair, count, order, status, owner, since, end
|
60
|
-
puts StocksExchangeApiClient::Private.trade_history
|
61
|
-
|
62
|
-
# Get information about all closed orders from Register
|
63
|
-
# Params: currency, since, end
|
64
|
-
puts StocksExchangeApiClient::Private.trade_register_history
|
65
|
-
|
66
|
-
# Get information about all orders User
|
67
|
-
# Params: since, end
|
68
|
-
puts StocksExchangeApiClient::Private.user_history
|
69
|
-
|
70
|
-
# Get information about your deposits and withdrawals.
|
71
|
-
# Params: currency, count, order, operation, status
|
72
|
-
puts StocksExchangeApiClient::Private.trans_history
|
73
|
-
|
74
|
-
# Get information about trade statistic.
|
75
|
-
# Params: currency, count, order, operation, status, since, end
|
76
|
-
puts StocksExchangeApiClient::Private.grafic
|
77
|
-
|
78
|
-
# Generate currency wallet address.
|
79
|
-
# Params: currency
|
80
|
-
puts StocksExchangeApiClient::Private.generate_wallets('ONION')
|
81
|
-
|
82
|
-
# Get information about your wallet to deposit funds.
|
83
|
-
# Params: currency
|
84
|
-
puts StocksExchangeApiClient::Private.deposit('ETH')
|
85
|
-
|
86
|
-
# Withdraw your funds.
|
87
|
-
# Params: currency, address, amount
|
88
|
-
puts StocksExchangeApiClient::Private.withdraw('EAG', '12345', 1.001)
|
89
|
-
|
90
|
-
# Get all available currencies with additional info.
|
91
|
-
puts StocksExchangeApiClient::Public.currencies
|
92
|
-
|
93
|
-
# Get all available currency pairs with additional info.
|
94
|
-
puts StocksExchangeApiClient::Public.markets
|
95
|
-
|
96
|
-
# Get currency pair with additional info.
|
97
|
-
# Params Currency1 and Currency2
|
98
|
-
puts StocksExchangeApiClient::Public.markets_summary('BTC', 'USDT')
|
99
|
-
|
100
|
-
# Use it to get the recommended retail exchange rates for all currency pairs.
|
101
|
-
puts StocksExchangeApiClient::Public.ticker
|
102
|
-
|
103
|
-
# Use it to get the new retail exchange rates for all currency pairs.
|
104
|
-
puts StocksExchangeApiClient::Public.prices
|
105
|
-
|
106
|
-
# Used to retrieve the latest trades that have occurred for a specific market.
|
107
|
-
# Params Pair
|
108
|
-
puts StocksExchangeApiClient::Public.trade_history('BTC_USDT')
|
109
|
-
|
110
|
-
# Used to get retrieve the orderbook for a given market.
|
111
|
-
# Params Pair
|
112
|
-
puts StocksExchangeApiClient::Public.order_book('BTC_USDT')
|
113
|
-
```
|
114
|
-
|
115
|
-
### Example V3
|
32
|
+
### Example
|
116
33
|
```ruby
|
117
34
|
StocksExchangeApiClient.configure do |conf|
|
118
35
|
conf.url = 'https://api3.stex.com'
|
119
|
-
conf.use_version = 3
|
120
36
|
conf.option = {
|
121
37
|
client_id: '',
|
122
38
|
client_secret: '',
|
@@ -131,8 +47,23 @@ end
|
|
131
47
|
|
132
48
|
puts StocksExchangeApiClient::PrivateApiV3.profile_info
|
133
49
|
```
|
50
|
+
### Example Server-To-Server integrations
|
51
|
+
```ruby
|
52
|
+
StocksExchangeApiClient.configure do |conf|
|
53
|
+
conf.s2s = true
|
54
|
+
conf.option = {
|
55
|
+
token_object: {
|
56
|
+
access_token: '<access_token>',
|
57
|
+
},
|
58
|
+
scope: 'profile trade withdrawal reports push settings'
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
puts StocksExchangeApiClient::PrivateApiV3.profile_info
|
63
|
+
```
|
64
|
+
|
134
65
|
## Lists Methods
|
135
|
-
- [Sandbox API
|
66
|
+
- [Sandbox API](https://apidocs.stex.com).
|
136
67
|
```
|
137
68
|
profile_info() // Get general information about the current user.
|
138
69
|
wallets() // Get a list of user wallets.
|
@@ -7,14 +7,10 @@ require 'date'
|
|
7
7
|
# Version
|
8
8
|
require 'stocks_exchange_api_client/version'
|
9
9
|
|
10
|
-
# Private API
|
11
|
-
require 'stocks_exchange_api_client/private'
|
12
|
-
# Private API V3 method
|
10
|
+
# Private API method
|
13
11
|
require 'stocks_exchange_api_client/private_v3'
|
14
12
|
|
15
|
-
#
|
16
|
-
require 'stocks_exchange_api_client/public'
|
17
|
-
# Private API V3 method
|
13
|
+
# Private API method
|
18
14
|
require 'stocks_exchange_api_client/public_v3'
|
19
15
|
|
20
16
|
# Configuration
|
@@ -22,18 +18,18 @@ require 'stocks_exchange_api_client/configuration'
|
|
22
18
|
|
23
19
|
module StocksExchangeApiClient
|
24
20
|
METHOD_NAME = {
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
21
|
+
get_info: 'GetInfo',
|
22
|
+
active_orders: 'ActiveOrders',
|
23
|
+
trade: 'Trade',
|
24
|
+
cancel_order: 'CancelOrder',
|
25
|
+
trade_history: 'TradeHistory',
|
26
|
+
trade_register_history: 'TradeRegisterHistory',
|
27
|
+
user_history: 'UserHistory',
|
28
|
+
trans_history: 'TransHistory',
|
29
|
+
grafic: 'Grafic',
|
30
|
+
generate_wallets: 'GenerateWallets',
|
31
|
+
deposit: 'Deposit',
|
32
|
+
withdraw: 'Withdraw'
|
37
33
|
}.freeze
|
38
34
|
|
39
35
|
HEX_ALGORITHM = 'sha512'.freeze
|
@@ -44,81 +40,86 @@ module StocksExchangeApiClient
|
|
44
40
|
yield(configuration)
|
45
41
|
end
|
46
42
|
|
47
|
-
def
|
48
|
-
configuration.validate!
|
49
|
-
if method == :post
|
50
|
-
params[:method] = type
|
51
|
-
params[:nonce] = Time.now.to_i
|
52
|
-
encode_www_form = URI.encode_www_form(params)
|
53
|
-
sign = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new(HEX_ALGORITHM), configuration.option[:api_secret], encode_www_form)
|
54
|
-
response = JSON.parse(
|
55
|
-
HTTParty.post(configuration.url, body: params, headers: {
|
56
|
-
Sign: sign,
|
57
|
-
Key: configuration.option[:api_key]
|
58
|
-
}).body
|
59
|
-
)
|
60
|
-
response = OpenStruct.new(response)
|
61
|
-
end
|
62
|
-
if method == :get
|
63
|
-
response = JSON.parse(HTTParty.get("#{configuration.url}/#{type}").body)
|
64
|
-
end
|
65
|
-
response
|
66
|
-
end
|
67
|
-
|
68
|
-
def make_api_request_v3(url, params = {}, method = :get, _type = :url)
|
43
|
+
def make_api_request_v3(url, params = {}, method = :get, _type = :url, auth = true)
|
69
44
|
configuration.validate!
|
70
45
|
post_data = URI.encode_www_form(params)
|
71
46
|
url_full = "#{configuration.url}/#{url}#{post_data == '' ? '' : '?'}#{post_data}"
|
72
|
-
if
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
47
|
+
if auth
|
48
|
+
if method == :post
|
49
|
+
response = HTTParty.post(url_full, body: params, headers: {
|
50
|
+
'Authorization' => "Bearer #{get_token}",
|
51
|
+
'Accept' => 'application/json',
|
52
|
+
'User-Agent' => 'stocks.exchange-client'
|
53
|
+
}).body
|
54
|
+
end
|
55
|
+
if method == :get
|
56
|
+
response = HTTParty.get(url_full, headers: {
|
57
|
+
'Authorization' => "Bearer #{get_token}",
|
58
|
+
'Accept' => 'application/json',
|
59
|
+
'User-Agent' => 'stocks.exchange-client'
|
60
|
+
}).body
|
61
|
+
end
|
62
|
+
if method == :delete
|
63
|
+
response = HTTParty.delete(url_full, headers: {
|
64
|
+
'Authorization' => "Bearer #{get_token}",
|
65
|
+
'Accept' => 'application/json',
|
66
|
+
'User-Agent' => 'stocks.exchange-client'
|
67
|
+
}).body
|
68
|
+
end
|
69
|
+
else
|
70
|
+
if method == :post
|
71
|
+
response = HTTParty.post(url_full, body: params, headers: {
|
72
|
+
'Accept' => 'application/json',
|
73
|
+
'User-Agent' => 'stocks.exchange-client'
|
74
|
+
}).body
|
75
|
+
end
|
76
|
+
if method == :get
|
77
|
+
response = HTTParty.get(url_full, headers: {
|
78
|
+
'Accept' => 'application/json',
|
79
|
+
'User-Agent' => 'stocks.exchange-client'
|
80
|
+
}).body
|
81
|
+
end
|
82
|
+
if method == :delete
|
83
|
+
response = HTTParty.delete(url_full, headers: {
|
84
|
+
'Accept' => 'application/json',
|
85
|
+
'User-Agent' => 'stocks.exchange-client'
|
86
|
+
}).body
|
87
|
+
end
|
92
88
|
end
|
93
89
|
response
|
94
90
|
end
|
95
91
|
|
96
92
|
def get_token
|
97
|
-
if
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
93
|
+
if !configuration.s2s
|
94
|
+
if File.exist?(JSON_SETTINGS)
|
95
|
+
current_token = JSON.parse(File.read(JSON_SETTINGS))
|
96
|
+
else
|
97
|
+
current_token = {'access_token' => configuration.option[:token_object][:access_token],
|
98
|
+
'refresh_token' => configuration.option[:token_object][:refresh_token],
|
99
|
+
'expires_in' => nil,
|
100
|
+
'expires_in_date' => nil}
|
101
|
+
end
|
102
|
+
if !current_token.nil? && !current_token['expires_in_date'].nil?
|
103
|
+
return current_token['access_token'] if DateTime.parse(current_token['expires_in_date']).to_datetime > DateTime.now.to_datetime
|
104
|
+
end
|
105
|
+
begin
|
106
|
+
response = HTTParty.post(configuration.option[:access_token_url], body: {
|
107
|
+
grant_type: 'refresh_token',
|
108
|
+
refresh_token: current_token['refresh_token'],
|
109
|
+
client_id: configuration.option[:client_id],
|
110
|
+
client_secret: configuration.option[:client_secret],
|
111
|
+
scope: configuration.option[:scope]
|
112
|
+
}).body
|
113
|
+
current_token = JSON.parse(response)
|
114
|
+
current_token['expires_in_date'] = Time.at(Time.now.to_i + current_token['expires_in']).to_s
|
115
|
+
File.write(JSON_SETTINGS, current_token.to_json)
|
116
|
+
current_token['access_token']
|
117
|
+
rescue StandardError => e
|
118
|
+
puts "Rescued: #{e.inspect}"
|
119
|
+
end
|
107
120
|
end
|
108
|
-
|
109
|
-
|
110
|
-
grant_type: 'refresh_token',
|
111
|
-
refresh_token: current_token['refresh_token'],
|
112
|
-
client_id: configuration.option[:client_id],
|
113
|
-
client_secret: configuration.option[:client_secret],
|
114
|
-
scope: configuration.option[:scope]
|
115
|
-
}).body
|
116
|
-
current_token = JSON.parse(response)
|
117
|
-
current_token['expires_in_date'] = Time.at(Time.now.to_i + current_token['expires_in']).to_s
|
118
|
-
File.write(JSON_SETTINGS, current_token.to_json)
|
119
|
-
current_token['access_token']
|
120
|
-
rescue StandardError => e
|
121
|
-
puts "Rescued: #{e.inspect}"
|
121
|
+
if configuration.s2s
|
122
|
+
configuration.option[:token_object][:access_token]
|
122
123
|
end
|
123
124
|
end
|
124
125
|
|
@@ -1,25 +1,31 @@
|
|
1
|
+
require 'stocks_exchange_api_client/errors/configuration_error'
|
2
|
+
|
1
3
|
module StocksExchangeApiClient
|
2
4
|
class Configuration
|
3
|
-
URL_V2 = 'https://app.stocks.exchange/api2'.freeze
|
4
5
|
URL_V3 = 'https://api3.stex.com'.freeze
|
5
|
-
attr_accessor :url, :option, :use_version
|
6
|
+
attr_accessor :url, :option, :use_version, :s2s
|
6
7
|
|
7
|
-
def initialize
|
8
|
-
@
|
9
|
-
@
|
8
|
+
def initialize(url: URL_V3, option: {}, use_version: 3, s2s: false)
|
9
|
+
@url||= url
|
10
|
+
@option||= option
|
11
|
+
@use_version||= use_version
|
12
|
+
@s2s||= s2s
|
10
13
|
end
|
11
14
|
|
12
15
|
def validate!
|
13
16
|
if use_version == 2
|
14
|
-
|
15
|
-
raise Errors::ConfigurationError
|
16
|
-
end
|
17
|
+
raise 'Disabled supporting version 2 API'
|
17
18
|
end
|
18
|
-
if use_version == 3
|
19
|
+
if use_version == 3 && !s2s
|
19
20
|
unless option[:client_id] && option[:client_secret] && option[:token_object][:access_token] && option[:token_object][:refresh_token]
|
20
21
|
raise Errors::ConfigurationError
|
21
22
|
end
|
22
23
|
end
|
24
|
+
if use_version == 3 && s2s
|
25
|
+
unless option[:token_object][:access_token]
|
26
|
+
raise Errors::ConfigurationError
|
27
|
+
end
|
28
|
+
end
|
23
29
|
end
|
24
30
|
end
|
25
31
|
end
|
@@ -2,7 +2,7 @@ module StocksExchangeApiClient
|
|
2
2
|
module Errors
|
3
3
|
class ConfigurationError < StandardError
|
4
4
|
def initialize
|
5
|
-
super 'Not all config vars were set. Stocks Exchange requires API key and API secret. Get this fields on url https://app.
|
5
|
+
super 'Not all config vars were set. Stocks Exchange requires API key and API secret. Get this fields on url https://app.stex.com/profile/settings'
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -56,7 +56,7 @@ module StocksExchangeApiClient
|
|
56
56
|
'amount' => amount,
|
57
57
|
'address' => address
|
58
58
|
}
|
59
|
-
params['
|
59
|
+
params['additional_address_parameter'] = additional_address unless additional_address.nil?
|
60
60
|
StocksExchangeApiClient.make_api_request_v3(url, params, :post)
|
61
61
|
end
|
62
62
|
|
@@ -2,56 +2,98 @@ module StocksExchangeApiClient
|
|
2
2
|
class PublicApiV3
|
3
3
|
class << self
|
4
4
|
def ping
|
5
|
-
StocksExchangeApiClient.make_api_request_v3('/public/ping'
|
5
|
+
StocksExchangeApiClient.make_api_request_v3('/public/ping',
|
6
|
+
{},
|
7
|
+
:get,
|
8
|
+
:url,
|
9
|
+
false)
|
6
10
|
end
|
7
11
|
|
8
12
|
def currencies
|
9
|
-
StocksExchangeApiClient.make_api_request_v3('/public/currencies'
|
13
|
+
StocksExchangeApiClient.make_api_request_v3('/public/currencies',
|
14
|
+
{},
|
15
|
+
:get,
|
16
|
+
:url,
|
17
|
+
false)
|
10
18
|
end
|
11
19
|
|
12
20
|
def currencies_by_id(currency_id)
|
13
21
|
url = "/public/currencies/#{currency_id}"
|
14
|
-
StocksExchangeApiClient.make_api_request_v3(url
|
22
|
+
StocksExchangeApiClient.make_api_request_v3(url,
|
23
|
+
{},
|
24
|
+
:get,
|
25
|
+
:url,
|
26
|
+
false)
|
15
27
|
end
|
16
28
|
|
17
29
|
def markets
|
18
|
-
StocksExchangeApiClient.make_api_request_v3('/public/markets'
|
30
|
+
StocksExchangeApiClient.make_api_request_v3('/public/markets',
|
31
|
+
{},
|
32
|
+
:get,
|
33
|
+
:url,
|
34
|
+
false)
|
19
35
|
end
|
20
36
|
|
21
37
|
def pairs_list_by_code(code = 'ALL')
|
22
38
|
url = "/public/currency_pairs/list/#{code}"
|
23
|
-
StocksExchangeApiClient.make_api_request_v3(url
|
39
|
+
StocksExchangeApiClient.make_api_request_v3(url,
|
40
|
+
{},
|
41
|
+
:get,
|
42
|
+
:url,
|
43
|
+
false)
|
24
44
|
end
|
25
45
|
|
26
46
|
def pairs_list_by_id(id)
|
27
47
|
url = "/public/currency_pairs/#{id}"
|
28
|
-
StocksExchangeApiClient.make_api_request_v3(url
|
48
|
+
StocksExchangeApiClient.make_api_request_v3(url,
|
49
|
+
{},
|
50
|
+
:get,
|
51
|
+
:url,
|
52
|
+
false)
|
29
53
|
end
|
30
54
|
|
31
55
|
def ticker
|
32
|
-
StocksExchangeApiClient.make_api_request_v3('/public/ticker'
|
56
|
+
StocksExchangeApiClient.make_api_request_v3('/public/ticker',
|
57
|
+
{},
|
58
|
+
:get,
|
59
|
+
:url,
|
60
|
+
false)
|
33
61
|
end
|
34
62
|
|
35
63
|
def ticker_by_pair_id(id)
|
36
64
|
url = "/public/ticker/#{id}"
|
37
|
-
StocksExchangeApiClient.make_api_request_v3(url
|
65
|
+
StocksExchangeApiClient.make_api_request_v3(url,
|
66
|
+
{},
|
67
|
+
:get,
|
68
|
+
:url,
|
69
|
+
false)
|
38
70
|
end
|
39
71
|
|
40
72
|
def trades(currency_pair_id, params)
|
41
73
|
url = "/public/trades/#{currency_pair_id}"
|
42
|
-
StocksExchangeApiClient.make_api_request_v3(url,
|
74
|
+
StocksExchangeApiClient.make_api_request_v3(url,
|
75
|
+
params,
|
76
|
+
:get,
|
77
|
+
:url,
|
78
|
+
false)
|
43
79
|
end
|
44
80
|
|
45
81
|
def orderbook_by_pair_id(id, params)
|
46
82
|
url = "/public/orderbook/#{id}"
|
47
|
-
StocksExchangeApiClient.make_api_request_v3(url, params
|
83
|
+
StocksExchangeApiClient.make_api_request_v3(url, params,
|
84
|
+
:get,
|
85
|
+
:url,
|
86
|
+
false)
|
48
87
|
end
|
49
88
|
|
50
89
|
def chart(currency_pair_id, time_start, time_end, params, candles_type)
|
51
90
|
url = "/public/chart/#{currency_pair_id}/#{candles_type.nil? ? '1' : candles_type}"
|
52
91
|
params['timeStart'] = time_start
|
53
92
|
params['timeEnd'] = time_end
|
54
|
-
StocksExchangeApiClient.make_api_request_v3(url, params
|
93
|
+
StocksExchangeApiClient.make_api_request_v3(url, params,
|
94
|
+
:get,
|
95
|
+
:url,
|
96
|
+
false)
|
55
97
|
end
|
56
98
|
end
|
57
99
|
end
|
@@ -6,10 +6,10 @@ require 'stocks_exchange_api_client/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'stocks_exchange_api_client'
|
8
8
|
spec.version = StocksExchangeApiClient::VERSION
|
9
|
-
spec.authors = ['
|
9
|
+
spec.authors = ['STEX']
|
10
10
|
|
11
|
-
spec.summary = 'Stocks
|
12
|
-
spec.description = 'Stocks
|
11
|
+
spec.summary = 'STEX (former Stocks.Exchange) API client for ruby.'
|
12
|
+
spec.description = 'STEX (former Stocks.Exchange) provides all the core exchange functionality, and additional merchant tools available via the HTTP API where all returned messages are in JSON. Its much easier to work with the API by using one of the clients provided by STEX, so while this page describes the API in case you want or need to build your own client, the examples use the Ruby client.'
|
13
13
|
spec.homepage = 'https://github.com/StocksExchange/ruby-client#readme'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
@@ -29,6 +29,6 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.require_paths = ['lib']
|
30
30
|
|
31
31
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
32
|
-
spec.add_development_dependency 'rake', '~>
|
32
|
+
spec.add_development_dependency 'rake', '~> 12.3.3'
|
33
33
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
34
|
-
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stocks_exchange_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- STEX
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: openssl
|
@@ -48,22 +48,22 @@ dependencies:
|
|
48
48
|
name: json
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - "~>"
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '2.1'
|
54
51
|
- - ">="
|
55
52
|
- !ruby/object:Gem::Version
|
56
53
|
version: 2.1.0
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '2.1'
|
57
57
|
type: :runtime
|
58
58
|
prerelease: false
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
|
-
- - "~>"
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: '2.1'
|
64
61
|
- - ">="
|
65
62
|
- !ruby/object:Gem::Version
|
66
63
|
version: 2.1.0
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '2.1'
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: bundler
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,14 +84,14 @@ dependencies:
|
|
84
84
|
requirements:
|
85
85
|
- - "~>"
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version:
|
87
|
+
version: 12.3.3
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
90
|
version_requirements: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
92
|
- - "~>"
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
version:
|
94
|
+
version: 12.3.3
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
96
|
name: rspec
|
97
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,11 +106,11 @@ dependencies:
|
|
106
106
|
- - "~>"
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '3.0'
|
109
|
-
description: Stocks
|
110
|
-
merchant tools available via the HTTP API where all returned messages
|
111
|
-
Its much easier to work with the API by using one of the clients provided
|
112
|
-
so while this page describes the API in case you want or need to build
|
113
|
-
client, the examples use the Ruby client.
|
109
|
+
description: STEX (former Stocks.Exchange) provides all the core exchange functionality,
|
110
|
+
and additional merchant tools available via the HTTP API where all returned messages
|
111
|
+
are in JSON. Its much easier to work with the API by using one of the clients provided
|
112
|
+
by STEX, so while this page describes the API in case you want or need to build
|
113
|
+
your own client, the examples use the Ruby client.
|
114
114
|
email:
|
115
115
|
executables: []
|
116
116
|
extensions: []
|
@@ -127,9 +127,7 @@ files:
|
|
127
127
|
- lib/stocks_exchange_api_client.rb
|
128
128
|
- lib/stocks_exchange_api_client/configuration.rb
|
129
129
|
- lib/stocks_exchange_api_client/errors/configuration_error.rb
|
130
|
-
- lib/stocks_exchange_api_client/private.rb
|
131
130
|
- lib/stocks_exchange_api_client/private_v3.rb
|
132
|
-
- lib/stocks_exchange_api_client/public.rb
|
133
131
|
- lib/stocks_exchange_api_client/public_v3.rb
|
134
132
|
- lib/stocks_exchange_api_client/version.rb
|
135
133
|
- stocks_exchange_api_client.gemspec
|
@@ -152,9 +150,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
150
|
- !ruby/object:Gem::Version
|
153
151
|
version: '0'
|
154
152
|
requirements: []
|
155
|
-
|
156
|
-
rubygems_version: 2.7.6
|
153
|
+
rubygems_version: 3.0.3
|
157
154
|
signing_key:
|
158
155
|
specification_version: 4
|
159
|
-
summary: Stocks
|
156
|
+
summary: STEX (former Stocks.Exchange) API client for ruby.
|
160
157
|
test_files: []
|
@@ -1,157 +0,0 @@
|
|
1
|
-
module StocksExchangeApiClient
|
2
|
-
ASC = 'ASC'.freeze
|
3
|
-
|
4
|
-
ALL = 'ALL'.freeze
|
5
|
-
|
6
|
-
MAX_COUNT = 50
|
7
|
-
|
8
|
-
STATUS_ORDER = {
|
9
|
-
pending: 1,
|
10
|
-
processing: 2,
|
11
|
-
finished: 3,
|
12
|
-
canceled: 4
|
13
|
-
}.freeze
|
14
|
-
|
15
|
-
STATUS_ORDER_HUMAN_NAME = {
|
16
|
-
1 => 'PENDING',
|
17
|
-
2 => 'PROCESSING',
|
18
|
-
3 => 'FINISHED',
|
19
|
-
4 => 'CANCELED'
|
20
|
-
}.freeze
|
21
|
-
|
22
|
-
OWNER = {
|
23
|
-
all: 'ALL',
|
24
|
-
own: 'OWN'
|
25
|
-
}.freeze
|
26
|
-
|
27
|
-
INTERVAL = {
|
28
|
-
day: '1D',
|
29
|
-
month: '1M',
|
30
|
-
three_month: '3M',
|
31
|
-
year: '1Y'
|
32
|
-
}.freeze
|
33
|
-
|
34
|
-
DEFAULT_PAIRS = 'ETH_BTC'.freeze
|
35
|
-
|
36
|
-
class Private
|
37
|
-
class << self
|
38
|
-
def get_info
|
39
|
-
StocksExchangeApiClient.make_api_request(:post,
|
40
|
-
{},
|
41
|
-
METHOD_NAME[:get_info])
|
42
|
-
end
|
43
|
-
|
44
|
-
def active_order(params = {})
|
45
|
-
params[:pair] = params[:pair].nil? ? ALL : params[:pair]
|
46
|
-
params[:count] = params[:count].nil? ? MAX_COUNT : params[:count]
|
47
|
-
params[:order] = params[:order].nil? ? ASC : params[:order]
|
48
|
-
params[:type] = params[:type].nil? ? ALL : params[:type]
|
49
|
-
params[:owner] = params[:owner].nil? ? ALL : params[:owner]
|
50
|
-
|
51
|
-
params[:order] = ASC unless params[:since].nil? || params[:end].nil?
|
52
|
-
|
53
|
-
StocksExchangeApiClient.make_api_request(:post,
|
54
|
-
params,
|
55
|
-
METHOD_NAME[:active_orders])
|
56
|
-
end
|
57
|
-
|
58
|
-
def trade(type = nil, pair = nil, amount = nil, rate = nil)
|
59
|
-
params = {
|
60
|
-
type: type,
|
61
|
-
pair: pair,
|
62
|
-
amount: amount,
|
63
|
-
rate: rate
|
64
|
-
}
|
65
|
-
StocksExchangeApiClient.make_api_request(:post,
|
66
|
-
params,
|
67
|
-
METHOD_NAME[:trade])
|
68
|
-
end
|
69
|
-
|
70
|
-
def cancel_order(order_id)
|
71
|
-
params = { order_id: order_id }
|
72
|
-
StocksExchangeApiClient.make_api_request(:post,
|
73
|
-
params,
|
74
|
-
METHOD_NAME[:cancel_order])
|
75
|
-
end
|
76
|
-
|
77
|
-
def trade_history(params = {})
|
78
|
-
params[:pair] = params[:pair].nil? ? ALL : params[:pair]
|
79
|
-
params[:count] = params[:count].nil? ? MAX_COUNT : params[:count]
|
80
|
-
params[:order] = params[:order].nil? ? ASC : params[:order]
|
81
|
-
params[:owner] = params[:owner].nil? ? OWNER[:own] : params[:owner]
|
82
|
-
params[:status] = params[:status].nil? ? STATUS_ORDER[:finished] : params[:status]
|
83
|
-
params[:order] = ASC unless params[:since].nil? || params[:end].nil?
|
84
|
-
|
85
|
-
StocksExchangeApiClient.make_api_request(:post,
|
86
|
-
params,
|
87
|
-
METHOD_NAME[:trade_history])
|
88
|
-
end
|
89
|
-
|
90
|
-
def trade_register_history(params = {})
|
91
|
-
params[:currency] = params[:currency].nil? ? ALL : params[:currency]
|
92
|
-
|
93
|
-
StocksExchangeApiClient.make_api_request(:post,
|
94
|
-
params,
|
95
|
-
METHOD_NAME[:trade_register_history])
|
96
|
-
end
|
97
|
-
|
98
|
-
def user_history(params = {})
|
99
|
-
StocksExchangeApiClient.make_api_request(:post,
|
100
|
-
params,
|
101
|
-
METHOD_NAME[:user_history])
|
102
|
-
end
|
103
|
-
|
104
|
-
def trans_history(params = {})
|
105
|
-
params[:currency] = params[:currency].nil? ? ALL : params[:currency]
|
106
|
-
params[:count] = params[:count].nil? ? MAX_COUNT : params[:count]
|
107
|
-
params[:order] = params[:order].nil? ? 'DESC' : params[:order]
|
108
|
-
params[:operation] = params[:operation].nil? ? ALL : params[:operation]
|
109
|
-
params[:status] = params[:status].nil? ? STATUS_ORDER_HUMAN_NAME[STATUS_ORDER[:finished]] : params[:status]
|
110
|
-
params[:order] = ASC unless params[:since].nil? || params[:end].nil?
|
111
|
-
|
112
|
-
params[:status] = STATUS_ORDER_HUMAN_NAME[STATUS_ORDER[:finished]] unless params[:operation].nil? && params[:operation] == ALL
|
113
|
-
|
114
|
-
StocksExchangeApiClient.make_api_request(:post,
|
115
|
-
params,
|
116
|
-
METHOD_NAME[:trans_history])
|
117
|
-
end
|
118
|
-
|
119
|
-
def grafic(params = {})
|
120
|
-
params[:pair] = params[:pair].nil? ? DEFAULT_PAIRS : params[:pair]
|
121
|
-
params[:count] = params[:count].nil? ? MAX_COUNT : params[:count]
|
122
|
-
params[:order] = params[:order].nil? ? ASC : params[:order]
|
123
|
-
params[:interval] = params[:interval].nil? ? INTERVAL[:day] : params[:interval]
|
124
|
-
params[:page] = params[:page].nil? ? 1 : params[:page]
|
125
|
-
params[:order] = ASC unless params[:since].nil? || params[:end].nil?
|
126
|
-
|
127
|
-
StocksExchangeApiClient.make_api_request(:post,
|
128
|
-
params,
|
129
|
-
METHOD_NAME[:grafic])
|
130
|
-
end
|
131
|
-
|
132
|
-
def generate_wallets(currency)
|
133
|
-
StocksExchangeApiClient.make_api_request(:post,
|
134
|
-
{ currency: currency },
|
135
|
-
METHOD_NAME[:generate_wallets])
|
136
|
-
end
|
137
|
-
|
138
|
-
def deposit(currency)
|
139
|
-
StocksExchangeApiClient.make_api_request(:post,
|
140
|
-
{ currency: currency },
|
141
|
-
METHOD_NAME[:deposit])
|
142
|
-
end
|
143
|
-
|
144
|
-
def withdraw(currency, address, amount)
|
145
|
-
params = {
|
146
|
-
currency: currency,
|
147
|
-
address: address,
|
148
|
-
amount: amount
|
149
|
-
}
|
150
|
-
|
151
|
-
StocksExchangeApiClient.make_api_request(:post,
|
152
|
-
params,
|
153
|
-
METHOD_NAME[:withdraw])
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
module StocksExchangeApiClient
|
2
|
-
class Public
|
3
|
-
class << self
|
4
|
-
def currencies
|
5
|
-
StocksExchangeApiClient.make_api_request(:get,
|
6
|
-
nil,
|
7
|
-
'currencies')
|
8
|
-
end
|
9
|
-
|
10
|
-
def markets
|
11
|
-
StocksExchangeApiClient.make_api_request(:get,
|
12
|
-
nil,
|
13
|
-
'markets')
|
14
|
-
end
|
15
|
-
|
16
|
-
def markets_summary(currency1 = 'ETH', currency2 = 'BTC')
|
17
|
-
url = "market_summary/#{currency1}/#{currency2}"
|
18
|
-
StocksExchangeApiClient.make_api_request(:get,
|
19
|
-
nil,
|
20
|
-
url)
|
21
|
-
end
|
22
|
-
|
23
|
-
def ticker
|
24
|
-
StocksExchangeApiClient.make_api_request(:get,
|
25
|
-
nil,
|
26
|
-
'ticker')
|
27
|
-
end
|
28
|
-
|
29
|
-
def prices
|
30
|
-
StocksExchangeApiClient.make_api_request(:get,
|
31
|
-
nil,
|
32
|
-
'prices')
|
33
|
-
end
|
34
|
-
|
35
|
-
def trade_history(pair = DEFAULT_PAIRS)
|
36
|
-
url = "trades?pair=#{pair}"
|
37
|
-
StocksExchangeApiClient.make_api_request(:get,
|
38
|
-
nil,
|
39
|
-
url)
|
40
|
-
end
|
41
|
-
|
42
|
-
def order_book(pair = DEFAULT_PAIRS)
|
43
|
-
url = "orderbook?pair=#{pair}"
|
44
|
-
StocksExchangeApiClient.make_api_request(:get,
|
45
|
-
nil,
|
46
|
-
url)
|
47
|
-
end
|
48
|
-
|
49
|
-
def grafic(params = {})
|
50
|
-
params[:pair] = params[:pair].nil? ? DEFAULT_PAIRS : params[:pair]
|
51
|
-
params[:count] = params[:count].nil? ? MAX_COUNT : params[:count]
|
52
|
-
params[:order] = params[:order].nil? ? ASC : params[:order]
|
53
|
-
params[:interval] = params[:interval].nil? ? INTERVAL[:day] : params[:interval]
|
54
|
-
params[:page] = params[:page].nil? ? 1 : params[:page]
|
55
|
-
params[:order] = ASC unless params[:since].nil? || params[:end].nil?
|
56
|
-
encode_www_form = URI.encode_www_form(params)
|
57
|
-
|
58
|
-
url = "grafic_public?#{encode_www_form}"
|
59
|
-
StocksExchangeApiClient.make_api_request(:get,
|
60
|
-
nil,
|
61
|
-
url)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|