Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions src/ExchangeSharp/API/Exchanges/BinanceGroup/BinanceGroupCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,20 +438,24 @@ params string[] marketSymbols
name.Substring(0, name.IndexOf('@'))
);

// buy=0 -> m = true (The buyer is maker, while the seller is taker).
// buy=1 -> m = false(The seller is maker, while the buyer is taker).
await callback(
ExchangeTrade trade =
token.ParseTradeBinance(
amountKey: "q",
priceKey: "p",
typeKey: "m",
timestampKey: "T", // use trade time (T) instead of event time (E)
timestampType: TimestampType.UnixMilliseconds,
idKey: "a",
typeKeyIsBuyValue: "false");
trade.Exchange = Name;
trade.Symbol = marketSymbol;

// buy=0 -> m = true (The buyer is maker, while the seller is taker).
// buy=1 -> m = false(The seller is maker, while the buyer is taker).
await callback(
new KeyValuePair<string, ExchangeTrade>(
marketSymbol,
token.ParseTradeBinance(
amountKey: "q",
priceKey: "p",
typeKey: "m",
timestampKey: "T", // use trade time (T) instead of event time (E)
timestampType: TimestampType.UnixMilliseconds,
idKey: "a",
typeKeyIsBuyValue: "false"
)
trade
)
);
}
Expand Down Expand Up @@ -525,7 +529,7 @@ protected override async Task<ExchangeOrderBook> OnGetOrderBookAsync(
$"/depth?symbol={marketSymbol}&limit={maxCount}",
BaseUrlApi
);
return obj.ParseOrderBookFromJTokenArrays(sequence: "lastUpdateId");
return obj.ParseOrderBookFromJTokenArrays(exchange: Name, sequence: "lastUpdateId");
}

protected override async Task OnGetHistoricalTradesAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ protected override async Task<ExchangeOrderBook> OnGetOrderBookAsync(
}
result.MarketSymbol = NormalizeMarketSymbol(marketSymbol);
}
result.ExchangeName = Name;
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ protected override async Task<ExchangeOrderBook> OnGetOrderBookAsync(
};
}
}
orders.ExchangeName = Name;
return orders;
}

Expand Down
15 changes: 8 additions & 7 deletions src/ExchangeSharp/API/Exchanges/Gemini/ExchangeGeminiAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Xml;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ExchangeSharp
{
Expand All @@ -35,7 +33,7 @@ private ExchangeGeminiAPI()
MarketSymbolIsUppercase = false;
MarketSymbolSeparator = string.Empty;
WebSocketOrderBookType = WebSocketOrderBookType.FullBookFirstThenDeltas;
RateLimit = new RateGate(1, TimeSpan.FromSeconds(0.5));
RateLimit = new RateGate(600, TimeSpan.FromSeconds(60));
}

private async Task<ExchangeVolume> ParseVolumeAsync(JToken token, string symbol)
Expand Down Expand Up @@ -323,7 +321,7 @@ protected override async Task<ExchangeOrderBook> OnGetOrderBookAsync(
JToken obj = await MakeJsonRequestAsync<JToken>(
"/book/" + marketSymbol + "?limit_bids=" + maxCount + "&limit_asks=" + maxCount
);
return obj.ParseOrderBookFromJTokenDictionaries();
return obj.ParseOrderBookFromJTokenDictionaries(exchange: Name);
}

protected override async Task OnGetHistoricalTradesAsync(
Expand Down Expand Up @@ -489,7 +487,7 @@ protected override async Task<IEnumerable<ExchangeOrderResult>> OnGetOpenOrderDe
{
foreach (JToken token in array)
{
if (marketSymbol == null || token["symbol"].ToStringInvariant() == marketSymbol)
if (string.IsNullOrEmpty(marketSymbol) || token["symbol"].ToStringInvariant() == marketSymbol)
{
orders.Add(ParseOrder(token));
}
Expand Down Expand Up @@ -802,6 +800,8 @@ params string[] marketSymbols
foreach (var tradeToken in tradesToken)
{
var trade = ParseWebSocketTrade(tradeToken);
trade.Exchange = Name;
trade.Symbol = marketSymbol;
trade.Flags |= ExchangeTradeFlags.IsFromSnapshot;
await callback(
new KeyValuePair<string, ExchangeTrade>(marketSymbol, trade)
Expand All @@ -812,6 +812,7 @@ await callback(
{
string marketSymbol = token["symbol"].ToStringInvariant();
var trade = ParseWebSocketTrade(token);
trade.Exchange = Name;
await callback(
new KeyValuePair<string, ExchangeTrade>(marketSymbol, trade)
);
Expand Down
6 changes: 5 additions & 1 deletion src/ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ protected override async Task<ExchangeOrderBook> OnGetOrderBookAsync(
JToken obj = await MakeJsonRequestAsync<JToken>(
"/0/public/Depth?pair=" + marketSymbol + "&count=" + maxCount
);
return obj[marketSymbol].ParseOrderBookFromJTokenArrays();
return obj[marketSymbol].ParseOrderBookFromJTokenArrays(exchange: Name);
}

protected override async Task<IEnumerable<ExchangeTrade>> OnGetRecentTradesAsync(
Expand Down Expand Up @@ -1154,6 +1154,8 @@ private ExchangePosition ParsePosition(JToken token)
{
if (kvp.Value["descr"] is JObject descr)
{
result.ClientOrderId = kvp.Value["cl_ord_id"].ToObject<string>();
result.Status = kvp.Value["status"].ToObject<string>();
decimal epochMilliseconds = kvp.Value["opentm"].ToObject<decimal>();
// Preserve Kraken timestamp decimal precision by converting seconds to milliseconds.
epochMilliseconds = epochMilliseconds * 1000;
Expand Down Expand Up @@ -1399,6 +1401,8 @@ params string[] marketSymbols
idKey: null,
typeKeyIsBuyValue: "b"
);
trade.Exchange = Name;
trade.Symbol = marketSymbol;
await callback(
new KeyValuePair<string, ExchangeTrade>(marketSymbol, trade)
);
Expand Down
2 changes: 1 addition & 1 deletion src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ string marketSymbol
// not sure if this is needed, but adding it just in case
await new SynchronizationContextRemover();
var lookup = await this.GetExchangeMarketDictionaryFromCacheAsync();

if (lookup == null) return null;
foreach (var kvp in lookup)
{
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static class ExchangeAPIExtensions
/// <returns>Web socket, call Dispose to close</returns>
public static async Task<IWebSocket> GetFullOrderBookWebSocketAsync(
this IOrderBookProvider api,
string exchange,
Action<ExchangeOrderBook> callback,
int maxCount = 100,
params string[] symbols
Expand Down Expand Up @@ -192,6 +193,7 @@ out partialOrderBookQueue

fullOrderBook.LastUpdatedUtc = CryptoUtility.UtcNow;
trimFullOrderBook(fullOrderBook);
fullOrderBook.ExchangeName = exchange;
callback(fullOrderBook);
}

Expand Down Expand Up @@ -469,6 +471,7 @@ internal static ExchangeOrderBook ParseOrderBookFromJTokenArray(
/// <returns>Order book</returns>
internal static ExchangeOrderBook ParseOrderBookFromJTokenArrays(
this JToken token,
string exchange = "unknown",
string asks = "asks",
string bids = "bids",
string sequence = "ts"
Expand Down Expand Up @@ -518,6 +521,8 @@ internal static ExchangeOrderBook ParseOrderBookFromJTokenArrays(
Logger.Error($"No bids in {nameof(ParseOrderBookFromJTokenArrays)}");
}

book.ExchangeName = exchange;

return book;
}

Expand All @@ -532,6 +537,7 @@ internal static ExchangeOrderBook ParseOrderBookFromJTokenArrays(
/// <returns>Order book</returns>
internal static ExchangeOrderBook ParseOrderBookFromJTokenDictionaries(
this JToken token,
string exchange = "unknown",
string asks = "asks",
string bids = "bids",
string price = "price",
Expand Down Expand Up @@ -563,6 +569,8 @@ internal static ExchangeOrderBook ParseOrderBookFromJTokenDictionaries(
book.Bids[depth.Price] = depth;
}

book.ExchangeName = exchange;

return book;
}

Expand Down
10 changes: 10 additions & 0 deletions src/ExchangeSharp/Model/ExchangePosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ namespace ExchangeSharp
/// </summary>
public class ExchangePosition
{
/// <summary>
/// Client Order ID
/// </summary>
public string ClientOrderId { get; set; }

/// <summary>
/// Order Status
/// </summary>
public string Status { get; set; }

/// <summary>
/// Market Symbol
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions src/ExchangeSharp/Model/ExchangeTrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ namespace ExchangeSharp
/// </summary>
public class ExchangeTrade
{
/// <summary>
/// Exchange
/// </summary>
public string Exchange { get; set; }

/// <summary>
/// Symbol
/// </summary>
public string Symbol { get; set; }

/// <summary>
/// Timestamp
/// </summary>
Expand Down
Loading