Skip to content

Commit

Permalink
refactor all scrapers and release of web-ui
Browse files Browse the repository at this point in the history
refactor all scrapers and initial release of web-ui
  • Loading branch information
ahmethakanbesel committed Dec 29, 2023
2 parents 5c6f238 + 023d8d4 commit 19183af
Show file tree
Hide file tree
Showing 578 changed files with 7,992 additions and 358,086 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
go-version:
- 1.20.x
- 1.21.x
os:
- ubuntu

Expand All @@ -29,7 +29,7 @@ jobs:
strategy:
matrix:
go-version:
- 1.20.x
- 1.21.x
os:
- ubuntu

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.20'
go-version: '1.21'
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
Expand Down
71 changes: 67 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Default email is `admin@example.com` and password is `1234567890`.
`json` or `csv`. Default is `json`.

```
http://127.0.0.1:8090/api/yahoo/symbol/THYAO.IS?startDate=2023-06-01&endDate=2023-09-30&currency=TRY
http://127.0.0.1:8090/api/v1/yahoo/symbols/THYAO.IS?startDate=2023-06-01&endDate=2023-09-30&currency=TRY
```

### Use with Pandas
Expand All @@ -82,26 +82,89 @@ 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/yahoo/symbol/{symbol}?startDate={start_date}&endDate={end_date}&format=csv'
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
```

### Use as a Go package

Both `tefas` and `yahoo` packages can be used independently from the web API,
and they implement `Scraper` interface.

```golang
type Scraper interface {
GetSymbolData(symbol string, startDate, endDate time.Time) (<-chan *SymbolPrice, error)
}
```

```golang
package main

import (
"fmt"
"time"

"github.com/ahmethakanbesel/finance-api/tefas"
"github.com/ahmethakanbesel/finance-api/yahoo"
)

func main() {
tefasScraper := tefas.NewScraper(
tefas.WithWorkers(5),
)

// get last year's data for the given fund
tefasData, err := tefasScraper.GetSymbolData("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("SYMBOLCODE", time.Now().AddDate(-1, 0, 0), time.Now())
if err != nil {
// handle error
}

for data := range yahooData {
fmt.Println(data.Date, data.Close)
}
}
```

## Demo

- `TEFAS (json)`

```
https://finans.dokuz.gen.tr/api/tefas/fund/HKP?startDate=2023-06-01&endDate=2023-09-30&currency=TRY
https://finans.dokuz.gen.tr/api/v1/tefas/funds/HKP?startDate=2023-06-01&endDate=2023-09-30&currency=TRY
```

- `Yahoo Finance (csv)`

```
https://finans.dokuz.gen.tr/api/yahoo/symbol/THYAO.IS?startDate=2023-06-01&endDate=2023-09-30&currency=TRY&format=csv
https://finans.dokuz.gen.tr/api/v1/yahoo/symbols/THYAO.IS?startDate=2023-06-01&endDate=2023-09-30&currency=TRY&format=csv
```

## Web UI

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.

### Preview

![web ui preview](/docs/web-ui-preview.png "web ui preview")

## Credits

- [Pocketbase](https://github.com/pocketbase/pocketbase)
- [Tremor](https://www.tremor.so/)
84 changes: 0 additions & 84 deletions app/scrapers/scrapers.go

This file was deleted.

124 changes: 0 additions & 124 deletions app/scrapers/tefas.go

This file was deleted.

0 comments on commit 19183af

Please sign in to comment.