-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af7122c
commit 3834570
Showing
9 changed files
with
225 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ module Xtb | |
h1: 60, | ||
h4: 240, | ||
d1: 1440, | ||
w1: 10080, | ||
mn1: 43200 | ||
w1: 10_080, | ||
mn1: 43_200 | ||
}.freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
module Xtb | ||
module Http | ||
# http://developers.xstore.pro/documentation/current#getChartRangeRequest | ||
class ChartRangeRequest < Command | ||
RateInfoRecord = Data.define(:close, :ctm, :ctm_string, :high, :low, :open, :vol) | ||
ChartLastRequestResponse = Data.define(:digits, :rate_infos) | ||
|
||
# @param end_time [Time] End of chart block | ||
# @param period [Xtb::Period] Period code | ||
# @param start_time [Time] Start of chart block | ||
# @param symbol [String|Symbol] Symbol | ||
# @param ticks [Integer] (Optional) Number of ticks needed | ||
def initialize(end_time, period, start_time, symbol, ticks: nil) | ||
@end_time = end_time | ||
@period = period | ||
@start_time = start_time | ||
@symbol = symbol | ||
@ticks = ticks | ||
end | ||
|
||
def call | ||
digits, rate_infos = super.values_at(:digits, :rate_infos) | ||
rate_infos = rate_infos.map { |record| RateInfoRecord.new(**record) } | ||
ChartLastRequestResponse.new(digits:, rate_infos:) | ||
end | ||
|
||
private | ||
|
||
attr_reader :end_time, :period, :start_time, :symbol, :ticks | ||
|
||
def command = :getChartRangeRequest | ||
|
||
def arguments | ||
{ | ||
info: | ||
{ | ||
end: end_time, | ||
period:, | ||
start: start_time, | ||
symbol:, | ||
ticks: | ||
}.compact | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Xtb::Http::ChartRangeRequest do | ||
subject(:command) { described_class.new(end_time, period, start_time, symbol) } | ||
|
||
let(:end_time) { 1_272_529_161_605 } | ||
let(:period) { Xtb::Period[:m5] } | ||
let(:start_time) { 1_272_529_161_605 } | ||
let(:symbol) { 'KOMB.CZ' } | ||
|
||
let(:request) do | ||
{ | ||
command: :getChartRangeRequest, | ||
arguments: { | ||
info: { | ||
end: end_time, | ||
period: 5, | ||
start: start_time, | ||
symbol: symbol | ||
} | ||
} | ||
} | ||
end | ||
let(:response) do | ||
JSON.dump( | ||
{ | ||
'status': true, | ||
'return_data': { | ||
'digits': 4, | ||
'rateInfos': [ | ||
{ | ||
"close": 1.0, | ||
"ctm": 1_389_362_640_000, | ||
"ctmString": 'Jan 10, 2014 3:04:00 PM', | ||
"high": 6.0, | ||
"low": 0.0, | ||
"open": 41_848.0, | ||
"vol": 0.0 | ||
} | ||
] | ||
} | ||
} | ||
) | ||
end | ||
|
||
describe '#call' do | ||
specify do | ||
expect(Xtb::Http::SslClient) | ||
.to receive(:request) | ||
.with(JSON.dump(request)) | ||
.and_return(response) | ||
expect(command.call) | ||
.to have_attributes( | ||
digits: 4, | ||
rate_infos: [ | ||
have_attributes( | ||
close: 1.0, | ||
ctm: 1_389_362_640_000, | ||
ctm_string: 'Jan 10, 2014 3:04:00 PM', | ||
high: 6.0, | ||
low: 0.0, | ||
open: 41_848.0, | ||
vol: 0.0 | ||
) | ||
] | ||
) | ||
end | ||
|
||
context 'with ticks argument' do | ||
subject(:command) { described_class.new(end_time, period, start_time, symbol, ticks:) } | ||
|
||
let(:ticks) { 100 } | ||
|
||
let(:request) do | ||
{ | ||
command: :getChartRangeRequest, | ||
arguments: { | ||
info: { | ||
end: end_time, | ||
period: 5, | ||
start: start_time, | ||
symbol: symbol, | ||
ticks: | ||
} | ||
} | ||
} | ||
end | ||
|
||
specify do | ||
expect(Xtb::Http::SslClient) | ||
.to receive(:request) | ||
.with(JSON.dump(request)) | ||
.and_return(response) | ||
expect(command.call) | ||
.to have_attributes( | ||
digits: 4, | ||
rate_infos: [ | ||
have_attributes( | ||
close: 1.0, | ||
ctm: 1_389_362_640_000, | ||
ctm_string: 'Jan 10, 2014 3:04:00 PM', | ||
high: 6.0, | ||
low: 0.0, | ||
open: 41_848.0, | ||
vol: 0.0 | ||
) | ||
] | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters