Skip to content

Commit

Permalink
stream perp/spot markets configs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpe7s committed Oct 12, 2024
1 parent f21e50c commit b2363fb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package software.sava.anchor.programs.drift;

import java.util.Arrays;
import java.util.Collection;
import java.util.EnumMap;
import java.util.stream.Stream;

public interface PerpMarkets {

Expand All @@ -22,4 +24,8 @@ static PerpMarkets createRecord(final PerpMarketConfig[] marketConfigs) {
PerpMarketConfig forProduct(final DriftProduct product);

int numMarkets();

Stream<PerpMarketConfig> streamMarkets();

Collection<PerpMarketConfig> markets();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package software.sava.anchor.programs.drift;

import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.stream.Stream;

public record PerpMarketsRecord(PerpMarketConfig[] marketConfigs,
Map<DriftProduct, PerpMarketConfig> byProduct) implements PerpMarkets {
Expand All @@ -19,4 +22,14 @@ public PerpMarketConfig forProduct(final DriftProduct product) {
public int numMarkets() {
return marketConfigs.length;
}

@Override
public Stream<PerpMarketConfig> streamMarkets() {
return Arrays.stream(marketConfigs);
}

@Override
public Collection<PerpMarketConfig> markets() {
return byProduct.values();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package software.sava.anchor.programs.drift;

import java.util.Arrays;
import java.util.Collection;
import java.util.EnumMap;
import java.util.stream.Stream;

public interface SpotMarkets {

Expand All @@ -16,4 +18,8 @@ static SpotMarkets createRecord(final SpotMarketConfig[] marketConfigs) {
SpotMarketConfig forAsset(final DriftAsset asset);

int numMarkets();

Stream<SpotMarketConfig> streamMarkets();

Collection<SpotMarketConfig> markets();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package software.sava.anchor.programs.drift;

import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.stream.Stream;

record SpotMarketsRecord(SpotMarketConfig[] marketConfigs,
Map<DriftAsset, SpotMarketConfig> byAsset) implements SpotMarkets {
Expand All @@ -19,4 +22,14 @@ public SpotMarketConfig forAsset(final DriftAsset asset) {
public int numMarkets() {
return marketConfigs.length;
}

@Override
public Stream<SpotMarketConfig> streamMarkets() {
return Arrays.stream(marketConfigs);
}

@Override
public Collection<SpotMarketConfig> markets() {
return byAsset.values();
}
}

0 comments on commit b2363fb

Please sign in to comment.