Last active
October 22, 2019 07:48
-
-
Save imvision/c5a6f0f89f70e8ef14231306dcf5460e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MarketAllowed | |
{ | |
public string id { get; set; } | |
public string name { get; set; } | |
public int type { get; set; } | |
public string startTime { get; set; } | |
public string marketType { get; set; } | |
public string parent { get; set; } | |
public double totalMatched { get; set; } | |
public string eventId { get; set; } | |
public string eventName { get; set; } | |
public bool IsAllowed { get; set; } | |
public int eventTypeId { get; set; } | |
public string eventType { get; set; } | |
public bool InPlay { get; set; } | |
public bool IsVisible { get; set; } | |
public bool IsBetAllowed { get; set; } | |
public bool IsAllowSubMarkets { get; set; } | |
public DateTime MarketStartTime | |
{ | |
get | |
{ | |
return Convert.ToDateTime(startTime); | |
} | |
} | |
public string GetStartTimeAsString() | |
{ | |
var DateStr = ""; | |
try | |
{ | |
var Today = DateTime.Now; | |
var DaysDiff = MarketStartTime.DayOfYear - Today.DayOfYear; | |
if (DaysDiff == 0) | |
{ | |
DateStr = "Today"; | |
} | |
else if (DaysDiff == 1) | |
{ | |
DateStr = "Tomorrow"; | |
} | |
else if (DaysDiff == -1) | |
{ | |
DateStr = "Yesterday"; | |
} | |
else | |
{ | |
DateStr = string.Format("{0}-{1}", MarketStartTime.Day, MarketStartTime.Month); | |
} | |
} | |
catch { } | |
return DateStr; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MarketBookRequest | |
{ | |
public string RequestId { get; set; } | |
public IEnumerable<string> MarketIds { get; set; } | |
public bool IncludeProfitLoss { get; set; } | |
public bool CheckLineMarkets { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MarketData | |
{ | |
public string ID { get; set; } | |
public int Winners { get; set; } | |
public int BetDelay { get; set; } | |
public double TotalMatched { get; set; } | |
public string MarketStatus { get; set; } | |
public double MaxBetSize { get; set; } | |
public bool BettingAllowed { get; set; } | |
public string Commentry { get; set; } | |
public List<MarketRunner> Runners { get; set; } | |
public string GetWinner() | |
{ | |
var runner = Runners.Find(x => x.status.ToLower() == "winner"); | |
if (runner == null) | |
{ | |
return null; | |
} | |
return runner.id; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MarketDataResponse | |
{ | |
public string RequestId { get; set; } | |
public IEnumerable<MarketData> MarketBooks { get; set; } | |
public IEnumerable<ProfitLoss> ProfitLoss { get; set; } | |
public string Commentry { get; set; } | |
public int BetDelay { get; set; } | |
public bool BetAllowed { get; set; } | |
public double MaxBetSize { get; set; } | |
public Scoreboard Scoreboard { get; set; } | |
public List<FancyMarketPosition> Fancy { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MarketRunner | |
{ | |
public string id { get; set; } | |
public string name { get; set; } | |
public double? ifWin { get; set; } | |
public double? ifLose { get; set; } | |
public double? price1 { get; set; } | |
public double? price2 { get; set; } | |
public double? price3 { get; set; } | |
public double? size1 { get; set; } | |
public double? size2 { get; set; } | |
public double? size3 { get; set; } | |
public double? lay1 { get; set; } | |
public double? lay2 { get; set; } | |
public double? lay3 { get; set; } | |
public double? ls1 { get; set; } | |
public double? ls2 { get; set; } | |
public double? ls3 { get; set; } | |
public string status { get; set; } | |
public double? handicap { get; set; } | |
public double? adjFactor { get; set; } | |
public object GetPriceSizeObject() | |
{ | |
var obj = new { | |
b1 = price1, b2 = price2, b3 = price3, | |
l1 = lay1, l2 = lay2, l3 = lay3, | |
bs1 = size1, bs2 = size2, bs3 = size3, | |
ls1, ls2, ls3 | |
}; | |
return obj; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Order | |
{ | |
public long OrderId { get; set; } | |
public int BettorId { get; set; } | |
public string BettorName { get; set; } | |
public string ParentName { get; set; } | |
public string MarketId { get; set; } | |
public long ExternalId { get; set; } | |
public decimal ExternalShare { get; set; } | |
public decimal RequestedPrice { get; set; } | |
public decimal RequestedSize { get; set; } | |
public decimal MatchedPrice { get; set; } | |
public decimal MatchedSize { get; set; } | |
public decimal CancelledSize { get; set; } | |
public decimal VoidedSize { get; set; } | |
public long SelectionId { get; set; } | |
public string Runner { get; set; } | |
public string Side { get; set; } | |
public DateTime PlacedDate { get; set; } | |
public DateTime EntryDate { get; set; } | |
public DateTime LastUpdated { get; set; } | |
public int MasterId { get; set; } | |
public decimal MasterShare { get; set; } | |
public int SuperId { get; set; } | |
public decimal SuperShare { get; set; } | |
public decimal BookShare { get; set; } | |
public int AgentId { get; set; } | |
public decimal AgentShare { get; set; } | |
public decimal ProfitLoss { get; set; } | |
public DateTime SettledTime { get; set; } | |
public string MarketNameFull { get; set; } | |
public decimal Position { get; set; } | |
public decimal Commission { get; set; } | |
public bool IsLine { get; set; } | |
public bool IsProcessingByMonitor { get; set; } = false; | |
public string Device { get; set; } | |
public bool IsBack() | |
{ | |
return Side == "B"; | |
} | |
public bool UpdateOrder(decimal BestPrice) | |
{ | |
return IsLine ? UpdateLineOrder(BestPrice) : UpdateOddsOrder(BestPrice); | |
} | |
bool UpdateOddsOrder(decimal BestPrice) | |
{ | |
if (IsBack()) | |
{ | |
if (RequestedPrice <= BestPrice) | |
{ | |
MatchedPrice = GetPriceForOrderMatching(BestPrice); | |
MatchedSize = RequestedSize; | |
LastUpdated = DateTime.Now; | |
return true; | |
} | |
} | |
else | |
{ | |
if (RequestedPrice >= BestPrice) | |
{ | |
MatchedPrice = GetPriceForOrderMatching(BestPrice); | |
MatchedSize = RequestedSize; | |
LastUpdated = DateTime.Now; | |
return true; | |
} | |
} | |
return false; | |
} | |
bool UpdateLineOrder(decimal BestPrice) | |
{ | |
BestPrice = Math.Ceiling(BestPrice); | |
if (IsBack()) | |
{ | |
if (RequestedPrice >= BestPrice) | |
{ | |
MatchedPrice = GetPriceForOrderMatching(BestPrice); | |
MatchedSize = RequestedSize; | |
LastUpdated = DateTime.Now; | |
return true; | |
} | |
} | |
else | |
{ | |
if (RequestedPrice <= BestPrice) | |
{ | |
MatchedPrice = GetPriceForOrderMatching(BestPrice); | |
MatchedSize = RequestedSize; | |
LastUpdated = DateTime.Now; | |
return true; | |
} | |
} | |
return false; | |
} | |
private decimal GetPriceForOrderMatching(decimal BestPrice) | |
{ | |
return IsProcessingByMonitor ? RequestedPrice : BestPrice; | |
} | |
public void Cancel() | |
{ | |
// Dont cancel if already matched | |
if (MatchedSize == RequestedSize) return; | |
CancelledSize = RequestedSize; | |
RequestedSize = 0; | |
MatchedPrice = 0; | |
MatchedSize = 0; | |
LastUpdated = DateTime.Now; | |
} | |
public void Void() | |
{ | |
VoidedSize = RequestedSize; | |
MatchedPrice = 0; | |
MatchedSize = 0; | |
RequestedSize = 0; | |
LastUpdated = DateTime.Now; | |
} | |
public decimal GetOrderSize() | |
{ | |
return MatchedSize > 0 ? MatchedSize : RequestedSize; | |
} | |
public decimal GetMasterSize() | |
{ | |
return MatchedSize * MasterShare / 100; | |
} | |
public decimal GetSuperSize() | |
{ | |
return MatchedSize * SuperShare / 100; | |
} | |
public decimal GetBookSize() | |
{ | |
return MatchedSize * BookShare / 100; | |
} | |
public decimal GetAgentSize() | |
{ | |
return MatchedSize * AgentShare / 100; | |
} | |
public decimal GetStakeholderShare(int StakeholderId) | |
{ | |
if (StakeholderId == AgentId) | |
{ | |
return AgentShare * ProfitLoss / 100; | |
} | |
else if (StakeholderId == MasterId) | |
{ | |
return MasterShare * ProfitLoss / 100; | |
} | |
else if (StakeholderId == SuperId) | |
{ | |
return SuperShare * ProfitLoss / 100; | |
} | |
return 0; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OrderRequest | |
{ | |
[Required] | |
[JsonProperty(PropertyName = "size")] | |
public decimal Size { get; set; } | |
[Range(1.01, 1000)] | |
[JsonProperty(PropertyName = "price")] | |
public decimal Price { get; set; } | |
[JsonProperty(PropertyName = "persist")] | |
public bool Persist { get; set; } | |
[Required] | |
[JsonProperty(PropertyName = "side")] | |
public string Side { get; set; } | |
[Required] | |
[JsonProperty(PropertyName = "selectionId")] | |
public long SelectionId { get; set; } | |
[Required] | |
[JsonProperty(PropertyName = "marketId")] | |
public string MarketId { get; set; } | |
[JsonProperty(PropertyName = "identity")] | |
public string Identity | |
{ | |
get | |
{ | |
return _identity; | |
} | |
set | |
{ | |
var decodedBytes = Convert.FromBase64String(value); | |
_identity = System.Text.Encoding.UTF8.GetString(decodedBytes); | |
} | |
} | |
private string _identity; | |
public decimal GetPosition(long RunnerId) | |
{ | |
if(SelectionId == RunnerId) | |
{ | |
return PositionOnBetRunner(); | |
} | |
else | |
{ | |
return PositionOnOtherRunner(); | |
} | |
} | |
public decimal PositionOnBetRunner() | |
{ | |
var position = (Price - 1) * Size; | |
if (IsLay()) | |
{ | |
return -1 * position; | |
} | |
else | |
{ | |
return position; | |
} | |
} | |
public decimal PositionOnOtherRunner() | |
{ | |
if(Side == "B") | |
{ | |
return -1 * Size; | |
} | |
else | |
{ | |
return Size; | |
} | |
} | |
public decimal GetLinePosition() | |
{ | |
return -1 * Size; | |
} | |
public decimal GetProfit() | |
{ | |
if(Side == "B") | |
{ | |
return (Price - 1) * Size; | |
} | |
else | |
{ | |
return -1 * Size; | |
} | |
} | |
public bool IsLay() | |
{ | |
return Side == "L"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OrderVM | |
{ | |
// Order Id | |
public long id { get; set; } | |
public string bn { get; set; } | |
public string mn { get; set; } | |
public string rn { get; set; } | |
public decimal mp { get; set; } | |
public decimal ms { get; set; } | |
public decimal up { get; set; } | |
public decimal us { get; set; } | |
public string bs { get; set; } | |
// Market Id | |
public string mid { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProfitLoss | |
{ | |
public int ClientID { get; set; } | |
public string MarketId { get; set; } | |
public long SelectionID { get; set; } | |
public decimal IfWin { get; set; } | |
public decimal IfLose { get; set; } | |
public decimal Liable { get; set; } | |
public bool IsCleared { get; set; } | |
public string Username { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment