Project

dtn

0.0
The project is in a healthy, maintained state
Easy way tp access data from DTN (IQfeed).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
 Dependencies

Runtime

~> 2.4.0
 Project Readme

CircleCI Gem Version Reviewed by Hound Maintainability Test Coverage

Dtn

Unofficial DTN (IQFeed) client.

Dependencies

  • IQFeed client ~> 6.1

Installation

Add this line to your application's Gemfile:

gem 'dtn'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install dtn

Usage

Quick start

Dtn::Lookups::Historical::DailyTimeframe.call(
    symbol: :aapl,
    begin_date: Date.new(2021, 05, 01),
    end_date: Date.new(2021, 06, 01)
    )

=>
#<Dtn::Messages::Historical::DailyWeeklyMonthly request_id=1, timestamp=Mon, 03 May 2021 18:06:37 +0000, high=134.07, low=131.83, open=132.04, close=132.54, period_volume=75135100, open_interest=0>
#<Dtn::Messages::Historical::DailyWeeklyMonthly request_id=1, timestamp=Tue, 04 May 2021 18:06:37 +0000, high=131.4899, low=126.7, open=131.19, close=127.85, period_volume=137564718, open_interest=0>
#<Dtn::Messages::Historical::DailyWeeklyMonthly request_id=1, timestamp=Wed, 05 May 2021 18:06:37 +0000, high=130.45, low=127.97, open=129.2, close=128.1, period_volume=84000900, open_interest=0>
#<Dtn::Messages::Historical::DailyWeeklyMonthly request_id=1, timestamp=Thu, 06 May 2021 18:06:37 +0000, high=129.75, low=127.13, open=127.89, close=129.74, period_volume=78128334, open_interest=0>
...

# if block provided, then each message will be yielded as it is processed

Dtn::Lookups::News::Headline.call(limit: 10) do |message|
  # ...
end

Supported requests

Keep in mind, that at the moment os this writing DTN API has limit of 50 historical requests per minute.

TODO: Attach limiter gem after merge https://github.com/Shopify/limiter/pull/17 https://github.com/Shopify/limiter/pull/19 or use own branch of this gem.

News

Dtn::Lookups::News::Config.call
Dtn::Lookups::News::Headline.call limit: 10, symbols: 'aapl;fb'
Dtn::Lookups::News::StoryCount.call symbols: :aapl, date_range: Date.new(2020,1,1)..Date.new(2020,2,1)
Dtn::Lookups::News::Story.call story_id: '22424363689'

NOTES:

  • if XML output option selected, the response will return unparsed XML

Historical

Dtn::Lookups::Historical::IntervalDay.call(symbol: :aapl, interval: 3600, max_datapoints: 50, days: 2)
Dtn::Lookups::Historical::TickTimeframe.call(
              symbol: :aapl,
              begin_datetime: begin_datetime,
              end_datetime: end_datetime,
              max_datapoints: 50
            )
Dtn::Lookups::Historical::DailyDatapoint.call(symbol: :aapl, max_datapoints: 50)
Dtn::Lookups::Historical::IntervalTimeframe.call(
              symbol: :aapl,
              interval: 15,
              max_datapoints: 50,
              begin_datetime: DateTime.new(2020,05,01),
              end_datetime: DateTime.new(2020,06,01)
            )
Dtn::Lookups::Historical::TickDatapoint.call(symbol: :aapl, max_datapoints: 100)
Dtn::Lookups::Historical::WeeklyDatapoint.call(symbol: :aapl, max_datapoints: 10)
Dtn::Lookups::Historical::DailyTimeframe.call(
              symbol: :aapl,
              begin_date: Date.new(2020,05,01),
              end_date: Date.new(2020,06,01)
            )
Dtn::Lookups::Historical::IntervalDatapoint.call(symbol: :aapl, interval: 3600, max_datapoints: 100)
Dtn::Lookups::Historical::MonthlyDatapoint.call(symbol: :aapl, max_datapoints: 10)
Dtn::Lookups::Historical::TickDay.call(symbol: :aapl, days: 2, max_datapoints: 50)

NOTES:

  • Lookups have extra options from their parents classes. They have appropriate defaults and are easy to customize.

Catalogs

For symbol lookup and description API use a few catalogs, which describe each row. They very rarely change and we can treat them as constants. To reduce requests to API they are requested only once. For easy access to them you can use:

  • Dtn.listed_markets_catalog
  • Dtn.naic_codes_catalog
  • Dtn.security_types_catalog
  • Dtn.sic_codes_catalog
  • Dtn.trade_conditions_catalog

Symbol lookup

Dtn::Lookups::Symbol::BySic.call(search_line: '42')
Dtn::Lookups::Symbol::ByNaic.call(search_line: '42')
Dtn::Lookups::Symbol::ByFilter.call(field_to_search: "s", search_line: "aap", filter_type: "t", filter_value: "1")

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bundle exec rake to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Test specs are using recorded output from DTN client. The recorded file is set by the RSpec option socket_recorder, so you can share 1 recording with a few specs. If the file is missing, then specs will do real request to the api. socket_recorder will use the pre-defined Date for the specs from the file current_day to minimise recordings rewrites. To bump the date to the yesterday business day you can use

$ bundle exec rake spec:set_spec_date

To run the client you can use the docker-compose up (before execution pls fill in .env file with your credentials following the pattern from .env.example)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/kvokka/dtn. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Dtn project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.