public inbox for [email protected]
 help / color / mirror / Atom feed
From: Alviro Iskandar Setiawan <[email protected]>
To: Ammar Faizi <[email protected]>,
	Michael William Jonathan <[email protected]>
Cc: Alviro Iskandar Setiawan <[email protected]>,
	Ravel Kevin Ethan <[email protected]>,
	GNU/Weeb Mailing List <[email protected]>
Subject: [RFC PATCH 5/9] gwarnt: Create function to find arbitrage opportunities
Date: Tue, 10 Sep 2024 23:44:10 +0200	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

After collecting buy and sell ads from two different exchanges, find
the arbitrage opportunities.

Signed-off-by: Alviro Iskandar Setiawan <[email protected]>
---
 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 <gwarnt/arbitrage.hpp>
+
+namespace gwarnt {
+
+std::vector<struct arb_opp> find_arbitrage_opps(const std::vector<p2p_ad> &sell,
+						const std::vector<p2p_ad> &buy)
+{
+	std::vector<struct arb_opp> 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 <gwarnt/p2p_ad.hpp>
+
+namespace gwarnt {
+
+// Arbitrage opportunity
+struct arb_opp {
+	p2p_ad buy;
+	p2p_ad sell;
+};
+
+std::vector<struct arb_opp> find_arbitrage_opps(const std::vector<p2p_ad> &sell,
+						const std::vector<p2p_ad> &buy);
+
+} /* namespace gwarnt */
+
+#endif /* GWARNT__ARBITRAGE_HPP */
-- 
Alviro Iskandar Setiawan


  parent reply	other threads:[~2024-09-10 21:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-10 21:44 [RFC PATCH 0/9] Introducing GNU/Weeb Arbitrage Opportunity Notification Bot Alviro Iskandar Setiawan
2024-09-10 21:44 ` [RFC PATCH 2/9] gwarnt: Create initial P2P ad data structure Alviro Iskandar Setiawan
2024-09-10 21:44 ` [RFC PATCH 3/9] gwarnt: p2p: Add P2P Binance Alviro Iskandar Setiawan
2024-09-10 21:44 ` [RFC PATCH 4/9] gwarnt: p2p: Add P2P OKX Alviro Iskandar Setiawan
2024-09-10 21:44 ` Alviro Iskandar Setiawan [this message]
2024-09-10 21:44 ` [RFC PATCH 6/9] gwarnt: p2p/binance: Fix invalid page Alviro Iskandar Setiawan
2024-09-10 21:44 ` [RFC PATCH 7/9] gwarnt: Create the initial example Alviro Iskandar Setiawan
2024-09-10 21:44 ` [RFC PATCH 8/9] gwarnt: Add README file Alviro Iskandar Setiawan
2024-09-10 21:44 ` [RFC PATCH 9/9] gwarnt: Add Telegram bot Alviro Iskandar Setiawan
2024-09-10 22:21 ` [RFC PATCH 0/9] Introducing GNU/Weeb Arbitrage Opportunity Notification Bot Ammar Faizi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240910214414.3401712-6-alviro.iskandar@gnuweeb.org \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox