private async Task <OrderBook> GetOrderBookLocalAsync(IKrakenApi api, AssetPair assetPair, int?maxCount) { var pair = assetPair; var remotePair = new AssetPair(pair.Asset1.ToRemoteCode(this), pair.Asset2.ToRemoteCode(this)); var r = await api.GetOrderBookAsync(remotePair.ToTicker(this), maxCount ?? 0).ConfigureAwait(false); CheckResponseErrors(r); var data = r.result.FirstOrDefault(); var orderBook = new OrderBook(Network, assetPair); var asks = maxCount.HasValue ? data.Value.asks.Take(maxCount.Value / 2).ToArray() : data.Value.asks; var bids = maxCount.HasValue ? data.Value.bids.Take(maxCount.Value / 2).ToArray() : data.Value.bids; foreach (var i in bids.Select(GetBidAskData)) { orderBook.Add(OrderType.Bid, i.Price, i.Volume); } foreach (var i in asks.Select(GetBidAskData)) { orderBook.Add(OrderType.Ask, i.Price, i.Volume); } return(orderBook); }
private static void DataTest() { var a1 = "BTC".ToAssetRaw(); var a2 = "USD".ToAssetRaw(); var pair = new AssetPair(a1, a2); var ohcl = new OhlcDataAdapter(new OhlcResolutionContext() { Pair = pair }); ohcl.Init(); Console.WriteLine(ohcl.UtcDataStart.ToLongDateString()); }
private bool ComparePairs(AssetPair pair, string krakenPairCode) { var result = false; if (krakenPairCode.Length == 6) { result = pair.Equals(krakenPairCode.ToAssetPair(this, 3)); } else if (krakenPairCode.Length == 7) { result = pair.Equals(krakenPairCode.ToAssetPair(this, 3)) || pair.Equals(krakenPairCode.ToAssetPair(this, 4)); } else { var pattern = @"^(([X](?<asset10>\w{3}))|((?<asset11>.\w{3})))[XZ](?<asset20>\w{3})$"; var matches = Regex.Match(krakenPairCode, pattern); if (!matches.Success || !matches.Groups["asset20"].Success || (!matches.Groups["asset10"].Success && !matches.Groups["asset11"].Success)) { return(false); } var krakenPair = new AssetPair( matches.Groups["asset10"].Success ? matches.Groups["asset10"].Value : matches.Groups["asset11"].Value, matches.Groups["asset20"].Value, this ); result = pair.Equals(krakenPair); } return(result); }
public IReadOnlyList <MarketPrice> Get(AssetPair pair) { lock (_lock) return(_prices.ContainsKey(pair.Id) ? _prices[pair.Id].ToList() : new List <MarketPrice>()); }
public OrderBook(Network network, AssetPair pair) { Pair = pair; Network = network; }
public AssetPairDiscoveryRequestMessage(AssetPair pair, Network network = null) { Pair = pair; Network = network; }
/// <summary> /// Will search for the price in both directions (normal / reversed). /// </summary> public static MarketPrice GetPrice(this PriceGraph graph, Network network, AssetPair pair) { return(graph?.PricesByNetwork?.Get(network)?.GetPrice(pair)); }
public PublicVolumeResponse(Network network, AssetPair pair, decimal?vol24Base, decimal?vol24Quote = null) : this(new NetworkPairVolume(network, pair, vol24Base, vol24Quote)) { }
public async Task <IReadOnlyList <Network> > GetNetworksAsync(AssetPair pair, bool onlyDirect = false) { var r = await GetNetworkPairsAsync().ConfigureAwait(false); return(r.Select(x => x.Key).ToUniqueList()); }
public AggVolumeDataContext(AssetPair pair, ILogger logger = null) : base(logger) { Pair = pair; }
public OrderBookContext(AssetPair assetPair, int?maxRecordsCount = null, ILogger logger = null) : base(logger) { Pair = assetPair; MaxRecordsCount = maxRecordsCount; }
public OrderBookLiveContext(AssetPair assetPair, ILogger logger = null) : base(logger) { Pair = assetPair; }
public AssetPairDataContext(AggregatedAssetPairData data, ILogger logger = null) : base(logger) { Pair = data.AssetPair; Document = data; }
public AssetPairNetworks(AssetPair pair, IReadOnlyList <Network> networks) { Pair = pair; Networks = networks; }
public (TimeSpan duration, decimal percentage) PercentageDirection(Network network, AssetPair pair, TimeSpan span) { var prices = Get(pair).Where(x => x.Network.Id == network.Id).ToList(); if (prices.Count < 2) { return(TimeSpan.Zero, 0); } var ordered = prices.Where(x => x.UtcCreated.IsWithinTheLast(span)).OrderBy(x => x.UtcCreated).ToList(); if (ordered.Count < 2) { return(TimeSpan.Zero, 0); } var earliest = ordered.First(); var latest = ordered.Last(); var duration = latest.UtcCreated - earliest.UtcCreated; return(duration, earliest.PercentageDifference(latest)); }
public NetworksForPair(IEnumerable <Network> networks, AssetPair pair) { Pair = pair; Networks = networks.AsReadOnlyList(); }
public AssetPairNotSupportedException(AssetPair pair, INetworkProvider provider, [CallerMemberName] string method = "Unknown") : base($"Specified currency pair {pair} is not supported by provider", provider, method) { }
public OhlcContext(AssetPair pair, TimeResolution market, TimeRange range, ILogger logger = null) : base(logger) { Pair = pair; Market = market; Range = range; }
public AssetPairPosition(Network network, AssetPair pair) { Network = network; Pair = pair; }
internal AggregatedAssetPairData(AssetPair pair, INetworkProvider provider) { ProviderId = provider.Id; AssetPair = pair; Id = GetHash(pair); }
public PublicVolumeResponse(Network network, AssetPair pair, decimal volume24) : this(new NetworkPairVolume(network, pair, volume24)) { }
public static ObjectId GetHash(AssetPair pair) { return(("assetpair:" + pair.Asset1.ShortCode + ":" + pair.Asset2.ShortCode).GetObjectIdHashCode(true, true)); }
/// <summary> /// Will search for the price in both directions (normal / reversed). /// </summary> public static MarketPrice GetPrice(this PriceGraph graph, AssetPair pair) { return(graph?.Prices?.GetPrice(pair)); }
public MinimumTradeVolume(AssetPair market) : this() { Market = market; }
/// <summary> /// Will search for the price in both directions (normal / reversed). /// </summary> public static MarketPrice GetPrice(this IEnumerable <MarketPrice> prices, Network network, AssetPair pair) { var m = prices.FirstOrDefault(x => x.Pair.Id == pair.Id && x.Network.Id == network.Id); if (m != null) { return(m); } m = prices.FirstOrDefault(x => x.Pair.Id == pair.Reversed.Id && x.Network.Id == network.Id); return(m?.Reversed); }
public MinimumTradeVolume(AssetPair market, Money minimumBuy, Money minimumSell) : this(market) { MinimumBuy = minimumBuy; MinimumSell = minimumSell; }
public static ObjectId GetHash(AssetPair pair, TimeResolution market, Network network) { return($"prime:{pair.Asset1.ShortCode}:{pair.Asset2.ShortCode}:{(int)market}:{network.Id}".GetObjectIdHashCode(true, true)); }
public PairVolumeData(AssetPair pair) { Pair = pair.Normalised; Id = Pair.Id; }
public PrivatePairContext(UserContext userContext, AssetPair pair = null, ILogger logger = null) : base(userContext, logger) { Pair = pair; }
public NetworkPairVolume(Network network, AssetPair pair, decimal volume24) : this(network, pair) { HasVolume24Base = true; Volume24Base = new Money(volume24, pair.Asset1); }