Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
ryqdev committed May 29, 2024
1 parent b579298 commit 216fd8b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All in one trading engine
### Paper trading & live trading
- [x] Single live broker: IBKR
- [x] Live trading with single broker
- [ ] Async

## Demo
```shell
Expand Down
4 changes: 2 additions & 2 deletions src/cmds/paper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ async fn paper_trading(){


let contract = Contract {
symbol: "JPY".to_owned(),
symbol: "USD".to_owned(),
security_type: SecurityType::ForexPair,
currency: "USD".to_owned(),
currency: "JPY".to_owned(),
exchange: "IDEALPRO".to_owned(),
..Default::default()
};
Expand Down
7 changes: 6 additions & 1 deletion src/green/green.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ impl Green {
}
pub fn run(&mut self) {
log::info!("Running {:?}...", self.strategy);

//! .iter() : borrows the ownership
//! .into_iter(): transfers the ownership
for bar in self.data.iter() {
let order = self.strategy.next(bar);
let cash = self.broker.cash.last().unwrap();
Expand Down Expand Up @@ -105,7 +108,7 @@ impl Green {
type HistoricalData = (String, Vec<f64>);

impl GreenBuilder{
pub fn add_data_feed(&mut self, symbol: Box<dyn BaseData>) -> &mut GreenBuilder{
pub fn add_data_feed(&mut self, symbol: &str) -> &mut GreenBuilder{
let file = File::open(format!("data/{symbol}.csv")).unwrap();

let mut reader = csv::ReaderBuilder::new()
Expand All @@ -115,6 +118,8 @@ impl GreenBuilder{
let mut finance_data = vec![];
for result in reader.deserialize() {
let record: HistoricalData = result.unwrap();
// use record.1[2] rather than record.1.get(2)
// to get higher performance
let low = record.1[2];
let open = record.1[0];
let close = record.1[3];
Expand Down

0 comments on commit 216fd8b

Please sign in to comment.