diff --git a/.github/workflows/gosec.yml b/.github/workflows/gosec.yml new file mode 100644 index 0000000..087a446 --- /dev/null +++ b/.github/workflows/gosec.yml @@ -0,0 +1,25 @@ +name: Run Gosec +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + gosec: + name: GoSec Security Scanner + runs-on: ubuntu-latest + steps: + - name: Checkout Source + uses: actions/checkout@v3 + + - name: Install GoSec 2.18.2 + run: | + curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.19.0 + + - name: Run Gosec Security Scanner + run: | + cd radicalvpnd + $(go env GOPATH)/bin/gosec ./... diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d523e15 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,32 @@ +name: Release + +on: + push: + tags: + - v* + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + id: go + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..8575728 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,25 @@ +project_name: kraken-dca +builds: + - goos: + - linux + - darwin + goarch: + - amd64 + - arm + - arm64 + goarm: + - "6" + - "7" +release: + draft: true +snapshot: + name_template: "{{ .Version }}-{{.ShortCommit}}" +checksum: + name_template: "{{ .ProjectName }}_checksums.txt" +dockers: + - image_templates: + - "gcr.io/primexz/kraken_dca:{{ .Tag }}" + - "gcr.io/primexz/kraken_dca:latest" +changelog: + use: github + sort: asc \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index fbe40a7..9f33006 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,4 @@ -FROM golang:1.22 +FROM scratch -# Set destination for COPY -WORKDIR /app - -# Download Go modules -COPY go.mod go.sum ./ -RUN go mod download - -COPY . /app/ - -# Build -RUN CGO_ENABLED=0 GOOS=linux go build -o /kraken_dca - -EXPOSE 8080 - -# Run -CMD ["/kraken_dca"] \ No newline at end of file +ENTRYPOINT ["/kraken-dca"] +COPY kraken-dca / \ No newline at end of file diff --git a/bot/bot.go b/bot/bot.go index 0956622..6159d95 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -49,7 +49,7 @@ func run() { log.Println("Next Fiat deposit required at", timeOfEmptyFiat) - updateFiatBalance(fiatAmount) + lastFiatBalance = fiatAmount } lastBtcFiatPrice = kraken.GetCurrentBtcFiatPrice() @@ -60,22 +60,11 @@ func run() { if (timeOfNextOrder.Before(time.Now()) || newFiatMoney) && !initialRun { log.Println("Placing bitcoin purchase order. ₿") + kraken.BuyBtc() calculateTimeOfNextOrder() } log.Println("Next order in", fmtDuration(time.Until(timeOfNextOrder)), timeOfNextOrder) -} - -func calculateTimeOfNextOrder() { - fiatValueInBtc := fiatAmount / lastBtcFiatPrice - orderAmountUntilRefill := fiatValueInBtc / config.KrakenOrderSize - - now := time.Now().UnixMilli() - timeOfNextOrder = time.UnixMilli((timeOfEmptyFiat.UnixMilli()-now)/int64(orderAmountUntilRefill) + now) -} - -func updateFiatBalance(fiat float64) { - lastFiatBalance = fiat -} +} \ No newline at end of file diff --git a/bot/calculations.go b/bot/calculations.go new file mode 100644 index 0000000..3148b51 --- /dev/null +++ b/bot/calculations.go @@ -0,0 +1,27 @@ +package bot + +import ( + "time" + + "github.com/primexz/KrakenDCA/config" +) + +func computeNextFiatDepositDay() time.Time { + date := addMonthsToTime(1, time.Now()) + + //get the first day of the month + return date.AddDate(0, 0, -date.Day()+1) +} + +func calculateTimeOfNextOrder() { + orderAmountUntilRefill := getOrderAmountUntilRefill() + + now := time.Now().UnixMilli() + timeOfNextOrder = time.UnixMilli((timeOfEmptyFiat.UnixMilli()-now)/int64(orderAmountUntilRefill) + now) +} + +func getOrderAmountUntilRefill() float64 { + fiatValueInBtc := fiatAmount / lastBtcFiatPrice + + return fiatValueInBtc / config.KrakenOrderSize +} diff --git a/bot/time.go b/bot/time.go index 771acc1..6b8a42a 100644 --- a/bot/time.go +++ b/bot/time.go @@ -5,13 +5,6 @@ import ( "time" ) -func computeNextFiatDepositDay() time.Time { - date := addMonthsToTime(1, time.Now()) - - //get the first day of the month - return date.AddDate(0, 0, -date.Day()+1) -} - func addMonthsToTime(months int, time time.Time) time.Time { return time.AddDate(0, months, 0) }