Skip to content
This repository was archived by the owner on Jul 3, 2023. It is now read-only.
Open
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
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ build-iPhoneSimulator/

# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
# .ruby-version
# .ruby-gemset
Gemfile.lock
.ruby-version
.ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc

# Used by RuboCop. Remote config files pulled in from inherit_from directive.
# .rubocop-https?--*

# Ruby Gemfile.lock
*.lock

12 changes: 0 additions & 12 deletions .rspec_status

This file was deleted.

3 changes: 0 additions & 3 deletions .rubocop.yml

This file was deleted.

22 changes: 0 additions & 22 deletions .rubocop_todo.yml

This file was deleted.

1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

44 changes: 17 additions & 27 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
## [1.0.0-dev]

## [Unreleased]
Testing changes before merge.

- Prepare `version-0.4.1` to be ready for Open Source under MIT license.
- Removed gem `colorize` because of GPLv2.
- Override String class with color codes for Linux.
**About:**

## [0.4.0] - 2022-01-24
- Allow multiple sources
- Class-Template based - easy to add more APIs
- New sources are automatically required and added to `.gemspec`
- Each source can be required alone
- List helper - list available sources (required in gem)
- Cli helper - print colorized output (required only in executable)
- Save prices in `.csv` table
- Extract all data in `.json` file

- Add options `--loop` and `--wait` for terminal scripting
- Only signed and verified commits from `v-0.4.0`
- PGP Public key available at https://www.github.com/alx3dev/contact
- Before `v-0.4.0` unverified commits were pushed.
- From now on, only VERIFIED signed commits should be trusted
**Security:**

-----BEGIN PGP SIGNATURE-----
- `CTFC::Client` use `eval` - to call source class to extract data. Only source name is dinamic, and we check for persistence of source class before evaluation. There's no place for malicious use.

iQIzBAEBCgAdFiEEtl+v9iZj5AyyvRYdTFhE2vUGMucFAmHvxM0ACgkQTFhE2vUG
MuejCQ//Uw+xaFBNrat3evChlifrxAckEqhtQeUwiuluSkReYmV+TqdSNqhzzezh
BJkgp5d7/Lzt/7wCwK9aVuvejKG0op4Ernk1jRH7jdOkH7TeqVyRe8837XXbn8Q3
FRh5ih/dbbeQtvIVuI1Z7unRQGvlfMnBKK65wQfHRffJg3kTgO4ICx0Gz1LgxfCa
OwjSYp2+pXQtGOI+ab9/a7avBb6TIW5uQjegZ5LsVR/at3RySki8v1fOA0Tfmsgv
pZ4aKhZkpVhZ2l6fj181hBwBspmJPxpB8v4mZXhXAfe9z/425favlfyKLxRvmFu5
aQK6hZ/gTEXz2s0ypVVPtwQS5FK3YurhKeun6Vto1lQJM10MngwB53B18eNSAB3h
tsFks8QojwtPH2nttksWOKy5V5tQdBB0uCd72DdEwnAOo1jyMhG7Otkpt4ch5CAd
xRhmrC0Pp1GgqH2avpeezA3uQZ2HW2Gp1nFnKHeRhPutEBF8x8NLjCxbS3GExrgk
+Lijy13Eu/y4f2S7TIfN/LMB+ruqQrZe+NmzE8J1tuMcaDqIYsV17c5FXvaxGS/q
9mJ++v6xHfMykvCNR/FtuUxq+TaD/aNBm+pKYhjqzr4jmoAy2h1gvQEIl4OMXxlf
5xzgdP6ePWkdwWnYvMtrIbkVWfKvfaBUgYsT/+FRVDierWq2aj0=
=/ZSG
-----END PGP SIGNATURE-----
- Example of eval use in CTFC - call source class to extract data:

```ruby
eval "CTFC::API::#{source_class} if List.sources.include? source_class"
```
179 changes: 1 addition & 178 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,178 +1 @@
[**NOTE:**](https://www.github.com/alx3dev/ctfc/LICENSE_DEPENDENCIES.md)
>Removed gem `colorize` to allow **MIT** license.
>All comits from `v-0.4.0` must be signed and tagged **verified**.


# About
Convert any crypto to fiat currency, gather all data and/or save in `.csv` table.
For now only prices are printed/saved, while all data remain easily accessible from variable (for developers).


# How to install
Make sure you have ruby and git installed

Install from source:
```bash
git clone https://github.com/alx3dev/ctfc.git
cd ctfc && bundle install
```

Install from rubygems:

```bash
gem install ctfc
```
# How to run
- **Read documentation on:** https://rubydoc.info/gems/ctfc/CTFC/Data

```bash
ruby bin/ctfc fiat_1 fiat_2 fiat_3
```

This command also accept multiple arguments:

- `--no-save` - do not save `.csv.` output
- `--no-print` - do not print terminal output
- `--coins` - coins to scrap (default: BTC, LTC, XMR, ETH, BCH, ZEC )
- `--loop` - repeat script N times (default 1)
- `--wait` - wait N seconds between loops (default 0)
- `--help` - help menu


# Script Examples
1 - Run script without arguments (default options)

```ruby
ruby bin/ctfc

=> return:
print EUR rates for default coins (BTC, LTC, XMR, ETH, BCH, ZEC)
do not save '.csv' table
```


2 - Add fiat currencies as arguments

```ruby
ruby bin/ctfc eur usd rsd

=> return:
print EUR, USD, RSD rates for default coins
save data in '.csv' table with pattern: 'crypto_#{CURRENCY}.csv'
-> './crypto_eur.csv', './crypto_usd.csv', './crypto_rsd.csv'
```

3 - Use `--no-save`, `--no-print`, `--loop`, `--wait`

```ruby
ruby bin/ctfc eur --no-print --coins btc xmr ltc

=> return:
save EUR rates for BTC, XMR and LTC
do not print output


ruby bin/ctfc rsd --no-save --coins btc xmr

=> return:
print RSD rates for BTC and XMR


# added in version 0.4.0
ruby bin/ctfc rsd --no-print --loop 1440 --wait 60

=> return:
save RSD rates without print, run each minute for 24 hours
```


# Developer Examples
```ruby
# define coins to scrap
COINS = %w[ BTC XMR LTC ETH ]

# initialize Data class
@data = Ctfc.new :eur, save: false, print: false, coins: COINS
=> return Ctfc object to work with
-> #<Ctfc:0x000055b5c8b61a38 @coins=["BTC", "LTC", "XMR", "ETH", "BCH", "ZEC"], @fiat="EUR", @print=true, @save=true>

# execute request
@data.get
=> return Hash with upcase string coins as keys, and float prices
-> {"BTC"=>36760.11, "XMR"=>169.55, "LTC"=>114.4, "ETH"=>2746.22}

# now you can use ::Data instance methods
@data.response
=> return RestClient response to cryptocomare API
-> <RestClient::Response 200 "{\"RAW\":{\"BT...">

# check request url
@data.url
=> return Cryptocompare API url
-> "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=BTC&fsyms=LTC&fsyms=XMR&fsyms=ETH&fsyms=BCH&fsyms=ZEC&tsyms=EUR"

# name of csv table (saved in working directory)
@data.table
=> return '.csv' table name
-> 'ctfc_eur.csv'

# array of coins to work with
@data.coins
=> return coins for scrap, also allow setter method @data.coins = [...]
-> ['BTC', 'XMR', 'LTC', 'ETH']

# get all data about all coins (json api response)
@data.data
=> return all data returned by cryptocompare API
-> {"RAW"=>
{"BTC"=>
{"EUR"=>
{"TYPE"=>"5",
"MARKET"=>"CCCAGG",
"FROMSYMBOL"=>"BTC",
"TOSYMBOL"=>"EUR",
"FLAGS"=>"2049",
"PRICE"=>33851.17,
"LASTUPDATE"=>1642773847,
"MEDIAN"=>33853.8,
"LASTVOLUME"=>0.1,
"LASTVOLUMETO"=>3384.3676,
"LASTTRADEID"=>"2024043",
... ... ... ... ... ... ...


TO BE CONTINIUED ...
```

**Class methods as shortcuts:**

```ruby
# get default coins in EUR, save output without printing
prices = Ctfc.to :eur, print: false

# get default coins in RSD, print output, don't save
Ctfc.to :rsd, save: false

# For those who don't like name `Ctfc`, you can use `Crypto` too:
prices = Crypto.to :eur, coins: %w[BTC XMR]
```

# Tests
To run tests call `rspec --format doc`
To test code syntax use `./check-syntax.sh`.
This command will run rubocop for code inspection, but with some errors hidden by `.rubocop_todo.yml`. Using check-syntax script, all test should pass.


# Contribution
Any contribution is highly appreciated, as long as you follow Code of Conduct.

- Fork repository
- Make your changes
- Write tests
- Submit pull request

# License
Don't be a dick - it's MIT.

# To-Do:
See **Projects**
This is development branch, testing code before merge.
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#/usr/bin/env ruby
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'pry'
Expand Down
54 changes: 25 additions & 29 deletions bin/ctfc
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require_relative '../lib/ctfc'
require 'optimist'
require_relative '../lib/ctfc'
require_relative '../lib/ctfc/helpers/cli'

COINS = %w[BTC XMR ETH LTC].freeze

opts = Optimist.options do
version "Crypto To Fiat Currency\n".cyan.bold \
+ "Gem Version: #{CTFC::VERSION}"
version "Crypto To Fiat Currency\nGem Version: #{CTFC::VERSION}"

banner ''
banner ' Enter fiat currencies with/out additional arguments:'
Expand All @@ -15,44 +17,38 @@ opts = Optimist.options do
banner ' ruby bin/ctfc eur usd --no-save --coins btc xmr ltc'
banner ''

opt :coins, 'Set crypto coins', default: CTFC::CONFIG::COINS
opt :no_save, "Do not save '.csv' output"
opt :no_print, 'Do not print terminal output'
opt :loop, 'Run script N times', default: 1, type: :integer
opt :wait, 'Wait N seconds between loop', default: 0, type: :integer
opt :coins, 'Set crypto coins', default: COINS
opt :save, "Save prices in '.csv' table", default: false
opt :export, "Export all data in '.json' file", default: false
opt :no_print, 'Do not print terminal output', default: false
opt :source, 'Set source to extract data', default: 'cryptocompare'
opt :loop, 'Run script N times', default: 1, type: :integer
opt :wait, 'Wait N seconds between loop', default: 0, type: :integer
end

coins = opts[:coins]
save = opts[:no_save] ? false : true
print = opts[:no_print] ? false : true

@crypto = Ctfc.new
coins = opts[:coins]
source = opts[:source]
save = opts[:save]
export = opts[:export]
print = true unless opts[:no_print]

if ARGV.empty?

# default behavior without arguments - change to suit your needs
@crypto.get(:eur, save: false, print: true, coins: coins)

prices = Crypto.to :usd, coins, source.to_sym, save: save, export: export
Cli.print_output :USD, prices if print
else

opts[:loop].times do
ARGV.each do |fiat|
next if opts.include?(fiat.downcase)
# in Ruby 3.1: @crypto.get(fiat, save:, print:, coins:)
@crypto.get(fiat,
save: save,
print: print,
coins: coins)
sleep 1 # wait between requests

prices = Crypto.to fiat, coins, source.to_sym, save: save, export: export
next unless print

system 'clear' or system 'cls'
Cli.print_output fiat, prices
end

# end if no `--loop` arg
next unless opts[:loop] > 1

# pause between loops
sleep opts[:wait]

# clear screan - depending on OS
system 'clear' or system 'cls'
end
end
Loading