Add partial account management
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -22,11 +22,36 @@ pub async fn run(config: Arc<Config>) {
|
||||
alpaca::websocket::trading::subscribe(&mut websocket_sink, &mut websocket_stream).await;
|
||||
|
||||
rehydrate(&config).await;
|
||||
check_positions(&config).await;
|
||||
|
||||
spawn(websocket::run(config, websocket_stream, websocket_sink));
|
||||
}
|
||||
|
||||
pub async fn check_account(config: &Arc<Config>) {
|
||||
let account = alpaca::api::incoming::account::get(config, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(
|
||||
!(account.status != alpaca::api::incoming::account::Status::Active),
|
||||
"Account status is not active: {:?}.",
|
||||
account.status
|
||||
);
|
||||
assert!(
|
||||
!account.trade_suspend_by_user,
|
||||
"Account trading is suspended by user."
|
||||
);
|
||||
assert!(!account.trading_blocked, "Account trading is blocked.");
|
||||
assert!(!account.blocked, "Account is blocked.");
|
||||
|
||||
if account.cash == 0.0 {
|
||||
warn!("Account cash is zero, qrust will not be able to trade.");
|
||||
}
|
||||
|
||||
warn!(
|
||||
"qrust active with {}{}, avoid transferring funds without shutting down.",
|
||||
account.currency, account.cash
|
||||
);
|
||||
}
|
||||
|
||||
pub async fn check_positions(config: &Arc<Config>) {
|
||||
let positions_future = async {
|
||||
alpaca::api::incoming::position::get(config, None)
|
||||
|
Reference in New Issue
Block a user