// Always create a new price if we can't match on the RemoteId
err:=InsertPriceTx(transaction,price)
iferr!=nil{
returnerr
}
returnnil
}
varprices[]*Price
_,err:=transaction.Select(&prices,"SELECT * from prices where SecurityId=? AND CurrencyId=? AND Date=? AND Value=?",price.SecurityId,price.CurrencyId,price.Date,price.Value)
iferr!=nil{
returnerr
}
iflen(prices)>0{
returnnil// price already exists
}
err=InsertPriceTx(transaction,price)
iferr!=nil{
returnerr
}
returnnil
}
// Return the latest price for security in currency units before date
err:=transaction.SelectOne(&p,"SELECT * from prices where SecurityId=? AND CurrencyId=? AND Date <= ? ORDER BY Date DESC LIMIT 1",security.SecurityId,currency.SecurityId,date)
iferr!=nil{
returnnil,err
}
return&p,nil
}
// Return the earliest price for security in currency units after date
err:=transaction.SelectOne(&p,"SELECT * from prices where SecurityId=? AND CurrencyId=? AND Date >= ? ORDER BY Date ASC LIMIT 1",security.SecurityId,currency.SecurityId,date)
iferr!=nil{
returnnil,err
}
return&p,nil
}
// Return the price for security in currency closest to date