From 4b35f7c2c3edc5c2fc8a9198dca3cd4031ecc2ed Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Sat, 25 Jul 2020 01:35:31 +0300 Subject: Initial --- main.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 main.go (limited to 'main.go') diff --git a/main.go b/main.go new file mode 100644 index 0000000..bb867cb --- /dev/null +++ b/main.go @@ -0,0 +1,42 @@ +package main + +import "log" + +const ( + OFZ_URL = `https://iss.moex.com/iss/engines/stock/markets/bonds/boards/TQOB/securities.xml?iss.meta=off&iss.only=securities&securities.columns=SECID,NEXTCOUPON,COUPONVALUE,SECNAME,COUPONPERCENT,MATDATE,COUPONPERIOD` + CORP_URL = `https://iss.moex.com/iss/engines/stock/markets/bonds/boards/TQCB/securities.xml?iss.meta=off&iss.only=securities&securities.columns=SECID,NEXTCOUPON,COUPONVALUE,SECNAME,COUPONPERCENT,MATDATE,COUPONPERIOD` +) + +func main() { + d1, err := processFile(OFZ_URL) + if err != nil { + log.Fatal(err) + } + if err := export("офз.csv", d1); err != nil { + log.Fatal(err) + } + d2, err := processFile(CORP_URL) + if err != nil { + log.Fatal(err) + } + if err := export("корп.csv", d2); err != nil { + log.Fatal(err) + } +} + +func processFile(url string) ([]*Document, error) { + in, err := download(url) + if err != nil { + return nil, err + } + var documents []*Document + for _, item := range in.Data.Rows.Items { + d, err := parse(item) + if err != nil { + log.Println(err) + continue + } + documents = append(documents, d) + } + return documents, nil +} -- cgit v1.2.3