-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into SCRUM-57-publish-user-service-events
- Loading branch information
Showing
18 changed files
with
548 additions
and
129 deletions.
There are no files selected for viewing
76 changes: 37 additions & 39 deletions
76
...Service/src/main/java/com/joe/trading/marketdataservice/MarketDataServiceApplication.java
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,39 +1,37 @@ | ||
package com.joe.trading.marketdataservice; | ||
|
||
import com.joe.trading.marketdataservice.model.MarketData; | ||
import com.joe.trading.marketdataservice.services.MarketDataService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@SpringBootApplication | ||
public class MarketDataServiceApplication { | ||
|
||
private final MarketDataService mdService; | ||
|
||
@Autowired | ||
public MarketDataServiceApplication(MarketDataService mdService) { | ||
this.mdService = mdService; | ||
} | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(MarketDataServiceApplication.class, args); | ||
} | ||
|
||
public CommandLineRunner startupMDRunner(){ | ||
|
||
return args -> { | ||
List<MarketData> marketDataList = new ArrayList<>(); | ||
// get market data from Exchange 1; | ||
marketDataList.addAll(mdService.getAllMarketDataFromExchange("exchange1")); | ||
// get market data from Exchange 2; | ||
marketDataList.addAll(mdService.getAllMarketDataFromExchange("exchange2")); | ||
|
||
}; | ||
} | ||
|
||
} | ||
package com.joe.trading.marketdataservice; | ||
|
||
import com.joe.trading.marketdataservice.services.MarketDataServiceImpl; | ||
import com.joe.trading.marketdataservice.services.orderbook.OrderBookService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.stereotype.Component; | ||
|
||
@SpringBootApplication(scanBasePackages = "com.joe.trading") | ||
public class MarketDataServiceApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(MarketDataServiceApplication.class, args); | ||
} | ||
|
||
@Component | ||
public static class StartupRunner implements CommandLineRunner { | ||
|
||
private final MarketDataServiceImpl mdService; | ||
private final OrderBookService orderBookService; | ||
|
||
@Autowired | ||
public StartupRunner(MarketDataServiceImpl mdService, OrderBookService orderBookService) { | ||
this.mdService = mdService; | ||
this.orderBookService = orderBookService; | ||
} | ||
|
||
@Override | ||
public void run(String... args) throws Exception { | ||
mdService.buildInitialCacheEntry(); | ||
orderBookService.publishOrderBook(); | ||
} | ||
} | ||
|
||
} |
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
14 changes: 14 additions & 0 deletions
14
...ataService/src/main/java/com/joe/trading/marketdataservice/config/RestTemplateConfig.java
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,14 @@ | ||
package com.joe.trading.marketdataservice.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Configuration | ||
public class RestTemplateConfig { | ||
|
||
@Bean | ||
public RestTemplate restTemplate(){ | ||
return new RestTemplate(); | ||
} | ||
} |
35 changes: 31 additions & 4 deletions
35
.../main/java/com/joe/trading/marketdataservice/controllers/MarketDataWebhookController.java
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
40 changes: 40 additions & 0 deletions
40
MarketDataService/src/main/java/com/joe/trading/marketdataservice/model/Executions.java
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,40 @@ | ||
package com.joe.trading.marketdataservice.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Objects; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Executions { | ||
private Integer quantity; | ||
private String timestamp; | ||
private Double price; | ||
|
||
@Override | ||
public String toString() { | ||
return "Executions{" + | ||
"quantity=" + quantity + | ||
", timestamp=" + timestamp + | ||
", price=" + price + | ||
'}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (this == object) return true; | ||
if (!(object instanceof Executions that)) return false; | ||
return Objects.equals(quantity, that.quantity) && Objects.equals(timestamp, that.timestamp) && Objects.equals(price, that.price); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(quantity, timestamp, price); | ||
} | ||
} |
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
61 changes: 61 additions & 0 deletions
61
MarketDataService/src/main/java/com/joe/trading/marketdataservice/model/OrderBook.java
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,61 @@ | ||
package com.joe.trading.marketdataservice.model; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
public class OrderBook { | ||
private String orderID; | ||
private Double price; | ||
private String product; | ||
private Integer quantity; | ||
private Integer cumulatitiveQuantity; | ||
private Double cumulatitivePrice; | ||
private String side; | ||
private String orderType; | ||
|
||
private List<Executions> executions = new ArrayList(); | ||
|
||
public OrderBook(String product, String id, Integer quantity, String side, String type) { | ||
this.product = product; | ||
this.orderID = id; | ||
this.quantity = quantity; | ||
this.side = side; | ||
this.orderType = type; | ||
this.cumulatitiveQuantity = 0; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
OrderBook orderBook = (OrderBook) o; | ||
return Objects.equals(orderID, orderBook.orderID); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(orderID); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "OrderBook{" + | ||
"orderID=" + orderID + | ||
"price=" + price + | ||
", product='" + product + '\'' + | ||
", quantity=" + quantity + | ||
", cumulatitiveQuantity=" + cumulatitiveQuantity + | ||
", side='" + side + '\'' + | ||
", type='" + orderType + '\'' + | ||
", executions=" + executions + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.