chain-bot / prices

API-Scraper + API for crypto prices built in Go
MIT License
2 stars 2 forks source link

Make WriteAPI A Part of the Repository Impl #45

Closed zahin-mohammad closed 3 years ago

zahin-mohammad commented 3 years ago
func (repo *RepositoryImpl) UpsertOHLCData(
    ohlcData []*models.OHLCMarketData,
    exchange string,
    pair *models.Symbol,
) {
    writeAPI := (*repo.influxClient).WriteAPI(repo.influxOrg, repo.ohlcBucket)
    tags := map[string]string{
        "quote":    pair.NormalizedQuote,
        "exchange": exchange,
    }
    for index := range ohlcData {
        ohlc := ohlcData[index]
        fields := map[string]interface{}{
            "open":   ohlc.OpenPrice,
            "high":   ohlc.HighPrice,
            "low":    ohlc.LowPrice,
            "close":  ohlc.ClosePrice,
            "volume": ohlc.Volume,
        }
        p := influxdb2.NewPoint(
            pair.NormalizedBase,
            tags,
            fields,
            ohlc.StartTime)
        writeAPI.WritePoint(p)
    }
}

We create a new writeAPI each time we upsert OHLC data, we should instead just make this a part of the RepositoryImpl type.