精 簡

個人筆記部落格

0%

軟體開發-台灣銀行美金匯率擷取

前言、目的 #

此專案是為了複習java 程式設計.

需求

需求分析

  1. 擷取指定日期美金匯率(R/E)(包含營業時間及非營業時間)
  2. 查詢以擷取的美金匯率

—————-以上基本—————–
3. 計算出指定日期的平均匯率
4. 已指定價格查詢上一次(買入或賣出)此價格出現的日期

專案管理

  1. 建立github專案儲藏庫
    https://github.com/Kaponcer/RoEAnalyze
    git : https://github.com/Kaponcer/RoEAnalyze.git
  1. eclipse=>建立maven Project => maven-archetype-quickstart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>idv.kaponcer</groupId>
<artifactId>RoEAnalyze</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>RoEAnalyze</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>idv.kaponcer.RoEAnalyze.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

.gitignore

1
2
3
4
5
6
7
8
#maven build 相關檔案及日誌檔
/target/
log/

#eclipse 專案及設定檔
.classpath
.project
.settings
  1. 將github專案儲藏庫複製到工作目錄下
    1
    2
    git clone https://github.com/Kaponcer/RoEAnalyze.git

    第一次commit+push使用eclipse套件

資料分析

台灣銀行歷史匯率查詢
名詞 解釋
現金匯率 以現金交易的匯率
即期匯率 使用存摺扣款交易的匯率
  1. 每日營業時間匯率(HTTPS://GET)
    https://rate.bot.com.tw/xrt/quote/yyyy-MM-dd/USD
    Example: https://rate.bot.com.tw/xrt/quote/2018-12-12/USD
  2. 每日非營業時間匯率(HTTPS://GET)
    https://rate.bot.com.tw/xrt/quote/yyyy-MM-dd/USD/spot/1
    Example: https://rate.bot.com.tw/xrt/quote/2018-12-12/USD/spot/1
日期 時間 幣別 現金買入價 現金賣出價 即期買入價 即期賣出價
2019/02/21 09:00:33 USD 30.42 31.11 30.79 30.89
交易序號 日期 時間 現金買入價 現金賣出價 即期買入價 即期賣出價 營業或非營業時間
autoInteger 2019/02/21 09:00:33 30.42 31.11 30.79 30.89 營業時間
primary key —super— —key—
INTEGER DATE TIME SMALLINT SMALLINT SMALLINT SMALLINT BOOLEAN
TID T_DATE T_TIME C_BUY C_SELL R_BUY R_SELL WORKED

資料庫使用嵌入式H2,jdbc:h2:~/RoEAnalyze
RoEAnalyze=>資料庫名稱

建立資料庫

1
2
3
4
5
6
7
8
9
create table Transaction
(TID INTEGER PRIMARY KEY AUTO_INCREMENT,
T_DATE DATE,
T_TIME TIME,
C_BUY SMALLINT,
C_SELL SMALLINT,
R_BUY SMALLINT,
R_SELL SMALLINT,
WORKED BOOLEAN)

查詢資料

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
select *
from Transaction

select *
from Transaction
where T_ID = ?

select *
from Transaction
where T_DATE = ? AND T_TIME = ?

select *
from Transaction
where T_DATE = ? AND T_TIME = ? AND WORKED = ?

插入資料

1
2
3
insert into Tranaction
( T_DATE,T_TIME, C_BUY, C_SELL, R_BUY, R_SELL, WORKED)
values (?,?,?,?,?,?,?,?)

更新資料

1
2
3
4
update Transaction
SET T_DATE = ? , T_TIME = ? , C_BUY = ? , C_SELL = ? , R_BUY = ? , R_SELL = ?,WORKED = ?
where TID = ?

刪除資料

1
2
delete from Transaction
where TID = ?