• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

OmegaChartのソースコードの保守


Commit MetaInfo

修訂ef641739ac92a13ce42dd93111b2918da1e728c1 (tree)
時間2014-03-19 19:16:53
作者panacoran <panacoran@user...>
Commiterpanacoran

Log Message

株価データを http://k-db.com/site/default.aspx からダウンロードする

Change Summary

差異

--- a/DownloadOrder.cs
+++ b/DownloadOrder.cs
@@ -140,12 +140,9 @@ namespace Zanetti.DataSource
140140 throw new NotSupportedException("全銘柄一括ダウンロードはサポートされていません。");
141141 case StockDownload.Bookmark:
142142 throw new NotSupportedException("ブックマーク内のダウンロードはサポートされていません。");
143- case StockDownload.Recent: {
144- Specialized.MujinzouDataSource m = new Specialized.MujinzouDataSource(_dateArray);
145- m.IncludesDomesticIndices = true; //最近の銘柄で国内指数はカバーする
146- stock_ds = m;
143+ case StockDownload.Recent:
144+ stock_ds = new Specialized.KdbComDataSource(_dateArray);
147145 break;
148- }
149146 }
150147 if(stock_ds!=null) col.Add(stock_ds);
151148 #endif //BUILD_INITIAL_DATA
--- /dev/null
+++ b/KdbCom.cs
@@ -0,0 +1,184 @@
1+// Copyright (c) 2014 panacoran <panacoran@users.sourceforge.jp>
2+// This program is part of OmegaChart.
3+// OmegaChart is licensed under the Apache License, Version 2.0.
4+
5+using System;
6+using System.Collections.Generic;
7+using System.Diagnostics;
8+using System.IO;
9+using System.Text;
10+using Zanetti.Data;
11+
12+namespace Zanetti.DataSource.Specialized
13+{
14+ internal class KdbComDataSource : DailyDataSource
15+ {
16+ public KdbComDataSource(int[] dates) : base(dates)
17+ {
18+ }
19+
20+ public override void Run()
21+ {
22+ GetMarketVolume(); // 先に東証一部の出来高を読み込む。
23+ var newdata = new Dictionary<int, Dictionary<int, NewDailyData>>();
24+ foreach (var date in _dates)
25+ {
26+ newdata[date] = FillData(date);
27+ SendMessage(AsyncConst.WM_ASYNCPROCESS, (date & DATE_MASK), AsyncConst.LPARAM_PROGRESS_SUCCESSFUL);
28+ }
29+ foreach (AbstractBrand br in Env.BrandCollection.Values)
30+ {
31+ if (br.Market == MarketType.B && !IsSupportedIndex(br.Code) || br.Market == MarketType.Custom)
32+ continue;
33+ using (var farm = (DailyDataFarm)br.CreateDailyFarm(_dates.Length))
34+ {
35+ var traceFlag = false;
36+ foreach (var date in _dates)
37+ {
38+ NewDailyData td;
39+ if (newdata[date].TryGetValue(br.Code, out td))
40+ {
41+ farm.UpdateDataFarm(date, td);
42+ }
43+ else
44+ {
45+ if (traceFlag)
46+ continue;
47+ traceFlag = true;
48+ Debug.WriteLine("Data not found(k-db.com) : code=" + br.Code + " market=" + br.Market);
49+ }
50+ farm.Save(Util.GetDailyDataFileName(br.Code));
51+ }
52+ SendMessage(AsyncConst.WM_ASYNCPROCESS, br.Code, AsyncConst.LPARAM_PROGRESS_SUCCESSFUL);
53+ }
54+ }
55+ }
56+
57+ private Dictionary<DateTime, int> _indexVolume;
58+
59+ private void GetMarketVolume()
60+ {
61+ _indexVolume = new Dictionary<DateTime, int>();
62+ const string url = "http://k-db.com/site/toukei.aspx?market=T1&download=csv";
63+ using (var reader = new StreamReader(Util.HttpDownload(url), Encoding.GetEncoding("shift_jis")))
64+ {
65+ string line;
66+ while ((line = reader.ReadLine()) != null)
67+ {
68+ var tokens = line.Split(',');
69+ switch (tokens[0])
70+ {
71+ case "東証1部":
72+ case "日付":
73+ continue;
74+ }
75+ var date = DateTime.Parse(tokens[0]);
76+ var volume = double.Parse(tokens[1]);
77+ _indexVolume[date] = (int)(volume * 0.001);
78+ }
79+ }
80+ }
81+
82+ private Dictionary<int, NewDailyData> FillData(int date)
83+ {
84+ var result = new Dictionary<int, NewDailyData>();
85+ var d2 = Util.IntToDate(date);
86+ var url = "http://k-db.com/site/download.aspx?p=all&download=csv&date=" + d2.ToString("yyyy-MM-dd");
87+ using (var reader = new StreamReader(Util.HttpDownload(url), Encoding.GetEncoding("shift_jis")))
88+ {
89+ string line;
90+ while ((line = reader.ReadLine()) != null)
91+ {
92+ var tokens = line.Split(',');
93+ int code;
94+ int volume;
95+ var pv = 1.0;
96+ if (tokens[0] == "10" || tokens[0] == "67")
97+ {
98+ code = tokens[0] == "67" ? (int)BuiltInIndex.Nikkei225 : (int)BuiltInIndex.TOPIX;
99+ volume = _indexVolume[d2];
100+ pv = 100;
101+ }
102+ else if (tokens[0].Length == 6)
103+ {
104+ code = int.Parse(tokens[0].Substring(0, 4));
105+ var br = Env.BrandCollection.FindBrand(code) as BasicBrand;
106+ if (br == null || !CheckMarket(br.Market, tokens[2]))
107+ continue;
108+ volume = (int)ParseField(tokens[8]);
109+ }
110+ else
111+ {
112+ continue;
113+ }
114+ var td = new NewDailyData
115+ {
116+ volume = volume,
117+ open = (int)(ParseField(tokens[4]) * pv),
118+ high = (int)(ParseField(tokens[5]) * pv),
119+ low = (int)(ParseField(tokens[6]) * pv),
120+ close = (int)(ParseField(tokens[7]) * pv)
121+ };
122+ result[code] = td;
123+ }
124+ }
125+ return result;
126+ }
127+
128+ private bool CheckMarket(MarketType market, string name)
129+ {
130+ switch (name)
131+ {
132+ case "東証":
133+ case "東証1部":
134+ return market == MarketType.T1;
135+ case "東証2部":
136+ return market == MarketType.T2;
137+ case "東証マザーズ":
138+ case "東証マザーズ外国":
139+ return market == MarketType.M;
140+ case "東証TPM":
141+ return market == MarketType.Custom;
142+ case "東証1部外国":
143+ return market == MarketType.T1;
144+ case "大証":
145+ case "大証1部":
146+ return market == MarketType.O1;
147+ case "大証2部":
148+ return market == MarketType.O2;
149+ case "東証JQグロース":
150+ case "東証JQスタンダード":
151+ case "東証JQスタンダード外国":
152+ case "JQ":
153+ case "JQスタンダード":
154+ case "JQスタンダード外国":
155+ case "JQグロース":
156+ case "JQNEO":
157+ return market == MarketType.J;
158+ case "HCスタンダード":
159+ case "HCスタンダード外国":
160+ case "HCグロース":
161+ return market == MarketType.H;
162+ case "福証":
163+ case "福証QBoard":
164+ case "札証":
165+ case "札証アンビシャス":
166+ case "名証":
167+ return false;
168+ }
169+ return false;
170+ }
171+
172+ private bool IsSupportedIndex(int code)
173+ {
174+ return code == (int)BuiltInIndex.Nikkei225 ||
175+ code == (int)BuiltInIndex.TOPIX;
176+ }
177+
178+ private double ParseField(string s)
179+ {
180+ // 無効なフィールドを示す"-"を0として扱う。
181+ return s == "-" ? 0 : double.Parse(s);
182+ }
183+ }
184+}
\ No newline at end of file
--- a/zanetti.csproj
+++ b/zanetti.csproj
@@ -1,4 +1,5 @@
1-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1+<?xml version="1.0" encoding="utf-8"?>
2+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
23 <PropertyGroup>
34 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
45 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -11,6 +12,12 @@
1112 <AssemblyName>OmegaChart</AssemblyName>
1213 <StartupObject>Zanetti.Env</StartupObject>
1314 <ApplicationIcon>omegachart.ico</ApplicationIcon>
15+ <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
16+ <FileUpgradeFlags>
17+ </FileUpgradeFlags>
18+ <UpgradeBackupLocation>
19+ </UpgradeBackupLocation>
20+ <OldToolsVersion>2.0</OldToolsVersion>
1421 </PropertyGroup>
1522 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1623 <DebugSymbols>true</DebugSymbols>
@@ -34,11 +41,11 @@
3441 <ItemGroup>
3542 <Reference Include="DotNetMagic2005, Version=4.1.0.0, Culture=neutral, PublicKeyToken=6cf6edec59e036ec, processorArchitecture=MSIL">
3643 <SpecificVersion>False</SpecificVersion>
37- <HintPath>lib\DotNetMagic2005.dll</HintPath>
44+ <HintPath>.\DotNetMagic2005.dll</HintPath>
3845 </Reference>
3946 <Reference Include="grammatica-1.4, Version=0.0.0.0, Culture=neutral">
4047 <SpecificVersion>False</SpecificVersion>
41- <HintPath>lib\grammatica-1.4.dll</HintPath>
48+ <HintPath>.\grammatica-1.4.dll</HintPath>
4249 </Reference>
4350 <Reference Include="System" />
4451 <Reference Include="System.Data" />
@@ -152,6 +159,7 @@
152159 <Compile Include="InitializeData.cs">
153160 <SubType>Form</SubType>
154161 </Compile>
162+ <Compile Include="KdbCom.cs" />
155163 <Compile Include="KenMille.cs" />
156164 <Compile Include="KeyConfig.cs" />
157165 <Compile Include="KeyConfigDialog.cs">
@@ -190,6 +198,9 @@
190198 <DependentUpon>AboutBox.cs</DependentUpon>
191199 <SubType>Designer</SubType>
192200 </EmbeddedResource>
201+ <EmbeddedResource Include="AutoTradingDialog.resx">
202+ <DependentUpon>AutoTradingDialog.cs</DependentUpon>
203+ </EmbeddedResource>
193204 <EmbeddedResource Include="AutoTradingSummaryDialog.resx">
194205 <DependentUpon>AutoTradingSummaryDialog.cs</DependentUpon>
195206 <SubType>Designer</SubType>
--- a/zanetti.sln
+++ b/zanetti.sln
@@ -1,6 +1,6 @@
11 
2-Microsoft Visual Studio Solution File, Format Version 9.00
3-# Visual Studio 2005
2+Microsoft Visual Studio Solution File, Format Version 12.00
3+# Visual Studio 2012
44 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "zanetti", "zanetti.csproj", "{4E5C819F-CA68-4F7C-924F-8D861648C959}"
55 EndProject
66 Global