vaultoro 0.1.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 +7 -0
- data/CHANGELOG.md +4 -0
- data/LICENSE.md +20 -0
- data/README.md +583 -0
- data/lib/vaultoro.rb +57 -0
- data/lib/vaultoro/base.rb +32 -0
- data/lib/vaultoro/basic_api/bid_ask.rb +38 -0
- data/lib/vaultoro/basic_api/buy_orders.rb +37 -0
- data/lib/vaultoro/basic_api/client.rb +47 -0
- data/lib/vaultoro/basic_api/latest_price.rb +25 -0
- data/lib/vaultoro/basic_api/latest_trades.rb +44 -0
- data/lib/vaultoro/basic_api/market_data.rb +56 -0
- data/lib/vaultoro/basic_api/order.rb +10 -0
- data/lib/vaultoro/basic_api/order_book.rb +46 -0
- data/lib/vaultoro/basic_api/price_volume.rb +11 -0
- data/lib/vaultoro/basic_api/sell_orders.rb +37 -0
- data/lib/vaultoro/basic_api/trade.rb +12 -0
- data/lib/vaultoro/basic_api/transaction.rb +11 -0
- data/lib/vaultoro/basic_api/transactions.rb +45 -0
- data/lib/vaultoro/configuration.rb +72 -0
- data/lib/vaultoro/trading_api/balance.rb +11 -0
- data/lib/vaultoro/trading_api/balances.rb +39 -0
- data/lib/vaultoro/trading_api/buy.rb +51 -0
- data/lib/vaultoro/trading_api/cancel.rb +33 -0
- data/lib/vaultoro/trading_api/client.rb +59 -0
- data/lib/vaultoro/trading_api/order.rb +13 -0
- data/lib/vaultoro/trading_api/orders.rb +53 -0
- data/lib/vaultoro/trading_api/sell.rb +48 -0
- data/lib/vaultoro/trading_api/trade.rb +16 -0
- data/lib/vaultoro/trading_api/trades.rb +65 -0
- data/lib/vaultoro/trading_api/withdraw.rb +36 -0
- data/lib/vaultoro/version.rb +11 -0
- metadata +105 -0
data/lib/vaultoro.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'vaultoro/base'
|
2
|
+
require 'vaultoro/version'
|
3
|
+
require 'vaultoro/configuration'
|
4
|
+
require 'vaultoro/basic_api/client'
|
5
|
+
require 'vaultoro/basic_api/bid_ask'
|
6
|
+
require 'vaultoro/basic_api/buy_orders'
|
7
|
+
require 'vaultoro/basic_api/latest_price'
|
8
|
+
require 'vaultoro/basic_api/latest_trades'
|
9
|
+
require 'vaultoro/basic_api/market_data'
|
10
|
+
require 'vaultoro/basic_api/order'
|
11
|
+
require 'vaultoro/basic_api/order_book'
|
12
|
+
require 'vaultoro/basic_api/price_volume'
|
13
|
+
require 'vaultoro/basic_api/sell_orders'
|
14
|
+
require 'vaultoro/basic_api/trade'
|
15
|
+
require 'vaultoro/basic_api/transaction'
|
16
|
+
require 'vaultoro/basic_api/transactions'
|
17
|
+
require 'vaultoro/trading_api/client'
|
18
|
+
require 'vaultoro/trading_api/balance'
|
19
|
+
require 'vaultoro/trading_api/balances'
|
20
|
+
require 'vaultoro/trading_api/buy'
|
21
|
+
require 'vaultoro/trading_api/cancel'
|
22
|
+
require 'vaultoro/trading_api/order'
|
23
|
+
require 'vaultoro/trading_api/orders'
|
24
|
+
require 'vaultoro/trading_api/sell'
|
25
|
+
require 'vaultoro/trading_api/trade'
|
26
|
+
require 'vaultoro/trading_api/trades'
|
27
|
+
require 'vaultoro/trading_api/withdraw'
|
28
|
+
|
29
|
+
module Vaultoro
|
30
|
+
@@configuration = nil
|
31
|
+
|
32
|
+
def self.configure
|
33
|
+
@@configuration = Configuration.new
|
34
|
+
yield(configuration) if block_given?
|
35
|
+
configuration
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.configuration
|
39
|
+
@@configuration || configure
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.method_missing(method_sym, *arguments, &block)
|
43
|
+
if configuration.respond_to?(method_sym)
|
44
|
+
configuration.send(method_sym)
|
45
|
+
else
|
46
|
+
super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.respond_to?(method_sym, include_private = false)
|
51
|
+
if configuration.respond_to?(method_sym, include_private)
|
52
|
+
true
|
53
|
+
else
|
54
|
+
super
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
|
3
|
+
module Vaultoro
|
4
|
+
class Base
|
5
|
+
include Virtus.model
|
6
|
+
include Virtus::Equalizer.new(name || inspect)
|
7
|
+
|
8
|
+
attribute :errors, Array[String]
|
9
|
+
attribute :status, String # SUCCESS or FAILURE or PENDING
|
10
|
+
|
11
|
+
def inspect
|
12
|
+
values = Hash[instance_variables.map{|name| [name, instance_variable_get(name)]}]
|
13
|
+
"<#{self.class.name} #{values}>"
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def ensure_attribute_has_value(*attributes)
|
19
|
+
@errors.clear
|
20
|
+
attributes.each do |attr|
|
21
|
+
unless instance_variable_get(("@" + attr.to_s).intern)
|
22
|
+
@errors << "#{attr.to_s} is required"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_errors(response)
|
28
|
+
hash = JSON.parse(response.body)
|
29
|
+
@errors << hash["message"]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Vaultoro
|
2
|
+
module BasicAPI
|
3
|
+
class BidAsk < Base
|
4
|
+
attribute :list, Array[PriceVolume]
|
5
|
+
|
6
|
+
def fetch
|
7
|
+
@errors.clear
|
8
|
+
|
9
|
+
response = Client.get('/bidandask', {})
|
10
|
+
code = response.code rescue ""
|
11
|
+
|
12
|
+
case code
|
13
|
+
when '200'
|
14
|
+
hash = JSON.parse(response.body)
|
15
|
+
@status = 'SUCCESS'
|
16
|
+
|
17
|
+
hash['bids'].each do |bid|
|
18
|
+
@list << PriceVolume.new(type: 'bid', price: bid[0].to_f, volume: bid[1].to_f)
|
19
|
+
end
|
20
|
+
|
21
|
+
hash['asks'].each do |ask|
|
22
|
+
@list << PriceVolume.new(type: 'ask', price: bid[0].to_f, volume: bid[1].to_f)
|
23
|
+
end
|
24
|
+
|
25
|
+
unless @status == 'SUCCESS'
|
26
|
+
set_errors(response)
|
27
|
+
return false
|
28
|
+
end
|
29
|
+
|
30
|
+
return true
|
31
|
+
else
|
32
|
+
set_errors(response)
|
33
|
+
return false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Vaultoro
|
2
|
+
module BasicAPI
|
3
|
+
class BuyOrders < Base
|
4
|
+
attribute :list, Array[Order]
|
5
|
+
|
6
|
+
def fetch
|
7
|
+
@errors.clear
|
8
|
+
|
9
|
+
response = Client.get('/buyorders', {})
|
10
|
+
code = response.code rescue ""
|
11
|
+
|
12
|
+
case code
|
13
|
+
when '200'
|
14
|
+
hash = JSON.parse(response.body)
|
15
|
+
@status = hash['status'].upcase
|
16
|
+
|
17
|
+
if @status == 'SUCCESS'
|
18
|
+
hash['data'].each do |item|
|
19
|
+
@list << BuyOrder.new(
|
20
|
+
gold_amount: item['Gold_Amount'].to_f,
|
21
|
+
gold_price: item['Gold_Price'].to_f
|
22
|
+
)
|
23
|
+
end
|
24
|
+
else
|
25
|
+
set_errors(response)
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
|
29
|
+
return true
|
30
|
+
else
|
31
|
+
set_errors(response)
|
32
|
+
return false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Vaultoro
|
7
|
+
module BasicAPI
|
8
|
+
class Client
|
9
|
+
def self.get(endpoint, params = {})
|
10
|
+
begin
|
11
|
+
uri = URI.parse([Vaultoro.api_uri, endpoint].join)
|
12
|
+
uri.query = URI.encode_www_form(params)
|
13
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
14
|
+
http.use_ssl = uri.scheme == 'https'
|
15
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
16
|
+
request = Net::HTTP::Get.new(uri, headers)
|
17
|
+
response = http.request(request)
|
18
|
+
rescue StandardError => error
|
19
|
+
puts "Request failed (#{error.message})"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.post(endpoint, params = {})
|
24
|
+
begin
|
25
|
+
uri = URI.parse([Vaultoro.api_uri, endpoint].join)
|
26
|
+
uri.query = URI.encode_www_form(params)
|
27
|
+
# body = URI.encode_www_form(params)
|
28
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
29
|
+
http.use_ssl = uri.scheme == 'https'
|
30
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
31
|
+
request = Net::HTTP::Post.new(uri, headers)
|
32
|
+
request.add_field "Content-Type", "application/x-www-form-urlencoded"
|
33
|
+
# request.body = body
|
34
|
+
response = http.request(request)
|
35
|
+
rescue StandardError => error
|
36
|
+
puts "Request failed (#{error.message})"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def headers
|
43
|
+
{ 'User-Agent' => Vaultoro::VERSION::SUMMARY, 'Accept' => 'application/json' }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Vaultoro
|
2
|
+
module BasicAPI
|
3
|
+
class LatestPrice < Base
|
4
|
+
attribute :gold_price, Float
|
5
|
+
|
6
|
+
def fetch
|
7
|
+
@errors.clear
|
8
|
+
|
9
|
+
response = Client.get('/latest', {})
|
10
|
+
code = response.code rescue ""
|
11
|
+
|
12
|
+
case code
|
13
|
+
when '200'
|
14
|
+
@status = 'SUCCESS'
|
15
|
+
@gold_price = response.body.to_f
|
16
|
+
|
17
|
+
return true
|
18
|
+
else
|
19
|
+
set_errors(response)
|
20
|
+
return false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Vaultoro
|
2
|
+
module BasicAPI
|
3
|
+
class LatestTrades < Base
|
4
|
+
attribute :since, Integer # Transaction Identifier
|
5
|
+
attribute :count, Integer # Size range: 1-250
|
6
|
+
attribute :list, Array[Trade]
|
7
|
+
|
8
|
+
def fetch
|
9
|
+
@errors.clear
|
10
|
+
@errors << ":since or :count argument is required" unless @since || @count
|
11
|
+
@errors << ":count argument must be between 1-250" unless @count && @count >= 1 && @count <= 250
|
12
|
+
|
13
|
+
return false if @errors.any?
|
14
|
+
|
15
|
+
params = {}
|
16
|
+
params.merge!(since: @since) if @since
|
17
|
+
params.merge!(count: @count) if @count
|
18
|
+
|
19
|
+
response = Client.get("/latesttrades", params)
|
20
|
+
code = response.code rescue ""
|
21
|
+
|
22
|
+
case code
|
23
|
+
when '200'
|
24
|
+
hash = JSON.parse(response.body)
|
25
|
+
@status = 'SUCCESS'
|
26
|
+
|
27
|
+
hash.each do |trade|
|
28
|
+
@list << Trade.new(
|
29
|
+
transaction_id: trade['tid'],
|
30
|
+
price: trade['price'].to_f,
|
31
|
+
amount: trade['amount'].to_f,
|
32
|
+
time: DateTime.strptime(trade['date'], '%Y-%m-%dT%H:%M:%S.%L%z').to_time.utc
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
return true
|
37
|
+
else
|
38
|
+
set_errors(response)
|
39
|
+
return false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Vaultoro
|
2
|
+
module BasicAPI
|
3
|
+
class MarketData < Base
|
4
|
+
attribute :market_currency, String
|
5
|
+
attribute :base_currency, String
|
6
|
+
attribute :market_currency_name, String
|
7
|
+
attribute :base_currency_name, String
|
8
|
+
attribute :min_trade_size, Float
|
9
|
+
attribute :market_name, String
|
10
|
+
attribute :is_active, Boolean
|
11
|
+
attribute :min_unit_qty, Float
|
12
|
+
attribute :min_price, Float
|
13
|
+
attribute :last_price, Float
|
14
|
+
attribute :daily_low, Float
|
15
|
+
attribute :daily_high, Float
|
16
|
+
attribute :daily_volume, Float
|
17
|
+
|
18
|
+
def fetch
|
19
|
+
@errors.clear
|
20
|
+
|
21
|
+
response = Client.get('/markets', {})
|
22
|
+
code = response.code rescue ""
|
23
|
+
|
24
|
+
case code
|
25
|
+
when '200'
|
26
|
+
hash = JSON.parse(response.body)
|
27
|
+
@status = hash['status'].upcase
|
28
|
+
|
29
|
+
if @status == 'SUCCESS'
|
30
|
+
@market_currency = hash['data']['MarketCurrency']
|
31
|
+
@base_currency = hash['data']['BaseCurrency']
|
32
|
+
@market_currency_name = hash['data']['MarketCurrencyLong']
|
33
|
+
@base_currency_name = hash['data']['BaseCurrencyLong']
|
34
|
+
@min_trade_size = ("%f" % "#{hash['data']['MinTradeSize']}").to_f
|
35
|
+
@market_name = hash['data']['MarketName']
|
36
|
+
@is_active = hash['data']['IsActive']
|
37
|
+
@min_unit_qty = hash['data']['MinUnitQty'].to_f
|
38
|
+
@min_price = hash['data']['MinPrice'].to_f
|
39
|
+
@last_price = hash['data']['LastPrice'].to_f
|
40
|
+
@daily_low = hash['data']['24hLow'].to_f
|
41
|
+
@daily_high = hash['data']['24hHigh'].to_f
|
42
|
+
@daily_volume = hash['data']['24HVolume'].to_f
|
43
|
+
else
|
44
|
+
set_errors(response)
|
45
|
+
return false
|
46
|
+
end
|
47
|
+
|
48
|
+
return true
|
49
|
+
else
|
50
|
+
set_errors(response)
|
51
|
+
return false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Vaultoro
|
2
|
+
module BasicAPI
|
3
|
+
class OrderBook < Base
|
4
|
+
attribute :list, Array[Order]
|
5
|
+
|
6
|
+
def fetch
|
7
|
+
@errors.clear
|
8
|
+
|
9
|
+
response = Client.get('/orderbook', {})
|
10
|
+
code = response.code rescue ""
|
11
|
+
|
12
|
+
case code
|
13
|
+
when '200'
|
14
|
+
hash = JSON.parse(response.body)
|
15
|
+
@status = hash['status'].upcase
|
16
|
+
|
17
|
+
if @status == 'SUCCESS'
|
18
|
+
hash['data'].each do |orders|
|
19
|
+
orders['b'] do |buy|
|
20
|
+
@list << Order.new(
|
21
|
+
gold_amount: buy['Gold_Amount'].to_f,
|
22
|
+
gold_price: buy['Gold_Price'].to_f
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
orders['s'] do |sell|
|
27
|
+
@list << Order.new(
|
28
|
+
gold_amount: buy['Gold_Amount'].to_f,
|
29
|
+
gold_price: buy['Gold_Price'].to_f
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
else
|
34
|
+
set_errors(response)
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
|
38
|
+
return true
|
39
|
+
else
|
40
|
+
set_errors(response)
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Vaultoro
|
2
|
+
module BasicAPI
|
3
|
+
class SellOrders < Base
|
4
|
+
attribute :list, Array[Order]
|
5
|
+
|
6
|
+
def fetch
|
7
|
+
@errors.clear
|
8
|
+
|
9
|
+
response = Client.get('/sellorders', {})
|
10
|
+
code = response.code rescue ""
|
11
|
+
|
12
|
+
case code
|
13
|
+
when '200'
|
14
|
+
hash = JSON.parse(response.body)
|
15
|
+
@status = hash['status'].upcase
|
16
|
+
|
17
|
+
if @status == 'SUCCESS'
|
18
|
+
hash['data'].each do |item|
|
19
|
+
@list << Order.new(
|
20
|
+
gold_amount: item['Gold_Amount'].to_f,
|
21
|
+
gold_price: item['Gold_Price'].to_f
|
22
|
+
)
|
23
|
+
end
|
24
|
+
else
|
25
|
+
set_errors(response)
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
|
29
|
+
return true
|
30
|
+
else
|
31
|
+
set_errors(response)
|
32
|
+
return false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|