Skip to content

Commit

Permalink
Bugfix/etd 1401 connectors coinmate.api dont co (#470)
Browse files Browse the repository at this point in the history
* feature/ETD-1340-container-update-simplecoin-csv

* bugfix/ETD-1401-connectors-coinmate.api-dont-co-

* new version

* Feature/etd 1418 rates add exchange rate for spe (#454)

* new version

* bugfix/ETD-1401-connectors-coinmate.api-dont-co-

---------

Co-authored-by: martinkyov <[email protected]>
Co-authored-by: Martin <[email protected]>
  • Loading branch information
3 people authored Dec 4, 2024
1 parent 457fea6 commit cf11438
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class CoinmateConnector implements IConnector {
private static final long DELAY = 24 * 60 * 60 * 1000L;
// MAX 100 request per minute per user, https://coinmate.docs.apiary.io/#reference/request-limits
// https://coinmate.docs.apiary.io/#reference/transaction-history/get-transaction-history
private static final int TX_PER_REQUEST = 799;
private static final int TX_PER_REQUEST = 1000;
private static final Logger LOG = LoggerFactory.getLogger(CoinmateConnector.class);
private static final int MAX_ITERATIONS = 80;

Expand Down Expand Up @@ -118,42 +118,46 @@ private List<CoinmateTransactionHistoryEntry> downloadTransactions(DownloadState
setTxFromTimestamp(state);
List<CoinmateTransactionHistoryEntry> allData = new ArrayList<>();

long now = Instant.now().toEpochMilli();
long txFrom = state.getTxFrom();
long txTo = state.getTxTo() == 0L ? now : state.getTxTo();
int offset = state.getOffset();
long txTo = state.getTxTo() == 0L ? Instant.now().toEpochMilli() : state.getTxTo();

int iterationCount = 0;

while (true) {
if (iterationCount++ >= MAX_ITERATIONS) {
throw new IllegalStateException("Maximum iterations reached. Possible infinite loop detected.");
}
final List<CoinmateTransactionHistoryEntry> userTransactionBlock;

List<CoinmateTransactionHistoryEntry> userTransactionBlock;
try {
userTransactionBlock = rawServices.getCoinmateTransactionHistory(
offset, TX_PER_REQUEST, SORT_DESC, txFrom, txTo, null).getData();
0, TX_PER_REQUEST, SORT_DESC, txFrom, txTo, null).getData();
} catch (IOException e) {
throw new IllegalStateException("Download user trade history failed.", e);
}

if (userTransactionBlock.isEmpty()) {
state.offset = 0;
state.txFrom = txTo;
state.txTo = 0L;
break;
}
if(userTransactionBlock.size() < TX_PER_REQUEST) {
state.offset = 0;

allData.addAll(userTransactionBlock);

if (userTransactionBlock.size() < TX_PER_REQUEST) {
state.txFrom = txTo;
state.txTo = 0L;
allData.addAll(userTransactionBlock);
break;
} else {
txTo = now;
offset += TX_PER_REQUEST;
state.txTo = now;
state.offset = offset;
allData.addAll(userTransactionBlock);
}

txTo = userTransactionBlock.get(userTransactionBlock.size() - 1).getTimestamp() - 1;
state.txTo = txTo;

try {
Thread.sleep(600);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException("Thread was interrupted during sleep.", e);
}
}
return allData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ public Map<?, List<KrakenBeanV2>> removeGroupsWithUnsupportedRows(Map<?, List<Kr
Map<Object, List<KrakenBeanV2>> result = new HashMap<>();
for (Map.Entry<?, List<KrakenBeanV2>> entry : rowGroups.entrySet()) {
var rowsInGroup = entry.getValue();
var isOneOrMoreUnsupportedRows =
!rowsInGroup.stream().filter(r -> r.isUnsupportedRow() == true).collect(Collectors.toList()).isEmpty();
var isOneOrMoreUnsupportedRows = rowsInGroup.stream().anyMatch(KrakenBeanV2::isUnsupportedRow);
if (!isOneOrMoreUnsupportedRows) {
result.put(entry.getKey(), entry.getValue());
} else {
var ids = rowsInGroup.stream().map(r -> r.getRowId()).collect(Collectors.toList());
var ids = rowsInGroup.stream().map(KrakenBeanV2::getRowId).toList();
var s = BinanceSortedGroupV4.parseIds(ids);
setRowsAsUnsupported(rowsInGroup, "One or more rows in group " + "( rows: " + s + ") is unsupported");
}
Expand Down

0 comments on commit cf11438

Please sign in to comment.