2021-02-06 03:34:53 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2021-02-27 10:40:53 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
|
|
|
"github.com/c9s/bbgo/pkg/exchange/ftx"
|
2021-02-06 03:34:53 +00:00
|
|
|
"github.com/c9s/bbgo/pkg/types"
|
|
|
|
)
|
|
|
|
|
2022-01-31 16:54:55 +00:00
|
|
|
func inQuoteAsset(balances types.BalanceMap, market types.Market, price float64) float64 {
|
|
|
|
quote := balances[market.QuoteCurrency]
|
|
|
|
base := balances[market.BaseCurrency]
|
|
|
|
return base.Total().Float64()*price + quote.Total().Float64()
|
|
|
|
}
|
|
|
|
|
2021-02-06 03:34:53 +00:00
|
|
|
func inBaseAsset(balances types.BalanceMap, market types.Market, price float64) float64 {
|
|
|
|
quote := balances[market.QuoteCurrency]
|
|
|
|
base := balances[market.BaseCurrency]
|
2022-01-31 16:54:55 +00:00
|
|
|
return base.Total().Float64() + (quote.Total().Float64() / price)
|
2021-02-06 03:34:53 +00:00
|
|
|
}
|
|
|
|
|
2021-02-27 10:40:53 +00:00
|
|
|
func newExchange(session string) (types.Exchange, error) {
|
|
|
|
switch session {
|
|
|
|
case "ftx":
|
|
|
|
return ftx.NewExchange(
|
|
|
|
viper.GetString("ftx-api-key"),
|
|
|
|
viper.GetString("ftx-api-secret"),
|
2021-05-17 04:42:04 +00:00
|
|
|
viper.GetString("ftx-subaccount"),
|
2021-02-27 10:40:53 +00:00
|
|
|
), nil
|
|
|
|
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("unsupported session %s", session)
|
|
|
|
}
|