From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1726004660; bh=cyyJBGow7JXwrKDnF4QZJmK7SgAdYZfsRoxvFmG8nF8=; h=From:To:Cc:Subject:Message-Id:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:From; b=FVJDexVydal7Iv+rXG24Ym8BNc3EBmU0TmJY7SSE8U5CHrvuVzNMEx3A7Imp1U+bO Yc9FN3hN+gwTmLYPxwkYNafIqlkCqXhQSjwdLdiuwDs8ZEHYTBnzKgsx6itfX+YHc6 1+/vavy75QcxAaWUbSHKE2ZKg9zeb8AWJD1r8y/LOdklORwipYWCy179R1QdmOLfMo BiOg4W2y2Xyll3qWCRCJkHMQ/+LI2uZbzpKU9ZhRVKtwSarervkEnud5fHw1SsJG5l Q/C0DZjWLGKhq1NrujllPsSgYjWLC8S9w2cafv+MSWMdJUDkNrmjJjMq5DisVR5GGj fRuxUCcRX35Dw== Received: from server-vie001.gnuweeb.org (unknown [192.168.57.1]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id 09B7F3106503; Tue, 10 Sep 2024 21:44:20 +0000 (UTC) From: Alviro Iskandar Setiawan To: Ammar Faizi , Michael William Jonathan Cc: Alviro Iskandar Setiawan , Ravel Kevin Ethan , GNU/Weeb Mailing List Subject: [RFC PATCH 5/9] gwarnt: Create function to find arbitrage opportunities Date: Tue, 10 Sep 2024 23:44:10 +0200 Message-Id: <20240910214414.3401712-6-alviro.iskandar@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910214414.3401712-1-alviro.iskandar@gnuweeb.org> References: <20240910214414.3401712-1-alviro.iskandar@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: After collecting buy and sell ads from two different exchanges, find the arbitrage opportunities. Signed-off-by: Alviro Iskandar Setiawan --- Makefile | 1 + src/gwarnt/arbitrage.cpp | 27 +++++++++++++++++++++++++++ src/gwarnt/arbitrage.hpp | 21 +++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 src/gwarnt/arbitrage.cpp create mode 100644 src/gwarnt/arbitrage.hpp diff --git a/Makefile b/Makefile index 6aa0b32..f775bfc 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ DEPFLAGS = -MT "$@" -MMD -MP -MF $(@:%.o=%.d) C_SOURCES := CXX_SOURCES := \ + src/gwarnt/arbitrage.cpp \ src/gwarnt/entry.cpp \ src/gwarnt/helpers.cpp \ src/gwarnt/net.cpp \ diff --git a/src/gwarnt/arbitrage.cpp b/src/gwarnt/arbitrage.cpp new file mode 100644 index 0000000..ec7c771 --- /dev/null +++ b/src/gwarnt/arbitrage.cpp @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include + +namespace gwarnt { + +std::vector find_arbitrage_opps(const std::vector &sell, + const std::vector &buy) +{ + std::vector ret; + + for (const auto &i : buy) { + for (const auto &j : sell) { + if (j.price_ < i.price_) { + struct arb_opp opp; + + opp.buy = i; + opp.sell = j; + ret.push_back(opp); + } + } + } + + return ret; +} + +} /* namespace gwarnt */ diff --git a/src/gwarnt/arbitrage.hpp b/src/gwarnt/arbitrage.hpp new file mode 100644 index 0000000..0b0338e --- /dev/null +++ b/src/gwarnt/arbitrage.hpp @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#ifndef GWARNT__ARBITRAGE_HPP +#define GWARNT__ARBITRAGE_HPP + +#include + +namespace gwarnt { + +// Arbitrage opportunity +struct arb_opp { + p2p_ad buy; + p2p_ad sell; +}; + +std::vector find_arbitrage_opps(const std::vector &sell, + const std::vector &buy); + +} /* namespace gwarnt */ + +#endif /* GWARNT__ARBITRAGE_HPP */ -- Alviro Iskandar Setiawan