Skip to content

Commit

Permalink
Merge pull request #5 from swhite24/feature/basis-logs
Browse files Browse the repository at this point in the history
Feature/basis logs
  • Loading branch information
swhite24 authored Apr 16, 2021
2 parents 5a292a1 + 84d948f commit 7620946
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions pkg/cmd/cbprobuy.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +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 %.0f days.\n", cfg.BasisWindowStart)
// Calculate average cost
c := &basisconfig.Config{
Key: cfg.Key,
Expand All @@ -54,7 +54,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)
Expand All @@ -64,10 +64,15 @@ 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
} else {
fmt.Println("Current price greater than average price. Not adjusting buy amount.")
}
}

Expand Down
17 changes: 9 additions & 8 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
1 change: 1 addition & 0 deletions terraform/var.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7620946

Please sign in to comment.