bitget.rb 0.4.0 → 0.6.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/README.md +59 -0
- data/bitget.rb.gemspec +1 -1
- data/lib/Bitget/Configuration.rb +32 -0
- data/lib/Bitget/Error.rb +33 -1
- data/lib/Bitget/V2/Client.rb +1812 -48
- data/lib/Bitget/{VERSION.rb → VERSiON.rb} +1 -1
- data/lib/{bitget.rb → Bitget.rb} +2 -0
- data/test/Configuration_test.rb +87 -0
- data/test/V2/client_test.rb +1066 -44
- data/test/helper.rb +16 -2
- data/test/test_all.rb +2 -2
- metadata +7 -10
- data/lib/Bitget/V2/Client2.rb +0 -500
- data/lib/Hash/to_parameter_string.rb +0 -26
- data/lib/Hash/x_www_form_urlencode.rb +0 -7
- data/lib/Thoran/Hash/XWwwFormUrlencode/x_www_form_urlencode.rb +0 -26
- data/test/client_test.rb +0 -109
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b73e07027de34083f0b3733d967c45f9556436af137a9b22accb4c7ebccc4403
|
|
4
|
+
data.tar.gz: 59f22d1ae6e505a996d08e89923df0262d1dc65c9f898463d26d154370db1dce
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 59530b4225ba03fa3c1d0070a4cb7595bc2ec3d679767f4287290beee42a42622a0859599d361ddae04630bbb0066f7dd642b83aec3a871af45fde1d7ea626c8
|
|
7
|
+
data.tar.gz: a6897b20c54c8d996f853d206c252d9c553fe31879d248a1dcfc6d553763b989684763f14bfbc7d87f19ae07bc63af839a57c5236b79284bc7715ee125a83191
|
data/README.md
CHANGED
|
@@ -30,6 +30,65 @@ bitget_client = Bitget::Client.new(
|
|
|
30
30
|
)
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
### Configuration
|
|
34
|
+
|
|
35
|
+
Settings may be declared once, and every client built afterwards reads them as its defaults.
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
Bitget.configure do |config|
|
|
39
|
+
config.api_key = 'api_key0'
|
|
40
|
+
config.api_secret = 'api_secret0'
|
|
41
|
+
config.api_passphrase = 'api_passphrase0'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
bitget_client = Bitget::Client.new
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The settings are `api_key`, `api_secret`, `api_passphrase`, `debug` and `logger`.
|
|
48
|
+
|
|
49
|
+
Any of them may still be given per client, which wins over the configured value. The
|
|
50
|
+
credentials are named arguments; the rest go under `options`.
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
bitget_client = Bitget::Client.new(
|
|
54
|
+
api_key: 'api_key1',
|
|
55
|
+
options: {logger: Logger.new('bitget.log', 'daily')}
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Logging
|
|
60
|
+
|
|
61
|
+
A client logs when it has somewhere to log to, and not at all when it does not. Hand it any
|
|
62
|
+
object answering to `#info` and `#error`; the standard library's `Logger` will do.
|
|
63
|
+
|
|
64
|
+
```ruby
|
|
65
|
+
require 'logger'
|
|
66
|
+
|
|
67
|
+
Bitget.configure do |config|
|
|
68
|
+
config.logger = Logger.new($stdout)
|
|
69
|
+
end
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`Logger` rotates by itself, so a daily log file wants no more than its second argument. It
|
|
73
|
+
will not create the directory, so make that first.
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
require 'fileutils'
|
|
77
|
+
require 'logger'
|
|
78
|
+
|
|
79
|
+
log_file_path = File.expand_path(File.join(%w{~ log bitget log.txt}))
|
|
80
|
+
FileUtils.mkdir_p(File.dirname(log_file_path))
|
|
81
|
+
|
|
82
|
+
Bitget.configure do |config|
|
|
83
|
+
config.logger = Logger.new(log_file_path, 'daily')
|
|
84
|
+
end
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Before 0.6.0 the client chose the path, created the directory and rotated the file itself. It
|
|
88
|
+
no longer does any of that: what is logged is the client's business and where it goes is
|
|
89
|
+
yours, which is what lets a StringIO logger in a test, or a levelled one, or something which
|
|
90
|
+
is not a Logger at all, work as well as the above.
|
|
91
|
+
|
|
33
92
|
### Retrieve Info on All the Coins Traded
|
|
34
93
|
```ruby
|
|
35
94
|
bitget_client.spot_public_coins
|
data/bitget.rb.gemspec
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Bitget/Configuration.rb
|
|
2
|
+
# Bitget::Configuration
|
|
3
|
+
|
|
4
|
+
module Bitget
|
|
5
|
+
class Configuration
|
|
6
|
+
attr_accessor :api_key, :api_secret, :api_passphrase, :debug, :logger
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
@api_key = nil
|
|
10
|
+
@api_secret = nil
|
|
11
|
+
@api_passphrase = nil
|
|
12
|
+
@debug = false
|
|
13
|
+
@logger = nil
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class << self
|
|
18
|
+
attr_writer :configuration
|
|
19
|
+
|
|
20
|
+
def configuration
|
|
21
|
+
@configuration ||= Configuration.new
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def configure
|
|
25
|
+
yield(configuration)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def reset_configuration!
|
|
29
|
+
@configuration = Configuration.new
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
data/lib/Bitget/Error.rb
CHANGED
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
# Bitget/Error.rb
|
|
2
2
|
# Bitget::Error
|
|
3
3
|
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
4
6
|
module Bitget
|
|
5
7
|
class Error < RuntimeError
|
|
6
|
-
attr_reader
|
|
8
|
+
attr_reader\
|
|
9
|
+
:code,
|
|
10
|
+
:message,
|
|
11
|
+
:body
|
|
12
|
+
|
|
13
|
+
# Bitget answers most errors with a JSON body carrying its own code and
|
|
14
|
+
# message, which are more use than the HTTP ones. Not all of them: a 418
|
|
15
|
+
# arrives with an empty body and there is nothing to parse. Where the body
|
|
16
|
+
# says nothing the HTTP code and message answer instead, so that an error
|
|
17
|
+
# renders as something rather than as a pair of blanks.
|
|
18
|
+
def error_code
|
|
19
|
+
@parsed_body['code'] || @code
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def error_message
|
|
23
|
+
@parsed_body['msg'] || @parsed_body['message'] || @message
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def to_s
|
|
27
|
+
"Bitget::Error: #{error_code} - #{error_message}"
|
|
28
|
+
end
|
|
7
29
|
|
|
8
30
|
private
|
|
9
31
|
|
|
@@ -11,6 +33,16 @@ module Bitget
|
|
|
11
33
|
@code = code
|
|
12
34
|
@message = message
|
|
13
35
|
@body = body
|
|
36
|
+
@parsed_body = parsed(body)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# An error is raised in answer to something already having gone wrong, so it
|
|
40
|
+
# must construct from whatever arrived. Raising a JSON::ParserError from
|
|
41
|
+
# here loses the error being reported and replaces it with one about parsing.
|
|
42
|
+
def parsed(body)
|
|
43
|
+
JSON.parse(body)
|
|
44
|
+
rescue JSON::ParserError
|
|
45
|
+
{}
|
|
14
46
|
end
|
|
15
47
|
end
|
|
16
48
|
end
|