orionx-sdk-ruby 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ed4c66070a8ad82ab878ad33243410552cd1851c1a76e4963c563fee933fd626
4
+ data.tar.gz: 1499809d859429c7e6cfac873f67cbf342c1808ffc95716b7f9e8bad21aebdf6
5
+ SHA512:
6
+ metadata.gz: 44c135c8cfae47a8bce9421affd62caf2abeb7dd1f9f45b2e7bcde07bd80c15edd6a206047cc37674ab0a9109cbc81e961b26b5b552a31742d06fdfca9c7f79c
7
+ data.tar.gz: 47f9f5629c9280706ccea0b23f8223028b5ce862be08e44212039739f9a10f040bdac4d8c2c73d4e369737d09462c95a201486fc52cd7c7d8a2851f0b769a3d3
data/CHANGELOG.md ADDED
@@ -0,0 +1,64 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.0] - 2024-10-03
9
+
10
+ ### Added
11
+ - Initial release of OrionX Ruby SDK
12
+ - Complete GraphQL API coverage for OrionX exchange
13
+ - HMAC-SHA512 authentication implementation
14
+ - Comprehensive error handling with custom exception classes:
15
+ - `OrionX::AuthenticationError`
16
+ - `OrionX::ValidationError`
17
+ - `OrionX::RateLimitError`
18
+ - `OrionX::NetworkError`
19
+ - `OrionX::APIError`
20
+ - Debug mode with detailed HTTP request/response logging
21
+ - Automatic retry mechanism with exponential backoff
22
+ - Full endpoint coverage:
23
+ - User operations (`user.me`, `user.user_id`)
24
+ - Account management (`accounts.get_accounts`, `accounts.get_balance`)
25
+ - Market data (`markets.get_markets`, `markets.get_orderbook`)
26
+ - Order management (limit, market, stop-limit, stop-market orders)
27
+ - Transaction operations (`transactions.get_transactions`, `transactions.send_crypto`)
28
+ - Configuration management with global and per-client settings
29
+ - Comprehensive test suite with RSpec
30
+ - Multiple usage examples:
31
+ - Basic usage demonstration
32
+ - Trading operations with safety comments
33
+ - Real-time market data monitoring
34
+ - Debug and error handling patterns
35
+ - Complete documentation with API reference
36
+ - Ruby gem packaging with proper dependencies
37
+ - MIT license
38
+
39
+ ### Features
40
+ - Thread-safe configuration
41
+ - Configurable timeouts and retry policies
42
+ - Flexible logging system with custom logger support
43
+ - Input validation for all API methods
44
+ - Proper handling of OrionX currency units and precision
45
+ - Connection health checking with `ping` method
46
+ - Market statistics aggregation helpers
47
+ - Transaction history filtering and pagination
48
+
49
+ ### Documentation
50
+ - Comprehensive README with quick start guide
51
+ - Detailed API reference for all methods
52
+ - Error handling best practices
53
+ - Security recommendations
54
+ - Development setup instructions
55
+ - Contributing guidelines
56
+ - Multiple working code examples
57
+
58
+ ### Dependencies
59
+ - `faraday` ~> 2.0 for HTTP client
60
+ - `faraday-net_http` ~> 3.0 for HTTP adapter
61
+ - `logger` ~> 1.5 for logging functionality
62
+ - Development dependencies for testing and code quality
63
+
64
+ [1.0.0]: https://github.com/orionx-dev/orionx-sdk-ruby/releases/tag/v1.0.0
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,152 @@
1
+ # Contributing to OrionX Ruby SDK
2
+
3
+ Thank you for your interest in contributing to the OrionX Ruby SDK! This document provides guidelines for contributing to this project.
4
+
5
+ ## Code of Conduct
6
+
7
+ This project and everyone participating in it is governed by our Code of Conduct. By participating, you are expected to uphold this code.
8
+
9
+ ## How to Contribute
10
+
11
+ ### Reporting Bugs
12
+
13
+ Before creating bug reports, please check the existing issues to see if the problem has already been reported. When creating a bug report, please include:
14
+
15
+ - A clear and descriptive title
16
+ - Steps to reproduce the issue
17
+ - Expected behavior
18
+ - Actual behavior
19
+ - Ruby version and gem version
20
+ - Any relevant error messages or logs
21
+
22
+ ### Suggesting Features
23
+
24
+ Feature requests are welcome! Please provide:
25
+
26
+ - A clear and descriptive title
27
+ - A detailed description of the proposed feature
28
+ - Use cases and examples
29
+ - Any relevant implementation details
30
+
31
+ ### Pull Requests
32
+
33
+ 1. Fork the repository
34
+ 2. Create a feature branch from `main`
35
+ 3. Make your changes
36
+ 4. Add tests for new functionality
37
+ 5. Ensure all tests pass
38
+ 6. Run RuboCop and fix any style issues
39
+ 7. Update documentation as needed
40
+ 8. Submit a pull request
41
+
42
+ ## Development Setup
43
+
44
+ ```bash
45
+ git clone https://github.com/PabloB07/orionx-sdk-ruby.git
46
+ cd orionx-sdk-ruby
47
+ bundle install
48
+ ```
49
+
50
+ ## Running Tests
51
+
52
+ ```bash
53
+ # Run all tests
54
+ bundle exec rspec
55
+
56
+ # Run with coverage report
57
+ COVERAGE=true bundle exec rspec
58
+
59
+ # Run specific test file
60
+ bundle exec rspec spec/client_spec.rb
61
+
62
+ # Run specific test
63
+ bundle exec rspec spec/client_spec.rb:15
64
+ ```
65
+
66
+ ## Code Style
67
+
68
+ This project uses RuboCop for code formatting and style enforcement:
69
+
70
+ ```bash
71
+ # Check for style issues
72
+ bundle exec rubocop
73
+
74
+ # Auto-fix issues where possible
75
+ bundle exec rubocop -A
76
+
77
+ # Check specific files
78
+ bundle exec rubocop lib/orionx/client.rb
79
+ ```
80
+
81
+ ## Writing Tests
82
+
83
+ - All new features must include tests
84
+ - Tests should be written using RSpec
85
+ - Use descriptive test names and contexts
86
+ - Mock external API calls using WebMock
87
+ - Aim for high test coverage
88
+
89
+ Example test structure:
90
+
91
+ ```ruby
92
+ RSpec.describe OrionX::NewFeature do
93
+ describe "#new_method" do
94
+ context "when given valid parameters" do
95
+ it "returns expected result" do
96
+ # Test implementation
97
+ end
98
+ end
99
+
100
+ context "when given invalid parameters" do
101
+ it "raises validation error" do
102
+ # Test implementation
103
+ end
104
+ end
105
+ end
106
+ end
107
+ ```
108
+
109
+ ## Documentation
110
+
111
+ - Update README.md for new features
112
+ - Add YARD documentation for new methods
113
+ - Include code examples where helpful
114
+ - Update CHANGELOG.md following Keep a Changelog format
115
+
116
+ ## Commit Messages
117
+
118
+ Use clear and meaningful commit messages:
119
+
120
+ - Use present tense ("Add feature" not "Added feature")
121
+ - Use imperative mood ("Move cursor to..." not "Moves cursor to...")
122
+ - Limit first line to 72 characters or less
123
+ - Reference issues and pull requests liberally
124
+
125
+ Examples:
126
+ ```
127
+ Add retry mechanism for failed API requests
128
+
129
+ Fix authentication error handling in API client
130
+
131
+ Update README with new configuration options
132
+
133
+ Refs #123
134
+ ```
135
+
136
+ ## Release Process
137
+
138
+ 1. Update version in `lib/orionx/version.rb`
139
+ 2. Update CHANGELOG.md with new version details
140
+ 3. Create release commit: `git commit -m "Release vX.X.X"`
141
+ 4. Create git tag: `git tag -a vX.X.X -m "Release vX.X.X"`
142
+ 5. Push changes and tags: `git push origin main --tags`
143
+
144
+ ## Questions?
145
+
146
+ If you have questions about contributing, please:
147
+
148
+ 1. Check existing issues and discussions
149
+ 2. Create an issue for discussion
150
+ 3. Reach out to the maintainers
151
+
152
+ Thank you for contributing to OrionX Ruby SDK!
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in orionx-sdk.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 13.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "rubocop", "~> 1.21"
9
+
10
+ group :development do
11
+ gem "pry"
12
+ gem "yard"
13
+ gem "simplecov"
14
+ gem "webmock"
15
+ end
data/README.md ADDED
@@ -0,0 +1,408 @@
1
+ # Unofficial OrionX Ruby SDK
2
+
3
+ The unofficial OrionX SDK for Ruby - A comprehensive Ruby library for interacting with the OrionX cryptocurrency exchange API.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/orionx-sdk.svg)](https://badge.fury.io/rb/orionx-sdk)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Features
9
+
10
+ - 🔐 **Secure Authentication** - HMAC-SHA512 signature authentication
11
+ - 🐛 **Debug Mode** - Comprehensive logging and debugging capabilities
12
+ - 🛡️ **Error Handling** - Robust error handling with custom exception classes
13
+ - 🔄 **Auto Retry** - Automatic retry mechanism for failed requests
14
+ - 📈 **Trading Operations** - Full support for limit, market, and stop orders
15
+ - 💰 **Account Management** - Balance inquiries and account information
16
+ - 📊 **Market Data** - Real-time market data and orderbook information
17
+ - 💸 **Transactions** - Transaction history and cryptocurrency transfers
18
+ - 🧪 **Comprehensive Tests** - Well-tested with RSpec
19
+ - 📚 **Rich Examples** - Multiple usage examples included
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ ```ruby
26
+ gem 'orionx-sdk'
27
+ ```
28
+
29
+ And then execute:
30
+
31
+ ```bash
32
+ $ bundle install
33
+ ```
34
+
35
+ Or install it yourself as:
36
+
37
+ ```bash
38
+ $ gem install orionx-sdk
39
+ ```
40
+
41
+ ## Quick Start
42
+
43
+ ### 1. Get Your API Credentials
44
+
45
+ First, you'll need to get your API credentials from OrionX:
46
+
47
+ 1. Log in to your [OrionX account](https://orionx.com)
48
+ 2. Go to API settings
49
+ 3. Generate your API Key and Secret
50
+ 4. Follow [this tutorial](http://docs.orionx.com/docs/getStarted.html) for detailed instructions
51
+
52
+ ### 2. Configuration
53
+
54
+ Configure the SDK with your credentials:
55
+
56
+ ```ruby
57
+ require 'orionx'
58
+
59
+ # Global configuration (recommended)
60
+ OrionX.configure do |config|
61
+ config.api_key = 'your-api-key'
62
+ config.api_secret = 'your-api-secret'
63
+ config.debug = true # Enable debug logging (optional)
64
+ end
65
+
66
+ # Create client instance
67
+ client = OrionX::Client.new
68
+ ```
69
+
70
+ Or configure per client instance:
71
+
72
+ ```ruby
73
+ client = OrionX::Client.new(
74
+ api_key: 'your-api-key',
75
+ api_secret: 'your-api-secret',
76
+ debug: true
77
+ )
78
+ ```
79
+
80
+ ### 3. Basic Usage
81
+
82
+ ```ruby
83
+ # Test connection
84
+ ping = client.ping
85
+ puts ping # => { status: "ok", message: "Connection successful" }
86
+
87
+ # Get user information
88
+ user = client.me
89
+ puts user['name'] # => "Your Name"
90
+
91
+ # Get account balances
92
+ balances = client.accounts.get_balances
93
+ balances.each do |balance|
94
+ puts "#{balance[:currency]}: #{balance[:balance]}"
95
+ end
96
+
97
+ # Get market data
98
+ market = client.markets.get_market('BTCCLP')
99
+ puts "BTC/CLP Last Price: #{market.dig('lastTrade', 'price')}"
100
+ ```
101
+
102
+ ## API Reference
103
+
104
+ ### User Operations
105
+
106
+ ```ruby
107
+ # Get current user information
108
+ user = client.user.me
109
+ # Returns: { "_id" => "...", "email" => "...", "name" => "...", ... }
110
+
111
+ # Get user ID only
112
+ user_id = client.user.user_id
113
+ # Returns: "user_id_string"
114
+ ```
115
+
116
+ ### Account Management
117
+
118
+ ```ruby
119
+ # Get all account balances
120
+ balances = client.accounts.get_balances
121
+ # Returns array of balance objects
122
+
123
+ # Get specific currency account
124
+ btc_account = client.accounts.get_account('BTC')
125
+ # Returns: { "_id" => "...", "currency" => {...}, "balance" => 0, ... }
126
+
127
+ # Get balance for specific currency
128
+ btc_balance = client.accounts.get_balance('BTC')
129
+ # Returns: { currency: "BTC", balance: 0, available_balance: 0, ... }
130
+ ```
131
+
132
+ ### Market Data
133
+
134
+ ```ruby
135
+ # Get all available markets
136
+ markets = client.markets.get_markets
137
+ # Returns array of market objects
138
+
139
+ # Get specific market information
140
+ btc_market = client.markets.get_market('BTCCLP')
141
+ # Returns: { "code" => "BTCCLP", "name" => "BTC/CLP", ... }
142
+
143
+ # Get market orderbook
144
+ orderbook = client.markets.get_orderbook('BTCCLP', limit: 10)
145
+ # Returns: { "buy" => [...], "sell" => [...], "spread" => 0, "mid" => 0 }
146
+
147
+ # Get market statistics (convenience method)
148
+ stats = client.markets.get_market_stats('BTCCLP')
149
+ # Returns: { code: "BTCCLP", last_price: 0, spread: 0, ... }
150
+ ```
151
+
152
+ ### Order Management
153
+
154
+ ```ruby
155
+ # Get user's orders
156
+ orders = client.orders.get_orders(onlyOpen: true, limit: 10)
157
+
158
+ # Get specific order
159
+ order = client.orders.get_order('order_id')
160
+
161
+ # Place limit order
162
+ limit_order = client.orders.place_limit_order(
163
+ market_code: 'BTCCLP',
164
+ amount: 10000, # Amount in base currency units
165
+ limit_price: 50000000, # Price in quote currency units
166
+ sell: false # true for sell, false for buy
167
+ )
168
+
169
+ # Place market order
170
+ market_order = client.orders.place_market_order(
171
+ market_code: 'BTCCLP',
172
+ amount: 10000,
173
+ sell: false
174
+ )
175
+
176
+ # Place stop-limit order
177
+ stop_order = client.orders.place_stop_limit_order(
178
+ market_code: 'BTCCLP',
179
+ stop_price_up: 52000000, # Upper trigger price
180
+ stop_price_down: 48000000, # Lower trigger price
181
+ amount: 10000,
182
+ limit_price: 50000000,
183
+ sell: true
184
+ )
185
+
186
+ # Cancel order
187
+ cancelled = client.orders.cancel_order('order_id')
188
+ ```
189
+
190
+ ### Transaction Operations
191
+
192
+ ```ruby
193
+ # Get transaction history
194
+ transactions = client.transactions.get_transactions(
195
+ limit: 20,
196
+ page: 1,
197
+ types: ['trade-in', 'trade-out']
198
+ )
199
+
200
+ # Get specific transaction
201
+ transaction = client.transactions.get_transaction('transaction_id')
202
+
203
+ # Get transaction history for specific currency
204
+ btc_history = client.transactions.get_history('BTC', limit: 10)
205
+
206
+ # Send cryptocurrency (requires additional setup)
207
+ send_result = client.transactions.send_crypto(
208
+ wallet_id: 'wallet_id',
209
+ network: 'BTC',
210
+ amount: 100000,
211
+ contact_id: 'contact_id' # Optional
212
+ )
213
+ ```
214
+
215
+ ## Error Handling
216
+
217
+ The SDK provides comprehensive error handling with specific exception types:
218
+
219
+ ```ruby
220
+ begin
221
+ result = client.me
222
+ rescue OrionX::AuthenticationError => e
223
+ puts "Invalid API credentials: #{e.message}"
224
+ rescue OrionX::ValidationError => e
225
+ puts "Invalid parameters: #{e.message}"
226
+ rescue OrionX::RateLimitError => e
227
+ puts "Rate limit exceeded: #{e.message}"
228
+ rescue OrionX::NetworkError => e
229
+ puts "Network error: #{e.message}"
230
+ rescue OrionX::APIError => e
231
+ puts "API error: #{e.message}"
232
+ rescue OrionX::Error => e
233
+ puts "SDK error: #{e.message}"
234
+ end
235
+ ```
236
+
237
+ ### Exception Types
238
+
239
+ - `OrionX::AuthenticationError` - Invalid API credentials
240
+ - `OrionX::ValidationError` - Invalid parameters or input validation failed
241
+ - `OrionX::RateLimitError` - API rate limit exceeded
242
+ - `OrionX::NetworkError` - Network connectivity issues
243
+ - `OrionX::APIError` - General API errors
244
+ - `OrionX::Error` - Base SDK error class
245
+
246
+ ## Debug Mode
247
+
248
+ Enable debug mode to see detailed HTTP requests and responses:
249
+
250
+ ```ruby
251
+ # Global configuration
252
+ OrionX.configure do |config|
253
+ config.debug = true
254
+ end
255
+
256
+ # Or per client
257
+ client.debug = true
258
+
259
+ # The debug output includes:
260
+ # - HTTP request headers and body
261
+ # - GraphQL queries and variables
262
+ # - HTTP response status and body
263
+ # - Request/response timing
264
+ # - Signature generation details
265
+ ```
266
+
267
+ ## Configuration Options
268
+
269
+ ```ruby
270
+ OrionX.configure do |config|
271
+ config.api_key = 'your-api-key' # Required
272
+ config.api_secret = 'your-api-secret' # Required
273
+ config.api_endpoint = 'custom-endpoint' # Optional, defaults to OrionX API
274
+ config.debug = false # Optional, enables debug logging
275
+ config.timeout = 30 # Optional, request timeout in seconds
276
+ config.retries = 3 # Optional, number of retries for failed requests
277
+ config.logger = custom_logger # Optional, custom logger instance
278
+ end
279
+ ```
280
+
281
+ ## Examples
282
+
283
+ The SDK includes several comprehensive examples:
284
+
285
+ ### Basic Usage Example
286
+ ```bash
287
+ ruby examples/basic_usage.rb
288
+ ```
289
+ Demonstrates connection testing, user information, balances, and market data.
290
+
291
+ ### Trading Operations Example
292
+ ```bash
293
+ ruby examples/trading_operations.rb
294
+ ```
295
+ Shows how to place different order types, manage orders, and handle trading operations.
296
+
297
+ ### Market Data Monitor
298
+ ```bash
299
+ ruby examples/market_monitor.rb
300
+ ```
301
+ Real-time market monitoring with price updates and orderbook data.
302
+
303
+ ### Debug and Error Handling
304
+ ```bash
305
+ ruby examples/debug_and_errors.rb
306
+ ```
307
+ Comprehensive demonstration of debug features and error handling patterns.
308
+
309
+ ## Development
310
+
311
+ ### Setup
312
+
313
+ ```bash
314
+ git clone https://github.com/orionx-dev/orionx-sdk-ruby.git
315
+ cd orionx-sdk-ruby
316
+ bundle install
317
+ ```
318
+
319
+ ### Running Tests
320
+
321
+ ```bash
322
+ # Run all tests
323
+ bundle exec rspec
324
+
325
+ # Run with coverage
326
+ COVERAGE=true bundle exec rspec
327
+
328
+ # Run specific test file
329
+ bundle exec rspec spec/client_spec.rb
330
+ ```
331
+
332
+ ### Code Quality
333
+
334
+ ```bash
335
+ # Run RuboCop linter
336
+ bundle exec rubocop
337
+
338
+ # Auto-fix RuboCop issues
339
+ bundle exec rubocop -A
340
+ ```
341
+
342
+ ## API Reference Documentation
343
+
344
+ For detailed API documentation, visit:
345
+ - [OrionX API Documentation](http://docs.orionx.com/)
346
+ - [GraphQL Schema Reference](https://api.orionx.com/graphql)
347
+
348
+ ## Important Notes
349
+
350
+ ### Currency Units
351
+
352
+ OrionX uses specific units for different currencies:
353
+ - **BTC**: 8 decimal places (Satoshis) - 1 BTC = 100,000,000 units
354
+ - **ETH**: 18 decimal places (Wei) - 1 ETH = 1,000,000,000,000,000,000 units
355
+ - **CLP**: 0 decimal places - 1 CLP = 1 unit
356
+ - **USD**: 2 decimal places - 1 USD = 100 units
357
+
358
+ ### Rate Limits
359
+
360
+ The OrionX API has rate limits. The SDK automatically handles retries with exponential backoff for rate-limited requests.
361
+
362
+ ### Security
363
+
364
+ - Never commit your API credentials to version control
365
+ - Use environment variables for credentials in production
366
+ - Enable debug mode only in development environments
367
+ - Regularly rotate your API keys
368
+
369
+ ## Contributing
370
+
371
+ 1. Fork the repository
372
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
373
+ 3. Write tests for your changes
374
+ 4. Ensure all tests pass (`bundle exec rspec`)
375
+ 5. Run RuboCop (`bundle exec rubocop`)
376
+ 6. Commit your changes (`git commit -am 'Add amazing feature'`)
377
+ 7. Push to the branch (`git push origin feature/amazing-feature`)
378
+ 8. Open a Pull Request
379
+
380
+ ## Changelog
381
+
382
+ ### Version 1.0.0
383
+ - Initial release
384
+ - Complete API coverage for OrionX GraphQL API
385
+ - Comprehensive error handling and debug capabilities
386
+ - Full test suite with RSpec
387
+ - Multiple usage examples
388
+ - Detailed documentation
389
+
390
+ ## License
391
+
392
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
393
+
394
+ ## Support
395
+
396
+ - **Issues**: [GitHub Issues](https://github.com/orionx-dev/orionx-sdk-ruby/issues)
397
+ - **Documentation**: [OrionX API Docs](http://docs.orionx.com/)
398
+ - **Email**: [support@orionx.com](mailto:support@orionx.com)
399
+
400
+ ## Acknowledgments
401
+
402
+ - Inspired by the [official OrionX JavaScript SDK](https://github.com/orionx-dev/orionx-sdk-js)
403
+ - Built with Ruby community best practices
404
+ - Thanks to the OrionX development team for API support
405
+
406
+ ---
407
+
408
+ Made with ❤️ by PabloB07
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ require "rubocop/rake_task"
7
+
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: %i[spec rubocop]