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=9XaLemacV7pS6CyRKPzh1ezQcchenZVGteTIcHW+llQ=; h=From:To:Cc:Subject:Message-Id:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:From; b=Q38DQPp4eWodkfKIJ4a6pj4wSlbnYKZJa1eCc29DX82H4d2Bq5jRfIRmgs28yZq7S O3T+n9QL8QB3dlAoc7iUXartqws7aUZbWcWkcRisaSOTwujIuvNFUC9LbuAUKDRQOQ lmfuYCKiYdG1xuiQ6d72twcydHWtmsUi7dg3csNWVgfvzG3heb50sBnLvhvXeO5EJ8 zvIfw4/Wjz5rVOV6Vw7fTj3HPKS4zY/FUeXAd8dCMFIX4YcTBNSf/3qGpsxhPmsnoq axMHW8UoIK7aGm9ZN0EtDxZa/oWHyUpjYdfgpcsgiLCK8Xp6/LfyPI55aszeBQa7ey P3zxf/FlqDkcA== Received: from server-vie001.gnuweeb.org (unknown [192.168.57.1]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id 4263F3106505; 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 7/9] gwarnt: Create the initial example Date: Tue, 10 Sep 2024 23:44:12 +0200 Message-Id: <20240910214414.3401712-8-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: Initial example to show the usage. Signed-off-by: Alviro Iskandar Setiawan --- src/gwarnt/entry.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/gwarnt/entry.cpp b/src/gwarnt/entry.cpp index 4a74df9..044234e 100644 --- a/src/gwarnt/entry.cpp +++ b/src/gwarnt/entry.cpp @@ -1,6 +1,48 @@ // SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include +#include +#include + int main(void) { + std::vector buy_bnc, sell_bnc; + std::vector buy_okx, sell_okx; + std::vector opportunities; + gwarnt::p2p::binance bnc; + gwarnt::p2p::okx okx; + + while (1) { + printf("Fetching data ...\n"); + buy_bnc = bnc.get_data("IDR", "USDT", "BUY"); + sell_bnc = bnc.get_data("IDR", "USDT", "SELL"); + + buy_okx = okx.get_data("IDR", "USDT", "BUY"); + sell_okx = okx.get_data("IDR", "USDT", "SELL"); + printf("Binance: %lu buy, %lu sell\n", buy_bnc.size(), sell_bnc.size()); + printf("OKX: %lu buy, %lu sell\n", buy_okx.size(), sell_okx.size()); + + opportunities = gwarnt::find_arbitrage_opps(sell_okx, buy_bnc); + for (const auto &i : opportunities) { + std::cout << i.sell.dump() << std::endl; + std::cout << "====================" << std::endl; + std::cout << i.buy.dump() << std::endl; + std::cout << "----------------------------------------------" << std::endl; + } + + opportunities = gwarnt::find_arbitrage_opps(sell_bnc, buy_okx); + for (const auto &i : opportunities) { + std::cout << i.sell.dump() << std::endl; + std::cout << "====================" << std::endl; + std::cout << i.buy.dump() << std::endl; + std::cout << "----------------------------------------------" << std::endl; + } + + printf("Sleeping...\n"); + sleep(5); + } + return 0; } -- Alviro Iskandar Setiawan