-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into feature/zzhang/toki…
…o_v1
- Loading branch information
Showing
10 changed files
with
336 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
-- Add migration script here | ||
|
||
insert into trade_record select time, 'ETH_BTC', 1, random()*0.1, random()*100 | ||
from generate_series(timestamp '2020-01-02 00:00:00', timestamp '2020-01-03 00:00:00', interval '1 s') as time; | ||
insert into trade_record select time, 'ETH_USDT', 1, price, amount, price * amount, 'ask' | ||
from (select time, random()*300 + 1000 as price, random()*10 as amount | ||
from generate_series(now() - interval '1 day', now() + interval '1 day', interval '1 s') as time) t; | ||
|
||
insert into trade_record select time, 'ETH_BTC', 2, random()*0.1, random()*100 | ||
from generate_series(timestamp '2020-01-02 00:00:00', timestamp '2020-01-03 00:00:00', interval '2 s') as time; | ||
insert into trade_record select time, 'ETH_USDT', 1, price, amount, price * amount, 'ask' | ||
from (select time, random()*200 + 1000 as price, random()*30 as amount | ||
from generate_series(now() - interval '1 day', now() + interval '1 day', interval '3 s') as time) t; | ||
|
||
insert into trade_record select time, 'ETH_BTC', 3, random()*0.1, random()*100 | ||
from generate_series(timestamp '2020-01-02 00:00:00', timestamp '2020-01-03 00:00:00', interval '5 s') as time; | ||
insert into trade_record select time, 'BTC_USDT', 1, price, amount, price * amount, 'ask' | ||
from (select time, random()*200 + 1000 as price, random()*30 as amount | ||
from generate_series(now() - interval '1 day', now() + interval '1 day', interval '3 s') as time) t; | ||
|
||
insert into trade_record select time, 'ETH_USDT', 1, price, amount, price * amount, 'ask' | ||
from (select time, random()*200 + 1000 as price, random()*100 as amount | ||
from generate_series(now() - interval '1 day', now() + interval '1 day', interval '15 s') as time) t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] | ||
#[serde(default)] | ||
pub struct Trading { | ||
#[serde(with = "humantime_serde")] | ||
pub ticker_update_interval: std::time::Duration, | ||
#[serde(with = "humantime_serde")] | ||
pub ticker_interval: std::time::Duration, | ||
} | ||
|
||
impl Default for Trading { | ||
fn default() -> Self { | ||
Trading { | ||
ticker_update_interval: std::time::Duration::from_secs(5), | ||
ticker_interval: std::time::Duration::from_secs(86_400), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] | ||
#[serde(default)] | ||
pub struct Settings { | ||
pub workers: Option<usize>, | ||
pub trading: Trading, | ||
} | ||
|
||
impl Default for Settings { | ||
fn default() -> Self { | ||
Settings { | ||
workers: None, | ||
trading: Default::default(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod config; | ||
pub mod errors; | ||
pub mod mock; | ||
pub mod personal_history; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,51 @@ | ||
use super::types::UserInfo; | ||
use super::config::Settings; | ||
use super::types::{TickerResult, UserInfo}; | ||
|
||
use sqlx::postgres::Postgres; | ||
use std::cell::RefCell; | ||
use std::collections::HashMap; | ||
use std::sync::Mutex; | ||
pub struct AppState { | ||
pub user_addr_map: Mutex<HashMap<String, UserInfo>>, | ||
pub db: sqlx::pool::Pool<Postgres>, | ||
pub config: Settings, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct TradingData { | ||
pub ticker_ret_cache: HashMap<String, TickerResult>, | ||
} | ||
|
||
impl TradingData { | ||
pub fn new() -> Self { | ||
TradingData { | ||
ticker_ret_cache: HashMap::new(), | ||
} | ||
} | ||
} | ||
|
||
impl Default for TradingData { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
//TLS storage | ||
#[derive(Debug)] | ||
pub struct AppCache { | ||
pub trading: RefCell<TradingData>, | ||
} | ||
|
||
impl AppCache { | ||
pub fn new() -> Self { | ||
AppCache { | ||
trading: TradingData::new().into(), | ||
} | ||
} | ||
} | ||
|
||
impl Default for AppCache { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} |
Oops, something went wrong.