bitex 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -3
- data/lib/bitex/api.rb +2 -0
- data/lib/bitex/ask.rb +4 -4
- data/lib/bitex/base_order.rb +6 -6
- data/lib/bitex/bid.rb +4 -4
- data/lib/bitex/buy.rb +1 -1
- data/lib/bitex/market_data.rb +0 -1
- data/lib/bitex/match.rb +6 -4
- data/lib/bitex/rates.rb +3 -1
- data/lib/bitex/sell.rb +1 -1
- data/lib/bitex/specie_withdrawal.rb +2 -0
- data/lib/bitex/version.rb +1 -1
- data/spec/ask_spec.rb +2 -2
- data/spec/bid_spec.rb +2 -2
- data/spec/buy_spec.rb +2 -2
- data/spec/sell_spec.rb +2 -2
- data/spec/support/from_json_shared_examples.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '03555559d3d82a4f379a04f62d31c8ffaf2ab223'
|
4
|
+
data.tar.gz: 067a8204a071250238538d2b027bc98acc7a8174
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ff84068e327879b35f21bdb4eebc3ad1a2b23234f482b4705527b748e2184558b6f44c40e4ce0922daefdcd9e2f2b8be63765068b551167d9b1953555bfc56b
|
7
|
+
data.tar.gz: be63b22da048ff45b8048ceb613150d8f0e731ee0182d700038c9fd6fb73ba5e7e4fe6762c9c48011073801924595fff9bfcecdb0eaf68280035a7b37fd13d29
|
data/.rubocop.yml
CHANGED
data/lib/bitex/api.rb
CHANGED
@@ -20,6 +20,7 @@ module Bitex
|
|
20
20
|
@curl
|
21
21
|
end
|
22
22
|
|
23
|
+
# rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
23
24
|
def self.curl(verb, path, options = {}, files = {})
|
24
25
|
verb = verb.upcase.to_sym
|
25
26
|
query = verb == :GET ? "?#{options.to_query}" : ''
|
@@ -51,6 +52,7 @@ module Bitex
|
|
51
52
|
|
52
53
|
curl
|
53
54
|
end
|
55
|
+
# rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
54
56
|
|
55
57
|
def self.public(path, _options = {})
|
56
58
|
response = curl(:GET, path)
|
data/lib/bitex/ask.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Bitex
|
2
|
-
# An Ask is an order to sell a given
|
2
|
+
# An Ask is an order to sell a given order book.
|
3
3
|
# @see BaseOrder
|
4
4
|
class Ask < BaseOrder
|
5
5
|
# @!attribute id
|
@@ -8,7 +8,7 @@ module Bitex
|
|
8
8
|
# @!attribute created_at
|
9
9
|
# @return [Time] Time when this Ask was created.
|
10
10
|
|
11
|
-
# @!attribute
|
11
|
+
# @!attribute order_book
|
12
12
|
# @return [Symbol] :btc_usd or :btc_ars
|
13
13
|
|
14
14
|
# @!attribute quantity
|
@@ -53,12 +53,12 @@ module Bitex
|
|
53
53
|
|
54
54
|
# TODO: rever esta documentacion
|
55
55
|
# Create a new Ask for selling a Quantity of specie charging no less than Price per each.
|
56
|
-
# @param
|
56
|
+
# @param order_book [Symbol] :btc_usd or :btc_ars, whatever you're selling.
|
57
57
|
# @param quantity [BigDecimal] Quantity to sell.
|
58
58
|
# @param price [BigDecimal] Minimum price to charge when selling.
|
59
59
|
# @param wait [Boolean] Block the process and wait until this ask moves out of the :received state, defaults to false.
|
60
60
|
# @see https://bitex.la/developers#create-ask
|
61
|
-
def self.create!(
|
61
|
+
def self.create!(order_book, quantity, price, wait = false)
|
62
62
|
super
|
63
63
|
end
|
64
64
|
|
data/lib/bitex/base_order.rb
CHANGED
@@ -9,9 +9,9 @@ module Bitex
|
|
9
9
|
# @return [Time] Time when this Bid was created.
|
10
10
|
attr_accessor :created_at
|
11
11
|
|
12
|
-
# @!attribute
|
12
|
+
# @!attribute order_book
|
13
13
|
# @return [Symbol] :btc_usd or :btc_ars
|
14
|
-
attr_accessor :
|
14
|
+
attr_accessor :order_book
|
15
15
|
|
16
16
|
# @!attribute price
|
17
17
|
# @return [BigDecimal] Maximum price to pay per unit.
|
@@ -52,8 +52,8 @@ module Bitex
|
|
52
52
|
end
|
53
53
|
|
54
54
|
# @visibility private
|
55
|
-
def self.create!(
|
56
|
-
params = { amount: amount, price: price, orderbook: { btc_usd: 1, btc_ars: 5 }[
|
55
|
+
def self.create!(order_book, amount, price, wait = false)
|
56
|
+
params = { amount: amount, price: price, orderbook: { btc_usd: 1, btc_ars: 5 }[order_book] }
|
57
57
|
|
58
58
|
order = from_json(Api.private(:post, "/private#{base_path}", params))
|
59
59
|
retries = 0
|
@@ -75,7 +75,7 @@ module Bitex
|
|
75
75
|
# @visibility private
|
76
76
|
def self.from_json(json, order = nil)
|
77
77
|
Api.from_json(order || new, json) do |thing|
|
78
|
-
thing.
|
78
|
+
thing.order_book = order_books[json[3]]
|
79
79
|
thing.price = json[6].to_s.to_d
|
80
80
|
thing.status = statuses[json[7]]
|
81
81
|
thing.reason = reasons[json[8]]
|
@@ -91,7 +91,7 @@ module Bitex
|
|
91
91
|
order
|
92
92
|
end
|
93
93
|
|
94
|
-
def self.
|
94
|
+
def self.order_books
|
95
95
|
{ 1 => :btc_usd, 5 => :btc_ars }
|
96
96
|
end
|
97
97
|
|
data/lib/bitex/bid.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Bitex
|
2
|
-
# A Bid is an order to buy a given
|
2
|
+
# A Bid is an order to buy a given order book.
|
3
3
|
# @see BaseOrder
|
4
4
|
class Bid < BaseOrder
|
5
5
|
# @!attribute id
|
@@ -8,7 +8,7 @@ module Bitex
|
|
8
8
|
# @!attribute created_at
|
9
9
|
# @return [Time] Time when this Bid was created.
|
10
10
|
|
11
|
-
# @!attribute
|
11
|
+
# @!attribute order_book
|
12
12
|
# @return [Symbol] :btc_usd or :btc_ars
|
13
13
|
|
14
14
|
# @!attribute amount
|
@@ -51,12 +51,12 @@ module Bitex
|
|
51
51
|
end
|
52
52
|
|
53
53
|
# Create a new Bid for spending Amount USD paying no more than price per unit.
|
54
|
-
# @param
|
54
|
+
# @param order_book [Symbol] :btc_usd or :btc_ars, whatever you're buying.
|
55
55
|
# @param amount [BigDecimal] Amount to spend buying.
|
56
56
|
# @param price [BigDecimal] Maximum price to pay per unit.
|
57
57
|
# @param wait [Boolean] Block the process and wait until this bid moves out of the :received state, defaults to false.
|
58
58
|
# @see https://bitex.la/developers#create-bid
|
59
|
-
def self.create!(
|
59
|
+
def self.create!(order_book, amount, price, wait = false)
|
60
60
|
super
|
61
61
|
end
|
62
62
|
|
data/lib/bitex/buy.rb
CHANGED
data/lib/bitex/market_data.rb
CHANGED
@@ -12,7 +12,6 @@ module Bitex
|
|
12
12
|
# The species order book as a Hash with two keys: bids and asks.
|
13
13
|
# Each of them is a list of list consisting of [price, quantity]
|
14
14
|
# @see https://bitex.la/developers#orderbook
|
15
|
-
# TODO: standarize name for order-books: orderbook | order_book
|
16
15
|
def self.order_book
|
17
16
|
api_get('/market/order_book').symbolize_keys
|
18
17
|
end
|
data/lib/bitex/match.rb
CHANGED
@@ -3,22 +3,24 @@ module Bitex
|
|
3
3
|
# Both Buy and Sell are a kind of Match, they deserialize the same and have very similar fields, although their documentation
|
4
4
|
# may differ.
|
5
5
|
class Match
|
6
|
-
attr_accessor :id, :
|
6
|
+
attr_accessor :id, :order_book, :quantity, :amount, :fee, :price, :created_at
|
7
7
|
|
8
8
|
# @visibility private
|
9
|
+
# rubocop:disable Metrics/AbcSize
|
9
10
|
def self.from_json(json)
|
10
11
|
Api.from_json(new, json) do |thing|
|
11
|
-
thing.
|
12
|
+
thing.order_book = order_books[json[3]]
|
12
13
|
thing.quantity = json[4].to_s.to_d
|
13
14
|
thing.amount = json[5].to_s.to_d
|
14
15
|
thing.fee = json[6].to_s.to_d
|
15
16
|
thing.price = json[7].to_s.to_d
|
16
17
|
end
|
17
18
|
end
|
19
|
+
# rubocop:enable Metrics/AbcSize
|
18
20
|
|
19
21
|
private_class_method
|
20
22
|
|
21
|
-
def self.
|
23
|
+
def self.order_books
|
22
24
|
{ 1 => :btc_usd, 5 => :btc_ars }
|
23
25
|
end
|
24
26
|
|
@@ -33,7 +35,7 @@ module Bitex
|
|
33
35
|
private
|
34
36
|
|
35
37
|
def base_quote
|
36
|
-
|
38
|
+
order_book.upcase.to_s.split('_')
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
data/lib/bitex/rates.rb
CHANGED
@@ -22,6 +22,7 @@ module Bitex
|
|
22
22
|
@last_tree_fetch = nil
|
23
23
|
end
|
24
24
|
|
25
|
+
# rubocop:disable Metrics/AbcSize
|
25
26
|
def self.calculate_path(value, path)
|
26
27
|
value = value.to_d
|
27
28
|
path_to_calculator(path).each do |step|
|
@@ -57,12 +58,13 @@ module Bitex
|
|
57
58
|
end
|
58
59
|
value
|
59
60
|
end
|
61
|
+
# rubocop:enable Metrics/AbcSize
|
60
62
|
|
61
63
|
def self.path_to_calculator(path)
|
62
64
|
steps = tree
|
63
65
|
begin
|
64
66
|
path.each { |step| steps = steps[step] }
|
65
|
-
rescue StandardError
|
67
|
+
rescue StandardError
|
66
68
|
raise "InvalidPath: #{path}"
|
67
69
|
end
|
68
70
|
steps
|
data/lib/bitex/sell.rb
CHANGED
@@ -50,6 +50,7 @@ module Bitex
|
|
50
50
|
attr_accessor :transaction_id
|
51
51
|
|
52
52
|
# @visibility private
|
53
|
+
# rubocop:disable Metrics/AbcSize
|
53
54
|
def self.from_json(json)
|
54
55
|
Api.from_json(new, json) do |thing|
|
55
56
|
thing.specie = { 1 => :btc }[json[3]]
|
@@ -62,6 +63,7 @@ module Bitex
|
|
62
63
|
thing.transaction_id = json[10]
|
63
64
|
end
|
64
65
|
end
|
66
|
+
# rubocop:enable Metrics/AbcSize
|
65
67
|
|
66
68
|
def self.create!(specie, address, amount, label, kyc_profile_id = nil)
|
67
69
|
from_json(
|
data/lib/bitex/version.rb
CHANGED
data/spec/ask_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Bitex::Ask do
|
|
6
6
|
1, # 0 - API class reference
|
7
7
|
12345678, # 1 - id
|
8
8
|
946685400, # 2 - created_at
|
9
|
-
1, # 3 -
|
9
|
+
1, # 3 - order_book
|
10
10
|
100.0, # 4 - quantity
|
11
11
|
100.0, # 5 - remaining_quantity
|
12
12
|
1000.0, # 6 - price
|
@@ -18,7 +18,7 @@ describe Bitex::Ask do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it_behaves_like 'API class'
|
21
|
-
it_behaves_like 'API class with a
|
21
|
+
it_behaves_like 'API class with a order book'
|
22
22
|
it_behaves_like 'JSON deserializable order'
|
23
23
|
|
24
24
|
describe 'Api calls' do
|
data/spec/bid_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Bitex::Bid do
|
|
6
6
|
1, # 0 - API class reference
|
7
7
|
12_345_678, # 1 - id
|
8
8
|
946_685_400, # 2 - created_at
|
9
|
-
1, # 3 -
|
9
|
+
1, # 3 - order_book
|
10
10
|
100.0, # 4 - quantity
|
11
11
|
100.0, # 5 - remaining_quantity
|
12
12
|
1_000.0, # 6 - price
|
@@ -18,7 +18,7 @@ describe Bitex::Bid do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it_behaves_like 'API class'
|
21
|
-
it_behaves_like 'API class with a
|
21
|
+
it_behaves_like 'API class with a order book'
|
22
22
|
it_behaves_like 'JSON deserializable order'
|
23
23
|
|
24
24
|
describe 'Api calls' do
|
data/spec/buy_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Bitex::Buy do
|
|
6
6
|
4, # 0 - API class reference
|
7
7
|
12_345_678, # 1 - id
|
8
8
|
946_685_400, # 2 - created_at
|
9
|
-
1, # 3 -
|
9
|
+
1, # 3 - order_book
|
10
10
|
100.5, # 4 - quantity
|
11
11
|
201, # 5 - amount
|
12
12
|
0.05, # 6 - fee
|
@@ -16,7 +16,7 @@ describe Bitex::Buy do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it_behaves_like 'API class'
|
19
|
-
it_behaves_like 'API class with a
|
19
|
+
it_behaves_like 'API class with a order book'
|
20
20
|
it_behaves_like 'JSON deserializable match'
|
21
21
|
|
22
22
|
it 'sets the bid id' do
|
data/spec/sell_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Bitex::Sell do
|
|
6
6
|
3, # 0 - API class reference
|
7
7
|
12_345_678, # 1 - id
|
8
8
|
946685400, # 2 - created_at
|
9
|
-
1, # 3 -
|
9
|
+
1, # 3 - order_book
|
10
10
|
100.5, # 4 - quantity
|
11
11
|
201, # 5 - amount
|
12
12
|
0.05, # 6 - fee
|
@@ -16,7 +16,7 @@ describe Bitex::Sell do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it_behaves_like 'API class'
|
19
|
-
it_behaves_like 'API class with a
|
19
|
+
it_behaves_like 'API class with a order book'
|
20
20
|
it_behaves_like 'JSON deserializable match'
|
21
21
|
|
22
22
|
it 'sets the ask id' do
|
@@ -9,15 +9,15 @@ shared_examples_for 'API class' do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
shared_examples_for 'API class with a
|
13
|
-
it 'makes
|
12
|
+
shared_examples_for 'API class with a order book' do
|
13
|
+
it 'makes order book 1 into btc_usd' do
|
14
14
|
as_json[3] = 1
|
15
|
-
subject.class.from_json(as_json).
|
15
|
+
subject.class.from_json(as_json).order_book.should == :btc_usd
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'makes specie 5 into btc_ars' do
|
19
19
|
as_json[3] = 5
|
20
|
-
subject.class.from_json(as_json).
|
20
|
+
subject.class.from_json(as_json).order_book.should == :btc_ars
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nubis
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-05-
|
12
|
+
date: 2018-05-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|