1
1
pub use influxdb_client:: { Client , Point } ;
2
2
use {
3
- influxdb_client:: Precision ,
3
+ chrono:: Utc ,
4
+ influxdb_client:: { timestamp, Precision , Timestamp , TimestampOptions } ,
4
5
serde:: { Deserialize , Serialize } ,
5
6
std:: { env, sync:: Arc } ,
6
7
tokio:: sync:: RwLock ,
@@ -37,13 +38,15 @@ pub async fn send(config: Option<MetricsConfig>) {
37
38
. with_bucket ( config. bucket )
38
39
. with_precision ( Precision :: MS ) ;
39
40
//let client = client.insert_to_stdout();
41
+
42
+ // Write all metrics with the same timestamp to ensure multiple sys-lend APY and balance
43
+ // values line up
44
+ let timestamp = timestamp ! ( Utc :: now( ) . timestamp_millis( ) ) ;
40
45
client
41
- . insert_points (
42
- & * POINTS . write ( ) . await ,
43
- influxdb_client:: TimestampOptions :: None ,
44
- )
46
+ . insert_points ( & * POINTS . write ( ) . await , timestamp)
45
47
. await
46
48
. unwrap_or_else ( |err| eprintln ! ( "Failed to send metrics: {err:?}" ) ) ;
49
+ println ! ( "wrote" ) ;
47
50
}
48
51
}
49
52
@@ -53,25 +56,19 @@ pub mod dp {
53
56
exchange:: { Exchange , OrderSide } ,
54
57
token:: MaybeToken ,
55
58
} ,
56
- chrono:: Utc ,
57
- influxdb_client:: { Point , Timestamp , Value } ,
59
+ influxdb_client:: { Point , Value } ,
58
60
solana_sdk:: pubkey:: Pubkey ,
59
61
} ;
60
62
61
63
pub fn pubkey_to_value ( p : & Pubkey ) -> Value {
62
64
Value :: Str ( p. to_string ( ) )
63
65
}
64
66
65
- pub fn now ( ) -> Timestamp {
66
- Timestamp :: Int ( Utc :: now ( ) . timestamp_millis ( ) )
67
- }
68
-
69
67
pub fn exchange_deposit ( exchange : Exchange , maybe_token : MaybeToken , ui_amount : f64 ) -> Point {
70
68
Point :: new ( "exchange_deposit" )
71
69
. tag ( "exchange" , exchange. to_string ( ) . as_str ( ) )
72
70
. tag ( "token" , maybe_token. name ( ) )
73
71
. field ( "amount" , ui_amount)
74
- . timestamp ( now ( ) )
75
72
}
76
73
77
74
pub fn exchange_withdrawal (
@@ -85,7 +82,6 @@ pub mod dp {
85
82
. tag ( "token" , maybe_token. name ( ) )
86
83
. tag ( "address" , pubkey_to_value ( address) )
87
84
. field ( "amount" , ui_amount)
88
- . timestamp ( now ( ) )
89
85
}
90
86
91
87
pub fn exchange_fill (
@@ -103,6 +99,5 @@ pub mod dp {
103
99
. tag ( "token" , maybe_token. name ( ) )
104
100
. field ( "price" , price)
105
101
. field ( "amount" , amount)
106
- . timestamp ( now ( ) )
107
102
}
108
103
}
0 commit comments