./finance-api serve
./finance-api serve --http=0.0.0.0:8080
go run main.go serve
docker compose up -d
http://127.0.0.1:8090/api/v1/tefas/funds/:code
:code
is the code of the fund to be fetched.
http://127.0.0.1:8090/api/v1/yahoo/symbols/:symbol
:symbol
is the symbol of the stock to be fetched. For example, for THYAO.IS
:symbol
is THYAO.IS
.
http://127.0.0.1:8090/_
Default email is [email protected]
and password is 1234567890
.
startDate
: Start date of the data to be fetched. Format:YYYY-MM-DD
endDate
: Optional, if not providedtoday
will be used. End date of the data to be fetched. Format:YYYY-MM-DD
currency
: Currency of the data to be fetched. Can be eitherTRY
orUSD
- Note: Currently changing currency has no effect on the data.
format
: Optional. Format of the data to be fetched. Available formats:json
orcsv
. Default isjson
.
http://127.0.0.1:8090/api/v1/yahoo/symbols/THYAO.IS?startDate=2023-06-01&endDate=2023-09-30¤cy=TRY
import pandas as pd
API_URL = 'http://127.0.0.1:8090'
def get_data(symbol, start_date, end_date):
url = f'{API_URL}/api/v1/yahoo/symbols/{symbol}?startDate={start_date}&endDate={end_date}&format=csv'
df = pd.read_csv(url, parse_dates=['Date'])
df.set_index('Date', inplace=True)
return df
Both tefas
and yahoo
packages can be used independently from the web API,
and they implement Scraper
interface.
type Scraper interface {
GetSymbolData(symbol string, startDate, endDate time.Time) (<-chan *SymbolPrice, error)
}
package main
import (
"fmt"
"time"
"github.com/ahmethakanbesel/finance-api/tefas"
"github.com/ahmethakanbesel/finance-api/yahoo"
)
func main() {
ctx := context.Background()
tefasScraper := tefas.NewScraper(
tefas.WithWorkers(5),
)
// get last year's data for the given fund
tefasData, err := tefasScraper.GetSymbolData(ctx, "FUNDCODE", time.Now().AddDate(-1, 0, 0), time.Now())
if err != nil {
// handle error
}
for data := range tefasData {
fmt.Println(data.Date, data.Close)
}
yahooScraper := yahoo.NewScraper(
yahoo.WithWorkers(5),
)
// get last year's data for the given symbol
yahooData, err := yahooScraper.GetSymbolData(ctx, "SYMBOLCODE", time.Now().AddDate(-1, 0, 0), time.Now())
if err != nil {
// handle error
}
for data := range yahooData {
fmt.Println(data.Date, data.Close)
}
}
TEFAS (json)
https://finans.dokuz.gen.tr/api/v1/tefas/funds/HKP?startDate=2023-06-01&endDate=2023-09-30¤cy=TRY
Yahoo Finance (csv)
https://finans.dokuz.gen.tr/api/v1/yahoo/symbols/THYAO.IS?startDate=2023-06-01&endDate=2023-09-30¤cy=TRY&format=csv
The web UI is incomplete, and it is not ready to work out of the box. The source
code can be found under /ui
folder.