diff --git a/src/main/java/markets/arcana/obcranker/ObCrankerApplication.java b/src/main/java/markets/arcana/obcranker/ObCrankerApplication.java index 6babd61..b2e47dc 100644 --- a/src/main/java/markets/arcana/obcranker/ObCrankerApplication.java +++ b/src/main/java/markets/arcana/obcranker/ObCrankerApplication.java @@ -2,6 +2,7 @@ import com.google.common.io.Resources; import com.mmorrell.openbook.manager.OpenBookManager; +import com.mmorrell.openbook.model.OpenBookMarket; import lombok.extern.slf4j.Slf4j; import org.p2p.solanaj.core.Account; import org.p2p.solanaj.core.PublicKey; @@ -22,7 +23,7 @@ @Slf4j public class ObCrankerApplication { - private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2); public static void main(String[] args) { SpringApplication.run(ObCrankerApplication.class, args); @@ -33,18 +34,20 @@ public void crankEventHeapLoop() throws InterruptedException, IOException { OpenBookManager manager = new OpenBookManager(new RpcClient("https://mainnet.helius-rpc" + ".com/?api-key=a778b653-bdd6-41bc-8cda-0c7377faf1dd")); + Account tradingAccount = null; + try { + tradingAccount = Account.fromJson( + Resources.toString(Resources.getResource("mikeDBaJgkicqhZcoYDBB4dRwZFFJCThtWCYD7A9FAH.json"), Charset.defaultCharset())); + } catch (IOException e) { + e.printStackTrace(); + } + Account finalTradingAccount = tradingAccount; + scheduler.scheduleAtFixedRate(() -> { // SOL/USDC PublicKey marketId = PublicKey.valueOf("C3YPL3kYCSYKsmHcHrPWx1632GUXGqi2yMXJbfeCc57q"); - Account tradingAccount = null; - try { - tradingAccount = Account.fromJson( - Resources.toString(Resources.getResource("mikeDBaJgkicqhZcoYDBB4dRwZFFJCThtWCYD7A9FAH.json"), Charset.defaultCharset())); - } catch (IOException e) { - e.printStackTrace(); - } Optional transactionId = manager.consumeEvents( - tradingAccount, + finalTradingAccount, marketId, 8 ); @@ -56,5 +59,28 @@ public void crankEventHeapLoop() throws InterruptedException, IOException { } }, 0, 5, TimeUnit.SECONDS); + + scheduler.scheduleAtFixedRate(() -> { + manager.cacheMarkets(); + for (OpenBookMarket market : manager.getOpenBookMarkets()) { + Optional transactionId = manager.consumeEvents( + finalTradingAccount, + market.getMarketId(), + 8 + ); + + if (transactionId.isPresent()) { + log.info("Cranked events [{}]: {}", market.getName(), transactionId.get()); + } else { + log.info("No events found to consume."); + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + log.error("Error consuming: {}", e.getMessage()); + } + } + + }, 0, 60, TimeUnit.SECONDS); } } \ No newline at end of file