Class: Moex::Api

Inherits:
Object
  • Object
show all
Defined in:
app/lib/moex/api.rb

Overview

Moscow Exchange public api

Constant Summary collapse

BASE_URL =
"https://iss.moex.com/iss"

Instance Method Summary collapse

Instance Method Details

#history_engine_market_securities(engine, market, date, start: 0, lang: "en") ⇒ Array<Hash>

Get market data for all assets on a specific date

Parameters:

  • engine (String)

    engine name, `stock`, for sample (see #index)

  • market (String)

    market name, `shares`, for sample (see #index)

  • date (#to_s)

    date, `2019-10-16`, for sample

  • lang ("ru", "en") (defaults to: "en")

    language

Returns:

  • (Array<Hash>)

    market data for all assets in given conditions

See Also:


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/lib/moex/api.rb', line 18

def history_engine_market_securities(
  engine, market, date, start: 0, lang: "en"
)
  response = RestClient.get(
    "#{BASE_URL}/history/engines/#{engine}/markets/#{market
    }/securities.json",
    params: { date: date, start: start, lang: lang, "iss.json" => "extended",
              "iss.meta" => "off" }
  )
  result = JSON.parse(response.body).last
  cursor = result["history.cursor"].last
  history = result["history"]
  return history if cursor["INDEX"] + cursor["PAGESIZE"] >= cursor["TOTAL"]
  history + history_engine_market_securities(
    engine, market, date, start: start + cursor["PAGESIZE"], lang: lang
  )
end

#index(lang: "en") ⇒ Hash

Get references: engines, markets, boards, boardgroups, durations, securitytypes, securitygroups, securitycollections

Parameters:

  • lang ("ru", "en") (defaults to: "en")

    language

Returns:

  • (Hash)

    references

See Also:


42
43
44
45
46
47
48
# File 'app/lib/moex/api.rb', line 42

def index(lang: "en")
  response = RestClient.get(
    "#{BASE_URL}/index.json",
    params: { "iss.json" => "extended", "iss.meta" => "off", lang: lang }
  )
  JSON.parse(response.body).last
end