db: add sandbox deployment & fix master deployment

This commit is contained in:
realaltffour 2020-06-30 10:31:32 +03:00
parent cbf03bcaed
commit c8ebe26078
No known key found for this signature in database
GPG Key ID: C2EA08DBA4C2DF4A
9 changed files with 68 additions and 8 deletions

View File

@ -19,3 +19,4 @@ bench = false
[dependencies]
chrono = "0.4"
postgres = "0.17.3"
postgres-types = {version = "0.1.1", features = ["derive"]}

View File

@ -8,6 +8,8 @@ services:
POSTGRES_DB: pt_db
POSTGRES_USER: pt_usr
POSTGRES_PASSWORD: test
ports:
- 5432:5432
adminer:
image: adminer
restart: always

View File

@ -0,0 +1,17 @@
version: '3.1'
services:
db:
image: postgres
restart: always
environment:
POSTGRES_DB: pt_db
POSTGRES_USER: pt_usr
POSTGRES_PASSWORD: test
ports:
- 5432:5432
adminer:
image: adminer
restart: always
ports:
- 8080:8080

View File

@ -0,0 +1,7 @@
FROM rust
# Set up Root directory project
RUN mkdir /pt_proj/
WORKDIR pt_proj
ENTRYPOINT [ "cargo", "run", "sandbox" ]

3
scripts/deploy_sandbox.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
docker-compose -f ../DockerFiles/dockComp_sandbox.yml up

View File

@ -1,4 +1,28 @@
use libtrader::ds::account::account::Account;
use libtrader::ds::account::portfolio::Portfolio;
use postgres::{Client, NoTls};
fn main() {
let account = Account{
username: "test".to_string(),
email: "email".to_string(),
is_pass: true,
pass_hash: "passhash".to_string(),
portfolio: Portfolio{
position_history: Vec::new(),
open_positions: Vec::new()
},
transactions: Vec::new()
};
let mut client = Client::connect("host=localhost port=5432 user=pt_usr password=test dbname=pt_db", NoTls).unwrap();
client.batch_execute("
CREATE TABLE accounts (
id SERIAL PRIMARY KEY,
acct CHAR
)").unwrap();
println!("Hello World!");
}

View File

@ -1,6 +1,8 @@
use postgres_types::{ToSql, FromSql};
use crate::ds::account::portfolio::Portfolio;
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Debug, ToSql, FromSql)]
pub struct Account {
pub username: String,
pub email: String,

View File

@ -1,6 +1,8 @@
use postgres_types::{ToSql, FromSql};
use crate::ds::account::position::Position;
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Debug, ToSql, FromSql)]
pub struct Portfolio {
pub position_history: Vec<Position>,
pub open_positions: Vec<Position>

View File

@ -1,19 +1,21 @@
use postgres_types::{ToSql, FromSql};
use chrono::{DateTime, Utc};
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Debug, ToSql, FromSql)]
pub enum PositionType { Sell, Buy }
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Debug, ToSql, FromSql)]
pub struct Position {
pub action_type: PositionType,
pub stock_symbol: String,
pub stock_open_amount: isize,
pub stock_open_amount: i64,
pub stock_open_price: f64,
pub stock_open_cost: f64,
pub stock_close_amount: isize,
pub stock_close_amount: i64,
pub stock_close_price: f64,
pub stock_close_cost: f64,
pub open_date: DateTime<Utc>,
pub close_date: DateTime<Utc>,
//pub open_date: DateTime<Utc>,
//pub close_date: DateTime<Utc>,
pub is_open: bool,
}