diff --git a/README.md b/README.md index 43daac4..832a151 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ go get github.com/swhite24/cbpro-buy/cmd/cbpro-buy - Purchase any product on Coinbase Pro in any currency pair (that's available to your locale / account). - Automatically deposit funds to conduct the purchase if your USD / other currency account is unable to fulfill. - Automatically wait for deposit to clear before attempting to issue a market buy. +- Allow for weighing purchases if current price falls below average price over configured amount of time. ## Usage @@ -44,6 +45,29 @@ Flags: --use-basis Whether to adjust purchase amount if current price is below average cost over time window ``` +## Example + +```sh +$ export CBPRO_BUY_SECRET="..." +$ export CBPRO_BUY_KEY="..." +$ export CBPRO_BUY_PASSPHRASE="..." +$ cbpro-buy --amount 10 --autodeposit --use-basis +Use basis configured. Getting average purchase price over last 30 days. +Average purchase price: 56580.94 +Current book price: 54953.52 +Current price less than average price. +Adjusting buy amount from 10.00 to 15.00 +Fetching current funding account status. +Success. Available balance: 0.330014 +Available balance is less than requested purchase: 15.00 +Initiating deposit of 15.00 USD +Waiting for deposit to be available in account. +Checking available balance: 0.33 +Checking available balance: 15.33 +Initiating purchase of 15.00 USD worth of BTC +Purchase successful! +``` + ## Lambda Usage This repo also contains an example deployment using [AWS Lambda](https://aws.amazon.com/lambda/) executed on a schedule to provide a means to "dollar cost average" with scheduled buys regardless of price. This is handled with [terraform](https://www.terraform.io/). See [the terraform directory](terraform) for details. diff --git a/pkg/purchase/purchase.go b/pkg/purchase/purchase.go index 2559c68..d0603c6 100644 --- a/pkg/purchase/purchase.go +++ b/pkg/purchase/purchase.go @@ -41,12 +41,12 @@ func (p *purchaser) initiatePurchase() error { // Check if current balance is sufficient if initialBalance < p.cfg.Amount { - fmt.Printf("Available balance is less than requested purchase: %f\n", p.cfg.Amount) + fmt.Printf("Available balance is less than requested purchase: %.2f\n", p.cfg.Amount) if !p.cfg.AutoDeposit { return errors.New("insufficient funds for purchase") } // initiate and wait for deposit - fmt.Printf("Initiating deposit of %f %s\n", p.cfg.Amount, p.cfg.Currency) + fmt.Printf("Initiating deposit of %.2f %s\n", p.cfg.Amount, p.cfg.Currency) if err = p.deposit(p.cfg.Currency, p.cfg.Amount, p.cfg.UseCoinbase); err != nil { return err } @@ -66,7 +66,7 @@ func (p *purchaser) initiatePurchase() error { continue } - fmt.Printf("Checking available balance: %f\n", balance) + fmt.Printf("Checking available balance: %.2f\n", balance) if balance >= cfg.Amount { ch <- 1 @@ -85,7 +85,7 @@ func (p *purchaser) initiatePurchase() error { } // Make purchase - fmt.Printf("Initiating purchase of %f %s worth of %s\n", p.cfg.Amount, p.cfg.Currency, p.cfg.Product) + fmt.Printf("Initiating purchase of %.2f %s worth of %s\n", p.cfg.Amount, p.cfg.Currency, p.cfg.Product) return p.purchase(p.cfg.Product, p.cfg.Currency, p.cfg.Amount) }