From 29810ce03fdbe9576570a7de54bd99982acdb38e Mon Sep 17 00:00:00 2001 From: Steven White Date: Fri, 16 Apr 2021 09:37:45 -0400 Subject: [PATCH 1/4] update docs --- README.md | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3b33052..43daac4 100644 --- a/README.md +++ b/README.md @@ -29,16 +29,19 @@ Usage: cbpro-buy [flags] Flags: - --amount float Amount of product to purchase (default 50) - --autodeposit Whether to auto deposit funds if current account is less than amount - --coinbase Whether to use coinbase account for funds instead of ACH - --currency string Currency to deposit / purchase with (USD, EUR, etc.) (default "USD") - -h, --help help for cbpro-buy - --key string Coinbase Pro API key - --passphrase string Coinbase Pro API key passphrase - --product string Product to purchase from coinbase pro (BTC, ETH, etc.) (default "BTC") - --sandbox Whether to use coinbase pro sandbox environment (will require different api key - --secret string Coinbase Pro API key secret + --amount float Amount of product to purchase (default 50) + --autodeposit Whether to auto deposit funds if current account is less than amount + --basis-multiplier float Scale to apply to purchase amount if current price is less than average cost (default 1.5) + --basis-window-start float Mumber of days in the past to for beginning of basis window (default 30) + --coinbase Whether to use coinbase account for funds instead of ACH + --currency string Currency to deposit / purchase with (USD, EUR, etc.) (default "USD") + -h, --help help for cbpro-buy + --key string Coinbase Pro API key + --passphrase string Coinbase Pro API key passphrase + --product string Product to purchase from coinbase pro (BTC, ETH, etc.) (default "BTC") + --sandbox Whether to use coinbase pro sandbox environment (will require different api key + --secret string Coinbase Pro API key secret + --use-basis Whether to adjust purchase amount if current price is below average cost over time window ``` ## Lambda Usage From 10bb1e218e85d70ac21fefe88610612ab9bf9396 Mon Sep 17 00:00:00 2001 From: Steven White Date: Fri, 16 Apr 2021 09:47:32 -0400 Subject: [PATCH 2/4] add logs around basis calculation flow --- pkg/cmd/cbprobuy.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/cbprobuy.go b/pkg/cmd/cbprobuy.go index fc4d1de..324030a 100644 --- a/pkg/cmd/cbprobuy.go +++ b/pkg/cmd/cbprobuy.go @@ -39,6 +39,7 @@ func init() { // Determine basis if configured if cfg.UseBasis { + fmt.Printf("use-basis configured; getting average purchase price over last %f days.\n", cfg.BasisWindowStart) // Calculate average cost c := &basisconfig.Config{ Key: cfg.Key, @@ -54,7 +55,7 @@ func init() { fmt.Println(err) os.Exit(1) } - fmt.Println(c, info, err) + fmt.Printf("Average purchase price: %s\n", info.AverageCost) // Get current price average, _ := strconv.ParseFloat(info.AverageCost, 64) @@ -64,9 +65,12 @@ func init() { fmt.Println(err) os.Exit(1) } + fmt.Printf("Current book price: %.2f\n", price) // Update purchase amount if current price is less than average cost if price < average { + fmt.Println("Current price less than average price.") + fmt.Printf("Adjusting buy amount from %.2f to %.2f\n", cfg.Amount, cfg.Amount*cfg.BasisMultiplier) cfg.Amount = cfg.Amount * cfg.BasisMultiplier } } From 4591019f9a8c3150f9e1adf37335c862f53eab69 Mon Sep 17 00:00:00 2001 From: Steven White Date: Fri, 16 Apr 2021 09:50:45 -0400 Subject: [PATCH 3/4] add log when not adjusting buy amount --- pkg/cmd/cbprobuy.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/cbprobuy.go b/pkg/cmd/cbprobuy.go index 324030a..1d08e22 100644 --- a/pkg/cmd/cbprobuy.go +++ b/pkg/cmd/cbprobuy.go @@ -35,11 +35,10 @@ func init() { Run: func(cmd *cobra.Command, args []string) { cfg := config.InitializeConfig(cmd.Flags()) client := initializeClient(cfg) - fmt.Println(cfg) // Determine basis if configured if cfg.UseBasis { - fmt.Printf("use-basis configured; getting average purchase price over last %f days.\n", cfg.BasisWindowStart) + fmt.Printf("Use basis configured. Getting average purchase price over last %.0f days.\n", cfg.BasisWindowStart) // Calculate average cost c := &basisconfig.Config{ Key: cfg.Key, @@ -72,6 +71,8 @@ func init() { fmt.Println("Current price less than average price.") fmt.Printf("Adjusting buy amount from %.2f to %.2f\n", cfg.Amount, cfg.Amount*cfg.BasisMultiplier) cfg.Amount = cfg.Amount * cfg.BasisMultiplier + } else { + fmt.Println("Current price greater than average price. Not adjusting buy amount.") } } From 84d948ffc41ff006411775b7d43ee97306e1bbad Mon Sep 17 00:00:00 2001 From: Steven White Date: Fri, 16 Apr 2021 09:53:19 -0400 Subject: [PATCH 4/4] configure basis window start in tf --- terraform/main.tf | 17 +++++++++-------- terraform/var.tf | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index 7ded78c..fe1d981 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -35,14 +35,15 @@ resource "aws_lambda_function" "cbpro_buy" { environment { variables = { - CBPRO_BUY_KEY = var.cbpro_key - CBPRO_BUY_PASSPHRASE = var.cbpro_passphrase - CBPRO_BUY_SECRET = var.cbpro_secret - CBPRO_BUY_CURRENCY = var.currency - CBPRO_BUY_PRODUCT = var.product - CBPRO_BUY_AMOUNT = var.amount - CBPRO_BUY_AUTODEPOSIT = var.auto_deposit - CBPRO_BUY_USE_BASIS = var.use_basis + CBPRO_BUY_KEY = var.cbpro_key + CBPRO_BUY_PASSPHRASE = var.cbpro_passphrase + CBPRO_BUY_SECRET = var.cbpro_secret + CBPRO_BUY_CURRENCY = var.currency + CBPRO_BUY_PRODUCT = var.product + CBPRO_BUY_AMOUNT = var.amount + CBPRO_BUY_AUTODEPOSIT = var.auto_deposit + CBPRO_BUY_USE_BASIS = var.use_basis + CBPRO_BUY_BASIS_WINDOW_START = var.basis_window_start } } } diff --git a/terraform/var.tf b/terraform/var.tf index 8076459..e7eb141 100644 --- a/terraform/var.tf +++ b/terraform/var.tf @@ -9,6 +9,7 @@ variable "amount" { default = 50 } variable "currency" { default = "USD" } variable "product" { default = "BTC" } variable "use_basis" { default = true } +variable "basis_window_start" { default = 60 } variable "cbpro_key" { type = string sensitive = true