Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed PerMarket public keys #81

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion SharedBuildProperties.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Product>Solnet.Mango</Product>
<Version>6.0.3.3</Version>
<Version>6.0.3.4</Version>
<Copyright>Copyright 2021 &#169; blockmountain</Copyright>
<Authors>blockmountain</Authors>
<PublisherName>blockmountain</PublisherName>
Expand Down
6 changes: 3 additions & 3 deletions Solnet.Mango.Examples/SubscribeOrderBook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class SubscribeOrderBook : IRunnableExample
private readonly IMangoClient _mangoClient;
private static Dictionary<string, string> Markets = new Dictionary<string, string>()
{
{ "SOL-PERP", "CqxX2QupYiYafBSbA519j4vRVxxecidbh2zwX66Lmqem" },
{ "BTC-PERP", "4nfmQP3KmUqEJ6qJLsS3offKgE96YUB4Rp7UQvm2Fbi9" },
{ "MNGO-PERP", "2TgaaVoHgnSeEtXvWTx13zQeTf4hYWAMEiMQdcG6EwHi" }
{ "SOL-PERP", "2TgaaVoHgnSeEtXvWTx13zQeTf4hYWAMEiMQdcG6EwHi" },
{ "BTC-PERP", "DtEcjPLyD4YtTBB4q8xwFZ9q49W89xZCZtJyrGebi5t8" },
{ "MNGO-PERP", "4nfmQP3KmUqEJ6qJLsS3offKgE96YUB4Rp7UQvm2Fbi9" }
};

private Dictionary<string, List<OpenOrder>> allAskOrders;
Expand Down
2 changes: 1 addition & 1 deletion Solnet.Mango.Test/MangoClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ public void GetOrderBookSideWithExpired()
Assert.IsTrue(obs.ParsedResult.Metadata.IsInitialized);
Assert.AreEqual(DataType.Bids, obs.ParsedResult.Metadata.DataType);
var bids = obs.ParsedResult.GetOrders();
Assert.AreEqual(11, bids.Count); // there's 11 orders without expiry
Assert.AreEqual(14, bids.Count); // there's 14 orders without expiry
var bidsWithExpired = obs.ParsedResult.GetOrders(true);
Assert.AreEqual(16, bidsWithExpired.Count); // there's 16 orders total including expired
}
Expand Down
7 changes: 3 additions & 4 deletions Solnet.Mango/Models/Matching/LeafNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,13 @@ internal static class ExtraLayout
/// <remarks>
/// This is checked by the order's <see cref="TimeInForce"/> value.
/// If it is equal to<see cref="byte.MinValue"/> the order never expires,
/// otherwise the order expires after <see cref="Timestamp"/> plus <see cref="byte.MaxValue"/> seconds.</remarks>
/// otherwise the order expires at <see cref="Timestamp"/> plus <see cref="byte.MaxValue"/> seconds.</remarks>
/// </summary>
/// <returns>true if it is valid, otherwise false.</returns>
public bool IsValid()
public bool IsValid(ulong timestamp)
{
var expiry = Timestamp + TimeInForce;
var now = (ulong) DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
return TimeInForce == 0 || now <= expiry;
return TimeInForce == 0 || timestamp < expiry;
}

/// <summary>
Expand Down
40 changes: 19 additions & 21 deletions Solnet.Mango/Models/Matching/OrderBookSide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,35 +106,33 @@ internal static class Layout
/// <returns>A list of open orders on the book side.</returns>
public List<OpenOrder> GetOrders(bool includeExpired = false)
{
bool isBids = Metadata.DataType == DataType.Bids;

_orders = new List<OpenOrder>();

foreach (var node in Nodes)
var leafNodes = Nodes.Where(n => n is LeafNode).Cast<LeafNode>().ToList();
ulong timestamp = leafNodes.Select(n => n.Timestamp).Max();

foreach (LeafNode leafNode in leafNodes)
{
if (node is LeafNode leafNode)
var valid = leafNode.IsValid(timestamp);
if (valid || includeExpired)
{
var valid = leafNode.IsValid();
if (valid || includeExpired)
_orders.Add(new OpenOrder
{
_orders.Add(new OpenOrder
{
RawPrice = leafNode.Price,
RawQuantity = leafNode.Quantity,
ClientOrderId = leafNode.ClientOrderId,
Owner = leafNode.Owner,
OrderIndex = leafNode.OwnerSlot,
OrderId = new BigInteger(leafNode.Key),
Timestamp = leafNode.Timestamp,
ExpiryTimestamp = leafNode.TimeInForce != 0 ? leafNode.Timestamp + leafNode.TimeInForce : ulong.MaxValue,
TimeInForce = leafNode.TimeInForce,
OrderType = leafNode.OrderType,
});
}
RawPrice = leafNode.Price,
RawQuantity = leafNode.Quantity,
ClientOrderId = leafNode.ClientOrderId,
Owner = leafNode.Owner,
OrderIndex = leafNode.OwnerSlot,
OrderId = new BigInteger(leafNode.Key),
Timestamp = leafNode.Timestamp,
ExpiryTimestamp = leafNode.TimeInForce != 0 ? leafNode.Timestamp + leafNode.TimeInForce : ulong.MaxValue,
TimeInForce = leafNode.TimeInForce,
OrderType = leafNode.OrderType,
});
}
}

if (!isBids)
if (Metadata.DataType != DataType.Bids)
{
_orders.Sort(Comparer<OpenOrder>.Create((order, order1) => order.RawPrice.CompareTo(order1.RawPrice)));
}
Expand Down