Add order/position management

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2024-02-14 17:07:30 +00:00
parent 6ec71ee144
commit 648d413ac7
44 changed files with 826 additions and 497 deletions

View File

@@ -4,17 +4,13 @@ use crate::{
database,
types::{
alpaca::{
self,
api::{self, outgoing::Sort},
shared::Source,
api,
shared::{Sort, Source},
},
news::Prediction,
Backfill, Bar, Class, News,
},
utils::{
duration_until, last_minute, remove_slash_from_pair, FIFTEEN_MINUTES, ONE_MINUTE,
ONE_SECOND,
},
utils::{duration_until, last_minute, FIFTEEN_MINUTES, ONE_MINUTE, ONE_SECOND},
};
use async_trait::async_trait;
use futures_util::future::join_all;
@@ -216,21 +212,12 @@ impl Handler for BarHandler {
&self,
symbol: String,
) -> Result<Option<Backfill>, clickhouse::error::Error> {
database::backfills::select_latest_where_symbol(
&self.config.clickhouse_client,
&database::backfills::Table::Bars,
&symbol,
)
.await
database::backfills_bars::select_where_symbol(&self.config.clickhouse_client, &symbol).await
}
async fn delete_backfills(&self, symbols: &[String]) -> Result<(), clickhouse::error::Error> {
database::backfills::delete_where_symbols(
&self.config.clickhouse_client,
&database::backfills::Table::Bars,
symbols,
)
.await
database::backfills_bars::delete_where_symbols(&self.config.clickhouse_client, symbols)
.await
}
async fn delete_data(&self, symbols: &[String]) -> Result<(), clickhouse::error::Error> {
@@ -252,7 +239,7 @@ impl Handler for BarHandler {
let mut next_page_token = None;
loop {
let Ok(message) = alpaca::api::incoming::bar::get_historical(
let Ok(message) = api::incoming::bar::get_historical(
&self.config,
self.data_url,
&(self.api_query_constructor)(
@@ -289,16 +276,12 @@ impl Handler for BarHandler {
let backfill = bars.last().unwrap().clone().into();
database::bars::upsert_batch(&self.config.clickhouse_client, bars)
database::bars::upsert_batch(&self.config.clickhouse_client, &bars)
.await
.unwrap();
database::backfills_bars::upsert(&self.config.clickhouse_client, &backfill)
.await
.unwrap();
database::backfills::upsert(
&self.config.clickhouse_client,
&database::backfills::Table::Bars,
&backfill,
)
.await
.unwrap();
info!("Backfilled bars for {}.", symbol);
}
@@ -318,21 +301,12 @@ impl Handler for NewsHandler {
&self,
symbol: String,
) -> Result<Option<Backfill>, clickhouse::error::Error> {
database::backfills::select_latest_where_symbol(
&self.config.clickhouse_client,
&database::backfills::Table::News,
&symbol,
)
.await
database::backfills_news::select_where_symbol(&self.config.clickhouse_client, &symbol).await
}
async fn delete_backfills(&self, symbols: &[String]) -> Result<(), clickhouse::error::Error> {
database::backfills::delete_where_symbols(
&self.config.clickhouse_client,
&database::backfills::Table::News,
symbols,
)
.await
database::backfills_news::delete_where_symbols(&self.config.clickhouse_client, symbols)
.await
}
async fn delete_data(&self, symbols: &[String]) -> Result<(), clickhouse::error::Error> {
@@ -352,10 +326,10 @@ impl Handler for NewsHandler {
let mut next_page_token = None;
loop {
let Ok(message) = alpaca::api::incoming::news::get_historical(
let Ok(message) = api::incoming::news::get_historical(
&self.config,
&api::outgoing::news::News {
symbols: vec![remove_slash_from_pair(&symbol)],
symbols: vec![symbol.clone()],
start: Some(fetch_from),
end: Some(fetch_to),
limit: Some(50),
@@ -421,16 +395,12 @@ impl Handler for NewsHandler {
let backfill = (news.last().unwrap().clone(), symbol.clone()).into();
database::news::upsert_batch(&self.config.clickhouse_client, news)
database::news::upsert_batch(&self.config.clickhouse_client, &news)
.await
.unwrap();
database::backfills_news::upsert(&self.config.clickhouse_client, &backfill)
.await
.unwrap();
database::backfills::upsert(
&self.config.clickhouse_client,
&database::backfills::Table::News,
&backfill,
)
.await
.unwrap();
info!("Backfilled news for {}.", symbol);
}