Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
## [Unreleased]
# Changelog

## [0.1.0] - 2025-01-19
All notable changes to this project will be documented in this file.

- Initial release
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0] - 2024-01-21

### Added
- Initial release of ta_lib_ffi
- Basic FFI wrapper for TA-Lib
- Cross-platform support:
- Windows (64-bit)
- macOS (via Homebrew)
- Linux (Debian/Ubuntu packages)
- Automated tests with GitHub Actions
- Basic documentation and usage examples

### Changed
- N/A

### Deprecated
- N/A

### Removed
- N/A

### Fixed
- N/A

### Security
- N/A

[0.1.0]: https://github.com/Youngv/ta_lib_ffi/releases/tag/v0.1.0
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
byebug (11.1.3)
diff-lcs (1.5.1)
fiddle (1.1.6)
json (2.9.1)
Expand Down Expand Up @@ -70,7 +69,6 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
byebug (~> 11.1)
rake (~> 13.2)
rspec (~> 3.13)
rubocop-rspec (~> 3.3)
Expand Down
79 changes: 67 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,89 @@

![Tests](https://github.com/Youngv/ta_lib_ffi/actions/workflows/main.yml/badge.svg)

Ruby FFI wrapper for TA-Lib (Technical Analysis Library)
## Introduction

TALib is a Ruby binding for [TA-Lib](https://ta-lib.org/) (Technical Analysis Library) using FFI (Foreign Function Interface). It provides a comprehensive set of functions for technical analysis of financial market data.

## Requirements

- Ruby >= 3.0.0
- TA-Lib >= 0.6.4

## Installation

TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
### [Install TA-Lib](https://ta-lib.org/install/)

#### Windows
Download and run the installer: [ta-lib-0.6.4-windows-x86_64.msi](https://github.com/ta-lib/ta-lib/releases/download/v0.6.4/ta-lib-0.6.4-windows-x86_64.msi)

#### macOS
```bash
brew install ta-lib
```

#### Linux (Debian/Ubuntu)
```bash
# For Intel/AMD 64-bit
wget https://github.com/ta-lib/ta-lib/releases/download/v0.6.4/ta-lib_0.6.4_amd64.deb
sudo dpkg -i ta-lib_0.6.4_amd64.deb

# For ARM64
wget https://github.com/ta-lib/ta-lib/releases/download/v0.6.4/ta-lib_0.6.4_arm64.deb
sudo dpkg -i ta-lib_0.6.4_arm64.deb

# For Intel/AMD 32-bits
wget https://github.com/ta-lib/ta-lib/releases/download/v0.6.4/ta-lib_0.6.4_i386.deb
sudo dpkg -i ta-lib_0.6.4_i386.deb
```

Install the gem and add to the application's Gemfile by executing:
### Installing the Ruby Gem

$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
Add this to your application's Gemfile:

If bundler is not being used to manage dependencies, install the gem by executing:
```ruby
gem 'ta_lib_ffi'
```

$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
Then execute:

$ bundle install

Or install it directly:

$ gem install ta_lib_ffi

## Usage

TODO: Write usage instructions here
```ruby
require 'ta_lib'

## Development
# Initialize data
prices = [10.0, 11.0, 12.0, 11.0, 10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0]

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
# Calculate SMA
puts TALib.sma(prices, time_period: 3)
# => [11.0, 11.333333333333334, 11.0, 10.0, 9.0, 8.0, 7.0, 6.0, 5.0]
```

## TODO
- [ ] Add RDoc documentation for Ruby methods
- [ ] Create detailed function examples with input/output samples
- [ ] Add more tests for each function
- [ ] Support custom TA-Lib installation location

## Development

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -am 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Create a Pull Request

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ta_lib_ffi.
Bug reports and pull requests are welcome on GitHub at https://github.com/Youngv/ta_lib_ffi

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
This gem is available as open source under the terms of the [MIT License](LICENSE).
4 changes: 1 addition & 3 deletions lib/ta_lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ def call_func(func_name, args)
begin
setup_input_parameters(params_ptr, input_arrays, func_name)
setup_optional_parameters(params_ptr, options, func_name)
lookback = calculate_lookback(params_ptr)
puts "Lookback: #{lookback}"
_lookback = calculate_lookback(params_ptr)
calculate_results(params_ptr, input_arrays.first.length, func_name)
ensure
TA_ParamHolderFree(params_ptr)
Expand Down Expand Up @@ -438,7 +437,6 @@ def calculate_results(params_ptr, input_size, func_name)
check_ta_return_code(ret_code)

actual_size = out_size[0, Fiddle::SIZEOF_INT].unpack1("l")
puts "actual_size: #{actual_size}"
format_output_results(output_arrays, actual_size, func_name)
ensure
out_begin.free
Expand Down
1 change: 0 additions & 1 deletion spec/ta_lib_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "spec_helper"
require "byebug"

RSpec.describe TALib do
shared_examples "ta_lib_input_validation" do |method_name|
Expand Down
19 changes: 9 additions & 10 deletions ta_lib_ffi.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ Gem::Specification.new do |spec|
spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/Youngv/ta_lib_ffi"
spec.metadata["changelog_uri"] = "https://github.com/Youngv/ta_lib_ffi/blob/main/CHANGELOG.md"

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(__dir__) do
`git ls-files -z`.split("\x0").reject do |f|
(File.expand_path(f) == __FILE__) ||
f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
end
end
spec.files = Dir[
"lib/**/*",
"LICENSE.txt",
"README.md",
"CHANGELOG.md",
"Gemfile",
"Rakefile",
"ta_lib_ffi.gemspec",
]
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "fiddle", "~> 1.1"
spec.add_development_dependency "byebug", "~> 11.1"
spec.add_development_dependency "rake", "~> 13.2"
spec.add_development_dependency "rspec", "~> 3.13"
spec.add_development_dependency "rubocop-rspec", "~> 3.3"
Expand Down
Loading