Added some functions related to AssetPair creation etc.

This commit is contained in:
7u83 2018-12-23 11:29:12 +01:00
parent c56ed5abcd
commit 0c5e75a7a1
3 changed files with 26 additions and 11 deletions

View File

@ -75,9 +75,6 @@ public class GodWorld implements GetJson, World {
/* HashSet<AbstractAsset> assetsById = new HashSet<>(); /* HashSet<AbstractAsset> assetsById = new HashSet<>();
HashMap<String, AbstractAsset> assetsBySymbol = new HashMap<>(); HashMap<String, AbstractAsset> assetsBySymbol = new HashMap<>();
*/ */
IDGenerator orderIdGenerator = new IDGenerator(); IDGenerator orderIdGenerator = new IDGenerator();
private Scheduler scheduler = new Scheduler(); private Scheduler scheduler = new Scheduler();
@ -231,12 +228,12 @@ public class GodWorld implements GetJson, World {
// return ex; // return ex;
return null; return null;
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Assets // Assets
// -------------------------------------------------------------------- // --------------------------------------------------------------------
private final HashMap<String, AbstractAsset> assets = new HashMap<>(); private final HashMap<String, AbstractAsset> assets = new HashMap<>();
@Override @Override
public Collection<AbstractAsset> getAssetCollection() { public Collection<AbstractAsset> getAssetCollection() {
return Collections.unmodifiableCollection(assets.values()); return Collections.unmodifiableCollection(assets.values());
@ -250,14 +247,29 @@ public class GodWorld implements GetJson, World {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// AssetsPairs // AssetsPairs
// -------------------------------------------------------------------- // --------------------------------------------------------------------
private final HashSet<AssetPair> asset_pairs = new HashSet<>(); private final HashMap<String, AssetPair> asset_pairs = new HashMap<>();
private AssetPair default_asset_pair = null;
public Collection<AssetPair> getAssetPairsCollection() { public Collection<AssetPair> getAssetPairsCollection() {
return Collections.unmodifiableCollection(asset_pairs); return Collections.unmodifiableCollection(asset_pairs.values());
} }
public void add(AssetPair pair) { public void add(AssetPair pair) {
asset_pairs.add(pair); asset_pairs.put(pair.getSymbol(), pair);
if (default_asset_pair == null) {
default_asset_pair = pair;
}
}
public AssetPair addAssetPair(String currency, String asset) {
AssetPair pair = new AssetPair(assets.get(currency), assets.get(asset));
add(pair);
return pair;
}
public AssetPair getDefaultAssetPair() {
return default_asset_pair;
} }
@ -375,9 +387,6 @@ public class GodWorld implements GetJson, World {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Stuff belonging to accounts // Stuff belonging to accounts
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Pseudo random generator stuff // Pseudo random generator stuff
// -------------------------------------------------------------------- // --------------------------------------------------------------------

View File

@ -80,4 +80,9 @@ public class RealWorld implements World {
return godworld.getDefaultExchange(); return godworld.getDefaultExchange();
} }
@Override
public AssetPair getDefaultAssetPair() {
return godworld.getDefaultAssetPair();
}
} }

View File

@ -42,6 +42,7 @@ public interface World {
Collection<Exchange> getExchangeCollection(); Collection<Exchange> getExchangeCollection();
public Exchange getDefaultExchange(); public Exchange getDefaultExchange();
public AssetPair getDefaultAssetPair();
Collection<Trader> getTradersCollection(); Collection<Trader> getTradersCollection();