Skip to content

Commit

Permalink
Merge pull request #6 from swhite24/feature/log-formatting
Browse files Browse the repository at this point in the history
Feature/log formatting
  • Loading branch information
swhite24 authored Apr 19, 2021
2 parents 7620946 + 6c57700 commit cde9437
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions pkg/purchase/purchase.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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)
}

Expand Down

0 comments on commit cde9437

Please sign in to comment.