accounts
This commit is contained in:
+27
-1
@@ -1,12 +1,15 @@
|
||||
use anyhow::Context;
|
||||
use futures_util::{SinkExt, StreamExt};
|
||||
use serde_json::json;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream, connect_async};
|
||||
|
||||
use crate::types::NewToken;
|
||||
use crate::{account::AccountManager, executor::Executor, types::NewToken};
|
||||
|
||||
pub struct Bot {
|
||||
pub ws: WebSocketStream<MaybeTlsStream<TcpStream>>,
|
||||
pub accounts: AccountManager,
|
||||
pub executor: Box<dyn Executor>,
|
||||
}
|
||||
|
||||
impl Bot {
|
||||
@@ -17,11 +20,34 @@ impl Bot {
|
||||
|
||||
impl Bot {
|
||||
pub async fn new() -> anyhow::Result<Self> {
|
||||
let accounts = AccountManager::get().await?;
|
||||
|
||||
let account = accounts
|
||||
.accounts
|
||||
.get(&accounts.active)
|
||||
.context("Failed to get account")?
|
||||
.clone();
|
||||
|
||||
Ok(Self {
|
||||
ws: connect_async("wss://pumpdev.io/ws").await?.0,
|
||||
executor: Box::new(account.executor()),
|
||||
accounts,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn refresh_account(&mut self) -> anyhow::Result<()> {
|
||||
let account = self
|
||||
.accounts
|
||||
.accounts
|
||||
.get(&self.accounts.active)
|
||||
.context("Failed to get account")?
|
||||
.clone();
|
||||
|
||||
self.executor = Box::new(account.executor());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn initialize_websocket_subscribe(&mut self) -> anyhow::Result<()> {
|
||||
self.ws
|
||||
.send(tokio_tungstenite::tungstenite::Message::Text(
|
||||
|
||||
+2
-2
@@ -4,8 +4,8 @@ use rust_decimal::Decimal;
|
||||
|
||||
use crate::account::Account;
|
||||
|
||||
|
||||
#[allow(async_fn_in_trait, unused_variables)]
|
||||
#[allow(unused_variables)]
|
||||
#[async_trait::async_trait]
|
||||
pub trait Executor {
|
||||
async fn buy(
|
||||
&self,
|
||||
|
||||
@@ -84,6 +84,7 @@ impl PumpDev {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Executor for PumpDev {
|
||||
async fn buy(
|
||||
&self,
|
||||
|
||||
Reference in New Issue
Block a user