mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
add more margin info columns
This commit is contained in:
parent
01273f7c4c
commit
8a93f0921f
|
@ -649,7 +649,7 @@ func (environ *Environment) Sync(ctx context.Context, userConfig ...*Config) err
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (environ *Environment) RecordAsset(t time.Time, sessionName string, exchangeName types.ExchangeName, account string, assets types.AssetMap) {
|
func (environ *Environment) RecordAsset(t time.Time, session *ExchangeSession, assets types.AssetMap) {
|
||||||
// skip for back-test
|
// skip for back-test
|
||||||
if environ.BacktestService != nil {
|
if environ.BacktestService != nil {
|
||||||
return
|
return
|
||||||
|
@ -659,7 +659,15 @@ func (environ *Environment) RecordAsset(t time.Time, sessionName string, exchang
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := environ.AccountService.InsertAsset(t, sessionName, exchangeName, account, assets); err != nil {
|
if err := environ.AccountService.InsertAsset(
|
||||||
|
t,
|
||||||
|
session.Name,
|
||||||
|
session.ExchangeName,
|
||||||
|
session.SubAccount,
|
||||||
|
session.Margin,
|
||||||
|
session.IsolatedMargin,
|
||||||
|
session.IsolatedMarginSymbol,
|
||||||
|
assets); err != nil {
|
||||||
log.WithError(err).Errorf("can not insert asset record")
|
log.WithError(err).Errorf("can not insert asset record")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,8 @@ func NewAccountService(db *sqlx.DB) *AccountService {
|
||||||
return &AccountService{DB: db}
|
return &AccountService{DB: db}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AccountService) InsertAsset(time time.Time, session string, name types.ExchangeName, account string, assets types.AssetMap) error {
|
// TODO: should pass bbgo.ExchangeSession to this function, but that might cause cyclic import
|
||||||
|
func (s *AccountService) InsertAsset(time time.Time, session string, name types.ExchangeName, account string, isMargin bool, isIsolatedMargin bool, isolatedMarginSymbol string, assets types.AssetMap) error {
|
||||||
if s.DB == nil {
|
if s.DB == nil {
|
||||||
// skip db insert when no db connection setting.
|
// skip db insert when no db connection setting.
|
||||||
return nil
|
return nil
|
||||||
|
@ -37,9 +38,25 @@ func (s *AccountService) InsertAsset(time time.Time, session string, name types.
|
||||||
locked,
|
locked,
|
||||||
borrowed,
|
borrowed,
|
||||||
net_asset,
|
net_asset,
|
||||||
price_in_usd)
|
price_in_usd,
|
||||||
values (?,?,?,?,?,?,?,?,?,?,?,?,?);
|
is_margin, is_isolated, isolated_symbol)
|
||||||
`, session, name, account, time, v.Currency, v.InUSD, v.InBTC, v.Total, v.Available, v.Locked, v.Borrowed, v.NetAsset, v.PriceInUSD)
|
values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);`,
|
||||||
|
session,
|
||||||
|
name,
|
||||||
|
account,
|
||||||
|
time,
|
||||||
|
v.Currency,
|
||||||
|
v.InUSD,
|
||||||
|
v.InBTC,
|
||||||
|
v.Total,
|
||||||
|
v.Available,
|
||||||
|
v.Locked,
|
||||||
|
v.Borrowed,
|
||||||
|
v.NetAsset,
|
||||||
|
v.PriceInUSD,
|
||||||
|
isMargin,
|
||||||
|
isIsolatedMargin,
|
||||||
|
isolatedMarginSymbol)
|
||||||
|
|
||||||
err = multierr.Append(err, _err) // successful request
|
err = multierr.Append(err, _err) // successful request
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ func TestAccountService(t *testing.T) {
|
||||||
service := &AccountService{DB: xdb}
|
service := &AccountService{DB: xdb}
|
||||||
|
|
||||||
t1 := time.Now()
|
t1 := time.Now()
|
||||||
err = service.InsertAsset(t1, "binance", types.ExchangeBinance, "main", types.AssetMap{
|
err = service.InsertAsset(t1, "binance", types.ExchangeBinance, "main", false, false, "", types.AssetMap{
|
||||||
"BTC": types.Asset{
|
"BTC": types.Asset{
|
||||||
Currency: "BTC",
|
Currency: "BTC",
|
||||||
Total: fixedpoint.MustNewFromString("1.0"),
|
Total: fixedpoint.MustNewFromString("1.0"),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user