accounts
This commit is contained in:
Generated
+12
@@ -84,6 +84,17 @@ version = "0.7.8"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56"
|
checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "async-trait"
|
||||||
|
version = "0.1.91"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ae36dc4177970ef04fde5178d3e2429882def40e57a451f919c098f72baa6cec"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 3.0.3",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atomic-waker"
|
name = "atomic-waker"
|
||||||
version = "1.1.2"
|
version = "1.1.2"
|
||||||
@@ -1712,6 +1723,7 @@ name = "sol-hunter"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"async-trait",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"log",
|
"log",
|
||||||
|
|||||||
@@ -21,3 +21,4 @@ log = "0.4.33"
|
|||||||
env_logger = "0.11.11"
|
env_logger = "0.11.11"
|
||||||
rust_decimal = "1.42.1"
|
rust_decimal = "1.42.1"
|
||||||
reqwest = { version = "0.13.4", features = ["json"] }
|
reqwest = { version = "0.13.4", features = ["json"] }
|
||||||
|
async-trait = "0.1.91"
|
||||||
|
|||||||
+27
-1
@@ -1,12 +1,15 @@
|
|||||||
|
use anyhow::Context;
|
||||||
use futures_util::{SinkExt, StreamExt};
|
use futures_util::{SinkExt, StreamExt};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream, connect_async};
|
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream, connect_async};
|
||||||
|
|
||||||
use crate::types::NewToken;
|
use crate::{account::AccountManager, executor::Executor, types::NewToken};
|
||||||
|
|
||||||
pub struct Bot {
|
pub struct Bot {
|
||||||
pub ws: WebSocketStream<MaybeTlsStream<TcpStream>>,
|
pub ws: WebSocketStream<MaybeTlsStream<TcpStream>>,
|
||||||
|
pub accounts: AccountManager,
|
||||||
|
pub executor: Box<dyn Executor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Bot {
|
impl Bot {
|
||||||
@@ -17,11 +20,34 @@ impl Bot {
|
|||||||
|
|
||||||
impl Bot {
|
impl Bot {
|
||||||
pub async fn new() -> anyhow::Result<Self> {
|
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 {
|
Ok(Self {
|
||||||
ws: connect_async("wss://pumpdev.io/ws").await?.0,
|
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<()> {
|
pub async fn initialize_websocket_subscribe(&mut self) -> anyhow::Result<()> {
|
||||||
self.ws
|
self.ws
|
||||||
.send(tokio_tungstenite::tungstenite::Message::Text(
|
.send(tokio_tungstenite::tungstenite::Message::Text(
|
||||||
|
|||||||
+2
-2
@@ -4,8 +4,8 @@ use rust_decimal::Decimal;
|
|||||||
|
|
||||||
use crate::account::Account;
|
use crate::account::Account;
|
||||||
|
|
||||||
|
#[allow(unused_variables)]
|
||||||
#[allow(async_fn_in_trait, unused_variables)]
|
#[async_trait::async_trait]
|
||||||
pub trait Executor {
|
pub trait Executor {
|
||||||
async fn buy(
|
async fn buy(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ impl PumpDev {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
impl Executor for PumpDev {
|
impl Executor for PumpDev {
|
||||||
async fn buy(
|
async fn buy(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
Reference in New Issue
Block a user