예제 #1
0
        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);
        }
예제 #2
0
        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());
        }
예제 #3
0
        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);
        }
예제 #4
0
 public IReadOnlyList <MarketPrice> Get(AssetPair pair)
 {
     lock (_lock)
         return(_prices.ContainsKey(pair.Id) ? _prices[pair.Id].ToList() : new List <MarketPrice>());
 }
예제 #5
0
 public OrderBook(Network network, AssetPair pair)
 {
     Pair    = pair;
     Network = network;
 }
예제 #6
0
 public AssetPairDiscoveryRequestMessage(AssetPair pair, Network network = null)
 {
     Pair    = pair;
     Network = network;
 }
예제 #7
0
 /// <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));
 }
예제 #8
0
 public PublicVolumeResponse(Network network, AssetPair pair, decimal?vol24Base, decimal?vol24Quote = null) : this(new NetworkPairVolume(network, pair, vol24Base, vol24Quote))
 {
 }
예제 #9
0
        public async Task <IReadOnlyList <Network> > GetNetworksAsync(AssetPair pair, bool onlyDirect = false)
        {
            var r = await GetNetworkPairsAsync().ConfigureAwait(false);

            return(r.Select(x => x.Key).ToUniqueList());
        }
예제 #10
0
 public AggVolumeDataContext(AssetPair pair, ILogger logger = null) : base(logger)
 {
     Pair = pair;
 }
예제 #11
0
 public OrderBookContext(AssetPair assetPair, int?maxRecordsCount = null, ILogger logger = null) : base(logger)
 {
     Pair            = assetPair;
     MaxRecordsCount = maxRecordsCount;
 }
예제 #12
0
 public OrderBookLiveContext(AssetPair assetPair, ILogger logger = null) : base(logger)
 {
     Pair = assetPair;
 }
예제 #13
0
 public AssetPairDataContext(AggregatedAssetPairData data, ILogger logger = null) : base(logger)
 {
     Pair     = data.AssetPair;
     Document = data;
 }
예제 #14
0
 public AssetPairNetworks(AssetPair pair, IReadOnlyList <Network> networks)
 {
     Pair     = pair;
     Networks = networks;
 }
예제 #15
0
        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));
        }
예제 #16
0
 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)
 {
 }
예제 #18
0
 public OhlcContext(AssetPair pair, TimeResolution market, TimeRange range, ILogger logger = null) : base(logger)
 {
     Pair   = pair;
     Market = market;
     Range  = range;
 }
예제 #19
0
 public AssetPairPosition(Network network, AssetPair pair)
 {
     Network = network;
     Pair    = pair;
 }
예제 #20
0
 internal AggregatedAssetPairData(AssetPair pair, INetworkProvider provider)
 {
     ProviderId = provider.Id;
     AssetPair  = pair;
     Id         = GetHash(pair);
 }
예제 #21
0
 public PublicVolumeResponse(Network network, AssetPair pair, decimal volume24) : this(new NetworkPairVolume(network, pair, volume24))
 {
 }
예제 #22
0
 public static ObjectId GetHash(AssetPair pair)
 {
     return(("assetpair:" + pair.Asset1.ShortCode + ":" + pair.Asset2.ShortCode).GetObjectIdHashCode(true, true));
 }
예제 #23
0
 /// <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));
 }
예제 #24
0
 public MinimumTradeVolume(AssetPair market) : this()
 {
     Market = market;
 }
예제 #25
0
        /// <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);
        }
예제 #26
0
 public MinimumTradeVolume(AssetPair market, Money minimumBuy, Money minimumSell) : this(market)
 {
     MinimumBuy  = minimumBuy;
     MinimumSell = minimumSell;
 }
예제 #27
0
 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));
 }
예제 #28
0
 public PairVolumeData(AssetPair pair)
 {
     Pair = pair.Normalised;
     Id   = Pair.Id;
 }
예제 #29
0
 public PrivatePairContext(UserContext userContext, AssetPair pair = null, ILogger logger = null) : base(userContext, logger)
 {
     Pair = pair;
 }
예제 #30
0
 public NetworkPairVolume(Network network, AssetPair pair, decimal volume24) : this(network, pair)
 {
     HasVolume24Base = true;
     Volume24Base    = new Money(volume24, pair.Asset1);
 }