Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
eurhisfirm
dfih-ui
Commits
2edafb02
Commit
2edafb02
authored
Oct 17, 2018
by
Emmanuel Raviart
Browse files
Rename stock to security.
parent
1d42f894
Changes
14
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
2edafb02
...
...
@@ -15,7 +15,7 @@ Edit `src/server-config.js` to change database informations. Then
npm
install
```
## Retrieve or generate JSON files of issuers, s
tock
s, etc
## Retrieve or generate JSON files of issuers, s
ecuritie
s, etc
### Either retrieve JSON files from their git repository
...
...
@@ -28,7 +28,7 @@ git clone https://gitlab.huma-num.fr/eurhisfirm/dfih-open-data.git data
```
bash
node_modules/.bin/babel-node scripts/generate-issuers.js
node_modules/.bin/babel-node scripts/generate-stock-exchanges.js
node_modules/.bin/babel-node scripts/generate-s
tock
s.js
node_modules/.bin/babel-node scripts/generate-s
ecuritie
s.js
```
## Launch server
...
...
src/components/SectorTreeNode.html
View file @
2edafb02
...
...
@@ -14,7 +14,7 @@
<ul>
{#each rows as row (row[0])}
<li>
<a
id=
"{row[2]}"
href=
"/s
tock
s/{row[0]}/prices"
data-container=
"body"
data-trigger=
"manual"
data-toggle=
"popover"
<a
id=
"{row[2]}"
href=
"/s
ecuritie
s/{row[0]}/prices"
data-container=
"body"
data-trigger=
"manual"
data-toggle=
"popover"
data-html=
"true"
data-placement=
"top"
data-content=
"Loading price data..."
on:mouseenter=
"popoverHover(event)"
on:mouseleave=
"popoverLeave(event)"
>
{row[1]}
</a>
</li>
...
...
src/routes/api/s
tocks/[stock
([0-9]+)]/prices.js
→
src/routes/api/s
ecurities/[security
([0-9]+)]/prices.js
View file @
2edafb02
...
...
@@ -3,123 +3,123 @@ import oracledb from "oracledb"
import
{
pool
}
from
"
../../../../database
"
export
async
function
get
(
req
,
res
)
{
const
{
s
tock
:
stock
Id
}
=
req
.
params
const
{
s
ecurity
:
security
Id
}
=
req
.
params
const
connection
=
await
pool
.
getConnection
()
let
result
=
null
try
{
result
=
await
connection
.
execute
(
`
select comptant.notation,
select comptant.notation,
(comptant.day - to_date('1970/01/01','YYYY/MM/DD'))*86400000 as EPOCH,
comptant.prix as prix_comptant,
terme.Open_Liq15, terme.Open_LiqFin,
terme.Close_Liq15, terme.Close_LiqFin,
terme.Min_Liq15, terme.Min_LiqFin,
terme.Max_Liq15, terme.Max_LiqFin
comptant.prix as prix_comptant,
terme.Open_Liq15, terme.Open_LiqFin,
terme.Close_Liq15, terme.Close_LiqFin,
terme.Min_Liq15, terme.Min_LiqFin,
terme.Max_Liq15, terme.Max_LiqFin
from
(
select last_value(notation ignore nulls) over (order by day, notation) as notation,
day,
max(Open_Liq15) as Open_Liq15, max(Open_LiqFin) as Open_LiqFin,
day,
max(Open_Liq15) as Open_Liq15, max(Open_LiqFin) as Open_LiqFin,
max(Close_Liq15) as Close_Liq15, max(Close_LiqFin) as Close_LiqFin,
min(Min_Liq15) as Min_Liq15, min(Min_LiqFin) as Min_LiqFin,
max(Max_Liq15) as Max_Liq15, max(Max_LiqFin) as Max_LiqFin
FROM
(select c.notation, cd.exact_date as day,
nvl(c.Open_Liq15, c.Open_Liq151) as Open_Liq15,
(select c.notation, cd.exact_date as day,
nvl(c.Open_Liq15, c.Open_Liq151) as Open_Liq15,
nvl(c.Open_LiqFin, c.Open_LiqFin1) as Open_LiqFin,
nvl(c.Close_Liq15, c.Close_Liq151) as Close_Liq15,
nvl(c.Close_Liq15, c.Close_Liq151) as Close_Liq15,
nvl(c.Close_LiqFin, c.Close_LiqFin1) as Close_LiqFin,
nvl(c.Min_Liq15, c.Min_Liq151) as Min_Liq15,
nvl(c.Min_Liq15, c.Min_Liq151) as Min_Liq15,
nvl(c.Min_LiqFin, c.Min_LiqFin1) as Min_LiqFin,
nvl(c.Max_Liq15, c.Max_Liq151) as Max_Liq15,
nvl(c.Max_Liq15, c.Max_Liq151) as Max_Liq15,
nvl(c.Max_LiqFin, c.Max_LiqFin1) as Max_LiqFin
from
from
control_dates cd
left join
(
select np.day, np.notation,
decode(np.setdate, 20, np.open) Open_Liq15,
decode(np.setdate, 15, np.open, 17, np.open, 18, np.open, 19, np.open) Open_LiqFin,
(case when extract(day from np.day) between 10 and 20
select np.day, np.notation,
decode(np.setdate, 20, np.open) Open_Liq15,
decode(np.setdate, 15, np.open, 17, np.open, 18, np.open, 19, np.open) Open_LiqFin,
(case when extract(day from np.day) between 10 and 20
then decode(np.setdate, 13, np.open) END) as Open_Liq151,
(case when extract(day from np.day) < 10 or extract(day from np.day) > 20
(case when extract(day from np.day) < 10 or extract(day from np.day) > 20
then decode(np.setdate, 13, np.open) END) as Open_LiqFin1,
decode(np.setdate, 20, np.close) Close_Liq15,
decode(np.setdate, 15, np.close, 17, np.close, 18, np.close, 19, np.close) Close_LiqFin,
(case when extract(day from np.day) between 10 and 20
decode(np.setdate, 20, np.close) Close_Liq15,
decode(np.setdate, 15, np.close, 17, np.close, 18, np.close, 19, np.close) Close_LiqFin,
(case when extract(day from np.day) between 10 and 20
then decode(np.setdate, 13, np.close) END) as Close_Liq151,
(case when extract(day from np.day) < 10 or extract(day from np.day) > 20
(case when extract(day from np.day) < 10 or extract(day from np.day) > 20
then decode(np.setdate, 13, np.close) END) as Close_LiqFin1,
decode(np.setdate, 20, np.min) Min_Liq15,
decode(np.setdate, 15, np.min, 17, np.min, 18, np.min, 19, np.min) Min_LiqFin,
(case when extract(day from np.day) between 10 and 20
decode(np.setdate, 20, np.min) Min_Liq15,
decode(np.setdate, 15, np.min, 17, np.min, 18, np.min, 19, np.min) Min_LiqFin,
(case when extract(day from np.day) between 10 and 20
then decode(np.setdate, 13, np.min) END) as Min_Liq151,
(case when extract(day from np.day) < 10 or extract(day from np.day) > 20
(case when extract(day from np.day) < 10 or extract(day from np.day) > 20
then decode(np.setdate, 13, np.min) END) as Min_LiqFin1,
decode(np.setdate, 20, np.max) Max_Liq15,
decode(np.setdate, 15, np.max, 17, np.max, 18, np.max, 19, np.max) Max_LiqFin,
(case when extract(day from np.day) between 10 and 20
decode(np.setdate, 20, np.max) Max_Liq15,
decode(np.setdate, 15, np.max, 17, np.max, 18, np.max, 19, np.max) Max_LiqFin,
(case when extract(day from np.day) between 10 and 20
then decode(np.setdate, 13, np.max) END) as Max_Liq151,
(case when extract(day from np.day) < 10 or extract(day from np.day) > 20
(case when extract(day from np.day) < 10 or extract(day from np.day) > 20
then decode(np.setdate, 13, np.max) END) as Max_LiqFin1
from notation_price np
where np.notation in (select id from notation where stock = :s
tock
Id)
from notation_price np
where np.notation in (select id from notation where stock = :s
ecurity
Id)
and np.market = 1
) c ON (cd.exact_date = c.day)
where nvl(cd.exact_date, c.day) >= (select min(startdate) from notation where stock = :s
tock
Id)
and nvl(cd.exact_date, c.day) <= (select max(enddate) from notation where stock = :s
tock
Id)
where nvl(cd.exact_date, c.day) >= (select min(startdate) from notation where stock = :s
ecurity
Id)
and nvl(cd.exact_date, c.day) <= (select max(enddate) from notation where stock = :s
ecurity
Id)
)
group by notation, day
) terme
join
(
select distinct last_value(notation ignore nulls) over (order by day, notation) as notation,
day,
select distinct last_value(notation ignore nulls) over (order by day, notation) as notation,
day,
last_value(prix ignore nulls) over (order by day, notation) as prix
from
(
select nvl(pnep.notation, pnp.notation) as notation,
nvl(pnep.day, pnp.day) as day,
nvl(pnep.prix, pnp.prix) as prix
from
select nvl(pnep.notation, pnp.notation) as notation,
nvl(pnep.day, pnp.day) as day,
nvl(pnep.prix, pnp.prix) as prix
from
(
select notation, day, dernier_prix_comptant as prix from
select notation, day, dernier_prix_comptant as prix from
(
select distinct a.notation, cd.exact_date as day, a.dernier_prix_comptant
from
from
control_dates cd
left join
(
select nep.day, nep.notation,
first_value(nep.price)
select nep.day, nep.notation,
first_value(nep.price)
over (partition by nep.day, nep.notation order by nep.id desc) as dernier_prix_comptant
from notation_extra_price nep where nep.notation in (select id from notation where stock = :s
tock
Id)
from notation_extra_price nep where nep.notation in (select id from notation where stock = :s
ecurity
Id)
) a ON (cd.exact_date = a.day)
where nvl(cd.exact_date, a.day) >= (select min(startdate) from notation where stock = :s
tock
Id)
and nvl(cd.exact_date, a.day) <= (select max(enddate) from notation where stock = :s
tock
Id)
where nvl(cd.exact_date, a.day) >= (select min(startdate) from notation where stock = :s
ecurity
Id)
and nvl(cd.exact_date, a.day) <= (select max(enddate) from notation where stock = :s
ecurity
Id)
)
) pnep
full outer join
(
select notation, day, dernier_prix_comptant as prix from
select notation, day, dernier_prix_comptant as prix from
(
select distinct b.notation, nvl(cd.exact_date, b.day) as day, b.dernier_prix_comptant
from
from
control_dates cd
left join
(
select np.day, np.notation, nvl(np.price_yesterday, np.previous) as dernier_prix_comptant
from notation_price np
where np.notation in (select id from notation where stock = :s
tock
Id)
from notation_price np
where np.notation in (select id from notation where stock = :s
ecurity
Id)
and np.market = 2
) b ON (cd.exact_date = b.day)
where nvl(cd.exact_date, b.day) >= (select min(startdate) from notation where stock = :s
tock
Id)
and nvl(cd.exact_date, b.day) <= (select max(enddate) from notation where stock = :s
tock
Id)
where nvl(cd.exact_date, b.day) >= (select min(startdate) from notation where stock = :s
ecurity
Id)
and nvl(cd.exact_date, b.day) <= (select max(enddate) from notation where stock = :s
ecurity
Id)
)
) pnp
ON (pnep.notation = pnp.notation and pnep.day = pnp.day)
...
...
@@ -128,7 +128,7 @@ export async function get(req, res) {
order by comptant.day
`
,
{
s
tock
Id
:
{
dir
:
oracledb
.
BIND_IN
,
val
:
s
tock
Id
,
type
:
oracledb
.
STRING
},
s
ecurity
Id
:
{
dir
:
oracledb
.
BIND_IN
,
val
:
s
ecurity
Id
,
type
:
oracledb
.
STRING
},
}
)
}
catch
(
error
)
{
...
...
src/routes/api/static/s
tocks/[stock
([0-9]+)].js
→
src/routes/api/static/s
ecurities/[security
([0-9]+)].js
View file @
2edafb02
...
...
@@ -4,9 +4,9 @@ import path from "path"
import
serverConfig
from
"
../../../../server-config
"
export
function
get
(
req
,
res
)
{
const
{
s
tock
:
stock
Id
}
=
req
.
params
const
s
tock
FilePath
=
path
.
join
(
serverConfig
.
dataDir
,
"
s
tocks
"
,
`stock_
${
stock
Id
}
.json`
)
if
(
!
fs
.
existsSync
(
s
tock
FilePath
))
{
const
{
s
ecurity
:
security
Id
}
=
req
.
params
const
s
ecurity
FilePath
=
path
.
join
(
serverConfig
.
dataDir
,
"
s
ecurities
"
,
`security_
${
security
Id
}
.json`
)
if
(
!
fs
.
existsSync
(
s
ecurity
FilePath
))
{
res
.
writeHead
(
404
,
{
"
Content-Type
"
:
"
application/json
"
,
})
...
...
@@ -15,7 +15,7 @@ export function get(req, res) {
{
error
:
{
code
:
404
,
message
:
`S
tock
${
stock
Id
}
doesn't exist.`
,
message
:
`S
ecurity
${
security
Id
}
doesn't exist.`
,
},
},
null
,
...
...
@@ -23,7 +23,7 @@ export function get(req, res) {
)
)
}
if
(
!
fs
.
lstatSync
(
s
tock
FilePath
).
isFile
())
{
if
(
!
fs
.
lstatSync
(
s
ecurity
FilePath
).
isFile
())
{
res
.
writeHead
(
404
,
{
"
Content-Type
"
:
"
application/json
"
,
})
...
...
@@ -32,7 +32,7 @@ export function get(req, res) {
{
error
:
{
code
:
404
,
message
:
`S
tock
${
stock
Id
}
doesn't exist (not a file).`
,
message
:
`S
ecurity
${
security
Id
}
doesn't exist (not a file).`
,
},
},
null
,
...
...
@@ -43,5 +43,5 @@ export function get(req, res) {
res
.
writeHead
(
200
,
{
"
Content-Type
"
:
"
application/json
"
,
})
res
.
end
(
fs
.
readFileSync
(
s
tock
FilePath
))
res
.
end
(
fs
.
readFileSync
(
s
ecurity
FilePath
))
}
src/routes/issuers/[issuer([0-9]+)]/_layout.html
View file @
2edafb02
...
...
@@ -28,10 +28,10 @@
{/if}
</li>
<li
class=
"nav-item"
>
{#if child.segment === "s
tock
s"}
<a
class=
"nav-link active"
href=
"/issuers/{issuer.id}/s
tock
s"
rel=
"prefetch"
>
S
tock
s
<span
class=
"sr-only"
>
(current)
</span></a>
{#if child.segment === "s
ecuritie
s"}
<a
class=
"nav-link active"
href=
"/issuers/{issuer.id}/s
ecuritie
s"
rel=
"prefetch"
>
S
ecuritie
s
<span
class=
"sr-only"
>
(current)
</span></a>
{:else}
<a
class=
"nav-link"
href=
"/issuers/{issuer.id}/s
tock
s"
rel=
"prefetch"
>
S
tock
s
</a>
<a
class=
"nav-link"
href=
"/issuers/{issuer.id}/s
ecuritie
s"
rel=
"prefetch"
>
S
ecuritie
s
</a>
{/if}
</li>
<li
class=
"nav-item"
>
...
...
src/routes/issuers/[issuer([0-9]+)]/index.html
View file @
2edafb02
...
...
@@ -50,15 +50,15 @@
</div>
{/if}
<!-- {#if issuer.s
tock
s}
<!-- {#if issuer.s
ecuritie
s}
<div class="card my-3">
<div class="card-header">
<h3 class="mb-0">
<button class="btn btn-light" type="button">
{#if Object.keys(issuer.s
tock
s).length > 1}
{Object.keys(issuer.s
tock
s).length} s
tock
s
{#if Object.keys(issuer.s
ecuritie
s).length > 1}
{Object.keys(issuer.s
ecuritie
s).length} s
ecuritie
s
{:else}
{Object.keys(issuer.s
tock
s).length} stock
{Object.keys(issuer.s
ecuritie
s).length} stock
{/if}
</button>
</h3>
...
...
src/routes/issuers/[issuer([0-9]+)]/securities.html
0 → 100644
View file @
2edafb02
<p
class=
"my-4 text-muted"
>
{#if Object.keys(issuer.securities).length > 1}
{Object.keys(issuer.securities).length} results
{:else}
{Object.keys(issuer.securities).length} result
{/if}
</p>
<div
class=
"list-group"
>
{#each Object.values(issuer.securities) as security (security.id)}
<a
class=
"list-group-item list-group-item-action"
href=
"/securities/{security.id}"
>
<div>
{(security.name || "Titre sans nom").toUpperCase()}
</div>
<div
class=
"text-muted"
>
{security.share_type.name}
</div>
<div
class=
"text-muted"
>
{[...new Set(security.types.map(securityType => securityType.name))].sort().join(", ")}
</div>
</a>
{/each}
</div>
src/routes/issuers/[issuer([0-9]+)]/stocks.html
deleted
100644 → 0
View file @
1d42f894
<p
class=
"my-4 text-muted"
>
{#if Object.keys(issuer.stocks).length > 1}
{Object.keys(issuer.stocks).length} results
{:else}
{Object.keys(issuer.stocks).length} result
{/if}
</p>
<div
class=
"list-group"
>
{#each Object.values(issuer.stocks) as stock (stock.id)}
<a
class=
"list-group-item list-group-item-action"
href=
"/stocks/{stock.id}"
>
<div>
{(stock.name || "Titre sans nom").toUpperCase()}
</div>
<div
class=
"text-muted"
>
{stock.share_type.name}
</div>
<div
class=
"text-muted"
>
{[...new Set(stock.types.map(stockType => stockType.name))].sort().join(", ")}
</div>
</a>
{/each}
</div>
src/routes/s
tocks/[stock
([0-9]+)]/_layout.html
→
src/routes/s
ecurities/[security
([0-9]+)]/_layout.html
View file @
2edafb02
<svelte:head>
<title>
{s
tock
.name} | S
tock
s | Eurhisfirm
</title>
<title>
{s
ecurity
.name} | S
ecuritie
s | Eurhisfirm
</title>
</svelte:head>
<main
class=
"container-fluid"
>
<h1>
<span
class=
"text-muted"
>
S
tock
</span>
{s
tock
.name}
<span
class=
"text-muted"
>
S
ecurity
</span>
{s
ecurity
.name}
<small
class=
"text-muted"
>
{s
tock
.share_type.name}
{s
ecurity
.share_type.name}
/
{[...new Set(s
tock
.types.map(s
tock
Type => s
tock
Type.name))].sort().join(", ")}
{[...new Set(s
ecurity
.types.map(s
ecurity
Type => s
ecurity
Type.name))].sort().join(", ")}
</small>
</h1>
...
...
@@ -32,35 +32,35 @@
<ul
class=
"nav nav-tabs"
>
<li
class=
"nav-item"
>
{#if child.segment === undefined}
<a
class=
"nav-link active"
href=
"/s
tocks/{stock
.id}"
rel=
"prefetch"
>
Summary
<span
class=
"sr-only"
>
(current)
</span></a>
<a
class=
"nav-link active"
href=
"/s
ecurities/{security
.id}"
rel=
"prefetch"
>
Summary
<span
class=
"sr-only"
>
(current)
</span></a>
{:else}
<a
class=
"nav-link"
href=
"/s
tocks/{stock
.id}"
rel=
"prefetch"
>
Summary
</a>
<a
class=
"nav-link"
href=
"/s
ecurities/{security
.id}"
rel=
"prefetch"
>
Summary
</a>
{/if}
</li>
<li
class=
"nav-item"
>
{#if child.segment === "dividends"}
<a
class=
"nav-link active"
href=
"/s
tocks/{stock
.id}/dividends"
rel=
"prefetch"
>
Dividends
<span
class=
"sr-only"
>
(current)
</span></a>
<a
class=
"nav-link active"
href=
"/s
ecurities/{security
.id}/dividends"
rel=
"prefetch"
>
Dividends
<span
class=
"sr-only"
>
(current)
</span></a>
{:else}
<a
class=
"nav-link"
href=
"/s
tocks/{stock
.id}/dividends"
rel=
"prefetch"
>
Dividends
</a>
<a
class=
"nav-link"
href=
"/s
ecurities/{security
.id}/dividends"
rel=
"prefetch"
>
Dividends
</a>
{/if}
</li>
<li
class=
"nav-item"
>
{#if child.segment === "prices"}
<a
class=
"nav-link active"
href=
"/s
tocks/{stock
.id}/prices"
rel=
"prefetch"
>
Prices
<span
class=
"sr-only"
>
(current)
</span></a>
<a
class=
"nav-link active"
href=
"/s
ecurities/{security
.id}/prices"
rel=
"prefetch"
>
Prices
<span
class=
"sr-only"
>
(current)
</span></a>
{:else}
<a
class=
"nav-link"
href=
"/s
tocks/{stock
.id}/prices"
rel=
"prefetch"
>
Prices
</a>
<a
class=
"nav-link"
href=
"/s
ecurities/{security
.id}/prices"
rel=
"prefetch"
>
Prices
</a>
{/if}
</li>
</ul>
<svelte:component
this=
{child.component}
{...
child.props
}
{
s
tock
}
/>
<svelte:component
this=
{child.component}
{...
child.props
}
{
s
ecurity
}
/>
</main>
<script>
export
default
{
computed
:
{
simplifiedIssuers
({
s
tock
})
{
const
simplifiedIssuerByIdAndName
=
s
tock
.
issuers
.
reduce
((
accumulator
,
issuer
)
=>
{
simplifiedIssuers
({
s
ecurity
})
{
const
simplifiedIssuerByIdAndName
=
s
ecurity
.
issuers
.
reduce
((
accumulator
,
issuer
)
=>
{
accumulator
[
`
${
issuer
.
name
}
${
issuer
.
id
}
`
]
=
{
id
:
issuer
.
id
,
name
:
issuer
.
name
,
...
...
@@ -71,8 +71,8 @@
},
},
async
preload
({
params
/* , query */
})
{
const
{
s
tock
:
stock
Id
}
=
params
const
response
=
await
this
.
fetch
(
`/api/static/s
tocks/
${
stock
Id
}
`
)
const
{
s
ecurity
:
security
Id
}
=
params
const
response
=
await
this
.
fetch
(
`/api/static/s
ecurities/
${
security
Id
}
`
)
const
result
=
response
.
ok
||
response
.
status
===
400
?
await
response
.
json
()
...
...
@@ -80,7 +80,7 @@
if
(
result
.
error
)
{
return
this
.
error
(
result
.
error
.
code
,
result
.
error
.
message
)
}
return
{
s
tock
:
result
}
return
{
s
ecurity
:
result
}
},
}
</script>
\ No newline at end of file
src/routes/s
tocks/[stock
([0-9]+)]/dividends.html
→
src/routes/s
ecurities/[security
([0-9]+)]/dividends.html
View file @
2edafb02
<svelte:head>
<title>
Dividends | {s
tock
.name} | S
tock
s | Eurhisfirm
</title>
<title>
Dividends | {s
ecurity
.name} | S
ecuritie
s | Eurhisfirm
</title>
</svelte:head>
TODO
src/routes/s
tocks/[stock
([0-9]+)]/index.html
→
src/routes/s
ecurities/[security
([0-9]+)]/index.html
View file @
2edafb02
{#each Object.values(s
tock
.stock_exchanges || {}).sort(stockExchange => stockExchange.name) as stockExchange (`stock_exchange_${stockExchange.id}`)}
{#each Object.values(s
ecurity
.stock_exchanges || {}).sort(stockExchange => stockExchange.name) as stockExchange (`stock_exchange_${stockExchange.id}`)}
<div
class=
"card my-3"
>
<div
class=
"card-header"
>
Listed on
<i>
{stockExchange.name}
</i>
...
...
src/routes/s
tocks/[stock
([0-9]+)]/prices-plotly.html
→
src/routes/s
ecurities/[security
([0-9]+)]/prices-plotly.html
View file @
2edafb02
<svelte:head>
<title>
Prices | {s
tock
.name} | S
tock
s | Eurhisfirm
</title>
<title>
Prices | {s
ecurity
.name} | S
ecuritie
s | Eurhisfirm
</title>
</svelte:head>
<svelte:window
on:resize=
"resize()"
/>
...
...
@@ -112,8 +112,8 @@
)
},
async
preload
({
params
/* query */
})
{
const
{
s
tock
:
stock
Id
}
=
params
const
response
=
await
this
.
fetch
(
`/api/s
tocks/
${
stock
Id
}
/prices`
)
const
{
s
ecurity
:
security
Id
}
=
params
const
response
=
await
this
.
fetch
(
`/api/s
ecurities/
${
security
Id
}
/prices`
)
const
result
=
response
.
ok
||
response
.
status
===
400
?
await
response
.
json
()
...
...
src/routes/s
tocks/[stock
([0-9]+)]/prices.html
→
src/routes/s
ecurities/[security
([0-9]+)]/prices.html
View file @
2edafb02
<svelte:head>
<title>
Prices | {s
tock
.name} | S
tock
s | Eurhisfirm
</title>
<title>
Prices | {s
ecurity
.name} | S
ecuritie
s | Eurhisfirm
</title>
</svelte:head>
<div
id=
"container"
style=
"height:800px; width:100%;"
></div>
...
...
@@ -112,8 +112,8 @@
})
},
async
preload
({
params
/* query */
})
{
const
{
s
tock
:
stock
Id
}
=
params
const
response
=
await
this
.
fetch
(
`/api/s
tocks/
${
stock
Id
}
/prices`
)
const
{
s
ecurity
:
security
Id
}
=
params
const
response
=
await
this
.
fetch
(
`/api/s
ecurities/
${
security
Id
}
/prices`
)
const
result
=
response
.
ok
||
response
.
status
===
400
?
await
response
.
json
()
...
...
src/scripts/generate-s
tock
s.js
→
src/scripts/generate-s
ecuritie
s.js
View file @
2edafb02
...
...
@@ -10,7 +10,7 @@ import { cleanUpLine, objectsFromSqlResult } from "../model"
const
dataDir
=
"
data
"
let
pool
=
null
async
function
generateS
tock
s
()
{
async
function
generateS
ecuritie
s
()
{
const
connection
=
await
pool
.
getConnection
()
try
{
console
.
log
(
"
Reading stock exchanges...
"
)
...
...
@@ -44,8 +44,8 @@ async function generateStocks() {
}
}
console
.
log
(
"
Loading s
tock
types...
"
)
const
s
tock
TypeById
=
{}
console
.
log
(
"
Loading s
ecurity
types...
"
)
const
s
ecurity
TypeById
=
{}
{
const
entries
=
objectsFromSqlResult
(
await
connection
.
execute
(
...
...
@@ -59,22 +59,22 @@ async function generateStocks() {
)
)
for
(
let
entry
of
entries
)
{
s
tock
TypeById
[
entry
.
id
]
=
entry
s
ecurity
TypeById
[
entry
.
id
]
=
entry
}
}
const
s
tock
sDir
=
path
.
join
(
dataDir
,
"
s
tock
s
"
)
if
(
!
fs
.
existsSync
(
s
tock
sDir
))
{
fs
.
mkdirSync
(
s
tock
sDir
)
const
s
ecuritie
sDir
=
path
.
join
(
dataDir
,
"
s
ecuritie
s
"
)
if
(
!
fs
.
existsSync
(
s
ecuritie
sDir
))
{
fs
.
mkdirSync
(
s
ecuritie
sDir
)
}
const
existingS
tock
sFilenames
=
new
Set
(
fs
.
readdirSync
(
s
tock
sDir
).
filter
(
filename
=>
/^s
tock
_
[
0-9
]
+
\.
json$/
.
test
(
filename
))
const
existingS
ecuritie
sFilenames
=
new
Set
(
fs
.
readdirSync
(
s
ecuritie
sDir
).
filter
(
filename
=>
/^s
ecurity
_
[
0-9
]
+
\.
json$/
.
test
(
filename
))
)
console
.
log
(
"
Loading s
tock
s...
"
)
console
.
log
(
"
Loading s
ecuritie
s...
"
)
const
issuersDir
=
path
.
join
(
dataDir
,
"
issuers
"
)
assert
(
fs
.
existsSync
(
issuersDir
),
`Issuers directory not found:
${
issuersDir
}
`
)
const
s
tock
s
=
objectsFromSqlResult
(
const
s
ecuritie
s
=
objectsFromSqlResult
(
await
connection
.
execute
(
`
select
...
...
@@ -85,18 +85,19 @@ async function generateStocks() {
`
)
)
const
s
tock
sIds
=
new
Set
()
const
s
ecuritie
sIds
=
new
Set
()
const
summaryByIssuerId
=
{}
for
(
let
s
tock
of
stock
s
)
{
// console.log(`Loading s
tock ${stock
.id}...`)
s
tock
sIds
.
add
(
s
tock
.
id
)
for
(
let
s
ecurity
of
securitie
s
)
{
// console.log(`Loading s
ecurity ${security
.id}...`)
s
ecuritie
sIds
.
add
(
s
ecurity
.
id
)
stock
.
share_type
=
shareTypeById
[
stock
.
sharetype
]
assert
(
stock
.
share_type
!==
undefined
,
`Unknown share type "
${
stock
.
share_type
}
" for stock
${
stock
.
id
}
`
)
delete
stock
.
sharetype
security
.
share_type
=
shareTypeById
[
security
.
sharetype
]
assert
(
security
.
share_type
!==
undefined
,
`Unknown share type "
${
security
.
share_type
}
" for security
${
security
.
id
}
`
)
delete
security
.
sharetype
{
// Add issuers to s
tock
.
// Add issuers to s
ecurity
.
const
entries
=
objectsFromSqlResult
(
await
connection
.
execute
(
`
...
...
@@ -105,14 +106,14 @@ async function generateStocks() {
to_char(sc.startdate, 'YYYY-MM-DD') as start_date,
to_char(sc.enddate, 'YYYY-MM-DD') as end_date
from stock_corporation sc
where sc.stock = :s
tock
Id
where sc.stock = :s
ecurity
Id
`
,
{
s
tock
Id
:
{
dir
:
oracledb
.
BIND_IN
,
val
:
s
tock
.
id
,
type
:
oracledb
.
INTEGER
},
s
ecurity
Id
:
{
dir
:
oracledb
.
BIND_IN
,
val
:
s
ecurity
.
id
,
type
:
oracledb
.
INTEGER
},
}
)
)
s
tock
.
issuers
=
entries
s
ecurity
.
issuers
=
entries
.
map
(
entry
=>
{
const
issuerFilePath
=
path
.
join
(
issuersDir
,
`issuer_
${
entry
.
issuer_id
}
.json`
)
try
{
...
...
@@ -124,7 +125,7 @@ async function generateStocks() {
name
:
issuer
.
name
,
}
}
catch
(
e
)
{
console
.
log
(
`Unknown issuer
${
entry
.
issuer_id
}
for s
tock
${
stock
.
id
}
:
${
e
}
`
)
console
.
log
(
`Unknown issuer
${
entry
.
issuer_id
}
for s
ecurity
${
security
.
id
}
:
${
e
}
`
)
return
null
}
})
...
...
@@ -132,7 +133,7 @@ async function generateStocks() {
}
{
// Add types to s
tock
.
// Add types to s
ecurity
.
const
entries
=
objectsFromSqlResult
(
await
connection
.
execute
(
`
...
...
@@ -141,25 +142,25 @@ async function generateStocks() {
to_char(st.startdate, 'YYYY-MM-DD') as start_date,
to_char(st.enddate, 'YYYY-MM-DD') as end_date
from stock_type st
where st.stock = :s
tock
Id
where st.stock = :s
ecurity
Id
`
,
{
s
tock
Id
:
{
dir
:
oracledb
.
BIND_IN
,
val
:
s
tock
.
id
,
type
:
oracledb
.
INTEGER
},
s
ecurity
Id
:
{
dir
:
oracledb
.
BIND_IN
,
val
:
s
ecurity
.
id
,
type
:
oracledb
.
INTEGER
},
}
)
)
s
tock
.
types
=
entries
.
map
(
entry
=>
{
const
s
tock
Type
=
s
tock
TypeById
[
entry
.
type
]
assert
(
s
tock
Type
!==
undefined
,
`Unknown s
tock
type "
${
entry
.
type
}
" for s
tock
${
stock
.
id
}
`
)
s
ecurity
.
types
=
entries
.
map
(
entry
=>
{
const
s
ecurity
Type
=
s
ecurity
TypeById
[
entry
.
type
]