Best way to write real time data to a postgres table in batches

I am working with a C# program that is subscribing to options contract data with the updates coming in on multiple threads. i would like to run analytics every minute or so, so I was planning on storing the trades as the come in, in a ConcurrentQueue trades. i have my current implementation below which is a function that will attempt to write the trades in batches whenever I call it. Is this sufficient? or is there a better way to do this? It currently works for low volume, but unsure how it will hold up on large volumes of updates. Thanks!

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
using Npgsql;

public struct PriceSub
{
    public DateTime _timestamp;
    public string _name;
    public string _term;
    public DateTime? _expiration;
    public string _type;
    public string _product;
    public decimal? _strike;
    public ulong _instrumentID;

    public decimal _price;
    public decimal _userTV;
    public decimal _midImpliedTV;
    public string _theoPrice;

    public decimal _userVol;
    public decimal _midImpliedVol;

    public decimal _quantity;
    public decimal _totalQuanity;
    public decimal _openInterest;

    public long _thread;
}

public class TradeWriter
{
    private ConcurrentQueue<PriceSub> _trades;
    private string _connectionString;

    public TradeWriter(ConcurrentQueue<PriceSub> trades, string connectionString)
    {
        _trades = trades;
        _connectionString = connectionString;
    }

    public async Task WriteTradesToDbAsync(int batchSize)
    {
        List<PriceSub> batch = new List<PriceSub>();

        // Dequeue trades in batches
        while (batch.Count < batchSize && _trades.TryDequeue(out var trade))
        {
            batch.Add(trade);
        }

        // If there are trades to write, proceed with batch insertion
        if (batch.Count > 0)
        {
            await InsertTradesBatchAsync(batch);
        }
    }

    private async Task InsertTradesBatchAsync(List<PriceSub> tradesBatch)
    {
        // SQL query for batch insert
        string sql = @"INSERT INTO es_options_daily 
            (_timestamp, _name, _term, _expiration, _type, _product, _strike, _instrumentID,
            _price, _userTV, _midImpliedTV, _theoPrice, _userVol, _midImpliedVol, 
            _quantity, _totalQuantity, _openInterest, _thread) 
            VALUES 
            (@timestamp, @name, @term, @expiration, @type, @product, @strike, @instrumentID,
            @price, @userTV, @midImpliedTV, @theoPrice, @userVol, @midImpliedVol,
            @quantity, @totalQuantity, @openInterest, @thread)";

        using (var connection = new NpgsqlConnection(_connectionString))
        {
            await connection.OpenAsync();

            using (var transaction = await connection.BeginTransactionAsync())
            {
                using (var command = new NpgsqlCommand(sql, connection, transaction))
                {
                    foreach (var trade in tradesBatch)
                    {
                        // Add parameters for each trade in the batch
                        command.Parameters.AddWithValue("@timestamp", trade._timestamp);
                        command.Parameters.AddWithValue("@name", trade._name);
                        command.Parameters.AddWithValue("@term", trade._term);
                        command.Parameters.AddWithValue("@expiration", trade._expiration.HasValue ? (object)trade._expiration.Value : DBNull.Value);
                        command.Parameters.AddWithValue("@type", trade._type);
                        command.Parameters.AddWithValue("@product", trade._product);
                        command.Parameters.AddWithValue("@strike", trade._strike.HasValue ? (object)trade._strike.Value : DBNull.Value);
                        command.Parameters.AddWithValue("@instrumentID", trade._instrumentID);
                        command.Parameters.AddWithValue("@price", trade._price);
                        command.Parameters.AddWithValue("@userTV", trade._userTV);
                        command.Parameters.AddWithValue("@midImpliedTV", trade._midImpliedTV);
                        command.Parameters.AddWithValue("@theoPrice", trade._theoPrice);
                        command.Parameters.AddWithValue("@userVol", trade._userVol);
                        command.Parameters.AddWithValue("@midImpliedVol", trade._midImpliedVol);
                        command.Parameters.AddWithValue("@quantity", trade._quantity);
                        command.Parameters.AddWithValue("@totalQuantity", trade._totalQuanity);
                        command.Parameters.AddWithValue("@openInterest", trade._openInterest);
                        command.Parameters.AddWithValue("@thread", trade._thread);

                        // Execute insert for the current trade in the batch
                        await command.ExecuteNonQueryAsync();

                        // Clear parameters for the next trade
                        command.Parameters.Clear();
                    }
                }

                // Commit the transaction after batch insertion
                await transaction.CommitAsync();
            }
        }
    }
}

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật