diff --git a/README.md b/README.md index 26666b8..e08b858 100644 --- a/README.md +++ b/README.md @@ -28,13 +28,15 @@ $ go build ./ ``` ./dcagdax --help -usage: dcagdax --every=EVERY --usd=USD [] +usage: dcagdax --every=EVERY [] 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. diff --git a/main.go b/main.go index 0e0001a..3b36999 100644 --- a/main.go +++ b/main.go @@ -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", diff --git a/schedule.go b/schedule.go index 834a3d4..ed50604 100644 --- a/schedule.go +++ b/schedule.go @@ -52,6 +52,10 @@ 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", @@ -59,9 +63,17 @@ func newGdaxSchedule( )) } + // 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 { @@ -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 } }