Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- foreach (string symbol in account.OpenOrderDictionary.Keys)
- {
- if (symbol.EndsWith("SPOT")) continue;
- decimal symbolOrdersMargin = 0;
- decimal sumPV = 0;
- decimal sumV = 0;
- decimal sumsignV = 0;
- lock (account.OpenOrderDictionary[symbol].locker)
- {
- foreach (BbodOrder order in account.OpenOrderDictionary[symbol].OrderList)
- {
- if (order.OrderStatus.Equals('0') || order.OrderStatus.Equals('1')) //0-NEW, 1-PartialFill
- {
- if (order.Price != null)
- {
- decimal V = Math.Abs(order.LeavesQty.GetValueOrDefault());
- sumPV += order.Price.GetValueOrDefault() * V;
- sumV += V;
- if (order.Side.Equals('1')) sumsignV += V;
- else sumsignV -= V;
- }
- }
- }
- }
- if (Math.Round(sumsignV, 10) != 0 && sumV != 0)
- {
- var marketDbSymbol = SymbolsData.GetSymbolFromMarketContextByKey(symbol);
- Asset asset = assetMap.GetAsset(marketDbSymbol);
- if (asset != null)
- {
- decimal IMR = 0;
- if (assetIMRDictionary.ContainsKey(symbol))
- {
- IMR = assetIMRDictionary[symbol];
- }
- else
- {
- IMR = (decimal)asset.InitialMarginBasePercent * 0.01m;
- }
- symbolOrdersMargin = Math.Round(IMR * Math.Abs(sumsignV) * asset.ContractSize * sumPV / sumV, 8);
- account.TotalMarginOur += Math.Abs(symbolOrdersMargin);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement