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:
parent
d3661bac7b
commit
4bd37c776f
|
@ -19,6 +19,9 @@ use tokio::time;
|
|||
pub async fn runner(
|
||||
mango_client: Arc<MangoClient>,
|
||||
debugging_handle: impl Future,
|
||||
interval_update_banks: u64,
|
||||
interval_consume_events: u64,
|
||||
interval_update_funding: u64,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
let handles1 = mango_client
|
||||
.context
|
||||
|
@ -33,6 +36,7 @@ pub async fn runner(
|
|||
loop_update_index_and_rate(
|
||||
mango_client.clone(),
|
||||
chunk.copied().collect::<Vec<TokenIndex>>(),
|
||||
interval_update_banks,
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
@ -41,14 +45,28 @@ pub async fn runner(
|
|||
.context
|
||||
.perp_markets
|
||||
.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<_>>();
|
||||
|
||||
let handles3 = mango_client
|
||||
.context
|
||||
.perp_markets
|
||||
.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<_>>();
|
||||
|
||||
futures::join!(
|
||||
|
@ -64,8 +82,9 @@ pub async fn runner(
|
|||
pub async fn loop_update_index_and_rate(
|
||||
mango_client: Arc<MangoClient>,
|
||||
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 {
|
||||
interval.tick().await;
|
||||
|
||||
|
@ -154,8 +173,9 @@ pub async fn loop_consume_events(
|
|||
mango_client: Arc<MangoClient>,
|
||||
pk: Pubkey,
|
||||
perp_market: PerpMarket,
|
||||
interval: u64,
|
||||
) {
|
||||
let mut interval = time::interval(Duration::from_secs(5));
|
||||
let mut interval = time::interval(Duration::from_secs(interval));
|
||||
loop {
|
||||
interval.tick().await;
|
||||
|
||||
|
@ -271,8 +291,9 @@ pub async fn loop_update_funding(
|
|||
mango_client: Arc<MangoClient>,
|
||||
pk: Pubkey,
|
||||
perp_market: PerpMarket,
|
||||
interval: u64,
|
||||
) {
|
||||
let mut interval = time::interval(Duration::from_secs(5));
|
||||
let mut interval = time::interval(Duration::from_secs(interval));
|
||||
loop {
|
||||
interval.tick().await;
|
||||
|
||||
|
|
|
@ -43,6 +43,18 @@ struct Cli {
|
|||
|
||||
#[clap(subcommand)]
|
||||
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)]
|
||||
|
@ -76,7 +88,12 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
};
|
||||
|
||||
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,
|
||||
owner,
|
||||
)?);
|
||||
|
@ -103,7 +120,13 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
match cli.command {
|
||||
Command::Crank { .. } => {
|
||||
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 { .. } => {
|
||||
let client = mango_client.clone();
|
||||
|
|
Loading…
Reference in New Issue