fxdatapi 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/.rubocop.yml +16 -0
- data/.rubocop_currensees.yml +390 -0
- data/.rubocop_todo.yml +45 -0
- data/CHANGELOG.md +11 -0
- data/CODEOWNERS +2 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/CONTRIBUTORS +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +76 -0
- data/LICENSE +28 -0
- data/README.md +57 -0
- data/Rakefile +37 -0
- data/fxdatapi.gemspec +30 -0
- data/lib/currensees.rb +17 -0
- data/lib/fxdatapi/auth.rb +27 -0
- data/lib/fxdatapi/convert.rb +37 -0
- data/lib/fxdatapi/convert_all.rb +37 -0
- data/lib/fxdatapi/currencies.rb +47 -0
- data/lib/fxdatapi/daily_average.rb +30 -0
- data/lib/fxdatapi/historical.rb +47 -0
- data/lib/fxdatapi/margins_spreads.rb +47 -0
- data/lib/fxdatapi/monthly_average.rb +30 -0
- data/lib/fxdatapi/performances.rb +47 -0
- data/lib/fxdatapi/signals.rb +47 -0
- data/lib/fxdatapi/version.rb +5 -0
- data/lib/fxdatapi/weekly_average.rb +30 -0
- data/usage_example.rb +115 -0
- metadata +75 -0
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
## Currency API Ruby Gem
|
2
|
+
|
3
|
+
[![Gem](https://img.shields.io/gem/v/fxdatapi)](https://rubygems.org/gems/fxdatapi)
|
4
|
+
[![Build Status](https://github.com/moatsystems/fxdatapi-rb/actions/workflows/ci.yml/badge.svg)](https://github.com/moatsystems/fxdatapi-rb/actions/workflows/ci.yml)
|
5
|
+
|
6
|
+
A Ruby Gem to interact with the [Currency API](https://moatsystems.com/currency-api/).
|
7
|
+
|
8
|
+
[Moat Systems](https://moatsystems.com) provides customers with accurate and up-to-date currency data for making informed decisions in the global financial market, including Gold, Silver and Special Drawing Rights. Our reliable exchange rate data assist businesses in confidently managing foreign transactions, investments and risks. Accounting, E-commerce, CRM, and ERP software companies will find it helpful to integrate with us instead of developing a custom in-house solution.
|
9
|
+
|
10
|
+
### Requirements
|
11
|
+
|
12
|
+
- Ruby: MRI > 2.6+
|
13
|
+
|
14
|
+
### Installation
|
15
|
+
|
16
|
+
You can install the gem manually:
|
17
|
+
|
18
|
+
```shell
|
19
|
+
gem install fxdatapi
|
20
|
+
```
|
21
|
+
|
22
|
+
Or use Bundler and define it as a dependency in your Gemfile:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
gem 'fxdatapi', '~> 0.1.1'
|
26
|
+
```
|
27
|
+
|
28
|
+
### Documentation
|
29
|
+
|
30
|
+
#### Relevant links
|
31
|
+
|
32
|
+
- [Currency API product page](https://moatsystems.com/currency-api/)
|
33
|
+
- [Currency API support documentation](https://docs.fxdatapi.com/)
|
34
|
+
|
35
|
+
### Usage Example
|
36
|
+
|
37
|
+
Remember to update your `username` and `password` inside `usage_example.rb` before executing the command below.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
ruby usage_example.rb
|
41
|
+
```
|
42
|
+
|
43
|
+
### Setting up Currency API Account
|
44
|
+
|
45
|
+
Subscribe [here](https://moatsystems.com/currency-api/) for a user account.
|
46
|
+
|
47
|
+
### Using the Currency API
|
48
|
+
|
49
|
+
You can read the [API documentation](https://docs.fxdatapi.com/) to understand what's possible with the Currency API. If you need further assistance, don't hesitate to [contact us](https://moatsystems.com/contact/).
|
50
|
+
|
51
|
+
### License
|
52
|
+
|
53
|
+
This project is licensed under the [BSD 3-Clause License](./LICENSE).
|
54
|
+
|
55
|
+
### Copyright
|
56
|
+
|
57
|
+
(c) 2020 - 2023 [Moat Systems Limited](https://moatsystems.com).
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
# By default, run tests and linter.
|
4
|
+
task default: [:spec, :rubocop]
|
5
|
+
|
6
|
+
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new do |t|
|
10
|
+
t.verbose = !ENV["VERBOSE"].nil?
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
require 'rubocop/rake_task'
|
15
|
+
|
16
|
+
RuboCop::RakeTask.new
|
17
|
+
|
18
|
+
|
19
|
+
require 'yard'
|
20
|
+
|
21
|
+
YARD::Rake::YardocTask.new(:yardoc) do |y|
|
22
|
+
y.options = ["--output-dir", "yardoc"]
|
23
|
+
end
|
24
|
+
|
25
|
+
namespace :yardoc do
|
26
|
+
task :clobber do
|
27
|
+
rm_r "yardoc" rescue nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
task :clobber => "yardoc:clobber"
|
32
|
+
|
33
|
+
|
34
|
+
desc "Open an irb session preloaded with this library"
|
35
|
+
task :console do
|
36
|
+
sh "irb -r rubygems -I lib -r fxdatapi.rb"
|
37
|
+
end
|
data/fxdatapi.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/fxdatapi/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "fxdatapi"
|
7
|
+
spec.version = Fxdatapi::VERSION
|
8
|
+
spec.authors = ["Finbarrs Oketunji"]
|
9
|
+
spec.email = ["f@finbarrs.eu"]
|
10
|
+
spec.summary = "A Ruby Gem to interact with the Currency API"
|
11
|
+
spec.description = "A Ruby Gem to interact with the Currency API."
|
12
|
+
spec.homepage = "https://github.com/moatsystems/fxdatapi-rb"
|
13
|
+
spec.required_ruby_version = ">= 2.6.0"
|
14
|
+
spec.licenses = ['Nonstandard']
|
15
|
+
spec.extra_rdoc_files = %w(LICENSE)
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/moatsystems/fxdatapi-rb"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/moatsystems/fxdatapi-rb/CHANGLOG.md"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
end
|
data/lib/currensees.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "fxdatapi/version"
|
4
|
+
require_relative "fxdatapi/auth"
|
5
|
+
require_relative "fxdatapi/currencies"
|
6
|
+
require_relative "fxdatapi/historical"
|
7
|
+
require_relative "fxdatapi/margins_spreads"
|
8
|
+
require_relative "fxdatapi/performances"
|
9
|
+
require_relative "fxdatapi/signals"
|
10
|
+
require_relative "fxdatapi/daily_average"
|
11
|
+
require_relative "fxdatapi/weekly_average"
|
12
|
+
require_relative "fxdatapi/monthly_average"
|
13
|
+
require_relative "fxdatapi/convert"
|
14
|
+
require_relative "fxdatapi/convert_all"
|
15
|
+
|
16
|
+
module Fxdatapi
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Fxdatapi
|
7
|
+
class Authentication
|
8
|
+
def self.login(username, password)
|
9
|
+
uri = URI('https://fxdatapi.com/v1/login')
|
10
|
+
request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json', 'Accept' => 'application/json')
|
11
|
+
|
12
|
+
request.body = {
|
13
|
+
username: username,
|
14
|
+
password: password,
|
15
|
+
}.to_json
|
16
|
+
|
17
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
|
18
|
+
|
19
|
+
case response
|
20
|
+
when Net::HTTPSuccess
|
21
|
+
JSON.parse(response.body)
|
22
|
+
else
|
23
|
+
raise "Login failed: #{response.code} #{response.message}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# lib/fxdatapi/convert.rb
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'net/http'
|
6
|
+
require 'json'
|
7
|
+
require_relative 'auth'
|
8
|
+
|
9
|
+
module Fxdatapi
|
10
|
+
class Convert
|
11
|
+
BASE_URL = 'https://fxdatapi.com/v1/convert'
|
12
|
+
|
13
|
+
def self.convert_currency(username, password, date, base_currency, target_currency, amount)
|
14
|
+
login_result = Authentication.login(username, password)
|
15
|
+
cookie = "user_type=#{login_result['user_type']}; username=#{username}"
|
16
|
+
|
17
|
+
uri = URI(BASE_URL)
|
18
|
+
request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'Cookie' => cookie)
|
19
|
+
request.body = {
|
20
|
+
username: username,
|
21
|
+
date: date,
|
22
|
+
base_currency: base_currency,
|
23
|
+
target_currency: target_currency,
|
24
|
+
amount: amount,
|
25
|
+
}.to_json
|
26
|
+
|
27
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
|
28
|
+
|
29
|
+
case response
|
30
|
+
when Net::HTTPSuccess
|
31
|
+
JSON.parse(response.body)
|
32
|
+
else
|
33
|
+
raise "Failed to convert currency: #{response.code} #{response.message}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# lib/fxdatapi/convert_all.rb
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'net/http'
|
6
|
+
require 'json'
|
7
|
+
require_relative 'auth'
|
8
|
+
|
9
|
+
module Fxdatapi
|
10
|
+
class ConvertAll
|
11
|
+
BASE_URL = 'https://fxdatapi.com/v1/convert_all'
|
12
|
+
|
13
|
+
def self.convert_all(username, password, base_currency, amount, date)
|
14
|
+
login_result = Authentication.login(username, password)
|
15
|
+
cookie = "user_type=#{login_result['user_type']}; username=#{username}"
|
16
|
+
|
17
|
+
uri = URI(BASE_URL)
|
18
|
+
request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'Cookie' => cookie)
|
19
|
+
|
20
|
+
request.body = {
|
21
|
+
username: username,
|
22
|
+
base_currency: base_currency,
|
23
|
+
amount: amount,
|
24
|
+
date: date,
|
25
|
+
}.to_json
|
26
|
+
|
27
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
|
28
|
+
|
29
|
+
case response
|
30
|
+
when Net::HTTPSuccess
|
31
|
+
JSON.parse(response.body)
|
32
|
+
else
|
33
|
+
raise "Failed to fetch conversion for all currencies: #{response.code} #{response.message}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# lib/fxdatapi/currencies.rb
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'net/http'
|
6
|
+
require 'json'
|
7
|
+
require_relative 'auth'
|
8
|
+
|
9
|
+
module Fxdatapi
|
10
|
+
class Currencies
|
11
|
+
BASE_URL = 'https://fxdatapi.com/v1/currencies'
|
12
|
+
|
13
|
+
def self.get_currencies(username, password, day, month, year)
|
14
|
+
login_result = Authentication.login(username, password)
|
15
|
+
cookie = "user_type=#{login_result['user_type']}; username=#{username}"
|
16
|
+
|
17
|
+
uri = URI("#{BASE_URL}?username=#{username}&day=#{day}&month=#{month}&year=#{year}")
|
18
|
+
request = Net::HTTP::Get.new(uri, 'Accept' => 'application/json', 'Cookie' => cookie)
|
19
|
+
|
20
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
|
21
|
+
|
22
|
+
case response
|
23
|
+
when Net::HTTPSuccess
|
24
|
+
JSON.parse(response.body)
|
25
|
+
else
|
26
|
+
raise "Failed to fetch currencies: #{response.code} #{response.message}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get_currency_by_uuid(username, password, uuid, day, month, year)
|
31
|
+
login_result = Authentication.login(username, password)
|
32
|
+
cookie = "user_type=#{login_result['user_type']}; username=#{username}"
|
33
|
+
|
34
|
+
uri = URI("#{BASE_URL}/#{uuid}?username=#{username}&day=#{day}&month=#{month}&year=#{year}")
|
35
|
+
request = Net::HTTP::Get.new(uri, 'Accept' => 'application/json', 'Cookie' => cookie)
|
36
|
+
|
37
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
|
38
|
+
|
39
|
+
case response
|
40
|
+
when Net::HTTPSuccess
|
41
|
+
JSON.parse(response.body)
|
42
|
+
else
|
43
|
+
raise "Failed to fetch currency by uuid: #{response.code} #{response.message}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# lib/fxdatapi/daily_average.rb
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'net/http'
|
6
|
+
require 'json'
|
7
|
+
require_relative 'auth'
|
8
|
+
|
9
|
+
module Fxdatapi
|
10
|
+
class DailyAverage
|
11
|
+
BASE_URL = 'https://fxdatapi.com/v1/daily_average'
|
12
|
+
|
13
|
+
def self.get_daily_average(username, password, date)
|
14
|
+
login_result = Authentication.login(username, password)
|
15
|
+
cookie = "user_type=#{login_result['user_type']}; username=#{username}"
|
16
|
+
|
17
|
+
uri = URI("#{BASE_URL}/#{date}")
|
18
|
+
request = Net::HTTP::Get.new(uri, 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'Cookie' => cookie)
|
19
|
+
|
20
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
|
21
|
+
|
22
|
+
case response
|
23
|
+
when Net::HTTPSuccess
|
24
|
+
JSON.parse(response.body)
|
25
|
+
else
|
26
|
+
raise "Failed to fetch daily average: #{response.code} #{response.message}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# lib/fxdatapi/historical.rb
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'net/http'
|
6
|
+
require 'json'
|
7
|
+
require_relative 'auth'
|
8
|
+
|
9
|
+
module Fxdatapi
|
10
|
+
class Historical
|
11
|
+
BASE_URL = 'https://fxdatapi.com/v1/historical'
|
12
|
+
|
13
|
+
def self.get_historical_data(username, password, date, day, month, year)
|
14
|
+
login_result = Authentication.login(username, password)
|
15
|
+
cookie = "user_type=#{login_result['user_type']}; username=#{username}"
|
16
|
+
|
17
|
+
uri = URI("#{BASE_URL}?username=#{username}&date=#{date}&day=#{day}&month=#{month}&year=#{year}")
|
18
|
+
request = Net::HTTP::Get.new(uri, 'Accept' => 'application/json', 'Cookie' => cookie)
|
19
|
+
|
20
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
|
21
|
+
|
22
|
+
case response
|
23
|
+
when Net::HTTPSuccess
|
24
|
+
JSON.parse(response.body)
|
25
|
+
else
|
26
|
+
raise "Failed to fetch historical data: #{response.code} #{response.message}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get_historical_data_by_id(username, password, data_id, date_string, day, month, year)
|
31
|
+
login_result = Authentication.login(username, password)
|
32
|
+
cookie = "user_type=#{login_result['user_type']}; username=#{username}"
|
33
|
+
|
34
|
+
uri = URI("#{BASE_URL}/#{data_id}?username=#{username}&date_string=#{date_string}&day=#{day}&month=#{month}&year=#{year}")
|
35
|
+
request = Net::HTTP::Get.new(uri, 'Accept' => 'application/json', 'Cookie' => cookie)
|
36
|
+
|
37
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
|
38
|
+
|
39
|
+
case response
|
40
|
+
when Net::HTTPSuccess
|
41
|
+
JSON.parse(response.body)
|
42
|
+
else
|
43
|
+
raise "Failed to fetch historical data by ID: #{response.code} #{response.message}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# lib/fxdatapi/margins_spreads.rb
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'net/http'
|
6
|
+
require 'json'
|
7
|
+
require_relative 'auth'
|
8
|
+
|
9
|
+
module Fxdatapi
|
10
|
+
class MarginsSpreads
|
11
|
+
BASE_URL = 'https://fxdatapi.com/v1/margins_spreads'
|
12
|
+
|
13
|
+
def self.get_margins_spreads(username, password, day, month, year)
|
14
|
+
login_result = Authentication.login(username, password)
|
15
|
+
cookie = "user_type=#{login_result['user_type']}; username=#{username}"
|
16
|
+
|
17
|
+
uri = URI("#{BASE_URL}?username=#{username}&day=#{day}&month=#{month}&year=#{year}")
|
18
|
+
request = Net::HTTP::Get.new(uri, 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'Cookie' => cookie)
|
19
|
+
|
20
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
|
21
|
+
|
22
|
+
case response
|
23
|
+
when Net::HTTPSuccess
|
24
|
+
JSON.parse(response.body)
|
25
|
+
else
|
26
|
+
raise "Failed to fetch margins and spreads: #{response.code} #{response.message}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get_margin_spread_by_uuid(username, password, uuid, day, month, year)
|
31
|
+
login_result = Authentication.login(username, password)
|
32
|
+
cookie = "user_type=#{login_result['user_type']}; username=#{username}"
|
33
|
+
|
34
|
+
uri = URI("#{BASE_URL}/#{uuid}?username=#{username}&day=#{day}&month=#{month}&year=#{year}")
|
35
|
+
request = Net::HTTP::Get.new(uri, 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'Cookie' => cookie)
|
36
|
+
|
37
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
|
38
|
+
|
39
|
+
case response
|
40
|
+
when Net::HTTPSuccess
|
41
|
+
JSON.parse(response.body)
|
42
|
+
else
|
43
|
+
raise "Failed to fetch margin and spread by uuid: #{response.code} #{response.message}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# lib/fxdatapi/monthly_average.rb
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'net/http'
|
6
|
+
require 'json'
|
7
|
+
require_relative 'auth'
|
8
|
+
|
9
|
+
module Fxdatapi
|
10
|
+
class MonthlyAverage
|
11
|
+
BASE_URL = 'https://fxdatapi.com/v1/monthly_average'
|
12
|
+
|
13
|
+
def self.get_monthly_average(username, password, year, month)
|
14
|
+
login_result = Authentication.login(username, password)
|
15
|
+
cookie = "user_type=#{login_result['user_type']}; username=#{username}"
|
16
|
+
|
17
|
+
uri = URI("#{BASE_URL}/#{year}/#{month}")
|
18
|
+
request = Net::HTTP::Get.new(uri, 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'Cookie' => cookie)
|
19
|
+
|
20
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
|
21
|
+
|
22
|
+
case response
|
23
|
+
when Net::HTTPSuccess
|
24
|
+
JSON.parse(response.body)
|
25
|
+
else
|
26
|
+
raise "Failed to fetch monthly average data: #{response.code} #{response.message}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# lib/fxdatapi/performances.rb
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'net/http'
|
6
|
+
require 'json'
|
7
|
+
require_relative 'auth'
|
8
|
+
|
9
|
+
module Fxdatapi
|
10
|
+
class Performances
|
11
|
+
BASE_URL = 'https://fxdatapi.com/v1/performances'
|
12
|
+
|
13
|
+
def self.get_performances(username, password)
|
14
|
+
login_result = Authentication.login(username, password)
|
15
|
+
cookie = "user_type=#{login_result['user_type']}; username=#{username}"
|
16
|
+
|
17
|
+
uri = URI("#{BASE_URL}?username=#{username}")
|
18
|
+
request = Net::HTTP::Get.new(uri, 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'Cookie' => cookie)
|
19
|
+
|
20
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
|
21
|
+
|
22
|
+
case response
|
23
|
+
when Net::HTTPSuccess
|
24
|
+
JSON.parse(response.body)
|
25
|
+
else
|
26
|
+
raise "Failed to fetch performances: #{response.code} #{response.message}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get_performance_by_id(username, password, performance_id)
|
31
|
+
login_result = Authentication.login(username, password)
|
32
|
+
cookie = "user_type=#{login_result['user_type']}; username=#{username}"
|
33
|
+
|
34
|
+
uri = URI("#{BASE_URL}/#{performance_id}?username=#{username}")
|
35
|
+
request = Net::HTTP::Get.new(uri, 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'Cookie' => cookie)
|
36
|
+
|
37
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
|
38
|
+
|
39
|
+
case response
|
40
|
+
when Net::HTTPSuccess
|
41
|
+
JSON.parse(response.body)
|
42
|
+
else
|
43
|
+
raise "Failed to fetch performance by ID: #{response.code} #{response.message}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# lib/fxdatapi/signals.rb
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'net/http'
|
6
|
+
require 'json'
|
7
|
+
require_relative 'auth'
|
8
|
+
|
9
|
+
module Fxdatapi
|
10
|
+
class Signals
|
11
|
+
BASE_URL = 'https://fxdatapi.com/v1/signals'
|
12
|
+
|
13
|
+
def self.get_signals(username, password)
|
14
|
+
login_result = Authentication.login(username, password)
|
15
|
+
cookie = "user_type=#{login_result['user_type']}; username=#{username}"
|
16
|
+
|
17
|
+
uri = URI("#{BASE_URL}?username=#{username}")
|
18
|
+
request = Net::HTTP::Get.new(uri, 'Accept' => 'application/json', 'Cookie' => cookie)
|
19
|
+
|
20
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
|
21
|
+
|
22
|
+
case response
|
23
|
+
when Net::HTTPSuccess
|
24
|
+
JSON.parse(response.body)
|
25
|
+
else
|
26
|
+
raise "Failed to fetch signals: #{response.code} #{response.message}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get_signal_by_id(username, password, signal_id)
|
31
|
+
login_result = Authentication.login(username, password)
|
32
|
+
cookie = "user_type=#{login_result['user_type']}; username=#{username}"
|
33
|
+
|
34
|
+
uri = URI("#{BASE_URL}/#{signal_id}?username=#{username}")
|
35
|
+
request = Net::HTTP::Get.new(uri, 'Accept' => 'application/json', 'Cookie' => cookie)
|
36
|
+
|
37
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
|
38
|
+
|
39
|
+
case response
|
40
|
+
when Net::HTTPSuccess
|
41
|
+
JSON.parse(response.body)
|
42
|
+
else
|
43
|
+
raise "Failed to fetch signal by id: #{response.code} #{response.message}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# lib/fxdatapi/weekly_average.rb
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'net/http'
|
6
|
+
require 'json'
|
7
|
+
require_relative 'auth'
|
8
|
+
|
9
|
+
module Fxdatapi
|
10
|
+
class WeeklyAverage
|
11
|
+
BASE_URL = 'https://fxdatapi.com/v1/weekly_average'
|
12
|
+
|
13
|
+
def self.get_weekly_average(username, password, from_date, to_date)
|
14
|
+
login_result = Authentication.login(username, password)
|
15
|
+
cookie = "user_type=#{login_result['user_type']}; username=#{username}"
|
16
|
+
|
17
|
+
uri = URI("#{BASE_URL}/#{from_date}/#{to_date}")
|
18
|
+
request = Net::HTTP::Get.new(uri, 'Accept' => 'application/json', 'Cookie' => cookie)
|
19
|
+
|
20
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
|
21
|
+
|
22
|
+
case response
|
23
|
+
when Net::HTTPSuccess
|
24
|
+
JSON.parse(response.body)
|
25
|
+
else
|
26
|
+
raise "Failed to fetch weekly average data: #{response.code} #{response.message}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|