bbgo_origin/pkg/cmd/utils.go

37 lines
957 B
Go
Raw Normal View History

2021-02-06 03:34:53 +00:00
package cmd
import (
"fmt"
"github.com/spf13/viper"
"github.com/c9s/bbgo/pkg/exchange/ftx"
2022-02-07 03:40:30 +00:00
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
2021-02-06 03:34:53 +00:00
)
2022-02-07 03:40:30 +00:00
func inQuoteAsset(balances types.BalanceMap, market types.Market, price fixedpoint.Value) fixedpoint.Value {
quote := balances[market.QuoteCurrency]
base := balances[market.BaseCurrency]
2022-02-07 03:40:30 +00:00
return base.Total().Mul(price).Add(quote.Total())
}
2022-02-07 03:40:30 +00:00
func inBaseAsset(balances types.BalanceMap, market types.Market, price fixedpoint.Value) fixedpoint.Value {
2021-02-06 03:34:53 +00:00
quote := balances[market.QuoteCurrency]
base := balances[market.BaseCurrency]
2022-02-07 03:40:30 +00:00
return quote.Total().Div(price).Add(base.Total())
2021-02-06 03:34: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"),
viper.GetString("ftx-subaccount"),
), nil
}
return nil, fmt.Errorf("unsupported session %s", session)
}