public void ConfigureMap(IMapperConfigurationExpression cfg) { cfg.CreateMap <CandleResponse, CandleDto>() .ForMember(d => d.ExchangeName, o => o.MapFrom(s => ExchangeConfig.ExchangeName)) .ForMember(d => d.Instrument, o => o.MapFrom(s => _exchangeApi.ToInstrumentType(s.Symbol))) .ForMember(d => d.Period, o => o.Ignore()); cfg.CreateMap <TradeResponse, TradeDto>() .ForMember(d => d.ExchangeName, o => o.MapFrom(s => ExchangeConfig.ExchangeName)) .ForMember(d => d.Instrument, o => o.MapFrom(s => _exchangeApi.ToInstrumentType(s.Symbol))) .ForMember(d => d.Side, o => o.MapFrom(s => BitmexUtils.ToTradeType(s.Side))) .ForMember(d => d.Timestamp, o => o.MapFrom(s => BitmexUtils.Now())); cfg.CreateMap <BookResponse, BookDto>() .ForMember(d => d.Instrument, o => o.MapFrom(s => _exchangeApi.ToInstrumentType(s.Symbol))) .ForMember(d => d.Side, o => o.MapFrom(s => BitmexUtils.ToTradeType(s.Side))); cfg.CreateMap <OrderResponse, OrderDto>() .ForMember(d => d.ExchangeName, o => o.MapFrom(s => ExchangeConfig.ExchangeName)) .ForMember(d => d.Instrument, o => o.MapFrom(s => _exchangeApi.ToInstrumentType(s.Symbol))) .ForMember(d => d.Side, o => o.MapFrom(s => BitmexUtils.ToTradeType(s.Side))) .ForMember(d => d.Timestamp, o => o.MapFrom(s => BitmexUtils.Now())); cfg.CreateMap <PositionResponse, PositionDto>() .ForMember(d => d.ExchangeName, o => o.MapFrom(s => ExchangeConfig.ExchangeName)) .ForMember(d => d.Instrument, o => o.MapFrom(s => _exchangeApi.ToInstrumentType(s.Symbol))) .ForMember(d => d.Timestamp, o => o.MapFrom(s => BitmexUtils.Now())); }
private static string CreateSignature(string secret) { var message = $"GET/realtime{BitmexUtils.Expires()}"; var signatureBytes = StorageUtils.EncryptHMACSHA256(Encoding.UTF8.GetBytes(secret), Encoding.UTF8.GetBytes(message)); return(StorageUtils.ByteArrayToHexString(signatureBytes)); }
public static Dictionary <string, string> GetHttpAuthHeaders(string baseUrl, HttpMethod httpMethod, string requestPath, string urlQuery, string key, string secret) { var signatureMessage = $"{httpMethod.ToString()}/api/v1{requestPath}{urlQuery}{BitmexUtils.Expires()}"; var signatureBytes = StorageUtils.EncryptHMACSHA256(Encoding.UTF8.GetBytes(secret), Encoding.UTF8.GetBytes(signatureMessage)); return(new Dictionary <string, string> { { "api-expires", BitmexUtils.Expires().ToString() }, { "api-key", key }, { "api-signature", StorageUtils.ByteArrayToHexString(signatureBytes) } }); }
private async Task <List <T> > GetAllAsync <T, TY, TTy>(string path, TTy request) where T : ExchangeModel where TTy : ICollectionRequest { var stopwatch = new Stopwatch(); var total = 0; var count = 0; var returnModels = new List <T>(); do { using (var client = new ExchangeHttpClient(ExchangeConfig.RestUrl)) { stopwatch.Restart(); total += count; request.StartAt = total; var query = request.AsDictionary().BuildQueryString(); var response = await client.GetAsync <TY>(path, query, BitmexUtils.GetHttpAuthHeaders(ExchangeConfig.RestUrl, HttpMethod.GET, path, query, ExchangeConfig.UserConfig.Key, ExchangeConfig.UserConfig.Secret)); if (response == null) { throw new NullReferenceException(); } var models = response.Select(x => Mapper.Map <T>(x)).ToArray(); returnModels.AddRange(models); count = response.Length; if (count < request.Count) { count = 0; } if (stopwatch.Elapsed < TimeSpan.FromSeconds(1.01)) { await Task.Delay(TimeSpan.FromSeconds(1.5).Subtract(stopwatch.Elapsed)); } } } while (count > 0); return(returnModels); }
private string GetSocketRequest(ExchangeChannel channel) { switch (channel) { case ExchangeChannel.Trade: return(BitmexUtils.GetSocketRequest(ExchangeConfig.SupportedWebsocketChannels[ExchangeChannel.Trade], ToSymbol(Instrument.BTCUSD))); case ExchangeChannel.Book: return(BitmexUtils.GetSocketRequest(ExchangeConfig.SupportedWebsocketChannels[ExchangeChannel.Book], ToSymbol(Instrument.BTCUSD))); case ExchangeChannel.Candle: var paths = ExchangeConfig.SupportedTimePeriods.Values.Select(x => $"{ExchangeConfig.SupportedWebsocketChannels[ExchangeChannel.Candle]}{x}").ToList(); var args = paths.Select(x => new[] { ToSymbol(Instrument.BTCUSD) }).ToList(); return(BitmexUtils.GetSocketRequest(paths, args)); default: throw new ArgumentOutOfRangeException(nameof(channel), channel, null); } }
public static string GetSocketAuthCommand(string key, string secret) { return($@"{{""op"": ""authKeyExpires"", ""args"": [""{key}"", {BitmexUtils.Expires()}, ""{CreateSignature(secret)}""]}}"); }