diff --git a/pkg/accounting/cost_distribution.go b/pkg/accounting/cost_distribution.go index 7bdfb3d3e..e66f06592 100644 --- a/pkg/accounting/cost_distribution.go +++ b/pkg/accounting/cost_distribution.go @@ -7,8 +7,8 @@ import ( "strings" "sync" - "github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/c9s/bbgo/pkg/types" ) func zero(a float64) bool { @@ -57,15 +57,15 @@ type StockDistribution struct { } type DistributionStats struct { - PriceLevels []string `json:"priceLevels"` - TotalQuantity fixedpoint.Value `json:"totalQuantity"` - Quantities map[string]fixedpoint.Value `json:"quantities"` - Stocks map[string]StockSlice `json:"stocks"` + PriceLevels []string `json:"priceLevels"` + TotalQuantity fixedpoint.Value `json:"totalQuantity"` + Quantities map[string]fixedpoint.Value `json:"quantities"` + Stocks map[string]StockSlice `json:"stocks"` } func (m *StockDistribution) DistributionStats(level int) *DistributionStats { var d = DistributionStats{ - Quantities: map[string]fixedpoint.Value {}, + Quantities: map[string]fixedpoint.Value{}, Stocks: map[string]StockSlice{}, } diff --git a/pkg/accounting/cost_distribution_test.go b/pkg/accounting/cost_distribution_test.go index 5c1fd91a7..3addf28af 100644 --- a/pkg/accounting/cost_distribution_test.go +++ b/pkg/accounting/cost_distribution_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/assert" - "github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/c9s/bbgo/pkg/types" ) func TestStockManager(t *testing.T) { diff --git a/pkg/backtest/stream.go b/pkg/backtest/stream.go index ec91b444a..91e93a7b9 100644 --- a/pkg/backtest/stream.go +++ b/pkg/backtest/stream.go @@ -39,4 +39,3 @@ func (s *Stream) Connect(ctx context.Context) error { func (s *Stream) Close() error { return nil } - diff --git a/pkg/bbgo/context.go b/pkg/bbgo/context.go index 2613c0bc9..5c5a19364 100644 --- a/pkg/bbgo/context.go +++ b/pkg/bbgo/context.go @@ -8,4 +8,3 @@ import ( type Context struct { sync.Mutex } - diff --git a/pkg/bbgo/errors.go b/pkg/bbgo/errors.go index 3228b458f..cb0518be0 100644 --- a/pkg/bbgo/errors.go +++ b/pkg/bbgo/errors.go @@ -3,4 +3,3 @@ package bbgo import "errors" var ErrSessionAlreadyInitialized = errors.New("session is already initialized") - diff --git a/pkg/bbgo/interact.go b/pkg/bbgo/interact.go index cb13a13db..bfea185cc 100644 --- a/pkg/bbgo/interact.go +++ b/pkg/bbgo/interact.go @@ -8,9 +8,9 @@ import ( "strconv" "strings" + "github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/interact" "github.com/c9s/bbgo/pkg/types" - "github.com/c9s/bbgo/pkg/fixedpoint" ) type PositionCloser interface { @@ -128,7 +128,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) { } } - if kc, ok := reply.(interact.KeyboardController) ; ok { + if kc, ok := reply.(interact.KeyboardController); ok { kc.RemoveKeyboard() } @@ -176,7 +176,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) { if position.Base.IsZero() { reply.Message("No opened position") - if kc, ok := reply.(interact.KeyboardController) ; ok { + if kc, ok := reply.(interact.KeyboardController); ok { kc.RemoveKeyboard() } return fmt.Errorf("no opened position") @@ -197,7 +197,7 @@ func (it *CoreInteraction) Commands(i *interact.Interact) { return err } - if kc, ok := reply.(interact.KeyboardController) ; ok { + if kc, ok := reply.(interact.KeyboardController); ok { kc.RemoveKeyboard() } diff --git a/pkg/bbgo/moving_average_settings.go b/pkg/bbgo/moving_average_settings.go index d6d4dadd4..24118f169 100644 --- a/pkg/bbgo/moving_average_settings.go +++ b/pkg/bbgo/moving_average_settings.go @@ -11,7 +11,7 @@ type MovingAverageSettings struct { Interval types.Interval `json:"interval"` Window int `json:"window"` - Side *types.SideType `json:"side"` + Side *types.SideType `json:"side"` QuantityOrAmount } diff --git a/pkg/bbgo/order_execution.go b/pkg/bbgo/order_execution.go index e9310af4c..58c885a08 100644 --- a/pkg/bbgo/order_execution.go +++ b/pkg/bbgo/order_execution.go @@ -217,7 +217,7 @@ func (c *BasicRiskController) ProcessOrders(session *ExchangeSession, orders ... accumulativeQuoteAmount = accumulativeQuoteAmount.Add(notional) case types.SideTypeSell: - minNotion := market.MinNotional.Mul(increaseFactor) + minNotion := market.MinNotional.Mul(increaseFactor) // Critical conditions for placing SELL orders baseAssetBalance, ok := balances[market.BaseCurrency] diff --git a/pkg/bbgo/order_processor_test.go b/pkg/bbgo/order_processor_test.go index bd238be1b..997654868 100644 --- a/pkg/bbgo/order_processor_test.go +++ b/pkg/bbgo/order_processor_test.go @@ -3,8 +3,8 @@ package bbgo import ( "testing" - "github.com/stretchr/testify/assert" "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/stretchr/testify/assert" ) func TestAdjustQuantityByMinAmount(t *testing.T) { @@ -19,8 +19,8 @@ func TestAdjustQuantityByMinAmount(t *testing.T) { tests := []testcase{ { - name: "amount too small", - args: args{ + name: "amount too small", + args: args{ fixedpoint.MustNewFromString("0.1"), fixedpoint.MustNewFromString("10.0"), fixedpoint.MustNewFromString("10.0"), @@ -28,8 +28,8 @@ func TestAdjustQuantityByMinAmount(t *testing.T) { wanted: "1.0", }, { - name: "amount equals to min amount", - args: args{ + name: "amount equals to min amount", + args: args{ fixedpoint.MustNewFromString("1.0"), fixedpoint.MustNewFromString("10.0"), fixedpoint.MustNewFromString("10.0"), @@ -37,8 +37,8 @@ func TestAdjustQuantityByMinAmount(t *testing.T) { wanted: "1.0", }, { - name: "amount is greater than min amount", - args: args{ + name: "amount is greater than min amount", + args: args{ fixedpoint.MustNewFromString("2.0"), fixedpoint.MustNewFromString("10.0"), fixedpoint.MustNewFromString("10.0"), diff --git a/pkg/bbgo/scale_test.go b/pkg/bbgo/scale_test.go index 49d0fc9a1..66e8544e3 100644 --- a/pkg/bbgo/scale_test.go +++ b/pkg/bbgo/scale_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - ) const Delta = 1e-9 @@ -200,4 +199,3 @@ func TestPercentageScale(t *testing.T) { assert.InDelta(t, 100.0, v, Delta) }) } - diff --git a/pkg/bbgo/session.go b/pkg/bbgo/session.go index 089190ddd..525664872 100644 --- a/pkg/bbgo/session.go +++ b/pkg/bbgo/session.go @@ -173,8 +173,8 @@ type ExchangeSession struct { // Withdrawal is used for enabling withdrawal functions Withdrawal bool `json:"withdrawal,omitempty" yaml:"withdrawal,omitempty"` - MakerFeeRate fixedpoint.Value `json:"makerFeeRate,omitempty" yaml:"makerFeeRate,omitempty"` - TakerFeeRate fixedpoint.Value `json:"takerFeeRate,omitempty" yaml:"takerFeeRate,omitempty"` + MakerFeeRate fixedpoint.Value `json:"makerFeeRate" yaml:"makerFeeRate"` + TakerFeeRate fixedpoint.Value `json:"takerFeeRate" yaml:"takerFeeRate"` PublicOnly bool `json:"publicOnly,omitempty" yaml:"publicOnly"` Margin bool `json:"margin,omitempty" yaml:"margin"` diff --git a/pkg/bbgo/smart_stops.go b/pkg/bbgo/smart_stops.go index 7deb4f500..e3dd0ca26 100644 --- a/pkg/bbgo/smart_stops.go +++ b/pkg/bbgo/smart_stops.go @@ -115,7 +115,7 @@ func (c *TrailingStopController) Run(ctx context.Context, session *ExchangeSessi // if the profit rate is defined, and it is less than our minimum profit rate, we skip stop if c.MinProfit.Sign() > 0 && closePrice.Compare(c.averageCost) < 0 || - changeRate(closePrice, c.averageCost).Compare(c.MinProfit) < 0 { + changeRate(closePrice, c.averageCost).Compare(c.MinProfit) < 0 { return } diff --git a/pkg/bbgo/tradecollector_test.go b/pkg/bbgo/tradecollector_test.go index 2473b826c..149eb4997 100644 --- a/pkg/bbgo/tradecollector_test.go +++ b/pkg/bbgo/tradecollector_test.go @@ -5,8 +5,8 @@ import ( "github.com/stretchr/testify/assert" - "github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/c9s/bbgo/pkg/types" ) func TestTradeCollector_ShouldNotCountDuplicatedTrade(t *testing.T) { @@ -31,12 +31,12 @@ func TestTradeCollector_ShouldNotCountDuplicatedTrade(t *testing.T) { assert.Equal(t, 1, len(collector.tradeStore.Trades()), "should have one trade in the trade store") orderStore.Add(types.Order{ - SubmitOrder: types.SubmitOrder{ - Symbol: "BTCUSDT", - Side: types.SideTypeBuy, - Type: types.OrderTypeLimit, - Quantity: fixedpoint.One, - Price: fixedpoint.NewFromInt(40000), + SubmitOrder: types.SubmitOrder{ + Symbol: "BTCUSDT", + Side: types.SideTypeBuy, + Type: types.OrderTypeLimit, + Quantity: fixedpoint.One, + Price: fixedpoint.NewFromInt(40000), }, Exchange: types.ExchangeBinance, OrderID: 399, diff --git a/pkg/bbgo/twap_order_executor.go b/pkg/bbgo/twap_order_executor.go index ea534bda8..60bbf6108 100644 --- a/pkg/bbgo/twap_order_executor.go +++ b/pkg/bbgo/twap_order_executor.go @@ -283,7 +283,7 @@ func (e *TwapExecution) updateOrder(ctx context.Context) error { } func (e *TwapExecution) cancelActiveOrders() { - gracefulCtx, gracefulCancel := context.WithTimeout(context.TODO(), 30 * time.Second) + gracefulCtx, gracefulCancel := context.WithTimeout(context.TODO(), 30*time.Second) defer gracefulCancel() e.activeMakerOrders.GracefulCancel(gracefulCtx, e.Session.Exchange) } diff --git a/pkg/cmd/backtest.go b/pkg/cmd/backtest.go index b6334cb76..984de3850 100644 --- a/pkg/cmd/backtest.go +++ b/pkg/cmd/backtest.go @@ -21,15 +21,15 @@ import ( "github.com/c9s/bbgo/pkg/backtest" "github.com/c9s/bbgo/pkg/bbgo" "github.com/c9s/bbgo/pkg/cmd/cmdutil" + "github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/service" "github.com/c9s/bbgo/pkg/types" - "github.com/c9s/bbgo/pkg/fixedpoint" ) type BackTestReport struct { Symbol string `json:"symbol,omitempty"` - LastPrice fixedpoint.Value `json:"lastPrice,omitempty"` - StartPrice fixedpoint.Value `json:"startPrice,omitempty"` + LastPrice fixedpoint.Value `json:"lastPrice,omitempty"` + StartPrice fixedpoint.Value `json:"startPrice,omitempty"` PnLReport *pnl.AverageCostPnlReport `json:"pnlReport,omitempty"` InitialBalances types.BalanceMap `json:"initialBalances,omitempty"` FinalBalances types.BalanceMap `json:"finalBalances,omitempty"` diff --git a/pkg/cmd/balances.go b/pkg/cmd/balances.go index 26bb8cde0..d3252e27c 100644 --- a/pkg/cmd/balances.go +++ b/pkg/cmd/balances.go @@ -24,7 +24,6 @@ var balancesCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() - configFile, err := cmd.Flags().GetString("config") if err != nil { return err @@ -39,7 +38,6 @@ var balancesCmd = &cobra.Command{ return err } - // if config file exists, use the config loaded from the config file. // otherwise, use a empty config object var userConfig *bbgo.Config @@ -63,7 +61,6 @@ var balancesCmd = &cobra.Command{ return err } - if len(sessionName) > 0 { session, ok := environ.Session(sessionName) if !ok { @@ -89,7 +86,6 @@ var balancesCmd = &cobra.Command{ } } - return nil }, } diff --git a/pkg/cmd/builtin.go b/pkg/cmd/builtin.go index ee84eafdc..d97bd1b17 100644 --- a/pkg/cmd/builtin.go +++ b/pkg/cmd/builtin.go @@ -14,6 +14,7 @@ import ( _ "github.com/c9s/bbgo/pkg/strategy/pricedrop" _ "github.com/c9s/bbgo/pkg/strategy/rebalance" _ "github.com/c9s/bbgo/pkg/strategy/schedule" + _ "github.com/c9s/bbgo/pkg/strategy/skeleton" _ "github.com/c9s/bbgo/pkg/strategy/support" _ "github.com/c9s/bbgo/pkg/strategy/swing" _ "github.com/c9s/bbgo/pkg/strategy/techsignal" @@ -22,5 +23,4 @@ import ( _ "github.com/c9s/bbgo/pkg/strategy/xmaker" _ "github.com/c9s/bbgo/pkg/strategy/xnav" _ "github.com/c9s/bbgo/pkg/strategy/xpuremaker" - _ "github.com/c9s/bbgo/pkg/strategy/skeleton" ) diff --git a/pkg/cmd/cancel.go b/pkg/cmd/cancel.go index fa2e1c3ff..3e401b6e8 100644 --- a/pkg/cmd/cancel.go +++ b/pkg/cmd/cancel.go @@ -85,7 +85,6 @@ var cancelOrderCmd = &cobra.Command{ var sessions = environ.Sessions() - if len(sessionName) > 0 { ses, ok := environ.Session(sessionName) if !ok { diff --git a/pkg/cmd/cmdutil/exchange.go b/pkg/cmd/cmdutil/exchange.go index 493d45563..a3c2c5e28 100644 --- a/pkg/cmd/cmdutil/exchange.go +++ b/pkg/cmd/cmdutil/exchange.go @@ -13,7 +13,7 @@ import ( "github.com/c9s/bbgo/pkg/types" ) -func NewExchangePublic(exchangeName types.ExchangeName) (types.Exchange, error){ +func NewExchangePublic(exchangeName types.ExchangeName) (types.Exchange, error) { return NewExchangeStandard(exchangeName, "", "", "", "") } diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index 0b7087033..fa845ba1a 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -164,7 +164,6 @@ func runConfig(basectx context.Context, cmd *cobra.Command, userConfig *bbgo.Con environ.BindSync(userConfig) } - trader := bbgo.NewTrader(environ) if err := trader.Configure(userConfig); err != nil { return err diff --git a/pkg/cmd/sync.go b/pkg/cmd/sync.go index c9f0a4fc9..0c3dc64c6 100644 --- a/pkg/cmd/sync.go +++ b/pkg/cmd/sync.go @@ -58,8 +58,6 @@ var SyncCmd = &cobra.Command{ return err } - - sessionName, err := cmd.Flags().GetString("session") if err != nil { return err diff --git a/pkg/cmd/transfer.go b/pkg/cmd/transfer.go index 5a6c942df..9932db374 100644 --- a/pkg/cmd/transfer.go +++ b/pkg/cmd/transfer.go @@ -10,8 +10,8 @@ import ( "github.com/spf13/cobra" "github.com/c9s/bbgo/pkg/bbgo" - "github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/c9s/bbgo/pkg/types" ) func init() { diff --git a/pkg/cmd/utils.go b/pkg/cmd/utils.go index af82939e4..97d022a77 100644 --- a/pkg/cmd/utils.go +++ b/pkg/cmd/utils.go @@ -6,8 +6,8 @@ import ( "github.com/spf13/viper" "github.com/c9s/bbgo/pkg/exchange/ftx" - "github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/c9s/bbgo/pkg/types" ) func inQuoteAsset(balances types.BalanceMap, market types.Market, price fixedpoint.Value) fixedpoint.Value { diff --git a/pkg/fixedpoint/convert.go b/pkg/fixedpoint/convert.go index 2e0a39b11..6ef48fb9d 100644 --- a/pkg/fixedpoint/convert.go +++ b/pkg/fixedpoint/convert.go @@ -3,8 +3,8 @@ package fixedpoint import ( + "bytes" "database/sql/driver" - "encoding/json" "errors" "fmt" "math" @@ -57,7 +57,7 @@ func (v Value) Value() (driver.Value, error) { func (v *Value) Scan(src interface{}) error { switch d := src.(type) { case int64: - *v = Value(d) + *v = NewFromInt(d) return nil case float64: @@ -95,7 +95,8 @@ func (v Value) String() string { } func (v Value) FormatString(prec int) string { - return strconv.FormatFloat(float64(v)/DefaultPow, 'f', prec, 64) + result := strconv.FormatFloat(float64(v)/DefaultPow, 'f', prec+1, 64) + return result[:len(result)-1] } func (v Value) Percentage() string { @@ -109,7 +110,8 @@ func (v Value) FormatPercentage(prec int) string { if v == 0 { return "0" } - return strconv.FormatFloat(float64(v)/DefaultPow*100., 'f', prec, 64) + "%" + result := strconv.FormatFloat(float64(v)/DefaultPow*100., 'f', prec+1, 64) + return result[:len(result)-1] + "%" } func (v Value) SignedPercentage() string { @@ -223,36 +225,21 @@ func (v Value) MarshalJSON() ([]byte, error) { } func (v *Value) UnmarshalJSON(data []byte) error { - var a interface{} - var err = json.Unmarshal(data, &a) - if err != nil { + if bytes.Compare(data, []byte{'n', 'u', 'l', 'l'}) == 0 { + *v = Zero + return nil + } + if len(data) == 0 { + *v = Zero + return nil + } + var err error + if data[0] == '"' { + data = data[1 : len(data)-1] + } + if *v, err = NewFromString(string(data)); err != nil { return err } - - switch d := a.(type) { - case float64: - *v = NewFromFloat(d) - case float32: - *v = NewFromFloat(float64(d)) - - case int64: - *v = NewFromInt(d) - case int: - *v = NewFromInt(int64(d)) - - case string: - v2, err := NewFromString(d) - if err != nil { - return err - } - - *v = v2 - - default: - return fmt.Errorf("unsupported type: %T %v", d, d) - - } - return nil } diff --git a/pkg/fixedpoint/dec.go b/pkg/fixedpoint/dec.go index 0963f5b44..e9cb02e10 100644 --- a/pkg/fixedpoint/dec.go +++ b/pkg/fixedpoint/dec.go @@ -166,7 +166,7 @@ func NewFromFloat(f float64) Value { } _, e := math.Frexp(f) e = int(float32(e) / log2of10) - c := uint64(f / math.Pow(10, float64(e-16))) + c := uint64(f/math.Pow10(e-16) + 0.5) return newNoSignCheck(sign, c, e) } @@ -995,8 +995,9 @@ func (v *Value) UnmarshalYAML(unmarshal func(a interface{}) error) (err error) { return err } +// FIXME: should we limit to 8 prec? func (v Value) MarshalJSON() ([]byte, error) { - return []byte(v.String()), nil + return []byte(v.FormatString(8)), nil } func (v *Value) UnmarshalJSON(data []byte) error { diff --git a/pkg/indicator/ewma_test.go b/pkg/indicator/ewma_test.go index 45a60ef3c..f781f251c 100644 --- a/pkg/indicator/ewma_test.go +++ b/pkg/indicator/ewma_test.go @@ -1,12 +1,12 @@ package indicator import ( + "encoding/json" "math" "testing" - "encoding/json" - "github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/c9s/bbgo/pkg/types" ) // generated from: @@ -1030,7 +1030,7 @@ func Test_calculateEWMA(t *testing.T) { priceF KLinePriceMapper window int } - var input []fixedpoint.Value; + var input []fixedpoint.Value if err := json.Unmarshal(ethusdt5m, &input); err != nil { panic(err) } diff --git a/pkg/indicator/macd_test.go b/pkg/indicator/macd_test.go index d22c8adc5..6cf074fff 100644 --- a/pkg/indicator/macd_test.go +++ b/pkg/indicator/macd_test.go @@ -1,12 +1,12 @@ package indicator import ( + "encoding/json" "math" "testing" - "encoding/json" - "github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/c9s/bbgo/pkg/types" ) /* diff --git a/pkg/indicator/obv_test.go b/pkg/indicator/obv_test.go index 5b9247dd8..66d951a29 100644 --- a/pkg/indicator/obv_test.go +++ b/pkg/indicator/obv_test.go @@ -1,13 +1,13 @@ package indicator import ( - "testing" "encoding/json" + "testing" "github.com/stretchr/testify/assert" - "github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/c9s/bbgo/pkg/types" ) const Delta = 1e-9 @@ -33,7 +33,7 @@ func Test_calculateOBV(t *testing.T) { want types.Float64Slice }{ { - name: "trivial_case", + name: "trivial_case", kLines: buildKLines( []fixedpoint.Value{fixedpoint.Zero}, []fixedpoint.Value{fixedpoint.One}, ), @@ -53,7 +53,7 @@ func Test_calculateOBV(t *testing.T) { obv := OBV{IntervalWindow: types.IntervalWindow{Window: tt.window}} obv.calculateAndUpdate(tt.kLines) assert.Equal(t, len(obv.Values), len(tt.want)) - for i, v := range(obv.Values) { + for i, v := range obv.Values { assert.InDelta(t, v, tt.want[i], Delta) } }) diff --git a/pkg/indicator/stoch_test.go b/pkg/indicator/stoch_test.go index 9b349c24a..f8a90bfee 100644 --- a/pkg/indicator/stoch_test.go +++ b/pkg/indicator/stoch_test.go @@ -1,13 +1,13 @@ package indicator import ( + "encoding/json" "math" "testing" "time" - "encoding/json" - "github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/c9s/bbgo/pkg/types" ) /* diff --git a/pkg/indicator/vwap_test.go b/pkg/indicator/vwap_test.go index b56ecb2b9..4a89fc27d 100644 --- a/pkg/indicator/vwap_test.go +++ b/pkg/indicator/vwap_test.go @@ -1,13 +1,14 @@ package indicator import ( + "encoding/json" "math" "testing" - "encoding/json" - "github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/c9s/bbgo/pkg/types" ) + var trivialPrices = []byte(`[0]`) var trivialVolumes = []byte(`[1]`) var easyPrices = []byte(`[1, 2, 3]`) diff --git a/pkg/server/asset_fs.go b/pkg/server/asset_fs.go index a20570298..43b2eec68 100644 --- a/pkg/server/asset_fs.go +++ b/pkg/server/asset_fs.go @@ -1,4 +1,4 @@ -// +build web +//go:build web package server diff --git a/pkg/server/assets_dummy.go b/pkg/server/assets_dummy.go index ed501a5b9..4e50d2fd7 100644 --- a/pkg/server/assets_dummy.go +++ b/pkg/server/assets_dummy.go @@ -1,4 +1,4 @@ -// +build !web +//go:build !web package server diff --git a/pkg/strategy/bollmaker/strategy.go b/pkg/strategy/bollmaker/strategy.go index 5a3571080..cbf313d94 100644 --- a/pkg/strategy/bollmaker/strategy.go +++ b/pkg/strategy/bollmaker/strategy.go @@ -670,7 +670,7 @@ func calculateBandPercentage(up, down, sma, midPrice float64) float64 { return (midPrice - sma) / math.Abs(sma-down) } else if midPrice > sma { // should be positive percentage - return (midPrice - sma) / math.Abs(up - sma) + return (midPrice - sma) / math.Abs(up-sma) } return 0.0 diff --git a/pkg/strategy/etf/strategy.go b/pkg/strategy/etf/strategy.go index ebef50d3c..ff4631076 100644 --- a/pkg/strategy/etf/strategy.go +++ b/pkg/strategy/etf/strategy.go @@ -22,7 +22,6 @@ type Strategy struct { Notifiability *bbgo.Notifiability - TotalAmount fixedpoint.Value `json:"totalAmount,omitempty"` // Interval is the period that you want to submit order diff --git a/pkg/strategy/flashcrash/strategy.go b/pkg/strategy/flashcrash/strategy.go index d76229e25..a49378ac6 100644 --- a/pkg/strategy/flashcrash/strategy.go +++ b/pkg/strategy/flashcrash/strategy.go @@ -9,9 +9,9 @@ import ( log "github.com/sirupsen/logrus" "github.com/c9s/bbgo/pkg/bbgo" + "github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/indicator" "github.com/c9s/bbgo/pkg/types" - "github.com/c9s/bbgo/pkg/fixedpoint" ) const ID = "flashcrash" diff --git a/pkg/strategy/pricealert/strategy.go b/pkg/strategy/pricealert/strategy.go index c403f9035..345ac4d54 100644 --- a/pkg/strategy/pricealert/strategy.go +++ b/pkg/strategy/pricealert/strategy.go @@ -4,8 +4,8 @@ import ( "context" "github.com/c9s/bbgo/pkg/bbgo" - "github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/c9s/bbgo/pkg/types" ) const ID = "pricealert" @@ -19,8 +19,8 @@ type Strategy struct { bbgo.Notifiability // These fields will be filled from the config file (it translates YAML to JSON) - Symbol string `json:"symbol"` - Interval string `json:"interval"` + Symbol string `json:"symbol"` + Interval string `json:"interval"` MinChange fixedpoint.Value `json:"minChange"` } diff --git a/pkg/strategy/skeleton/strategy.go b/pkg/strategy/skeleton/strategy.go index 6095083f1..65df159c8 100644 --- a/pkg/strategy/skeleton/strategy.go +++ b/pkg/strategy/skeleton/strategy.go @@ -6,11 +6,12 @@ import ( "github.com/sirupsen/logrus" "github.com/c9s/bbgo/pkg/bbgo" - "github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/c9s/bbgo/pkg/types" ) const ID = "skeleton" + var log = logrus.WithField("strategy", ID) func init() { @@ -25,7 +26,6 @@ func (s *Strategy) ID() string { return ID } - func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) { log.Infof("subscribe %s", s.Symbol) session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: "1m"}) @@ -35,7 +35,7 @@ var Ten = fixedpoint.NewFromInt(10) // This strategy simply spent all available quote currency to buy the symbol whenever kline gets closed func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error { - market, ok := session.Market(s.Symbol) + market, ok := session.Market(s.Symbol) if !ok { log.Warnf("fetch market fail %s", s.Symbol) return nil @@ -73,7 +73,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se log.Infof("connected") }) - session.MarketDataStream.OnKLineClosed(callback) + session.MarketDataStream.OnKLineClosed(callback) return nil } diff --git a/pkg/strategy/support/strategy.go b/pkg/strategy/support/strategy.go index 469a15147..cbfe3e235 100644 --- a/pkg/strategy/support/strategy.go +++ b/pkg/strategy/support/strategy.go @@ -33,8 +33,8 @@ type State struct { } type Target struct { - ProfitPercentage fixedpoint.Value `json:"profitPercentage"` - QuantityPercentage fixedpoint.Value `json:"quantityPercentage"` + ProfitPercentage fixedpoint.Value `json:"profitPercentage"` + QuantityPercentage fixedpoint.Value `json:"quantityPercentage"` MarginOrderSideEffect types.MarginOrderSideEffectType `json:"marginOrderSideEffect"` } @@ -295,7 +295,7 @@ func (s *Strategy) calculateQuantity(session *bbgo.ExchangeSession, side types.S baseBalance, _ := session.Account.Balance(s.Market.BaseCurrency) if side == types.SideTypeSell { // quantity = bbgo.AdjustQuantityByMaxAmount(quantity, closePrice, quota) - if s.MinBaseAssetBalance.Sign() > 0 && + if s.MinBaseAssetBalance.Sign() > 0 && baseBalance.Total().Sub(quantity).Compare(s.MinBaseAssetBalance) < 0 { quota := baseBalance.Available.Sub(s.MinBaseAssetBalance) quantity = bbgo.AdjustQuantityByMaxAmount(quantity, closePrice, quota) diff --git a/pkg/strategy/swing/strategy.go b/pkg/strategy/swing/strategy.go index 3bc27f562..2d8d9e55b 100644 --- a/pkg/strategy/swing/strategy.go +++ b/pkg/strategy/swing/strategy.go @@ -7,8 +7,8 @@ import ( log "github.com/sirupsen/logrus" "github.com/c9s/bbgo/pkg/bbgo" - "github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/c9s/bbgo/pkg/types" ) const ID = "swing" diff --git a/pkg/strategy/techsignal/strategy.go b/pkg/strategy/techsignal/strategy.go index 88de8ddda..814af8474 100644 --- a/pkg/strategy/techsignal/strategy.go +++ b/pkg/strategy/techsignal/strategy.go @@ -130,7 +130,6 @@ func (s *Strategy) listenToFundingRate(ctx context.Context, exchange *binance.Ex } } - previousIndex = index if fundingRate24HoursLowIndex != nil { if fundingRate24HoursLowIndex.Time.Before(time.Now().Add(24 * time.Hour)) { diff --git a/pkg/strategy/xmaker/state.go b/pkg/strategy/xmaker/state.go index fd32e0ad4..f6a57c285 100644 --- a/pkg/strategy/xmaker/state.go +++ b/pkg/strategy/xmaker/state.go @@ -16,7 +16,7 @@ type State struct { type ProfitStats struct { bbgo.ProfitStats - lock sync.Mutex + lock sync.Mutex MakerExchange types.ExchangeName `json:"makerExchange"` diff --git a/pkg/strategy/xmaker/strategy.go b/pkg/strategy/xmaker/strategy.go index fb6a2bcb5..e32ed6d71 100644 --- a/pkg/strategy/xmaker/strategy.go +++ b/pkg/strategy/xmaker/strategy.go @@ -232,7 +232,7 @@ func (s *Strategy) updateQuote(ctx context.Context, orderExecutionRouter bbgo.Or // to make bid orders, we need enough base asset in the foreign exchange, // if the base asset balance is not enough for selling if s.StopHedgeBaseBalance.Sign() > 0 { - minAvailable := s.StopHedgeBaseBalance.Add(s.sourceMarket.MinQuantity) + minAvailable := s.StopHedgeBaseBalance.Add(s.sourceMarket.MinQuantity) if b.Available.Compare(minAvailable) > 0 { hedgeQuota.BaseAsset.Add(b.Available.Sub(minAvailable)) } else { @@ -467,6 +467,7 @@ func (s *Strategy) updateQuote(ctx context.Context, orderExecutionRouter bbgo.Or var lastPriceModifier = fixedpoint.NewFromFloat(1.001) var minGap = fixedpoint.NewFromFloat(1.02) + func (s *Strategy) Hedge(ctx context.Context, pos fixedpoint.Value) { side := types.SideTypeBuy if pos.IsZero() { diff --git a/pkg/strategy/xnav/csv.go b/pkg/strategy/xnav/csv.go index df42dff3b..d8793c52d 100644 --- a/pkg/strategy/xnav/csv.go +++ b/pkg/strategy/xnav/csv.go @@ -1,2 +1 @@ package xnav - diff --git a/pkg/strategy/xpuremaker/strategy.go b/pkg/strategy/xpuremaker/strategy.go index 12b602312..c6cb53bf8 100644 --- a/pkg/strategy/xpuremaker/strategy.go +++ b/pkg/strategy/xpuremaker/strategy.go @@ -162,7 +162,7 @@ func (s *Strategy) generateOrders(symbol string, side types.SideType, price, pri } decdigits := priceTick.Abs().NumIntDigits() - step := priceTick.Abs().MulExp(-decdigits+1) + step := priceTick.Abs().MulExp(-decdigits + 1) for i := 0; i < numOrders; i++ { quantityExp := fixedpoint.NewFromFloat(math.Exp(expBase.Float64())) @@ -190,7 +190,7 @@ func (s *Strategy) generateOrders(symbol string, side types.SideType, price, pri } price = price.Add(priceTick) - expBase = expBase.Add(step) + expBase = expBase.Add(step) } return orders diff --git a/pkg/types/active_book.go b/pkg/types/active_book.go index 5bb13ecf9..ab1254f4c 100644 --- a/pkg/types/active_book.go +++ b/pkg/types/active_book.go @@ -1,2 +1 @@ package types - diff --git a/pkg/types/currencies.go b/pkg/types/currencies.go index 4d859d3f2..3be262926 100644 --- a/pkg/types/currencies.go +++ b/pkg/types/currencies.go @@ -32,4 +32,3 @@ func IsFiatCurrency(currency string) bool { } return false } - diff --git a/pkg/types/deposit.go b/pkg/types/deposit.go index 2735a4445..d3340ff8d 100644 --- a/pkg/types/deposit.go +++ b/pkg/types/deposit.go @@ -1,8 +1,8 @@ package types import ( - "time" "github.com/c9s/bbgo/pkg/fixedpoint" + "time" ) type DepositStatus string @@ -23,15 +23,15 @@ const ( ) type Deposit struct { - GID int64 `json:"gid" db:"gid"` - Exchange ExchangeName `json:"exchange" db:"exchange"` - Time Time `json:"time" db:"time"` - Amount fixedpoint.Value `json:"amount" db:"amount"` - Asset string `json:"asset" db:"asset"` - Address string `json:"address" db:"address"` - AddressTag string `json:"addressTag"` - TransactionID string `json:"transactionID" db:"txn_id"` - Status DepositStatus `json:"status"` + GID int64 `json:"gid" db:"gid"` + Exchange ExchangeName `json:"exchange" db:"exchange"` + Time Time `json:"time" db:"time"` + Amount fixedpoint.Value `json:"amount" db:"amount"` + Asset string `json:"asset" db:"asset"` + Address string `json:"address" db:"address"` + AddressTag string `json:"addressTag"` + TransactionID string `json:"transactionID" db:"txn_id"` + Status DepositStatus `json:"status"` } func (d Deposit) EffectiveTime() time.Time { diff --git a/pkg/types/kline.go b/pkg/types/kline.go index 5a58cda22..8b877f34a 100644 --- a/pkg/types/kline.go +++ b/pkg/types/kline.go @@ -6,8 +6,8 @@ import ( "github.com/slack-go/slack" - "github.com/c9s/bbgo/pkg/util" "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/c9s/bbgo/pkg/util" ) type Direction int @@ -137,7 +137,6 @@ func (k KLine) GetAmplification() fixedpoint.Value { return k.GetMaxChange().Div(k.GetLow()) } - // GetThickness returns the thickness of the kline. 1 => thick, 0.1 => thin func (k KLine) GetThickness() fixedpoint.Value { out := k.GetChange().Div(k.GetMaxChange()) @@ -416,7 +415,7 @@ func (k KLineWindow) GetBody() fixedpoint.Value { } func (k KLineWindow) GetThickness() fixedpoint.Value { - out := k.GetChange().Div(k.GetMaxChange()) + out := k.GetChange().Div(k.GetMaxChange()) if out.Sign() < 0 { return out.Neg() } @@ -471,7 +470,7 @@ func (k KLineWindow) SlackAttachment() slack.Attachment { return slack.Attachment{ Text: fmt.Sprintf("*%s* KLineWindow %s x %d", first.Symbol, first.Interval, windowSize), Color: k.Color(), - Fields: []slack.AttachmentField { + Fields: []slack.AttachmentField{ {Title: "Open", Value: util.FormatValue(k.GetOpen(), 2), Short: true}, {Title: "High", Value: util.FormatValue(k.GetHigh(), 2), Short: true}, {Title: "Low", Value: util.FormatValue(k.GetLow(), 2), Short: true}, diff --git a/pkg/types/kline_test.go b/pkg/types/kline_test.go index a49b05fc4..f125f39d9 100644 --- a/pkg/types/kline_test.go +++ b/pkg/types/kline_test.go @@ -1,9 +1,9 @@ package types import ( - "testing" - "github.com/stretchr/testify/assert" "encoding/json" + "github.com/stretchr/testify/assert" + "testing" ) func TestKLineWindow_Tail(t *testing.T) { @@ -34,7 +34,7 @@ func TestKLineWindow_Tail(t *testing.T) { } func TestKLineWindow_Truncate(t *testing.T) { - var jsonWin = []byte(`[ + var jsonWin = []byte(`[ {"open": 11600.0, "close": 11600.0, "high": 11600.0, "low": 11600.0}, {"open": 11601.0, "close": 11600.0, "high": 11600.0, "low": 11600.0}, {"open": 11602.0, "close": 11600.0, "high": 11600.0, "low": 11600.0}, diff --git a/pkg/types/market_test.go b/pkg/types/market_test.go index 64e28ee06..de9055dd3 100644 --- a/pkg/types/market_test.go +++ b/pkg/types/market_test.go @@ -5,11 +5,11 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/stretchr/testify/assert" ) -var s func(string)fixedpoint.Value = fixedpoint.MustNewFromString +var s func(string) fixedpoint.Value = fixedpoint.MustNewFromString func TestFormatQuantity(t *testing.T) { quantity := formatQuantity( @@ -53,7 +53,7 @@ func TestDurationParse(t *testing.T) { { name: "float64 to second", input: `{ "duration": 1.1 }`, - expected: Duration(time.Second + 100 * time.Millisecond), + expected: Duration(time.Second + 100*time.Millisecond), }, { name: "2m", @@ -63,7 +63,7 @@ func TestDurationParse(t *testing.T) { { name: "2m3s", input: `{ "duration": "2m3s" }`, - expected: Duration(2 * time.Minute + 3 * time.Second), + expected: Duration(2*time.Minute + 3*time.Second), }, } for _, test := range tests { diff --git a/pkg/types/order.go b/pkg/types/order.go index 314c98e55..024003711 100644 --- a/pkg/types/order.go +++ b/pkg/types/order.go @@ -10,8 +10,8 @@ import ( "github.com/pkg/errors" "github.com/slack-go/slack" - "github.com/c9s/bbgo/pkg/util" "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/c9s/bbgo/pkg/util" ) func init() { @@ -186,8 +186,8 @@ func (o SubmitOrder) SlackAttachment() slack.Attachment { } type OrderQuery struct { - Symbol string - OrderID string + Symbol string + OrderID string ClientOrderID string } @@ -201,11 +201,11 @@ type Order struct { OrderID uint64 `json:"orderID" db:"order_id"` // order id UUID string `json:"uuid,omitempty"` - Status OrderStatus `json:"status" db:"status"` - ExecutedQuantity fixedpoint.Value `json:"executedQuantity" db:"executed_quantity"` - IsWorking bool `json:"isWorking" db:"is_working"` - CreationTime Time `json:"creationTime" db:"created_at"` - UpdateTime Time `json:"updateTime" db:"updated_at"` + Status OrderStatus `json:"status" db:"status"` + ExecutedQuantity fixedpoint.Value `json:"executedQuantity" db:"executed_quantity"` + IsWorking bool `json:"isWorking" db:"is_working"` + CreationTime Time `json:"creationTime" db:"created_at"` + UpdateTime Time `json:"updateTime" db:"updated_at"` IsMargin bool `json:"isMargin" db:"is_margin"` IsIsolated bool `json:"isIsolated" db:"is_isolated"` diff --git a/pkg/types/position_test.go b/pkg/types/position_test.go index 8f3c2bd1b..904f3bb8d 100644 --- a/pkg/types/position_test.go +++ b/pkg/types/position_test.go @@ -129,10 +129,10 @@ func TestPosition(t *testing.T) { }, expectedAverageCost: fixedpoint.NewFromFloat(1000.0 * 0.01). Div(fixedpoint.NewFromFloat(0.01).Mul(fixedpoint.One.Sub(feeRateValue))), - expectedBase: fixedpoint.NewFromFloat(0.01). + expectedBase: fixedpoint.NewFromFloat(0.01). Sub(fixedpoint.NewFromFloat(0.01).Mul(feeRateValue)), - expectedQuote: fixedpoint.NewFromFloat(0 - 1000.0*0.01), - expectedProfit: fixedpoint.Zero, + expectedQuote: fixedpoint.NewFromFloat(0 - 1000.0*0.01), + expectedProfit: fixedpoint.Zero, }, { name: "quote fee", @@ -149,9 +149,9 @@ func TestPosition(t *testing.T) { expectedAverageCost: fixedpoint.NewFromFloat(1000.0 * 0.01). Mul(fixedpoint.One.Sub(feeRateValue)). Div(fixedpoint.NewFromFloat(0.01)), - expectedBase: fixedpoint.NewFromFloat(-0.01), - expectedQuote: fixedpoint.NewFromFloat(0.0 + 1000.0 * 0.01 * (1.0 - feeRate)), - expectedProfit: fixedpoint.Zero, + expectedBase: fixedpoint.NewFromFloat(-0.01), + expectedQuote: fixedpoint.NewFromFloat(0.0 + 1000.0*0.01*(1.0-feeRate)), + expectedProfit: fixedpoint.Zero, }, { name: "long", diff --git a/pkg/types/price_volume_slice_test.go b/pkg/types/price_volume_slice_test.go index 069b38f11..cf0b1e8ab 100644 --- a/pkg/types/price_volume_slice_test.go +++ b/pkg/types/price_volume_slice_test.go @@ -3,8 +3,8 @@ package types import ( "testing" - "github.com/stretchr/testify/assert" "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/stretchr/testify/assert" ) func TestPriceVolumeSlice_Remove(t *testing.T) { diff --git a/pkg/types/rbtree_test.go b/pkg/types/rbtree_test.go index 96874aa92..0daddf199 100644 --- a/pkg/types/rbtree_test.go +++ b/pkg/types/rbtree_test.go @@ -9,7 +9,7 @@ import ( "github.com/c9s/bbgo/pkg/fixedpoint" ) -var itov func(int64)fixedpoint.Value = fixedpoint.NewFromInt +var itov func(int64) fixedpoint.Value = fixedpoint.NewFromInt func TestRBTree_InsertAndDelete(t *testing.T) { tree := NewRBTree() diff --git a/pkg/types/reward.go b/pkg/types/reward.go index a645e96e3..97a968003 100644 --- a/pkg/types/reward.go +++ b/pkg/types/reward.go @@ -33,10 +33,12 @@ type Reward struct { } type RewardSlice []Reward + func (s RewardSlice) Len() int { return len(s) } func (s RewardSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } type RewardSliceByCreationTime RewardSlice + func (s RewardSliceByCreationTime) Len() int { return len(s) } func (s RewardSliceByCreationTime) Swap(i, j int) { s[i], s[j] = s[j], s[i] } diff --git a/pkg/types/ticker.go b/pkg/types/ticker.go index fba23b3a3..a1649f419 100644 --- a/pkg/types/ticker.go +++ b/pkg/types/ticker.go @@ -1,8 +1,8 @@ package types import ( - "time" "github.com/c9s/bbgo/pkg/fixedpoint" + "time" ) type Ticker struct { diff --git a/pkg/types/trade.go b/pkg/types/trade.go index bbe35baf5..247c7cdf8 100644 --- a/pkg/types/trade.go +++ b/pkg/types/trade.go @@ -52,20 +52,20 @@ type Trade struct { GID int64 `json:"gid" db:"gid"` // ID is the source trade ID - ID uint64 `json:"id" db:"id"` - OrderID uint64 `json:"orderID" db:"order_id"` - Exchange ExchangeName `json:"exchange" db:"exchange"` - Price fixedpoint.Value `json:"price" db:"price"` - Quantity fixedpoint.Value `json:"quantity" db:"quantity"` - QuoteQuantity fixedpoint.Value `json:"quoteQuantity" db:"quote_quantity"` - Symbol string `json:"symbol" db:"symbol"` + ID uint64 `json:"id" db:"id"` + OrderID uint64 `json:"orderID" db:"order_id"` + Exchange ExchangeName `json:"exchange" db:"exchange"` + Price fixedpoint.Value `json:"price" db:"price"` + Quantity fixedpoint.Value `json:"quantity" db:"quantity"` + QuoteQuantity fixedpoint.Value `json:"quoteQuantity" db:"quote_quantity"` + Symbol string `json:"symbol" db:"symbol"` - Side SideType `json:"side" db:"side"` - IsBuyer bool `json:"isBuyer" db:"is_buyer"` - IsMaker bool `json:"isMaker" db:"is_maker"` - Time Time `json:"tradedAt" db:"traded_at"` - Fee fixedpoint.Value `json:"fee" db:"fee"` - FeeCurrency string `json:"feeCurrency" db:"fee_currency"` + Side SideType `json:"side" db:"side"` + IsBuyer bool `json:"isBuyer" db:"is_buyer"` + IsMaker bool `json:"isMaker" db:"is_maker"` + Time Time `json:"tradedAt" db:"traded_at"` + Fee fixedpoint.Value `json:"fee" db:"fee"` + FeeCurrency string `json:"feeCurrency" db:"fee_currency"` IsMargin bool `json:"isMargin" db:"is_margin"` IsFutures bool `json:"isFutures" db:"is_futures"` @@ -146,7 +146,6 @@ func (trade Trade) PlainText() string { var slackTradeTextTemplate = ":handshake: Trade {{ .Symbol }} {{ .Side }} {{ .Quantity }} @ {{ .Price }}" - func exchangeFooterIcon(exName ExchangeName) string { footerIcon := "" diff --git a/pkg/types/trade_test.go b/pkg/types/trade_test.go index 4e21973f2..d87a2c670 100644 --- a/pkg/types/trade_test.go +++ b/pkg/types/trade_test.go @@ -29,9 +29,9 @@ func Test_trimTrailingZero(t *testing.T) { { name: "non trailing zero", args: args{ - a: "1.0001234567", + a: "1.00012345", }, - want: "1.0001234567", + want: "1.00012345", }, { name: "integer", diff --git a/pkg/types/withdraw.go b/pkg/types/withdraw.go index bfb3bff36..6a3d5dae5 100644 --- a/pkg/types/withdraw.go +++ b/pkg/types/withdraw.go @@ -2,25 +2,25 @@ package types import ( "fmt" - "time" "github.com/c9s/bbgo/pkg/fixedpoint" + "time" ) type Withdraw struct { - GID int64 `json:"gid" db:"gid"` - Exchange ExchangeName `json:"exchange" db:"exchange"` - Asset string `json:"asset" db:"asset"` - Amount fixedpoint.Value `json:"amount" db:"amount"` - Address string `json:"address" db:"address"` - AddressTag string `json:"addressTag"` - Status string `json:"status"` + GID int64 `json:"gid" db:"gid"` + Exchange ExchangeName `json:"exchange" db:"exchange"` + Asset string `json:"asset" db:"asset"` + Amount fixedpoint.Value `json:"amount" db:"amount"` + Address string `json:"address" db:"address"` + AddressTag string `json:"addressTag"` + Status string `json:"status"` - TransactionID string `json:"transactionID" db:"txn_id"` + TransactionID string `json:"transactionID" db:"txn_id"` TransactionFee fixedpoint.Value `json:"transactionFee" db:"txn_fee"` - TransactionFeeCurrency string `json:"transactionFeeCurrency" db:"txn_fee_currency"` - WithdrawOrderID string `json:"withdrawOrderId"` - ApplyTime Time `json:"applyTime" db:"time"` - Network string `json:"network" db:"network"` + TransactionFeeCurrency string `json:"transactionFeeCurrency" db:"txn_fee_currency"` + WithdrawOrderID string `json:"withdrawOrderId"` + ApplyTime Time `json:"applyTime" db:"time"` + Network string `json:"network" db:"network"` } func (w Withdraw) String() string { @@ -35,4 +35,3 @@ type WithdrawalOptions struct { Network string AddressTag string } - diff --git a/pkg/util/math.go b/pkg/util/math.go index 2de0f5f1c..31e49b541 100644 --- a/pkg/util/math.go +++ b/pkg/util/math.go @@ -1,9 +1,9 @@ package util import ( + "github.com/c9s/bbgo/pkg/fixedpoint" "math" "strconv" - "github.com/c9s/bbgo/pkg/fixedpoint" ) const MaxDigits = 18 // MAX_INT64 ~ 9 * 10^18 diff --git a/pkg/util/reonce_test.go b/pkg/util/reonce_test.go index 647b3335a..7a18fc437 100644 --- a/pkg/util/reonce_test.go +++ b/pkg/util/reonce_test.go @@ -11,9 +11,9 @@ func TestReonce_DoAndReset(t *testing.T) { var cnt = 0 var reonce Reonce go reonce.Do(func() { - t.Log("once #1") - time.Sleep(10 * time.Millisecond) - cnt++ + t.Log("once #1") + time.Sleep(10 * time.Millisecond) + cnt++ }) // make sure it's locked @@ -22,12 +22,11 @@ func TestReonce_DoAndReset(t *testing.T) { reonce.Reset() go reonce.Do(func() { - t.Log("once #2") - time.Sleep(10 * time.Millisecond) - cnt++ + t.Log("once #2") + time.Sleep(10 * time.Millisecond) + cnt++ }) time.Sleep(time.Second) assert.Equal(t, 2, cnt) } - diff --git a/pkg/util/time.go b/pkg/util/time.go index 140ec90c9..d95d1a9a1 100644 --- a/pkg/util/time.go +++ b/pkg/util/time.go @@ -17,7 +17,7 @@ func BeginningOfTheDay(t time.Time) time.Time { } func Over24Hours(since time.Time) bool { - return time.Since(since) >= 24 * time.Hour + return time.Since(since) >= 24*time.Hour } func UnixMilli() int64 { @@ -33,7 +33,3 @@ func ParseTimeWithFormats(strTime string, formats []string) (time.Time, error) { } return time.Time{}, fmt.Errorf("failed to parse time %s, valid formats are %+v", strTime, formats) } - - - -