Skip to content

Commit

Permalink
Merge pull request #1 from blampe/master
Browse files Browse the repository at this point in the history
Merging from remote
  • Loading branch information
appsdesh authored Dec 20, 2017
2 parents a6588f7 + 0c3e942 commit d17d1a2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ $ go build ./

```
./dcagdax --help
usage: dcagdax --every=EVERY --usd=USD [<flags>]
usage: dcagdax --every=EVERY [<flags>]
Flags:
--help Show context-sensitive help (also try --help-long and --help-man).
--help Show context-sensitive help (also try --help-long and
--help-man).
--coin=BTC Which coin you want to buy: BTC, LTC, or ETH (default 'BTC').
--every=EVERY How often to make purchases, e.g. 1h, 7d, 3w.
--usd=USD How much USD to spend on each purchase.
--usd=USD How much USD to spend on each purchase. If unspecified, the
minimum purchase amount allowed will be used.
--until=UNTIL Stop executing trades after this date, e.g. 2017-12-31.
--trade Actually execute trades.
--autofund Automatically initiate ACH deposits.
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ var (

usd = kingpin.Flag(
"usd",
"How much USD to spend on each purchase.",
).Required().Float()
"How much USD to spend on each purchase. If unspecified, the minimum purchase amount allowed will be used.",
).Float()

until = registerDate(kingpin.Flag(
"until",
Expand Down
14 changes: 13 additions & 1 deletion schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,28 @@ func newGdaxSchedule(
return nil, err
}

if schedule.usd == 0.0 {
schedule.usd = minimum + 0.1
}

if schedule.usd < minimum {
return nil, errors.New(fmt.Sprintf(
"GDAX's minimum %s trade amount is $%.02f, but you're trying to purchase $%f",
schedule.coin, minimum, schedule.usd,
))
}

// GDAX has a limit of 8 decimal places.
schedule.usd = roundFloat(schedule.usd, 8)

return &schedule, nil
}

func roundFloat(f float64, places int) (float64) {
shift := math.Pow(10, float64(places))
return math.Floor(f * shift + .5) / shift;
}

// Sync initiates trades & funding with a DCA strategy.
func (s *gdaxSchedule) Sync() error {

Expand Down Expand Up @@ -147,7 +159,7 @@ func (s *gdaxSchedule) minimumUSDPurchase() (float64, error) {

for _, p := range products {
if p.BaseCurrency == s.coin {
return p.BaseMinSize * ticker.Price, nil
return math.Max(p.BaseMinSize * ticker.Price, 1.0), nil
}
}

Expand Down

0 comments on commit d17d1a2

Please sign in to comment.