bitget.rb 0.4.0 → 0.5.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.
data/test/client_test.rb CHANGED
@@ -10,99 +10,188 @@ describe Bitget::Client do
10
10
  )
11
11
  end
12
12
 
13
- describe "#spot_public_coins" do
14
- context "when a coin is NOT supplied" do
15
- it "retrieves a list of all coins" do
16
- VCR.use_cassette('v2/spot/public/coins-when_coin_is_not_supplied') do
17
- response = client.spot_public_coins
18
- _(response).must_include('data')
19
- _(response['data'].first).must_include('coinId')
20
- _(response['data'].first).must_include('coin')
21
- assert_operator response['data'].count, :>, 1500
22
- end
23
- end
24
- end
13
+ # Market
25
14
 
26
- context "when a coin IS supplied" do
27
- it "retrieves one coin" do
28
- VCR.use_cassette('v2/spot/public/coins-when_coin_is_supplied') do
29
- response = client.spot_public_coins(coin: 'BTC')
30
- _(response).must_include('data')
31
- _(response['data'].first).must_include('coinId')
32
- _(response['data'].first).must_include('coin')
33
- _(response['data'].count).must_equal(1)
15
+ %w[
16
+ spot_public_coins
17
+ spot_public_symbols
18
+ spot_market_vip_free_rate
19
+ spot_market_tickers
20
+ spot_market_merge_depth
21
+ spot_market_orderbook
22
+ spot_market_candles
23
+ spot_market_history_candles
24
+ spot_market_fills
25
+ spot_market_fills_history
26
+ ].each do |method|
27
+ describe "##{method}" do
28
+ it "delegates to V2::Client" do
29
+ mock_v2_client = Minitest::Mock.new
30
+ client.instance_variable_set(:@v2_client, mock_v2_client)
31
+
32
+ args = case method
33
+ when 'spot_market_merge_depth', 'spot_market_orderbook'
34
+ {symbol: 'BTCUSDT'}
35
+ when 'spot_market_candles', 'spot_market_history_candles'
36
+ {symbol: 'BTCUSDT', granularity: '1min'}
37
+ when 'spot_market_fills', 'spot_market_fills_history'
38
+ {symbol: 'BTCUSDT'}
39
+ else
40
+ {}
34
41
  end
42
+
43
+ mock_v2_client.expect(method.to_sym, nil, [args])
44
+ client.send(method, **args)
45
+ mock_v2_client.verify
35
46
  end
36
47
  end
48
+ end
49
+
50
+ # Trade
37
51
 
38
- context "when an error occurs" do
39
- it "logs then raises an error" do
40
- VCR.use_cassette('v2/spot/public/coins-when_an_error_occurs') do
41
- assert_raises(Bitget::Error) do
42
- mocked_method = Minitest::Mock.new
43
- mocked_method.expect(:call, nil, [], code: '418', message: "I'm a teapot", body: '')
44
- client.stub(:log_error, mocked_method) do
45
- client.spot_public_coins
46
- end
47
- mocked_method.verify
48
- end
52
+ %w[
53
+ spot_trade_place_order
54
+ spot_trade_cancel_replace_order
55
+ spot_trade_batch_cancel_replace_order
56
+ spot_trade_cancel_order
57
+ spot_trade_batch_orders
58
+ spot_trade_batch_cancel_order
59
+ spot_trade_cancel_symbol_order
60
+ spot_trade_order_info
61
+ spot_trade_unfilled_orders
62
+ spot_trade_history_orders
63
+ spot_trade_fills
64
+ ].each do |method|
65
+ describe "##{method}" do
66
+ it "delegates to V2::Client" do
67
+ mock_v2_client = Minitest::Mock.new
68
+ client.instance_variable_set(:@v2_client, mock_v2_client)
69
+
70
+ args = case method
71
+ when 'spot_trade_place_order'
72
+ {
73
+ symbol: 'BTCUSDT',
74
+ side: 'buy',
75
+ order_type: 'limit',
76
+ force: 'normal',
77
+ size: '0.001',
78
+ price: '30000'
79
+ }
80
+ when /cancel|modify|info/
81
+ {symbol: 'BTCUSDT', order_id: '123456'}
82
+ when /batch/
83
+ {symbol: 'BTCUSDT', order_ids: ['123', '456']}
84
+ else
85
+ {symbol: 'BTCUSDT'}
49
86
  end
87
+
88
+ mock_v2_client.expect(method.to_sym, nil, [args])
89
+ client.send(method, **args)
90
+ mock_v2_client.verify
50
91
  end
51
92
  end
52
93
  end
53
94
 
54
- describe "#spot_account_info" do
55
- it "retrieves account information" do
56
- VCR.use_cassette('v2/spot/account/info') do
57
- response = client.spot_account_info
58
- _(response).must_include('data')
59
- _(response['data']).must_include('userId')
60
- _(response['data']).must_include('channelCode')
61
- _(response['data']).must_include('authorities')
62
- end
63
- end
95
+ # Trigger
64
96
 
65
- context "when an error occurs" do
66
- it "logs then raises an error" do
67
- VCR.use_cassette('v2/spot/account/info-when_an_error_occurs') do
68
- assert_raises(Bitget::Error) do
69
- mocked_method = Minitest::Mock.new
70
- mocked_method.expect(:call, nil, [], code: '418', message: "I'm a teapot", body: '')
71
- client.stub(:log_error, mocked_method) do
72
- client.spot_account_info
73
- end
74
- mocked_method.verify
75
- end
97
+ %w[
98
+ spot_trade_place_plan_order
99
+ spot_trade_modify_plan_order
100
+ spot_trade_cancel_plan_order
101
+ spot_trade_current_plan_order
102
+ spot_trade_plan_sub_order
103
+ spot_trade_history_plan_order
104
+ spot_trade_batch_cancel_plan_order
105
+ ].each do |method|
106
+ describe "##{method}" do
107
+ it "delegates to V2::Client" do
108
+ mock_v2_client = Minitest::Mock.new
109
+ client.instance_variable_set(:@v2_client, mock_v2_client)
110
+
111
+ args = case method
112
+ when 'spot_trade_place_plan_order'
113
+ {
114
+ symbol: 'BTCUSDT',
115
+ side: 'buy',
116
+ order_type: 'limit',
117
+ size: '0.001',
118
+ trigger_price: '31000',
119
+ execute_price: '30000'
120
+ }
121
+ when 'spot_trade_modify_plan_order'
122
+ {
123
+ order_id: '123456',
124
+ trigger_price: '31000',
125
+ execute_price: '30000',
126
+ size: '0.001'
127
+ }
128
+ when 'spot_trade_cancel_plan_order'
129
+ {order_id: '123456'}
130
+ when 'spot_trade_plan_sub_order'
131
+ {order_id: '123456'}
132
+ when 'spot_trade_batch_cancel_plan_order'
133
+ {symbol: 'BTCUSDT', order_ids: ['123', '456']}
134
+ else
135
+ {symbol: 'BTCUSDT'}
76
136
  end
137
+
138
+ mock_v2_client.expect(method.to_sym, nil, [args])
139
+ client.send(method, **args)
140
+ mock_v2_client.verify
77
141
  end
78
142
  end
79
143
  end
80
144
 
81
- describe "#spot_account_assets" do
82
- it "retrieves account assets" do
83
- VCR.use_cassette('v2/spot/account/assets') do
84
- response = client.spot_account_assets
85
- _(response).must_include('data')
86
- _(response['data'].first).must_include('coin')
87
- _(response['data'].first).must_include('available')
88
- _(response['data'].first).must_include('frozen')
89
- _(response['data'].first).must_include('locked')
90
- _(response['data'].first).must_include('uTime')
91
- end
92
- end
145
+ # Account
93
146
 
94
- context "when an error occurs" do
95
- it "logs then raises an error" do
96
- VCR.use_cassette('v2/spot/account/assets-when_an_error_occurs') do
97
- assert_raises(Bitget::Error) do
98
- mocked_method = Minitest::Mock.new
99
- mocked_method.expect(:call, nil, [], code: '418', message: "I'm a teapot", body: '')
100
- client.stub(:log_error, mocked_method) do
101
- client.spot_account_assets
102
- end
103
- mocked_method.verify
104
- end
147
+ %w[
148
+ spot_account_info
149
+ spot_account_assets
150
+ spot_account_subaccount_assets
151
+ spot_account_bills
152
+ spot_account_sub_main_trans_record
153
+ spot_account_transfer_records
154
+ spot_account_switch_deduct
155
+ spot_account_deduct_info
156
+ spot_wallet_modify_deposit_account
157
+ spot_wallet_transfer
158
+ spot_wallet_transfer_coin_info
159
+ spot_wallet_subaccount_transfer
160
+ spot_wallet_withdrawal
161
+ spot_wallet_cancel_withdrawal
162
+ spot_wallet_deposit_address
163
+ spot_wallet_subaccount_deposit_address
164
+ spot_wallet_subaccount_deposit_records
165
+ spot_wallet_withdrawal_records
166
+ spot_wallet_deposit_records
167
+ ].each do |method|
168
+ describe "##{method}" do
169
+ it "delegates to V2::Client" do
170
+ mock_v2_client = Minitest::Mock.new
171
+ client.instance_variable_set(:@v2_client, mock_v2_client)
172
+
173
+ args = case method
174
+ when 'spot_wallet_withdrawal'
175
+ {
176
+ coin: 'USDT',
177
+ chain: 'TRC20',
178
+ address: '0x1234567890abcdef',
179
+ amount: '100'
180
+ }
181
+ when /transfer/
182
+ {
183
+ coin: 'USDT',
184
+ amount: '100'
185
+ }
186
+ when /subaccount/
187
+ {subaccount_id: '123456'}
188
+ else
189
+ {}
105
190
  end
191
+
192
+ mock_v2_client.expect(method.to_sym, nil, [args])
193
+ client.send(method, **args)
194
+ mock_v2_client.verify
106
195
  end
107
196
  end
108
197
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitget.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-16 00:00:00.000000000 Z
10
+ date: 2025-05-26 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: http.rb
@@ -35,14 +35,13 @@ files:
35
35
  - lib/Bitget/Client.rb
36
36
  - lib/Bitget/Error.rb
37
37
  - lib/Bitget/V2/Client.rb
38
- - lib/Bitget/V2/Client2.rb
39
- - lib/Bitget/VERSION.rb
40
- - lib/Hash/to_parameter_string.rb
38
+ - lib/Bitget/VERSiON.rb
41
39
  - lib/Hash/x_www_form_urlencode.rb
42
40
  - lib/String/url_encode.rb
43
41
  - lib/Thoran/Hash/XWwwFormUrlencode/x_www_form_urlencode.rb
44
42
  - lib/Thoran/String/UrlEncode/url_encode.rb
45
43
  - lib/bitget.rb
44
+ - test/V2/client_logging_test.rb
46
45
  - test/V2/client_test.rb
47
46
  - test/client_test.rb
48
47
  - test/helper.rb
@@ -65,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
64
  - !ruby/object:Gem::Version
66
65
  version: '0'
67
66
  requirements: []
68
- rubygems_version: 3.6.8
67
+ rubygems_version: 3.6.9
69
68
  specification_version: 4
70
69
  summary: Access the Bitget API with Ruby.
71
70
  test_files: []