Skip to content

Commit

Permalink
Left with the sleep and timing
Browse files Browse the repository at this point in the history
  • Loading branch information
saintmalik committed Aug 8, 2022
1 parent cec6ba3 commit 1ca105c
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 55 deletions.
49 changes: 24 additions & 25 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
"text/template"

Expand All @@ -18,51 +17,51 @@ import (
//go:embed all:templates/*
var TempFs embed.FS

const (
configYaml = "config.yaml"
configJSON = "config.json"
foldername = "cmd"
)

var tmpl *template.Template

// configCmd represents the config command
var configCmd = &cobra.Command{
Use: "config",
Short: "This command allows you to set DCA Configurations",
Long: `This command allows you to set your Binance API and Secret and other Configurations`,
Run: func(cmd *cobra.Command, args []string) {
setApi, _ := cmd.Flags().GetString("credapi")
if setApi == "reset" {
openbrowser("http://localhost:4046/api")
http.HandleFunc("/api", creds)
fmt.Println("Starting Server to set Binance API and Secret")
panic(http.ListenAndServe("localhost:4046", nil))
} else {
main()
setCreds, _ := cmd.Flags().GetString("set")
fmt.Println(setCreds)
switch {
case setCreds == "dcainfo":
dcaConfigRun()
case setCreds == "secret":
dcaCredsRun()
default:
fmt.Println("You have entered an invalid command")
}
},
}

var tmpl *template.Template

func init() {
rootCmd.AddCommand(configCmd)
configCmd.PersistentFlags().String("credapi", "reset", "Set your Binance API and SecretKey credentials")
configCmd.PersistentFlags().String("set", "", "Set your Binance Configurations")
tmpl = template.Must(template.ParseFS(TempFs, "templates/*.html"))
}

func main() {
func dcaConfigRun() {
openbrowser("http://localhost:4046/")
http.HandleFunc("/", form)
http.HandleFunc("/", dcaConfig)
fmt.Println("Starting Server to set Configurations")
panic(http.ListenAndServe("localhost:4046", nil))
}

func creds(w http.ResponseWriter, r *http.Request) {
func dcaCredsRun () {
openbrowser("http://localhost:4046/api")
http.HandleFunc("/api", dcaCreds)
fmt.Println("Starting Server to set Binance API and Secret")
panic(http.ListenAndServe("localhost:4046", nil))
}

func dcaCreds(w http.ResponseWriter, r *http.Request) {
model.Bapi = r.FormValue("bapi")
model.Bsecret = r.FormValue("bsecret") //picking up the value from the form

f, err := os.Create(filepath.Join(foldername, configYaml))
f, err := os.Create("config.yaml")
if err != nil {
fmt.Println(err)
return
Expand All @@ -87,15 +86,15 @@ func creds(w http.ResponseWriter, r *http.Request) {
}
}

func form(w http.ResponseWriter, r *http.Request) {
func dcaConfig(w http.ResponseWriter, r *http.Request) {
model.Coinid = r.FormValue("coinid")
model.Amount = r.FormValue("amount")
model.Alloted = r.FormValue("allottedpercent")
model.Buyinterval = r.FormValue("buyingintervals")
model.Fee = r.FormValue("feepercent")
model.Testvalue = r.FormValue("testing") //picking up the value from the form

f, err := os.Create(filepath.Join(foldername, configJSON))
f, err := os.Create("config.json")
if err != nil {
fmt.Println(err)
return
Expand Down
1 change: 0 additions & 1 deletion cmd/config.json

This file was deleted.

4 changes: 0 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
Expand Down
14 changes: 3 additions & 11 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"context"
_ "embed"
"encoding/json"
"fmt"
"log"
Expand All @@ -15,12 +14,6 @@ import (
"github.com/spf13/viper"
)

//go:embed all:vipercon.yaml
var configjsonFs string

//go:embed all:viper.yaml
var configyamlFs string

// runCmd represents the run command
var runCmd = &cobra.Command{
Use: "run",
Expand All @@ -33,9 +26,9 @@ var runCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(runCmd)
viper.SetConfigName(configjsonFs) // name of config file (without extension)
viper.SetConfigName("config") // name of config file (without extension)
viper.SetConfigType("json") // REQUIRED if the config file does not have the extension in the name
viper.AddConfigPath("cmd") // optionally look for config in the working directory
viper.AddConfigPath(".") // optionally look for config in the working directory
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("fatal error config file: %w", err))
Expand All @@ -44,7 +37,6 @@ func init() {
}

func perform() {
// time.Sleep(time.Hour * 6)
model.Testvalue = viper.GetString("testing")
if model.Testvalue == "true" {
fmt.Println("Real orders cannot be made in testing mode")
Expand Down Expand Up @@ -105,7 +97,7 @@ func dcaBuy() {

fmt.Println("Price per buy:", model.Priceperbuy)

viper.SetConfigFile(configyamlFs)
viper.SetConfigFile("./config.yaml")
viper.ReadInConfig()

client := binance.NewClient(viper.GetString("api"), viper.GetString("secretkey"))
Expand Down
1 change: 0 additions & 1 deletion cmd/viper.yaml

This file was deleted.

1 change: 0 additions & 1 deletion cmd/vipercon.yaml

This file was deleted.

1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"coins":"ETH","amount":"2000","percent":"20","fee":"0.15","testing":"false","buyintervals":"4"}
File renamed without changes.
24 changes: 12 additions & 12 deletions model/data.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package model

var (
Alloted string
Coinid string
Amount string
Buyinterval string
Fee string
Bapi string
Bsecret string
Testvalue string
Priceperbuy string
Config_allocated float64
Config_amount float64
Alloted string
Coinid string
Amount string
Buyinterval string
Fee string
Bapi string
Bsecret string
Testvalue string
Priceperbuy string
Config_allocated float64
Config_amount float64
Config_buyintervals int
Config_fee float64
Config_fee float64
)

type Config struct {
Expand Down

0 comments on commit 1ca105c

Please sign in to comment.