Organize modules
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use crate::types::Source;
|
use crate::types::alpaca::Source;
|
||||||
use governor::{DefaultDirectRateLimiter, Quota, RateLimiter};
|
use governor::{DefaultDirectRateLimiter, Quota, RateLimiter};
|
||||||
use reqwest::{header::HeaderMap, Client};
|
use reqwest::{header::HeaderMap, Client};
|
||||||
use std::{env, num::NonZeroU32, sync::Arc};
|
use std::{env, num::NonZeroU32, sync::Arc};
|
||||||
|
@@ -5,12 +5,12 @@ use crate::{
|
|||||||
},
|
},
|
||||||
data::authenticate_websocket,
|
data::authenticate_websocket,
|
||||||
database,
|
database,
|
||||||
time::{duration_until, last_minute, next_minute, ONE_MINUTE},
|
|
||||||
types::{
|
types::{
|
||||||
api::incoming,
|
alpaca::{api::incoming, websocket},
|
||||||
asset::{self, Asset},
|
asset::{self, Asset},
|
||||||
websocket, Bar, BarValidity, BroadcastMessage, Class,
|
Bar, BarValidity, BroadcastMessage, Class,
|
||||||
},
|
},
|
||||||
|
utils::{duration_until, last_minute, next_minute, ONE_MINUTE},
|
||||||
};
|
};
|
||||||
use core::panic;
|
use core::panic;
|
||||||
use futures_util::{
|
use futures_util::{
|
||||||
@@ -283,8 +283,9 @@ pub async fn backfill(
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
app_config.alpaca_rate_limit.until_ready().await;
|
app_config.alpaca_rate_limit.until_ready().await;
|
||||||
|
|
||||||
let response = request.send().await.unwrap();
|
let response = request.send().await.unwrap();
|
||||||
let mut response = if response.status() == reqwest::StatusCode::OK {
|
let response = if response.status() == reqwest::StatusCode::OK {
|
||||||
response.json::<incoming::bar::Message>().await.unwrap()
|
response.json::<incoming::bar::Message>().await.unwrap()
|
||||||
} else {
|
} else {
|
||||||
error!(
|
error!(
|
||||||
@@ -297,14 +298,11 @@ pub async fn backfill(
|
|||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
for bar in response
|
response.bars.into_iter().for_each(|(symbol, bar_vec)| {
|
||||||
.bars
|
bar_vec.unwrap_or_default().into_iter().for_each(|bar| {
|
||||||
.remove(&asset.symbol)
|
bars.push(Bar::from((bar, symbol.clone())));
|
||||||
.unwrap_or_default()
|
});
|
||||||
.unwrap_or_default()
|
});
|
||||||
{
|
|
||||||
bars.push(Bar::from((bar, asset.symbol.clone())));
|
|
||||||
}
|
|
||||||
|
|
||||||
if response.next_page_token.is_none() {
|
if response.next_page_token.is_none() {
|
||||||
break;
|
break;
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
pub mod market;
|
pub mod market;
|
||||||
|
|
||||||
use crate::{config::Config, types::websocket};
|
use crate::{config::Config, types::alpaca::websocket};
|
||||||
use core::panic;
|
use core::panic;
|
||||||
use futures_util::{
|
use futures_util::{
|
||||||
stream::{SplitSink, SplitStream},
|
stream::{SplitSink, SplitStream},
|
||||||
|
@@ -5,8 +5,8 @@ mod config;
|
|||||||
mod data;
|
mod data;
|
||||||
mod database;
|
mod database;
|
||||||
mod routes;
|
mod routes;
|
||||||
mod time;
|
|
||||||
mod types;
|
mod types;
|
||||||
|
mod utils;
|
||||||
|
|
||||||
use config::Config;
|
use config::Config;
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
use crate::config::{Config, ALPACA_ASSET_API_URL};
|
use crate::config::{Config, ALPACA_ASSET_API_URL};
|
||||||
use crate::database;
|
use crate::database;
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
api::incoming::{self, asset::Status},
|
alpaca::api::incoming::{self, asset::Status},
|
||||||
asset, Asset, BroadcastMessage,
|
asset, Asset, BroadcastMessage,
|
||||||
};
|
};
|
||||||
use axum::{extract::Path, Extension, Json};
|
use axum::{extract::Path, Extension, Json};
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
#![allow(clippy::struct_excessive_bools)]
|
#![allow(clippy::struct_excessive_bools)]
|
||||||
|
|
||||||
use crate::types::api::impl_from_enum;
|
use crate::types::alpaca::api::impl_from_enum;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
5
src/types/alpaca/mod.rs
Normal file
5
src/types/alpaca/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
pub mod api;
|
||||||
|
pub mod source;
|
||||||
|
pub mod websocket;
|
||||||
|
|
||||||
|
pub use source::Source;
|
@@ -1,12 +1,9 @@
|
|||||||
pub mod api;
|
pub mod alpaca;
|
||||||
pub mod asset;
|
pub mod asset;
|
||||||
pub mod bar;
|
pub mod bar;
|
||||||
pub mod source;
|
|
||||||
pub mod websocket;
|
|
||||||
|
|
||||||
pub use asset::{Asset, Class, Exchange};
|
pub use asset::{Asset, Class, Exchange};
|
||||||
pub use bar::{Bar, BarValidity};
|
pub use bar::{Bar, BarValidity};
|
||||||
pub use source::Source;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum BroadcastMessage {
|
pub enum BroadcastMessage {
|
||||||
|
3
src/utils/mod.rs
Normal file
3
src/utils/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
pub mod time;
|
||||||
|
|
||||||
|
pub use time::{duration_until, last_minute, next_minute, ONE_MINUTE};
|
Reference in New Issue
Block a user