bitget 0.6.13 → 0.7.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/CHANGELOG +12 -0
- data/README.md +31 -0
- data/Rakefile +5 -0
- data/lib/Bitget/ERROR_CODES.rb +1195 -0
- data/lib/Bitget/Error.rb +24 -0
- data/lib/Bitget/VERSION.rb +1 -1
- data/test/ERROR_CODES_test.rb +58 -0
- data/test/Error_test.rb +68 -0
- metadata +4 -1
data/lib/Bitget/Error.rb
CHANGED
|
@@ -3,8 +3,16 @@
|
|
|
3
3
|
|
|
4
4
|
require 'json'
|
|
5
5
|
|
|
6
|
+
require_relative './ERROR_CODES'
|
|
7
|
+
|
|
6
8
|
module Bitget
|
|
7
9
|
class Error < RuntimeError
|
|
10
|
+
# Codes for a market which cannot be traded at present, whether closed for
|
|
11
|
+
# maintenance, not yet open, or delisted. Chosen by hand rather than read
|
|
12
|
+
# from ERROR_CODES, since what a code is documented to mean and what it is
|
|
13
|
+
# returned for are not certain to agree.
|
|
14
|
+
MARKET_UNAVAILABLE_CODES = %w{25101 25102 40309 45043 50027}
|
|
15
|
+
|
|
8
16
|
attr_reader\
|
|
9
17
|
:code,
|
|
10
18
|
:message,
|
|
@@ -23,6 +31,22 @@ module Bitget
|
|
|
23
31
|
@parsed_body['msg'] || @parsed_body['message'] || @message
|
|
24
32
|
end
|
|
25
33
|
|
|
34
|
+
# The message documented for the code by the first of the lists in
|
|
35
|
+
# ERROR_CODES to document it, or nil for a code no list documents. A code
|
|
36
|
+
# listed more than once in the one list answers with each of its messages,
|
|
37
|
+
# numbered and separated: "(1) ...; (2) ...". The numbers delimit them, no
|
|
38
|
+
# documented message containing such a number, which bin/generate_error_codes
|
|
39
|
+
# checks, so a semicolon within a message is no matter.
|
|
40
|
+
def documented_message
|
|
41
|
+
message = ERROR_CODES.values.filter_map{|error_codes| error_codes[error_code.to_s]}.first
|
|
42
|
+
return message unless message.is_a?(Array)
|
|
43
|
+
message.each_with_index.map{|m, i| "(#{i + 1}) #{m}"}.join('; ')
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def market_unavailable?
|
|
47
|
+
MARKET_UNAVAILABLE_CODES.include?(error_code.to_s)
|
|
48
|
+
end
|
|
49
|
+
|
|
26
50
|
def to_s
|
|
27
51
|
"Bitget::Error: #{error_code} - #{error_message}"
|
|
28
52
|
end
|
data/lib/Bitget/VERSION.rb
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require_relative './helper'
|
|
2
|
+
|
|
3
|
+
describe Bitget do
|
|
4
|
+
describe "ERROR_CODES" do
|
|
5
|
+
it "has a table for each list, in order of precedence" do
|
|
6
|
+
_(Bitget::ERROR_CODES.keys).must_equal(%i{v2_rest v2_websocket uta_rest})
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "is frozen, as is each table" do
|
|
10
|
+
_(Bitget::ERROR_CODES.frozen?).must_equal(true)
|
|
11
|
+
Bitget::ERROR_CODES.each_value{|error_codes| _(error_codes.frozen?).must_equal(true)}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "keys each table by codes as strings of digits, leading zeros kept" do
|
|
15
|
+
Bitget::ERROR_CODES.each_value do |error_codes|
|
|
16
|
+
error_codes.each_key{|code| _(code).must_match(/\A\d+\z/)}
|
|
17
|
+
end
|
|
18
|
+
_(Bitget::ERROR_CODES[:v2_rest]).must_include('00001')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "gives each code a message, or an array of them" do
|
|
22
|
+
Bitget::ERROR_CODES.each_value do |error_codes|
|
|
23
|
+
error_codes.each_value do |message|
|
|
24
|
+
Array(message).each do |m|
|
|
25
|
+
_(m).must_be_instance_of(String)
|
|
26
|
+
_(m).wont_be_empty
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "keeps both meanings of a code listed twice in the one list, as an array" do
|
|
33
|
+
_(Bitget::ERROR_CODES[:v2_rest]['40104'].size).must_equal(2)
|
|
34
|
+
_(Bitget::ERROR_CODES[:v2_rest]['40104'].first).must_match(/located in a country or region/)
|
|
35
|
+
_(Bitget::ERROR_CODES[:v2_rest]['40104'].last).must_match(/Unable to withdraw to this account/)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "keeps a message Bitget itself separates with slashes as the one string" do
|
|
39
|
+
_(Bitget::ERROR_CODES[:uta_rest]['60053']).must_match(%r{\Aparam error / Order status is not unpaid})
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "has no message numbered as Bitget::Error#documented_message numbers them" do
|
|
43
|
+
Bitget::ERROR_CODES.each_value do |error_codes|
|
|
44
|
+
error_codes.each_value{|message| Array(message).each{|m| _(m).wont_match(/\(\d+\)/)}}
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "decodes HTML entities" do
|
|
49
|
+
_(Bitget::ERROR_CODES[:v2_rest]['22006']).must_equal('limit price > risk price')
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "omits Bitget's placeholder for an undescribed code" do
|
|
53
|
+
Bitget::ERROR_CODES.each_value do |error_codes|
|
|
54
|
+
_(error_codes.values).wont_include('未找到描述')
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
data/test/Error_test.rb
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require_relative './helper'
|
|
2
|
+
|
|
3
|
+
describe Bitget::Error do
|
|
4
|
+
def error(body)
|
|
5
|
+
Bitget::Error.new(code: 400, message: 'Bad Request', body: body)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
let(:suspended_body){'{"code":"25102","msg":"The symbol is currently suspended. Please refer to official announcements for the specific reopening time.","requestTime":1790320628183,"data":null}'}
|
|
9
|
+
|
|
10
|
+
describe "#error_code" do
|
|
11
|
+
it "is Bitget's code from the body" do
|
|
12
|
+
_(error(suspended_body).error_code).must_equal('25102')
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "is the HTTP code where the body has none" do
|
|
16
|
+
_(error('').error_code).must_equal(400)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe "#documented_message" do
|
|
21
|
+
it "is the message documented for the code" do
|
|
22
|
+
_(error(suspended_body).documented_message).must_equal('Trading pair temporarily closed for maintenance')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "prefers the V2 REST list over the others" do
|
|
26
|
+
_(error('{"code":"43117","msg":""}').documented_message).must_equal(Bitget::ERROR_CODES[:v2_rest]['43117'])
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "is each message of a code listed twice in the one list, numbered" do
|
|
30
|
+
first, second = Bitget::ERROR_CODES[:v2_rest]['40104']
|
|
31
|
+
_(error('{"code":"40104","msg":""}').documented_message).must_equal("(1) #{first}; (2) #{second}")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "is nil for a code no list documents" do
|
|
35
|
+
_(error('{"code":"99999999","msg":""}').documented_message).must_be_nil
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "is nil where the body has no code" do
|
|
39
|
+
_(error('').documented_message).must_be_nil
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe "#market_unavailable?" do
|
|
44
|
+
it "is true for each of the codes for a market which cannot be traded" do
|
|
45
|
+
Bitget::Error::MARKET_UNAVAILABLE_CODES.each do |code|
|
|
46
|
+
_(error(%Q{{"code":"#{code}","msg":""}}).market_unavailable?).must_equal(true)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "is true for a suspended symbol" do
|
|
51
|
+
_(error(suspended_body).market_unavailable?).must_equal(true)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "is false for any other code" do
|
|
55
|
+
_(error('{"code":"43012","msg":"Insufficient balance"}').market_unavailable?).must_equal(false)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "is false where the body has no code" do
|
|
59
|
+
_(error('').market_unavailable?).must_equal(false)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
describe "#to_s" do
|
|
64
|
+
it "gives Bitget's code and the message as returned" do
|
|
65
|
+
_(error(suspended_body).to_s).must_equal('Bitget::Error: 25102 - The symbol is currently suspended. Please refer to official announcements for the specific reopening time.')
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bitget
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thoran
|
|
@@ -38,12 +38,15 @@ files:
|
|
|
38
38
|
- lib/Bitget.rb
|
|
39
39
|
- lib/Bitget/Client.rb
|
|
40
40
|
- lib/Bitget/Configuration.rb
|
|
41
|
+
- lib/Bitget/ERROR_CODES.rb
|
|
41
42
|
- lib/Bitget/Error.rb
|
|
42
43
|
- lib/Bitget/V2/Client.rb
|
|
43
44
|
- lib/Bitget/VERSION.rb
|
|
44
45
|
- lib/String/url_encode.rb
|
|
45
46
|
- lib/Thoran/String/UrlEncode/url_encode.rb
|
|
46
47
|
- test/Configuration_test.rb
|
|
48
|
+
- test/ERROR_CODES_test.rb
|
|
49
|
+
- test/Error_test.rb
|
|
47
50
|
- test/V2/Client_test.rb
|
|
48
51
|
- test/VERSION_test.rb
|
|
49
52
|
- test/gemspec_test.rb
|