-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4 change endpoint to support multiple coins (#5)
* Fix #2 (#3) Transactions can be written to json again. * Refactorings Move iterating over transactions into service. * Fix #4
- Loading branch information
1 parent
b358482
commit 3afe55e
Showing
9 changed files
with
115 additions
and
81 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
...-service/src/main/java/com/github/kerner1000/terra/LunaWeightedMeanCalculatorService.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,17 @@ | ||
package com.github.kerner1000.terra; | ||
|
||
import com.github.kerner1000.terra.commons.Coin; | ||
import com.github.kerner1000.terra.transactions.*; | ||
|
||
import java.util.Arrays; | ||
|
||
public class LunaWeightedMeanCalculatorService extends WeightedMeanCalculatorService { | ||
|
||
public LunaWeightedMeanCalculatorService() { | ||
super(Coin.LUNA); | ||
} | ||
|
||
protected Iterable<? extends AbstractTransactionVisitor> getVisitors() { | ||
return Arrays.asList(new TerraswapTransactionVisitor(), new AstroportTransactionVisitor(), new MarketTransactionVisitor(), new LoopSwapTransactionVisitor()); | ||
} | ||
} |
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
41 changes: 26 additions & 15 deletions
41
...-api-service/src/main/java/com/github/kerner1000/terra/WeightedMeanCalculatorService.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,24 +1,35 @@ | ||
package com.github.kerner1000.terra; | ||
|
||
import com.github.kerner1000.terra.commons.BuySellMaps; | ||
import com.github.kerner1000.terra.commons.BuySellMapsForCoin; | ||
import com.github.kerner1000.terra.commons.Coin; | ||
import com.github.kerner1000.terra.json.data.Transaction; | ||
import com.github.kerner1000.terra.transactions.Transactions; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.context.annotation.RequestScope; | ||
import com.github.kerner1000.terra.transactions.AbstractTransactionVisitor; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
@RequestScope | ||
@Service | ||
public class WeightedMeanCalculatorService { | ||
|
||
public BuySellMaps visit(List<Transaction> transactions) throws InterruptedException { | ||
BuySellMaps wm = new Transactions().getWeightedMeanSwapMaps(transactions); | ||
// if(log.isDebugEnabled() && wm.getBuyMap().getMap().size() > 1 || wm.getSellMap().getMap().size() > 1) { | ||
// log.debug("swap map:\n{}\n======\nweighted mean: {}", result, new Transactions().getWeightedMean(result)); | ||
// } | ||
return wm; | ||
public abstract class WeightedMeanCalculatorService { | ||
|
||
private final Coin coin; | ||
|
||
protected WeightedMeanCalculatorService(Coin coin) { | ||
this.coin = coin; | ||
} | ||
|
||
public BuySellMapsForCoin visit(List<Transaction> transactions) throws InterruptedException { | ||
|
||
BuySellMaps result = new BuySellMaps(); | ||
|
||
for (Transaction transaction : transactions) { | ||
if(Thread.currentThread().isInterrupted()){ | ||
break; | ||
} | ||
for (AbstractTransactionVisitor visitor : getVisitors()) { | ||
result.add(visitor.visit(transaction)); | ||
} | ||
} | ||
return new BuySellMapsForCoin(coin, result); | ||
} | ||
|
||
protected abstract Iterable<? extends AbstractTransactionVisitor> getVisitors(); | ||
} |
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
1 change: 0 additions & 1 deletion
1
terra-stats-commons/src/main/java/com/github/kerner1000/terra/commons/BuySellMap.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
5 changes: 5 additions & 0 deletions
5
...a-stats-commons/src/main/java/com/github/kerner1000/terra/commons/BuySellMapsForCoin.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,5 @@ | ||
package com.github.kerner1000.terra.commons; | ||
|
||
public record BuySellMapsForCoin(Coin coin, BuySellMaps buySellMaps) { | ||
|
||
} |
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