poloniex.rb 0.0.0 → 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 +4 -4
- data/Gemfile +7 -8
- data/README.md +150 -5
- data/lib/Hash/x_www_form_urlencode.rb +7 -0
- data/lib/Object/inQ.rb +18 -0
- data/lib/Poloniex/V1/Client.rb +571 -86
- data/lib/Poloniex/V1.rb +14 -0
- data/lib/Poloniex/VERSION.rb +1 -1
- data/lib/Thoran/Hash/XWwwFormUrlencode/x_www_form_urlencode.rb +26 -0
- data/lib/Thoran/String/UrlEncode/url_encode.rb +26 -0
- data/lib/poloniex.rb +4 -3
- data/poloniex.rb.gemspec +1 -1
- data/test/Poloniex/Configuration_test.rb +70 -9
- data/test/Poloniex/V1/Client/test_account_endpoints.rb +69 -0
- data/test/Poloniex/V1/Client/test_margin_endpoints.rb +57 -0
- data/test/Poloniex/V1/{Client_test.rb → Client/test_public_endpoints.rb} +22 -57
- data/test/Poloniex/V1/Client/test_trading_endpoints.rb +139 -0
- data/test/Poloniex/V1/Client/test_wallet_endpoints.rb +60 -0
- data/test/Poloniex/VERSION_test.rb +16 -0
- data/test/helper.rb +5 -6
- metadata +14 -7
- data/lib/Poloniex/Client.rb +0 -8
- data/test/Poloniex/Client_test.rb +0 -26
- data/test/poloniex_test.rb +0 -23
data/lib/Poloniex/V1.rb
ADDED
data/lib/Poloniex/VERSION.rb
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Thoran/Hash/XWwwFormUrlEncode/x_www_form_urlencode.rb
|
|
2
|
+
# Thoran::Hash::XWwwFormUrlEncode#x_www_form_urlencode
|
|
3
|
+
|
|
4
|
+
# 20241009
|
|
5
|
+
# 0.2.0
|
|
6
|
+
|
|
7
|
+
# Changes since 0.1:
|
|
8
|
+
# -/0: (The class name and the snake case name are consistent now.)
|
|
9
|
+
# 1. /XWWWFormUrlEncode/XWwwFormUrlEncode/
|
|
10
|
+
|
|
11
|
+
require 'Thoran/String/UrlEncode/url_encode'
|
|
12
|
+
|
|
13
|
+
module Thoran
|
|
14
|
+
module Hash
|
|
15
|
+
module XWwwFormUrlEncode
|
|
16
|
+
|
|
17
|
+
def x_www_form_url_encode(joiner = '&')
|
|
18
|
+
inject([]){|a,e| a << "#{e.first.to_s.url_encode}=#{e.last.to_s.url_encode}" unless e.last.nil?; a}.join(joiner)
|
|
19
|
+
end
|
|
20
|
+
alias_method :x_www_form_urlencode, :x_www_form_url_encode
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
Hash.send(:include, Thoran::Hash::XWwwFormUrlEncode)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Thoran/String/UrlEncode/url_encode.rb
|
|
2
|
+
# Thoran::String::UrlEncode#url_encode
|
|
3
|
+
|
|
4
|
+
# 20160505
|
|
5
|
+
# 0.3.0
|
|
6
|
+
|
|
7
|
+
# Acknowledgements: I've simply ripped off and refashioned the code from the CGI module!...
|
|
8
|
+
|
|
9
|
+
# Changes since 0.2:
|
|
10
|
+
# 1. + Thoran namespace.
|
|
11
|
+
|
|
12
|
+
module Thoran
|
|
13
|
+
module String
|
|
14
|
+
module UrlEncode
|
|
15
|
+
|
|
16
|
+
def url_encode
|
|
17
|
+
self.gsub(/([^ a-zA-Z0-9_.-]+)/n) do
|
|
18
|
+
'%' + $1.unpack('H2' * $1.size).join('%').upcase
|
|
19
|
+
end.tr(' ', '+')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
String.send(:include, Thoran::String::UrlEncode)
|
data/lib/poloniex.rb
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
4
4
|
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
|
|
5
5
|
|
|
6
|
-
require_relative './Poloniex/Client'
|
|
7
|
-
require_relative './Poloniex/VERSION'
|
|
8
|
-
|
|
9
6
|
module Poloniex; end
|
|
7
|
+
|
|
8
|
+
require 'Poloniex/Configuration'
|
|
9
|
+
require 'Poloniex/V1'
|
|
10
|
+
require 'Poloniex/VERSION'
|
data/poloniex.rb.gemspec
CHANGED
|
@@ -1,16 +1,77 @@
|
|
|
1
1
|
require_relative '../helper'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
require 'logger'
|
|
4
|
+
|
|
5
|
+
describe "Poloniex::Configuration" do
|
|
6
|
+
describe ".configure" do
|
|
7
|
+
subject do
|
|
8
|
+
Poloniex::V1::Client.new
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
before do
|
|
12
|
+
Poloniex.configure do |config|
|
|
13
|
+
config.api_key = 'test_api_key'
|
|
14
|
+
config.api_secret = 'test_api_secret'
|
|
15
|
+
config.debug = false
|
|
16
|
+
config.logger = Logger.new('test_log_file')
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "uses global configuration by default" do
|
|
21
|
+
_(subject.api_key).must_equal('test_api_key')
|
|
22
|
+
_(subject.api_secret).must_equal('test_api_secret')
|
|
23
|
+
_(subject.debug).must_equal(false)
|
|
24
|
+
_(subject.logger).must_be_kind_of(Logger)
|
|
25
|
+
end
|
|
6
26
|
end
|
|
7
27
|
|
|
8
|
-
describe "
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
28
|
+
describe "using a configuration object" do
|
|
29
|
+
subject do
|
|
30
|
+
Poloniex::V1::Client.new(configuration: configuration)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
let(:configuration) do
|
|
34
|
+
Poloniex::Configuration.new(
|
|
35
|
+
api_key: 'test_api_key',
|
|
36
|
+
api_secret: 'test_api_secret',
|
|
37
|
+
debug: false,
|
|
38
|
+
logger: Logger.new('test_log_file')
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "accepts a configuration object as an argument" do
|
|
43
|
+
_(subject.api_key).must_equal('test_api_key')
|
|
44
|
+
_(subject.api_secret).must_equal('test_api_secret')
|
|
45
|
+
_(subject.debug).must_equal(false)
|
|
46
|
+
_(subject.logger).must_be_kind_of(Logger)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe "overriding configuration" do
|
|
51
|
+
subject do
|
|
52
|
+
Poloniex::V1::Client.new(
|
|
53
|
+
api_key: 'test_api_key',
|
|
54
|
+
api_secret: 'test_api_secret',
|
|
55
|
+
debug: true,
|
|
56
|
+
logger: Logger.new('test_log_file')
|
|
57
|
+
)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
before do
|
|
61
|
+
class FakeLogger; end
|
|
62
|
+
Poloniex.configure do |config|
|
|
63
|
+
config.api_key = 'overridden_test_api_key'
|
|
64
|
+
config.api_secret = 'overridden_test_api_secret'
|
|
65
|
+
config.debug = false
|
|
66
|
+
config.logger = FakeLogger.new
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "allows overriding configuration" do
|
|
71
|
+
_(subject.api_key).must_equal('test_api_key')
|
|
72
|
+
_(subject.api_secret).must_equal('test_api_secret')
|
|
73
|
+
_(subject.debug).must_equal(true)
|
|
74
|
+
_(subject.logger).must_be_kind_of(Logger)
|
|
14
75
|
end
|
|
15
76
|
end
|
|
16
77
|
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require_relative '../../../helper'
|
|
2
|
+
|
|
3
|
+
describe "Poloniex::V1::Client Account Endpoints" do
|
|
4
|
+
let(:api_key){ENV.fetch('POLONIEX_API_KEY', '<API_KEY>')}
|
|
5
|
+
let(:api_secret){ENV.fetch('POLONIEX_API_SECRET', '<API_SECRET>')}
|
|
6
|
+
|
|
7
|
+
subject do
|
|
8
|
+
Poloniex::V1::Client.new(
|
|
9
|
+
api_key: api_key,
|
|
10
|
+
api_secret: api_secret
|
|
11
|
+
)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "Account endpoints" do
|
|
15
|
+
it "fetches a list of accounts" do
|
|
16
|
+
VCR.use_cassette('v1/accounts') do
|
|
17
|
+
response = subject.accounts
|
|
18
|
+
_(response).must_be_kind_of(Array)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "fetches account balances" do
|
|
23
|
+
VCR.use_cassette('v1/accounts_balances') do
|
|
24
|
+
response = subject.accounts_balances
|
|
25
|
+
_(response).must_be_kind_of(Array)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "fetches account activity" do
|
|
30
|
+
VCR.use_cassette('v1/accounts_activity') do
|
|
31
|
+
response = subject.accounts_activity(limit: 10)
|
|
32
|
+
_(response).must_be_kind_of(Array)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "fetches account transfers" do
|
|
37
|
+
VCR.use_cassette('v1/accounts_transfer') do
|
|
38
|
+
response = subject.accounts_transfer(
|
|
39
|
+
currency: 'USDT',
|
|
40
|
+
amount: 10.5,
|
|
41
|
+
from_account: 'SPOT',
|
|
42
|
+
to_account: 'FUTURES'
|
|
43
|
+
)
|
|
44
|
+
_(response).must_be_kind_of(Hash)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "fetches account transfer records" do
|
|
49
|
+
VCR.use_cassette('v1/accounts_transfer_records') do
|
|
50
|
+
response = subject.accounts_transfer_records
|
|
51
|
+
_(response).must_be_kind_of(Array)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "fetches fee info" do
|
|
56
|
+
VCR.use_cassette('v1/fee_info') do
|
|
57
|
+
response = subject.fee_info
|
|
58
|
+
_(response).must_be_kind_of(Hash)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "fetches accounts interest history" do
|
|
63
|
+
VCR.use_cassette('v1/accounts_interest_history') do
|
|
64
|
+
response = subject.accounts_interest_history
|
|
65
|
+
_(response).must_be_kind_of(Array)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require_relative '../../../helper'
|
|
2
|
+
|
|
3
|
+
require 'logger'
|
|
4
|
+
|
|
5
|
+
describe "Poloniex::V1::Client Margin Endpoints" do
|
|
6
|
+
let(:api_key){ENV.fetch('POLONIEX_API_KEY', '<API_KEY>')}
|
|
7
|
+
let(:api_secret){ENV.fetch('POLONIEX_API_SECRET', '<API_SECRET>')}
|
|
8
|
+
|
|
9
|
+
subject do
|
|
10
|
+
Poloniex::V1::Client.new(
|
|
11
|
+
api_key: api_key,
|
|
12
|
+
api_secret: api_secret,
|
|
13
|
+
logger: Logger.new('/Users/thoran/log/poloniex/log.txt'),
|
|
14
|
+
debug: true
|
|
15
|
+
)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "#account_margin" do
|
|
19
|
+
it "fetches margin account info" do
|
|
20
|
+
VCR.use_cassette('v1/margin_account_margin') do
|
|
21
|
+
response = subject.account_margin
|
|
22
|
+
_(response).must_be_kind_of(Hash)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe "#borrow_status" do
|
|
28
|
+
it "fetches margin positions" do
|
|
29
|
+
VCR.use_cassette('v1/margin_borrow_status') do
|
|
30
|
+
response = subject.borrow_status
|
|
31
|
+
_(response).must_be_kind_of(Array)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "fetches margin positions for specific currency" do
|
|
36
|
+
VCR.use_cassette('v1/margin_borrow_status_btc') do
|
|
37
|
+
response = subject.borrow_status(currency: 'BTC')
|
|
38
|
+
_(response).must_be_kind_of(Array)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe "#max_buy_sell_amount" do
|
|
44
|
+
it "creates margin borrow" do
|
|
45
|
+
VCR.use_cassette('v1/max_buy_sell_amount') do
|
|
46
|
+
response = subject.max_buy_sell_amount('BTC_USDT')
|
|
47
|
+
_(response).must_be_kind_of(Hash)
|
|
48
|
+
_(response['symbol']).must_equal('BTC_USDT')
|
|
49
|
+
assert(response['maxLeverage'])
|
|
50
|
+
assert(response['maxAvailableBuy'])
|
|
51
|
+
assert(response['maxAvailableSell'])
|
|
52
|
+
assert(response['availableBuy'])
|
|
53
|
+
assert(response['availableSell'])
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -1,49 +1,14 @@
|
|
|
1
|
-
require_relative '
|
|
1
|
+
require_relative '../../../helper'
|
|
2
2
|
|
|
3
|
-
describe Poloniex::V1::Client do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
before do
|
|
9
|
-
Poloniex.configure do |config|
|
|
10
|
-
config.api_key = "test_api_key"
|
|
11
|
-
config.api_secret = "test_api_secret"
|
|
12
|
-
config.debug = false
|
|
13
|
-
end
|
|
14
|
-
WebMock.disable_net_connect!(allow_localhost: true)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe ".configuration" do
|
|
18
|
-
context "global configuration" do
|
|
19
|
-
it "uses global configuration by default" do
|
|
20
|
-
client = Poloniex::V1::Client.new
|
|
21
|
-
_(client).must_be_kind_of(Poloniex::V1::Client)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
context "configuration object " do
|
|
26
|
-
it "accepts a configuration object as an argument" do
|
|
27
|
-
configuration = Poloniex::Configuration.new(
|
|
28
|
-
api_key: "test_api_key",
|
|
29
|
-
api_secret: "test_api_secret",
|
|
30
|
-
debug: false
|
|
31
|
-
)
|
|
32
|
-
client = Poloniex::V1::Client.new(configuration: configuration)
|
|
33
|
-
_(client).must_be_kind_of(Poloniex::V1::Client)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
3
|
+
describe "Poloniex::V1::Client Public Endpoints" do
|
|
4
|
+
let(:api_key){ENV.fetch('POLONIEX_API_KEY', '<API_KEY>')}
|
|
5
|
+
let(:api_secret){ENV.fetch('POLONIEX_API_SECRET', '<API_SECRET>')}
|
|
36
6
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
debug: true
|
|
43
|
-
)
|
|
44
|
-
_(client).must_be_kind_of(Poloniex::V1::Client)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
7
|
+
subject do
|
|
8
|
+
Poloniex::V1::Client.new(
|
|
9
|
+
api_key: api_key,
|
|
10
|
+
api_secret: api_secret
|
|
11
|
+
)
|
|
47
12
|
end
|
|
48
13
|
|
|
49
14
|
describe "#candles" do
|
|
@@ -57,14 +22,14 @@ describe Poloniex::V1::Client do
|
|
|
57
22
|
|
|
58
23
|
describe "#currencies" do
|
|
59
24
|
it "fetches all currencies" do
|
|
60
|
-
VCR.use_cassette(
|
|
25
|
+
VCR.use_cassette('v1/currencies') do
|
|
61
26
|
response = subject.currencies
|
|
62
27
|
_(response).must_be_kind_of(Array)
|
|
63
28
|
end
|
|
64
29
|
end
|
|
65
30
|
|
|
66
31
|
it "fetches a specific currency" do
|
|
67
|
-
VCR.use_cassette(
|
|
32
|
+
VCR.use_cassette('v1/currencies_btc') do
|
|
68
33
|
response = subject.currencies('BTC')
|
|
69
34
|
_(response).must_be_kind_of(Hash)
|
|
70
35
|
_(response.count).must_equal(1)
|
|
@@ -74,17 +39,17 @@ describe Poloniex::V1::Client do
|
|
|
74
39
|
end
|
|
75
40
|
end
|
|
76
41
|
|
|
77
|
-
describe "#
|
|
42
|
+
describe "#mark_price" do
|
|
78
43
|
it "fetches all markets" do
|
|
79
|
-
VCR.use_cassette('v1/
|
|
80
|
-
response = subject.
|
|
44
|
+
VCR.use_cassette('v1/mark_price') do
|
|
45
|
+
response = subject.mark_price
|
|
81
46
|
_(response).must_be_kind_of(Array)
|
|
82
47
|
end
|
|
83
48
|
end
|
|
84
49
|
|
|
85
50
|
it "fetches a specific market" do
|
|
86
|
-
VCR.use_cassette('v1/
|
|
87
|
-
response = subject.
|
|
51
|
+
VCR.use_cassette('v1/mark_price_btcusdt') do
|
|
52
|
+
response = subject.mark_price('BTC_USDT')
|
|
88
53
|
_(response).must_be_kind_of(Hash)
|
|
89
54
|
_(response.count).must_equal(3)
|
|
90
55
|
_(response['symbol']).must_equal('BTC_USDT')
|
|
@@ -128,17 +93,17 @@ describe Poloniex::V1::Client do
|
|
|
128
93
|
end
|
|
129
94
|
end
|
|
130
95
|
|
|
131
|
-
describe "#
|
|
96
|
+
describe "#price" do
|
|
132
97
|
it "fetches prices for all symbols" do
|
|
133
|
-
VCR.use_cassette('v1/
|
|
134
|
-
response = subject.
|
|
98
|
+
VCR.use_cassette('v1/price') do
|
|
99
|
+
response = subject.price
|
|
135
100
|
_(response).must_be_kind_of(Array)
|
|
136
101
|
end
|
|
137
102
|
end
|
|
138
103
|
|
|
139
104
|
it "fetches price for a specific symbol" do
|
|
140
|
-
VCR.use_cassette('v1/
|
|
141
|
-
response = subject.
|
|
105
|
+
VCR.use_cassette('v1/price_btcusdt') do
|
|
106
|
+
response = subject.price('BTC_USDT')
|
|
142
107
|
_(response).must_be_kind_of(Hash)
|
|
143
108
|
end
|
|
144
109
|
end
|
|
@@ -162,7 +127,7 @@ describe Poloniex::V1::Client do
|
|
|
162
127
|
|
|
163
128
|
describe "#timestamp" do
|
|
164
129
|
it "fetches server timestamp" do
|
|
165
|
-
VCR.use_cassette(
|
|
130
|
+
VCR.use_cassette('v1/timestamp') do
|
|
166
131
|
response = subject.timestamp
|
|
167
132
|
_(response).must_be_kind_of(Hash)
|
|
168
133
|
_(response["serverTime"]).must_be_kind_of(Integer)
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
require_relative '../../../helper'
|
|
2
|
+
|
|
3
|
+
describe "Poloniex::V1::Client Trading Endpoints" do
|
|
4
|
+
let(:api_key){ENV.fetch('POLONIEX_API_KEY', '<API_KEY>')}
|
|
5
|
+
let(:api_secret){ENV.fetch('POLONIEX_API_SECRET', '<API_SECRET>')}
|
|
6
|
+
|
|
7
|
+
subject do
|
|
8
|
+
Poloniex::V1::Client.new(
|
|
9
|
+
api_key: api_key,
|
|
10
|
+
api_secret: api_secret
|
|
11
|
+
)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "#create_order" do
|
|
15
|
+
it "creates a new order" do
|
|
16
|
+
VCR.use_cassette('v1/create_order') do
|
|
17
|
+
response = subject.create_order(
|
|
18
|
+
symbol: 'BTC_USDT',
|
|
19
|
+
side: 'BUY',
|
|
20
|
+
type: 'LIMIT',
|
|
21
|
+
quantity: 0.001,
|
|
22
|
+
price: 20_000
|
|
23
|
+
)
|
|
24
|
+
_(response).must_be_kind_of(Hash)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe "create_multiple_orders" do
|
|
30
|
+
let(:order0) do
|
|
31
|
+
{
|
|
32
|
+
symbol: 'BTC_USDT',
|
|
33
|
+
side: 'BUY',
|
|
34
|
+
type: 'LIMIT',
|
|
35
|
+
quantity: 0.01,
|
|
36
|
+
price: 15_000
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
let(:order1) do
|
|
41
|
+
{
|
|
42
|
+
symbol: 'BTC_USDT',
|
|
43
|
+
side: 'BUY',
|
|
44
|
+
type: 'LIMIT',
|
|
45
|
+
quantity: 0.1,
|
|
46
|
+
price: 8_000
|
|
47
|
+
}
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "gets an order by ID" do
|
|
51
|
+
VCR.use_cassette('v1/create_multiple_orders') do
|
|
52
|
+
response = subject.create_multiple_orders([order0, order1])
|
|
53
|
+
_(response).must_be_kind_of(Array)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe "#cancel_replace_order" do
|
|
59
|
+
it "" do
|
|
60
|
+
VCR.use_cassette('v1/cancel_replace_order') do
|
|
61
|
+
response = subject.cancel_replace_order(order_id: 'blue')
|
|
62
|
+
_(response).must_be_kind_of(Hash)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
describe "#open_orders" do
|
|
68
|
+
it "retrieves the open orders" do
|
|
69
|
+
VCR.use_cassette('v1/open_orders') do
|
|
70
|
+
response = subject.open_orders
|
|
71
|
+
_(response).must_be_kind_of(Array)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "retrieves the open orders for a specific symbol" do
|
|
76
|
+
VCR.use_cassette('v1/open_orders_btc_usdt') do
|
|
77
|
+
response = subject.open_orders(symbol: 'BTC_USDT')
|
|
78
|
+
_(response).must_be_kind_of(Array)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
describe "#order_details" do
|
|
84
|
+
it "" do
|
|
85
|
+
VCR.use_cassette('v1/orders_details') do
|
|
86
|
+
response = subject.order_details(order_id: '21934611974062080')
|
|
87
|
+
_(response).must_be_kind_of(Hash)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
describe "#cancel_order" do
|
|
93
|
+
it "" do
|
|
94
|
+
VCR.use_cassette('v1/cancel_order') do
|
|
95
|
+
response = subject.cancel_order(order_id: '32487004629499904')
|
|
96
|
+
_(response).must_be_kind_of(Hash)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe "#cancel_multiple_orders" do
|
|
102
|
+
it "" do
|
|
103
|
+
VCR.use_cassette('v1/cancel_multiple_orders') do
|
|
104
|
+
response = subject.cancel_multiple_orders(order_ids: ['12345', '67890'])
|
|
105
|
+
_(response).must_be_kind_of(Array)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
describe "#cancel_all_orders" do
|
|
111
|
+
it "" do
|
|
112
|
+
VCR.use_cassette('v1/cancel_all_orders') do
|
|
113
|
+
response = subject.cancel_all_orders(
|
|
114
|
+
symbols: %w{BTC_USDT ETH_USDT},
|
|
115
|
+
account_types: %w{SPOT}
|
|
116
|
+
)
|
|
117
|
+
_(response).must_be_kind_of(Array)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
describe "#kill_switch" do
|
|
123
|
+
it "" do
|
|
124
|
+
VCR.use_cassette('v1/kill_switch') do
|
|
125
|
+
response = subject.kill_switch(timeout: 10)
|
|
126
|
+
_(response).must_be_kind_of(Hash)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
describe "#kill_switch_status" do
|
|
132
|
+
it "" do
|
|
133
|
+
VCR.use_cassette('v1/kill_switch_status') do
|
|
134
|
+
response = subject.kill_switch_status
|
|
135
|
+
_(response).must_be_kind_of(Hash)
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require_relative '../../../helper'
|
|
2
|
+
|
|
3
|
+
describe "Poloniex::V1::Client Wallet Endpoints" do
|
|
4
|
+
let(:api_key){ENV.fetch('POLONIEX_API_KEY', '<API_KEY>')}
|
|
5
|
+
let(:api_secret){ENV.fetch('POLONIEX_API_SECRET', '<API_SECRET>')}
|
|
6
|
+
|
|
7
|
+
subject do
|
|
8
|
+
Poloniex::V1::Client.new(
|
|
9
|
+
api_key: api_key,
|
|
10
|
+
api_secret: api_secret
|
|
11
|
+
)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "#deposit_addresses" do
|
|
15
|
+
it "fetches deposit addresses" do
|
|
16
|
+
VCR.use_cassette('v1/deposit_addresses') do
|
|
17
|
+
response = subject.deposit_addresses
|
|
18
|
+
assert_kind_of Hash, response
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "fetches deposit address for specific currency" do
|
|
23
|
+
VCR.use_cassette('v1/deposit_address_btc') do
|
|
24
|
+
response = subject.deposit_addresses('BTC')
|
|
25
|
+
assert_kind_of Hash, response
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe "#wallets_activity" do
|
|
31
|
+
it "fetches deposit history" do
|
|
32
|
+
VCR.use_cassette('v1/wallets_activity') do
|
|
33
|
+
response = subject.wallets_activity(start: 1754734725, finish: 1754739175)
|
|
34
|
+
assert_kind_of Hash, response
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "#new_currency_address" do
|
|
40
|
+
it "generates new deposit address" do
|
|
41
|
+
VCR.use_cassette('v1/new_currency_address') do
|
|
42
|
+
response = subject.new_currency_address('BTC')
|
|
43
|
+
assert_kind_of Hash, response
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe "#withdraw_currency" do
|
|
49
|
+
it "creates withdrawal" do
|
|
50
|
+
VCR.use_cassette('v1/withdraw_currency') do
|
|
51
|
+
response = subject.withdraw_currency(
|
|
52
|
+
currency: "BTC",
|
|
53
|
+
amount: "0.1",
|
|
54
|
+
address: "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
|
|
55
|
+
)
|
|
56
|
+
assert_kind_of Hash, response
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require_relative '../helper'
|
|
2
|
+
|
|
3
|
+
describe Poloniex::VERSION do
|
|
4
|
+
|
|
5
|
+
subject do
|
|
6
|
+
Poloniex::VERSION
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "has a version number string" do
|
|
10
|
+
_(subject).must_be_kind_of(String)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "has a version number in the right format" do
|
|
14
|
+
_(subject).must_match(/^\d\.\d\.\d$/)
|
|
15
|
+
end
|
|
16
|
+
end
|
data/test/helper.rb
CHANGED
|
@@ -4,23 +4,22 @@ require 'minitest-spec-context'
|
|
|
4
4
|
require 'vcr'
|
|
5
5
|
require 'webmock'
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
require 'poloniex'
|
|
7
|
+
require_relative '../lib/poloniex'
|
|
9
8
|
|
|
10
9
|
VCR.configure do |config|
|
|
11
10
|
config.cassette_library_dir = 'test/fixtures/vcr_cassettes'
|
|
12
11
|
|
|
13
12
|
config.hook_into :webmock
|
|
14
13
|
|
|
15
|
-
config.filter_sensitive_data('<API_KEY>')
|
|
16
|
-
config.filter_sensitive_data('<API_SECRET>')
|
|
14
|
+
config.filter_sensitive_data('<API_KEY>'){ENV['POLONIEX_API_KEY']}
|
|
15
|
+
config.filter_sensitive_data('<API_SECRET>'){ENV['POLONIEX_API_SECRET'] }
|
|
17
16
|
|
|
18
17
|
# Allow localhost connections for debugging
|
|
19
18
|
config.ignore_localhost = true
|
|
20
19
|
|
|
21
|
-
config.default_cassette_options = {
|
|
20
|
+
config.default_cassette_options = {
|
|
22
21
|
record: :new_episodes,
|
|
23
|
-
match_requests_on: [:method, :
|
|
22
|
+
match_requests_on: [:method, :path, :body]
|
|
24
23
|
}
|
|
25
24
|
end
|
|
26
25
|
|