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

View File

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