feat: add limit option for pnl command

This commit is contained in:
Jui-Nan Lin 2021-02-05 10:12:10 +08:00
parent b90cc2a8c9
commit 893b513605
2 changed files with 9 additions and 2 deletions

View File

@ -21,6 +21,7 @@ import (
func init() { func init() {
PnLCmd.Flags().String("exchange", "", "target exchange") PnLCmd.Flags().String("exchange", "", "target exchange")
PnLCmd.Flags().String("symbol", "BTCUSDT", "trading symbol") PnLCmd.Flags().String("symbol", "BTCUSDT", "trading symbol")
PnLCmd.Flags().Int("limit", 500, "number of orders")
RootCmd.AddCommand(PnLCmd) RootCmd.AddCommand(PnLCmd)
} }
@ -46,6 +47,11 @@ var PnLCmd = &cobra.Command{
return err return err
} }
limit, err := cmd.Flags().GetInt("limit")
if err != nil {
return err
}
exchange, err := cmdutil.NewExchange(exchangeName) exchange, err := cmdutil.NewExchange(exchangeName)
if err != nil { if err != nil {
return err return err
@ -67,6 +73,7 @@ var PnLCmd = &cobra.Command{
trades, err = tradeService.Query(service.QueryTradesOptions{ trades, err = tradeService.Query(service.QueryTradesOptions{
Exchange: exchange.Name(), Exchange: exchange.Name(),
Symbol: symbol, Symbol: symbol,
Limit: limit,
}) })
} }

View File

@ -163,13 +163,13 @@ func (s *TradeService) QueryForTradingFeeCurrency(ex types.ExchangeName, symbol
return s.scanRows(rows) return s.scanRows(rows)
} }
// Only return 500 items.
type QueryTradesOptions struct { type QueryTradesOptions struct {
Exchange types.ExchangeName Exchange types.ExchangeName
Symbol string Symbol string
LastGID int64 LastGID int64
// ASC or DESC // ASC or DESC
Ordering string Ordering string
Limit int
} }
func (s *TradeService) Query(options QueryTradesOptions) ([]types.Trade, error) { func (s *TradeService) Query(options QueryTradesOptions) ([]types.Trade, error) {
@ -225,7 +225,7 @@ func queryTradesSQL(options QueryTradesOptions) string {
sql += ` ORDER BY gid ` + ordering sql += ` ORDER BY gid ` + ordering
sql += ` LIMIT ` + strconv.Itoa(500) sql += ` LIMIT ` + strconv.Itoa(options.Limit)
return sql return sql
} }