service: insert asset fields

This commit is contained in:
c9s 2022-05-03 17:51:42 +08:00
parent 2fba2c335b
commit d93fd3cc48
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -16,19 +16,29 @@ func NewAccountService(db *sqlx.DB) *AccountService {
}
func (s *AccountService) InsertAsset(time time.Time, name types.ExchangeName, account string, assets types.AssetMap) error {
if s.DB == nil {
//skip db insert when no db connection setting.
// skip db insert when no db connection setting.
return nil
}
var err error
for _, v := range assets {
_, _err := s.DB.Exec(`
insert into nav_history_details ( exchange, subaccount, time, currency, balance_in_usd, balance_in_btc,
balance,available,locked)
values (?,?,?,?,?,?,?,?,?);
`, name, account, time, v.Currency, v.InUSD, v.InBTC, v.Total, v.Available, v.Locked)
INSERT INTO nav_history_details (
exchange,
subaccount,
time,
currency,
balance_in_usd,
balance_in_btc,
balance,
available,
locked,
borrowed,
net_asset,
price_in_usd)
values (?,?,?,?,?,?,?,?,?,?,?);
`, name, account, time, v.Currency, v.InUSD, v.InBTC, v.Total, v.Available, v.Locked, v.Borrowed, v.NetAsset, v.PriceInUSD)
err = multierr.Append(err, _err) // successful request