Skip to content

Commit

Permalink
* Rough update dependency to use golang 1.22
Browse files Browse the repository at this point in the history
* Remove clog dependency, use golang slog instead
* Update all dependency to latest
  • Loading branch information
edward-frankieone committed May 25, 2024
1 parent 7ec10cc commit d12c3d1
Show file tree
Hide file tree
Showing 30 changed files with 275 additions and 311 deletions.
2 changes: 1 addition & 1 deletion .deepsource.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ name = "go"
enabled = true

[analyzers.meta]
import_paths = ["github.com/ed-fx/go-duka"]
import_paths = ["github.com/edward-yakop/go-duka"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
![Go](https://github.com/ed-fx/go-duka/workflows/Go/badge.svg)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ed-fx_go-duka&metric=alert_status)](https://sonarcloud.io/dashboard?id=ed-fx_go-duka)
![Go](https://github.com/edward-yakop/go-duka/workflows/Go/badge.svg)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=edward-yakop_go-duka&metric=alert_status)](https://sonarcloud.io/dashboard?id=ed-fx_go-duka)

## 1 Tick Data Downloader

Expand Down
40 changes: 26 additions & 14 deletions api/instrument/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package instrument
import (
"encoding/json"
"fmt"
"io"
"log/slog"
"math"
"net/http"
"strconv"
"strings"
"time"
log "unknwon.dev/clog/v2"
)

// This file is a port of https://github.com/Leo4815162342/dukascopy-tools/blob/master/packages/dukascopy-node/src/config/instruments-metadata.ts
Expand Down Expand Up @@ -58,16 +59,15 @@ func (m *Metadata) PriceToString(price float64) string {
var codeToInstrument map[string]*Metadata = nil
var nameToInstrument map[string]*Metadata = nil

// Returns instrument with requested code.
//
// Returns [nil] if not found
// GetMetadata returns instrument with requested code.
// Returns nil if not found
func GetMetadata(code string) *Metadata {
loadMetadataFromJson()
LoadMetadataFromJson()
return codeToInstrument[strings.ToUpper(code)]
}

func GetMetadataByName(name string) *Metadata {
loadMetadataFromJson()
LoadMetadataFromJson()
return nameToInstrument[name]
}

Expand All @@ -81,24 +81,36 @@ type InstrumentJson struct {
StartYearForDailyCandles time.Time `json:"startYearForDailyCandles"`
}

func loadMetadataFromJson() {
var URL = "https://raw.githubusercontent.com/Leo4815162342/dukascopy-node/master/src/utils/instrument-meta-data/generated/instrument-meta-data.json"

func LoadMetadataFromJson() {
if codeToInstrument != nil {
return
}

codeToInstrument = make(map[string]*Metadata)
nameToInstrument = make(map[string]*Metadata)
codeToInstrument = map[string]*Metadata{}
nameToInstrument = map[string]*Metadata{}

const url = "https://raw.githubusercontent.com/Leo4815162342/dukascopy-tools/master/packages/dukascopy-node/src/utils/instrument-meta-data/generated/instrument-meta-data.json"
resp, err := http.Get(url)
resp, err := http.Get(URL)
if err != nil {
log.Warn("Failed to retrieve dukas instrument from [" + url + "]")
slog.Warn("Failed to retrieve dukas instrument from [%s]", URL)

Check failure on line 96 in api/instrument/metadata.go

View workflow job for this annotation

GitHub Actions / Build

call to slog.Warn missing a final value

return
}

defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)

var m map[string]InstrumentJson
json.NewDecoder(resp.Body).Decode(&m)
if unmarshalErr := json.NewDecoder(resp.Body).Decode(&m); unmarshalErr != nil {
slog.Error(
"failed to unmarshal instrument file",
slog.String("url", URL),
slog.Any("error", err),
)
}

for instrumentCode, instrument := range m {
metadata := jsonToMetadata(instrumentCode, instrument)
codeToInstrument[metadata.Code()] = metadata
Expand Down
6 changes: 3 additions & 3 deletions api/tickdata/downloader/tick.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package downloader

import (
"github.com/ed-fx/go-duka/api/instrument"
"github.com/ed-fx/go-duka/internal/bi5"
"github.com/ed-fx/go-duka/internal/misc"
"github.com/edward-yakop/go-duka/api/instrument"
"github.com/edward-yakop/go-duka/internal/bi5"
"github.com/edward-yakop/go-duka/internal/misc"
"time"
)

Expand Down
6 changes: 3 additions & 3 deletions api/tickdata/downloader/tick_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package downloader

import (
"github.com/ed-fx/go-duka/api/instrument"
"github.com/ed-fx/go-duka/internal/bi5"
"github.com/ed-fx/go-duka/internal/misc"
"github.com/edward-yakop/go-duka/api/instrument"
"github.com/edward-yakop/go-duka/internal/bi5"
"github.com/edward-yakop/go-duka/internal/misc"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
Expand Down
16 changes: 3 additions & 13 deletions api/tickdata/stream/stream.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package stream

import (
"github.com/ed-fx/go-duka/api/instrument"
"github.com/ed-fx/go-duka/api/tickdata"
"github.com/ed-fx/go-duka/internal/bi5"
"github.com/edward-yakop/go-duka/api/instrument"
"github.com/edward-yakop/go-duka/api/tickdata"
"github.com/edward-yakop/go-duka/internal/bi5"
"time"
"unknwon.dev/clog/v2"
)

// time is in UTC
Expand Down Expand Up @@ -63,17 +62,8 @@ func downloadEnd(end time.Time) time.Time {
return dEnd
}

var isLogSetup = false

// time are in UTC
func New(instrument *instrument.Metadata, start time.Time, end time.Time, downloadFolderPath string) *Stream {
if !isLogSetup {
isLogSetup = true
_ = clog.NewConsole(0, clog.ConsoleConfig{
Level: clog.LevelInfo,
})
}

return &Stream{
instrument: instrument,
start: start,
Expand Down
4 changes: 2 additions & 2 deletions api/tickdata/stream/stream_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package stream

import (
"github.com/ed-fx/go-duka/api/instrument"
"github.com/ed-fx/go-duka/api/tickdata"
"github.com/edward-yakop/go-duka/api/instrument"
"github.com/edward-yakop/go-duka/api/tickdata"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
Expand Down
16 changes: 4 additions & 12 deletions api/tickdata/ticks/ticks.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package ticks

import (
"github.com/ed-fx/go-duka/api/instrument"
"github.com/ed-fx/go-duka/api/tickdata"
"github.com/ed-fx/go-duka/internal/bi5"
"github.com/ed-fx/go-duka/internal/misc"
"github.com/edward-yakop/go-duka/api/instrument"
"github.com/edward-yakop/go-duka/api/tickdata"
"github.com/edward-yakop/go-duka/internal/bi5"
"github.com/edward-yakop/go-duka/internal/misc"
"github.com/pkg/errors"
"time"
"unknwon.dev/clog/v2"
)

type Ticks struct {
Expand Down Expand Up @@ -186,13 +185,6 @@ var isLogSetup = false

// time are in UTC
func New(instrument *instrument.Metadata, start time.Time, end time.Time, downloadFolderPath string) *Ticks {
if !isLogSetup {
isLogSetup = true
_ = clog.NewConsole(0, clog.ConsoleConfig{
Level: clog.LevelInfo,
})
}

return &Ticks{
instrument: instrument,
start: start,
Expand Down
2 changes: 1 addition & 1 deletion api/tickdata/ticks/ticks_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ticks

import (
"github.com/ed-fx/go-duka/api/instrument"
"github.com/edward-yakop/go-duka/api/instrument"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
Expand Down
6 changes: 3 additions & 3 deletions examples/stream/dd_finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package stream

import (
"fmt"
"github.com/ed-fx/go-duka/api/instrument"
"github.com/ed-fx/go-duka/api/tickdata"
"github.com/ed-fx/go-duka/api/tickdata/stream"
"github.com/edward-yakop/go-duka/api/instrument"
"github.com/edward-yakop/go-duka/api/tickdata"
"github.com/edward-yakop/go-duka/api/tickdata/stream"
"github.com/stretchr/testify/assert"
"io/ioutil"
"math"
Expand Down
14 changes: 0 additions & 14 deletions glide.lock

This file was deleted.

10 changes: 0 additions & 10 deletions glide.yaml

This file was deleted.

16 changes: 10 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
module github.com/ed-fx/go-duka
module github.com/edward-yakop/go-duka

go 1.15
go 1.22

require (
github.com/fatih/color v1.10.0 // indirect
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.4.0
github.com/ulikunitz/xz v0.5.9
unknwon.dev/clog/v2 v2.2.0
github.com/stretchr/testify v1.9.0
github.com/ulikunitz/xz v0.5.12
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
34 changes: 8 additions & 26 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/ulikunitz/xz v0.5.9 h1:RsKRIA2MO8x56wkkcd3LbtcE/uMszhb6DpRf+3uwa3I=
github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
unknwon.dev/clog/v2 v2.2.0 h1:jkPdsxux0MC04BT/9NHbT75z4prK92SH10VBNmIpVCc=
unknwon.dev/clog/v2 v2.2.0/go.mod h1:zvUlyibDHI4mykYdWyWje2G9nF/nBzfDOqRo2my4mWc=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading

0 comments on commit d12c3d1

Please sign in to comment.