-
-
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 * Fix #1 (#6) * Fix NPE when swap map is empty * Fix Mars transactions * Update gitignore * Longer sleep between API calls * Fix #7 (#8)
- Loading branch information
1 parent
a3b481b
commit ec4a8a9
Showing
26 changed files
with
2,654 additions
and
88 deletions.
There are no files selected for viewing
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
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()); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...-service/src/main/java/com/github/kerner1000/terra/MarsWeightedMeanCalculatorService.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 MarsWeightedMeanCalculatorService extends WeightedMeanCalculatorService { | ||
|
||
public MarsWeightedMeanCalculatorService() { | ||
super(Coin.MARS); | ||
} | ||
|
||
protected Iterable<? extends AbstractTransactionVisitor> getVisitors() { | ||
return Arrays.asList(new AstroportTransactionVisitorMars(), new TerraswapTransactionVisitorMars()); | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
terra-stats-api-service/src/main/java/com/github/kerner1000/terra/json/data/Send.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,35 @@ | ||
package com.github.kerner1000.terra.json.data; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.Data; | ||
|
||
import java.util.Base64; | ||
|
||
@Data | ||
public class Send { | ||
|
||
static ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
static { | ||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
} | ||
|
||
Number amount; | ||
|
||
String contract; | ||
|
||
Swap msg; | ||
|
||
@JsonProperty("msg") | ||
public void setMsg(JsonNode msg) throws JsonProcessingException { | ||
byte[] decodedBytes = Base64.getDecoder().decode(msg.textValue()); | ||
String decodedString = new String(decodedBytes); | ||
ExecuteMessage swap = objectMapper.readValue(decodedString, ExecuteMessage.class); | ||
this.msg = swap.getSwap(); | ||
} | ||
} |
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
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
29 changes: 29 additions & 0 deletions
29
terra-stats-api-service/src/test/java/com/github/kerner1000/terra/json/data/SwapTest.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,29 @@ | ||
package com.github.kerner1000.terra.json.data; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class SwapTest { | ||
|
||
@BeforeEach | ||
void setUp() { | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
} | ||
|
||
@Test | ||
void simpleTest() throws JsonProcessingException { | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
ExecuteMessage hans = objectMapper.readValue("{\"swap\":{\"max_spread\":\"0.005\",\"belief_price\":\"1.177687347092019071\"}}", ExecuteMessage.class); | ||
assertNotNull(hans); | ||
} | ||
} |
Oops, something went wrong.