Make keeper intervals configurable (#294)

* 1.10.35 compatibility

* cargo update

* Fix build

* cargo fmt

* Add configurable intervals to keeper

* 1.10.35 compatibility

* cargo update

* Fix build

* cargo fmt

* Add configurable intervals to keeper
This commit is contained in:
riordanp 2022-11-21 18:35:04 +00:00 committed by GitHub
parent d3661bac7b
commit 4bd37c776f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 7 deletions

View File

@ -19,6 +19,9 @@ use tokio::time;
pub async fn runner( pub async fn runner(
mango_client: Arc<MangoClient>, mango_client: Arc<MangoClient>,
debugging_handle: impl Future, debugging_handle: impl Future,
interval_update_banks: u64,
interval_consume_events: u64,
interval_update_funding: u64,
) -> Result<(), anyhow::Error> { ) -> Result<(), anyhow::Error> {
let handles1 = mango_client let handles1 = mango_client
.context .context
@ -33,6 +36,7 @@ pub async fn runner(
loop_update_index_and_rate( loop_update_index_and_rate(
mango_client.clone(), mango_client.clone(),
chunk.copied().collect::<Vec<TokenIndex>>(), chunk.copied().collect::<Vec<TokenIndex>>(),
interval_update_banks,
) )
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -41,14 +45,28 @@ pub async fn runner(
.context .context
.perp_markets .perp_markets
.values() .values()
.map(|perp| loop_consume_events(mango_client.clone(), perp.address, perp.market)) .map(|perp| {
loop_consume_events(
mango_client.clone(),
perp.address,
perp.market,
interval_consume_events,
)
})
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let handles3 = mango_client let handles3 = mango_client
.context .context
.perp_markets .perp_markets
.values() .values()
.map(|perp| loop_update_funding(mango_client.clone(), perp.address, perp.market)) .map(|perp| {
loop_update_funding(
mango_client.clone(),
perp.address,
perp.market,
interval_update_funding,
)
})
.collect::<Vec<_>>(); .collect::<Vec<_>>();
futures::join!( futures::join!(
@ -64,8 +82,9 @@ pub async fn runner(
pub async fn loop_update_index_and_rate( pub async fn loop_update_index_and_rate(
mango_client: Arc<MangoClient>, mango_client: Arc<MangoClient>,
token_indices: Vec<TokenIndex>, token_indices: Vec<TokenIndex>,
interval: u64,
) { ) {
let mut interval = time::interval(Duration::from_secs(60)); let mut interval = time::interval(Duration::from_secs(interval));
loop { loop {
interval.tick().await; interval.tick().await;
@ -154,8 +173,9 @@ pub async fn loop_consume_events(
mango_client: Arc<MangoClient>, mango_client: Arc<MangoClient>,
pk: Pubkey, pk: Pubkey,
perp_market: PerpMarket, perp_market: PerpMarket,
interval: u64,
) { ) {
let mut interval = time::interval(Duration::from_secs(5)); let mut interval = time::interval(Duration::from_secs(interval));
loop { loop {
interval.tick().await; interval.tick().await;
@ -271,8 +291,9 @@ pub async fn loop_update_funding(
mango_client: Arc<MangoClient>, mango_client: Arc<MangoClient>,
pk: Pubkey, pk: Pubkey,
perp_market: PerpMarket, perp_market: PerpMarket,
interval: u64,
) { ) {
let mut interval = time::interval(Duration::from_secs(5)); let mut interval = time::interval(Duration::from_secs(interval));
loop { loop {
interval.tick().await; interval.tick().await;

View File

@ -43,6 +43,18 @@ struct Cli {
#[clap(subcommand)] #[clap(subcommand)]
command: Command, command: Command,
#[clap(long, env, default_value_t = 60)]
interval_update_banks: u64,
#[clap(long, env, default_value_t = 5)]
interval_consume_events: u64,
#[clap(long, env, default_value_t = 5)]
interval_update_funding: u64,
#[clap(long, env, default_value_t = 10)]
timeout: u64,
} }
#[derive(Subcommand, Debug, Clone)] #[derive(Subcommand, Debug, Clone)]
@ -76,7 +88,12 @@ fn main() -> Result<(), anyhow::Error> {
}; };
let mango_client = Arc::new(MangoClient::new_for_existing_account( let mango_client = Arc::new(MangoClient::new_for_existing_account(
Client::new(cluster, commitment, &owner, Some(Duration::from_secs(10))), Client::new(
cluster,
commitment,
&owner,
Some(Duration::from_secs(cli.timeout)),
),
cli.mango_account, cli.mango_account,
owner, owner,
)?); )?);
@ -103,7 +120,13 @@ fn main() -> Result<(), anyhow::Error> {
match cli.command { match cli.command {
Command::Crank { .. } => { Command::Crank { .. } => {
let client = mango_client.clone(); let client = mango_client.clone();
rt.block_on(crank::runner(client, debugging_handle)) rt.block_on(crank::runner(
client,
debugging_handle,
cli.interval_update_banks,
cli.interval_consume_events,
cli.interval_update_funding,
))
} }
Command::Taker { .. } => { Command::Taker { .. } => {
let client = mango_client.clone(); let client = mango_client.clone();