bitget 0.6.8

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3e0d654613fdc8a82b59fba0720d2ab0b5537d753674aa9272526d0adf066345
4
+ data.tar.gz: 373b01b2e9c8687c0a34c205d0140a764cd673b78729f9a73fe0978ee7673d98
5
+ SHA512:
6
+ metadata.gz: 7d46832f9acb0ff24e2604f561b63b58cac07cad9aa0d9a7ee37a46176da0a8228882ae2162f796ee44d7dd4c775d1f2a89611198bccb1d146bd68c99974ac8b
7
+ data.tar.gz: 7bf05bb597bd6bc24207025828bf0a86dd63a539479d137c04132ab22f555de69fda4b20ee43847086c00b0a70a3ab17f527d326f59999f0fda7b2518ff28813
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'http.rb'
4
+
5
+ group :development, :test do
6
+ gem 'minitest'
7
+ gem 'minitest-spec-context'
8
+ gem 'vcr'
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 thoran
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,196 @@
1
+ # bitget.rb
2
+
3
+ ## Description
4
+
5
+ Access the Bitget API with Ruby.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'bitget.rb'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```bash
18
+ $ bundle
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```bash
24
+ $ gem install bitget.rb
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ### Setup
30
+
31
+ ```ruby
32
+ bitget_client = Bitget::Client.new(
33
+ api_key: 'api_key0',
34
+ api_secret: 'api_secret0',
35
+ api_passphrase: 'api_passphrase0'
36
+ )
37
+ ```
38
+
39
+ ### Configuration
40
+
41
+ Settings may be declared once, and every client built afterwards reads them as its defaults.
42
+
43
+ ```ruby
44
+ Bitget.configure do |config|
45
+ config.api_key = 'api_key0'
46
+ config.api_secret = 'api_secret0'
47
+ config.api_passphrase = 'api_passphrase0'
48
+ end
49
+
50
+ bitget_client = Bitget::Client.new
51
+ ```
52
+
53
+ The settings are `api_key`, `api_secret`, `api_passphrase`, `debug` and `logger`.
54
+
55
+ Any of them may still be given per client, which wins over the configured value. The
56
+ credentials are named arguments; the rest go under `options`.
57
+
58
+ ```ruby
59
+ bitget_client = Bitget::Client.new(
60
+ api_key: 'api_key1',
61
+ options: {logger: Logger.new('bitget.log', 'daily')}
62
+ )
63
+ ```
64
+
65
+ ### Logging
66
+
67
+ A client logs when it has somewhere to log to, and not at all when it does not. Hand it any
68
+ object answering to `#info` and `#error`; the standard library's `Logger` will do.
69
+
70
+ ```ruby
71
+ require 'logger'
72
+
73
+ Bitget.configure do |config|
74
+ config.logger = Logger.new($stdout)
75
+ end
76
+ ```
77
+
78
+ `Logger` rotates by itself, so a daily log file wants no more than its second argument. It
79
+ will not create the directory, so make that first.
80
+
81
+ ```ruby
82
+ require 'fileutils'
83
+ require 'logger'
84
+
85
+ log_file_path = File.expand_path(File.join(%w{~ log bitget log.txt}))
86
+ FileUtils.mkdir_p(File.dirname(log_file_path))
87
+
88
+ Bitget.configure do |config|
89
+ config.logger = Logger.new(log_file_path, 'daily')
90
+ end
91
+ ```
92
+
93
+ Before 0.6.0 the client chose the path, created the directory and rotated the file itself. It
94
+ no longer does any of that: what is logged is the client's business and where it goes is
95
+ yours, which is what lets a StringIO logger in a test, or a levelled one, or something which
96
+ is not a Logger at all, work as well as the above.
97
+
98
+ ### Retrieve Info on All the Coins Traded
99
+
100
+ ```ruby
101
+ bitget_client.spot_public_coins
102
+ # =>
103
+ # {
104
+ # "code" => "00000",
105
+ # "msg" => "success",
106
+ # "requestTime" => 1743252600562,
107
+ # "data" => [
108
+ # {
109
+ # "coinId" => "1460",
110
+ # "coin" => "U2U",
111
+ # "transfer" => "false",
112
+ # "chains" => [
113
+ # {
114
+ # "chain" => "UnicornUltraSolaris",
115
+ # ...
116
+ # }
117
+ # ]
118
+ # },
119
+ # ...
120
+ # {...}
121
+ # ]
122
+ # "areaCoin" => "no"
123
+ # }
124
+ ```
125
+
126
+ ### Retrieve Info for One of the Coins Traded
127
+
128
+ ```ruby
129
+ bitget_client.spot_public_coins(coin: 'BTC')
130
+ # =>
131
+ # {
132
+ # "code" => "00000",
133
+ # "msg" => "success",
134
+ # "requestTime" => 1743252619082,
135
+ # "data" => [
136
+ # {
137
+ # "coinId" => "1",
138
+ # "coin" => "BTC",
139
+ # "transfer" => "true",
140
+ # "chains" => [
141
+ # {
142
+ # "chain" => "BTC",
143
+ # "needTag" => "false",
144
+ # "withdrawable" => "true",
145
+ # "rechargeable" => "true",
146
+ # "withdrawFee" => "0.00005",
147
+ # "extraWithdrawFee" => "0",
148
+ # "depositConfirm" => "1",
149
+ # "withdrawConfirm" => "1",
150
+ # "minDepositAmount" => "0.00001",
151
+ # "minWithdrawAmount" => "0.0005",
152
+ # "browserUrl" => "https://www.blockchain.com/explorer/transactions/btc/",
153
+ # "contractAddress" => nil,
154
+ # "withdrawStep" => "0",
155
+ # "withdrawMinScale" => "8",
156
+ # "congestion" => "normal"
157
+ # },
158
+ # ...
159
+ # {...}
160
+ # ]
161
+ # }
162
+ # ]
163
+ # "areaCoin" => "no"
164
+ # }
165
+ ```
166
+
167
+ ### Get Account Information
168
+
169
+ ```ruby
170
+ bitget_client.spot_account_info
171
+ ```
172
+
173
+ ### Get Account Assets
174
+
175
+ ```ruby
176
+ bitget_client.spot_account_assets
177
+ ```
178
+
179
+ ```ruby
180
+ bitget_client.spot_account_assets(coin: 'BTC')
181
+ ```
182
+
183
+ See https://www.bitget.com/api-doc/spot/intro for further information on endpoint arguments.
184
+
185
+ ## Contributing
186
+
187
+ 1. Fork it (https://github.com/thoran/bitget.rb/fork)
188
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
189
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
190
+ 4. Push to the branch (`git push origin my-new-feature`)
191
+ 5. Create a new pull request
192
+
193
+
194
+ ## License
195
+
196
+ MIT
data/bitget.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # bitget.rb.gemspec
2
+
3
+ require_relative './lib/Bitget/VERSION'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'bitget'
7
+ spec.version = Bitget::VERSION
8
+
9
+ spec.summary = "Access the Bitget API with Ruby."
10
+ spec.description = "Access the Bitget API with Ruby."
11
+
12
+ spec.author = 'thoran'
13
+ spec.email = 'code@thoran.com'
14
+ spec.homepage = 'http://github.com/thoran/bitget.rb'
15
+ spec.license = 'Ruby'
16
+
17
+ spec.required_ruby_version = '>= 2.7'
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency('http.rb')
21
+ spec.files = [
22
+ 'bitget.gemspec',
23
+ Dir['lib/**/*.rb'],
24
+ Dir['test/**/*.rb'],
25
+ 'Gemfile',
26
+ 'LICENSE',
27
+ 'README.md',
28
+ ].flatten
29
+ end
@@ -0,0 +1,8 @@
1
+ # Bitget/Client.rb
2
+ # Bitget::Client
3
+
4
+ require_relative './V2/Client'
5
+
6
+ module Bitget
7
+ class Client < Bitget::V2::Client; end
8
+ end
@@ -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
@@ -0,0 +1,48 @@
1
+ # Bitget/Error.rb
2
+ # Bitget::Error
3
+
4
+ require 'json'
5
+
6
+ module Bitget
7
+ class Error < RuntimeError
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
29
+
30
+ private
31
+
32
+ def initialize(code:, message:, body:)
33
+ @code = code
34
+ @message = message
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
+ {}
46
+ end
47
+ end
48
+ end