Hi I'm working on Binance API for getting data but I'm not able to get data from getorder api. Link for APi (https://github.com/sonvister/Binance).
I've attached a image of error I'm getting as not aware of this issue.
public void Binance()
{
sqlConnection Conn = new sqlConnection();
Conn.LoadConnection();
Console.WriteLine("Connection Loaded.");
var apiClient = new ApiClient(apiKey, secretKey);
var binanceClient = new BinanceClient(apiClient);
var AllSymbol = binanceClient.GetAllPrices();
foreach (var symbol in AllSymbol.Result)
{
var Orders = binanceClient.GetOrder("BNBBTC").Result;
DataTable ltblAskOrdersHistory =
Orders.Asks.ToList().ToDataTable();
DataColumn column = new DataColumn("Symbol", typeof(string));
column.DefaultValue = symbol.Symbol;
ltblAskOrdersHistory.Columns.Add(column);
Conn.CreateTable("tbBinanceAskOrder");
Conn.ImportRecordsToTable(ltblAskOrdersHistory, "tbBinanceAskOrder");
Console.WriteLine("Ask Orders Table Updated.");
}
}
solved it as:
var Orders = binanceClient.GetAllOrders(symbol.Symbol).Result;
if (Orders.Count() > 0)
{
DataTable ltblOrders = Orders.ToList().ToDataTable();
Conn.CreateTable("tbBinanceOrder");
Conn.ImportRecordsToTable(ltblOrders, "tbBinanceOrder");
Console.WriteLine("tbBinanceOrder Table Updated.");
}
Related
I've got some code that I have used to pull Google Analytics data with a c# console application and it works great. Whenever I try to use that same code in an SSIS script task I get the error "Error deserializing JSON credential data.". I get the error when running locally and when deployed. I've got all the libraries added to the GAC and I'm using the same version libraries and .net Framework as the console app. Anyone have any ideas?
public void Main()
{
string SQL_Script = null;
string ErrorMessage = string.Empty;
string ExceptionMessage = "No error";
// Declare the variables that you'll be pulling from Google Analytics into the database
DateTime GA_Session_Date = new DateTime();
DateTime GA_End_Date = new DateTime();
GA_End_Date = DateTime.Today.AddDays(-1);
string GA_TransactionId = null;
string GA_ChannelGrouping = null;
string GA_Source = null;
string GA_Medium = null;
string GA_Keyword = null;
string GA_Campaign = null;
string GA_Device_Category = null;
string GA_Region = null;
int GA_Transactions = 0;
/*
* Get the last SessionDate loaded
*/
GA_Session_Date = Convert.ToDateTime(GetMaxSessionnDate());
GA_Session_Date = GA_Session_Date.AddDays(-1);
/*
* Delete the last SessionDate loaded from the table
*
* The free version of Google Analytics takes up to 24 hours to bake
* so reloading the last day will ensure that we get all of the data.
*/
SQL_Script = "DELETE FROM OmniChannelAnalytics.GoogleAnalytics.Transactions WHERE SessionDate >= '" + GA_Session_Date.ToString() + "';";
ErrorMessage = ExecuteSQL(SQL_Script);
/*
* Create the DataTable and DataSet to house the data from GA until
* it is bulk loaded into SQL
*/
DataSet dataSet = new DataSet();
DataTable sessionTable = new DataTable();
sessionTable.TableName = "Sessions";
// Add the columns to the Sessions table
sessionTable.Columns.Add("SessionDate", typeof(string));
sessionTable.Columns.Add("TransactionId", typeof(string));
sessionTable.Columns.Add("ChannelGrouping", typeof(string));
sessionTable.Columns.Add("Source", typeof(string));
sessionTable.Columns.Add("Medium", typeof(string));
sessionTable.Columns.Add("Keyword", typeof(string));
sessionTable.Columns.Add("Campaign", typeof(string));
sessionTable.Columns.Add("DeviceCategory", typeof(string));
sessionTable.Columns.Add("Region", typeof(string));
sessionTable.Columns.Add("Transactions", typeof(int));
sessionTable.Columns.Add("LoadDate", typeof(string));
dataSet.Tables.Add(sessionTable);
while (GA_Session_Date <= GA_End_Date)
{
try
{
var credential = Google.Apis.Auth.OAuth2.GoogleCredential.FromFile(GlobalVariables.GA_ClientSecretFileLocation)
.CreateScoped(new[] { Google.Apis.AnalyticsReporting.v4.AnalyticsReportingService.Scope.AnalyticsReadonly });
using (var analytics = new Google.Apis.AnalyticsReporting.v4.AnalyticsReportingService(new Google.Apis.Services.BaseClientService.Initializer
{
HttpClientInitializer = credential
}))
{
var request = analytics.Reports.BatchGet(new GetReportsRequest
{
ReportRequests = new[] {
new ReportRequest{
DateRanges = new[] { new DateRange{ StartDate = GA_Session_Date.ToString("yyyy-MM-dd"), EndDate = GA_Session_Date.ToString("yyyy-MM-dd") } },
Dimensions = new[] {
new Dimension{ Name = "ga:transactionId" }
, new Dimension { Name = "ga:channelGrouping" }
, new Dimension { Name = "ga:sourceMedium" }
, new Dimension { Name = "ga:keyword" }
, new Dimension { Name = "ga:campaign" }
, new Dimension { Name = "ga:deviceCategory" }
, new Dimension { Name = "ga:region" }
},
Metrics = new[] { new Metric{ Expression = "ga:transactions", Alias = "Transactions"}},
ViewId = GlobalVariables.GA_View_ID
}
}
});
var response = request.Execute();
foreach (var row in response.Reports[0].Data.Rows)
{
GA_TransactionId = row.Dimensions[0];
GA_ChannelGrouping = row.Dimensions[1];
GA_Source = row.Dimensions[2].Substring(0, row.Dimensions[2].IndexOf("/")).Trim().Replace("'", "''");
GA_Medium = row.Dimensions[2].Substring(row.Dimensions[2].IndexOf("/") + 1, row.Dimensions[2].Length - row.Dimensions[2].IndexOf("/") - 1).Trim().Replace("'", "''");
GA_Keyword = row.Dimensions[3];
GA_Campaign = row.Dimensions[4];
GA_Device_Category = row.Dimensions[5];
GA_Region = row.Dimensions[6];
foreach (var metric in row.Metrics)
{
GA_Transactions = Convert.ToInt32(metric.Values[0]);
}
// Populate the data table to hold until everything is bulk loaded into SQL
DataRow newRow = sessionTable.NewRow();
newRow["SessionDate"] = GA_Session_Date;
newRow["TransactionId"] = GA_TransactionId;
newRow["ChannelGrouping"] = GA_ChannelGrouping;
newRow["Source"] = GA_Source;
newRow["Medium"] = GA_Medium;
newRow["Keyword"] = GA_Keyword;
newRow["Campaign"] = GA_Campaign;
newRow["DeviceCategory"] = GA_Device_Category;
newRow["Region"] = GA_Region;
newRow["Transactions"] = GA_Transactions;
newRow["LoadDate"] = DateTime.Now;
sessionTable.Rows.Add(newRow);
} // foreach (var row in rows)
}
} // try
catch (Exception ex)
{
ExceptionMessage = ex.Message;
}
finally
{
// Import the current day's Session data
foreach (DataTable table in dataSet.Tables)
{
ImportTable(table);
}
sessionTable.Clear();
}
// Iterate the session date to import by 1
GA_Session_Date = GA_Session_Date.AddDays(1);
} // while (GA_Session_Date <= GA_End_Date)
Dts.TaskResult = (int)ScriptResults.Success;
}
Problem 1:
I am new to MICROSOFT DYNAMICS CRM 365. I have few tables with my CRM like(Account,Customer).I want to fetch all data from table account.
Below is my sample code for connection:(not sure this is correct or not but getting output message that i am connected to CRM)
public void ConnectToMSCRM(string UserName, string Password, string SoapOrgServiceUri)
{
try
{
ClientCredentials credentials = new ClientCredentials();
credentials.UserName.UserName = UserName;
credentials.UserName.Password = Password;
Uri serviceUri = new Uri(SoapOrgServiceUri);
OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, credentials, null);
proxy.EnableProxyTypes();
_services = (IOrganizationService)proxy;
Response.Write("Connected to CRM \n");
}
I need all data to be retrieved on button click event .
Output should be: result of "select * from ABC";
Problem 2:
if possible please suggest how to fetch records using given column name.
Output should be: result of "select * from ABC where ColumnName="test";
Fetching all entities list into List
var allEntities = **GetEntities(_service);**
foreach (var Entity in allEntities)
{
ddlEntityName.Items.Add(Entity.LogicalName);
}
//Function with single parameter (oganizationservice as a parameter)
//This will fetch Table/Entity Name Like ACCOUNT,CONTACT from Microsoft Dynamics CRM
public Microsoft.Xrm.Sdk.Metadata.EntityMetadata[] GetEntities(IOrganizationService organizationService)
{
Dictionary<string, string> attributesData = new Dictionary<string, string>();
RetrieveAllEntitiesRequest metaDataRequest = new RetrieveAllEntitiesRequest();
RetrieveAllEntitiesResponse metaDataResponse = new RetrieveAllEntitiesResponse();
metaDataRequest.EntityFilters = EntityFilters.Entity;
XmlDictionaryReaderQuotas myReaderQuotas = new XmlDictionaryReaderQuotas();
myReaderQuotas.MaxNameTableCharCount = 2147483647;
// Execute the request.
metaDataResponse = (RetrieveAllEntitiesResponse)organizationService.Execute(metaDataRequest);
var entities = metaDataResponse.EntityMetadata;
return entities.OrderBy(x => x.LogicalName).ToArray();//to arrange in ascending order
}
What about query expression?
This is your query :
Select * from ABC where ColumnName="test";
And this is the QueryExpression:
QueryExpression query = new QueryExpression()
{
EntityName = Contact.EntityLogicalName,
ColumnSet = new ColumnSet("address1_telephone1"),
};
to excute the query, this is how :
DataCollection<Entity> entityCollection = _services.RetrieveMultiple(query).Entities;
// Display the results.
foreach (Contact entity in entityCollection)
{
Console.WriteLine("my test: {0}", entity.address1_telephone1);
}
Regards
Having a bit of problem with some C# LDAP Queries. The immediately most concerting one is that I appear to be missing approximately 1/3rd of the expected data set.
Have two screen shots attached of the result set.
In regards to the C# Filter
I am generating the filter here
public string GenerateFilter()
{
var LastRunDateTime = Variables.LastRunDateTime;
var filter = "(ObjectClass=group)";
/*
string filter = string.Format(
"(&(ObjectClass=group)(whenChanged>={0:yyyyMMddHHmmss.0Z}))",//This is the DateTime format it takes.
LastRunDateTime.AddHours(-11) // Always use UTC to make life easy. Otherwise you need to change the above time formatting.
); */
return filter;
}
I have commented out the initial code which is returning the same count for the first run
In Regards to the work horse part of the code I can't see any reason why it isn't returning all the values.
I have been checking out the missing values (managed to track them down with a bit of logic) and there is literally no configuration difference between them.
public override void CreateNewOutputRows()
{
/*
Add rows by calling the AddRow method on the member variable named "<Output Name>Buffer".
For example, call MyOutputBuffer.AddRow() if your output was named "MyOutput".
*/
DataTable workTable = new DataTable("Ad_Users");
DataColumn workColumn = workTable.Columns.Add("SID", typeof(string));
workTable.Columns.Add("ObjectCategory", typeof(string));
workTable.Columns.Add("ObjectGUID", typeof(string));
workTable.Columns.Add("CanonicalName", typeof(string));
workTable.Columns.Add("SAMAccount", typeof(string));
workTable.Columns.Add("distinguishedName", typeof(string));
workTable.Columns.Add("DisplayName", typeof(string));
workTable.Columns.Add("Description", typeof(string));
workTable.Columns.Add("WhenCreated", typeof(DateTime));
workTable.Columns.Add("WhenChanged", typeof(DateTime));
// workTable.Columns.Add("MemberOf", typeof(string));
var domainController = "[REDACTED]";
using (var domain = new System.DirectoryServices.DirectoryEntry("LDAP://" + domainController))
{
using (var searcher = new DirectorySearcher(domain, GenerateFilter()))
{
searcher.PropertiesToLoad.Add("ObjectSID");
searcher.PropertiesToLoad.Add("ObjectCategory");
searcher.PropertiesToLoad.Add("ObjectGuid");
searcher.PropertiesToLoad.Add("CN");
searcher.PropertiesToLoad.Add("SAMAccountName");
searcher.PropertiesToLoad.Add("DisplayName");
searcher.PropertiesToLoad.Add("distinguishedName");
searcher.PropertiesToLoad.Add("Description");
searcher.PropertiesToLoad.Add("WhenCreated");
searcher.PropertiesToLoad.Add("WhenChanged");
// searcher.PropertiesToLoad.Add("MemberOf");
foreach (SearchResult result in searcher.FindAll())
{
var de = result.GetDirectoryEntry();
var sidInBytes = (byte[])de.Properties["ObjectSID"].Value;
var GUID = (byte[])de.Properties["ObjectGuid"].Value;
Guid guid = new Guid(GUID);
//INSERT VALUES INTO DATATABLE
DataRow workRow = workTable.NewRow();
workRow["SID"] = new System.Security.Principal.SecurityIdentifier(sidInBytes, 0);
workRow["ObjectCategory"] = de.Properties["ObjectCategory"].Value;
workRow["ObjectGUID"] = guid;
workRow["CanonicalName"] = de.Properties["CN"].Value;
workRow["SAMAccount"] = de.Properties["SAMAccountName"].Value;
workRow["DisplayName"] = de.Properties["DisplayName"].Value;
workRow["distinguishedName"] = de.Properties["distinguishedName"].Value;
workRow["Description"] = de.Properties["Description"].Value;
workRow["WhenCreated"] = Convert.ToDateTime(de.Properties["WhenCreated"].Value);
workRow["WhenChanged"] = Convert.ToDateTime(de.Properties["WhenChanged"].Value);
Output0Buffer.AddRow();
Output0Buffer.ObjectSID = workRow["SID"].ToString();
Output0Buffer.ObjectCategory = workRow["ObjectCategory"].ToString();
Output0Buffer.ObjectGUID = workRow["ObjectGUID"].ToString();
Output0Buffer.CanonicalName = workRow["CanonicalName"].ToString();
Output0Buffer.SamAccountName = workRow["SAMAccount"].ToString();
Output0Buffer.DisplayName = workRow["DisplayName"].ToString();
Output0Buffer.DistinguishedName = workRow["distinguishedName"].ToString();
Output0Buffer.Description = workRow["Description"].ToString();
Output0Buffer.WhenCreated = Convert.ToDateTime(workRow["WhenCreated"]);
Output0Buffer.WhenChanged = Convert.ToDateTime(workRow["WhenChanged"]);
}
}
}
}
}
If anyone would be able to assist it would be greatly appreciated
To get comparable results you should use
Get-ADGroup -LDAPFilter "(objectClass=group)"
I have two list (1st with values from a website, 2nd with values from a .csv file) and I'd like to join them in another list, starting two equals values, and display it in a datagridview.
Before to post the code, I'd like to say that I tried to fill my datagridview with these two lists separately and they work.
I didn't get any error, but I can't see my datagridview with values.
I'm going to post my code and explain it.
First List Code:
var url = textBox5.Text;
//var url = "http://www.betexplorer.com/soccer/norway/tippeligaen/results/";
var web = new HtmlWeb();
var doc = web.Load(url);
Bets = new List<Bet>();
// Lettura delle righe
var Rows = doc.DocumentNode.SelectNodes("//tr");
foreach (var row in Rows)
{
if (!row.GetAttributeValue("class", "").Contains("rtitle"))
{
if (string.IsNullOrEmpty(row.InnerText))
continue;
var rowBet = new Bet();
foreach (var node in row.ChildNodes)
{
var data_odd = node.GetAttributeValue("data-odd", "");
if (string.IsNullOrEmpty(data_odd))
{
if (node.GetAttributeValue("class", "").Contains("first-cell"))
{
rowBet.Match = node.InnerText.Trim();
var matchTeam = rowBet.Match.Split(new[] { " - " }, StringSplitOptions.RemoveEmptyEntries);
rowBet.Home = matchTeam[0];
rowBet.Host = matchTeam[1];
}
if (node.GetAttributeValue("class", "").Contains("result"))
{
rowBet.Result = node.InnerText.Trim();
var matchPoints = rowBet.Result.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
int help;
if (int.TryParse(matchPoints[0], out help))
{
rowBet.HomePoints = help;
}
if (matchPoints.Length == 2 && int.TryParse(matchPoints[1], out help))
{
rowBet.HostPoints = help;
}
}
if (node.GetAttributeValue("class", "").Contains("last-cell"))
rowBet.Date = node.InnerText.Trim();
}
else
{
rowBet.Odds.Add(data_odd);
}
}
if (!string.IsNullOrEmpty(rowBet.Match))
Bets.Add(rowBet);
}
}
Second List & Combined List Code:
string FileName = #"C:\mydir\testcsv.csv";
OleDbConnection conn = new OleDbConnection
("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " +
Path.GetDirectoryName(FileName) +
"; Extended Properties = \"Text;HDR=YES;FMT=Delimited\"");
conn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter
("SELECT * FROM " + Path.GetFileName(FileName), conn);
DataSet ds = new DataSet("Temp");
adapter.Fill(ds);
conn.Close();
// DataTable dt = new DataTable();
DataTable dt = ds.Tables[0];
//dataGridView2.DataSource = dt;
// dataGridView2.DataMember = "Table";
List<HT> matchlist = new List<HT>();
matchlist = (from DataRow dr in dt.Rows
select new HT()
{
Home = dr["Home"].ToString().Replace("Milan", "AC Milan").Replace("Roma", "AS Roma"),
Host = dr["Host"].ToString().Replace("Milan", "AC Milan").Replace("Roma", "AS Roma"),
ScoreHome = dr["ScoreHome"].ToString(),
ScoreAway = dr["ScoreAway"].ToString(),
//Segno = dr["Segno"].ToString(),
//odd1 = dr["odd1"].ToString(),
//oddx = dr["oddx"].ToString(),
//odd2 = dr["odd2"].ToString()
}).ToList();
// dataGridView2.DataSource = matchlist;
var combinedDataList = (from d1 in Bets
//join d2 in dataList2 on d1.Home equals d2.Home
join d2 in matchlist on new { d1.Home, d1.Host } equals new { d2.Home, d2.Host }
select new CombinedData
{
Data = d1.Date,
Home = d1.Home,
Away = d1.Host,
HSFT = d1.HomePoints,
ASFT = d1.HostPoints,
HSHT = d2.ScoreHome,
ASHT = d2.ScoreAway,
HODD = d1.odd1,
XODD = d1.oddX,
AODD = d1.odd2,
RisFin = d1.RisFin,
Over05SH = d1.over05sh,
Over05FT = d1.Over05FT,
Over15FT = d1.Over15FT,
Over25FT = d1.Over25FT,
Over35FT = d1.Over35FT,
Over45FT = d1.Over45FT
}).OrderBy(p => p.HODD);
dataGridView2.DataSource = combinedDataList;
Thank you for your attention. Have a fantastic sunday!
EDIT: I delete unnecessary code
EDIT2: I add the screen of my single list output. Let's see:
First List:
Second List:
So, I'd like to merge "ScoreHome" and "ScoreAway" from the second list in my first list based on "Home" and "Host" that I have in both lists.
my problem is very common, but I have not found any solution.
This is my code:
public async Task<QueryResult> RollbackQuery(ActionLog action)
{
var inputParameters = JsonConvert.DeserializeObject<Parameter[]>(action.Values);
var data = DeserailizeByteArrayToDataSet(action.RollBackData);
using (var structure = PrepareStructure(action.Query, action.Query.DataBase, inputParameters))
{
//_queryPlanner is the implementor for my interface
return await _queryPlanner.RollbackQuery(structure, data);
}
}
I need to load DataTable (from whereever) and replace data to database. This is my Rollback function. This function use a "CommandStructure" where I've incapsulated all SqlClient objects. PrepareStructure initialize all objects
//_dataLayer is an Helper for create System.Data.SqlClient objects
//ex: _dataLayer.CreateCommand(preSelect) => new SqlCommand(preSelect)
private CommandStructure PrepareStructure(string sql, string preSelect, DataBase db, IEnumerable<Parameter> inputParameters)
{
var parameters = inputParameters as IList<Parameter> ?? inputParameters.ToList();
var structure = new CommandStructure(_logger);
structure.Connection = _dataLayer.ConnectToDatabase(db);
structure.SqlCommand = _dataLayer.CreateCommand(sql);
structure.PreSelectCommand = _dataLayer.CreateCommand(preSelect);
structure.QueryParameters = _dataLayer.CreateParemeters(parameters);
structure.WhereParameters = _dataLayer.CreateParemeters(parameters.Where(p => p.IsWhereClause.HasValue && p.IsWhereClause.Value));
structure.CommandBuilder = _dataLayer.CreateCommandBuilder();
structure.DataAdapter = new SqlDataAdapter();
return structure;
}
So, my function uses SqlCommandBuilder and DataAdapter to operate on Database.
PreSelectCommand is like "Select * from Purchase where CustomerId = #id"
The table Purchase has one primaryKey on ID filed
public virtual async Task<QueryResult> RollbackQuery(CommandStructure cmd, DataTable oldData)
{
await cmd.OpenConnectionAsync();
int record = 0;
using (var cmdPre = cmd.PreSelectCommand as SqlCommand)
using (var dataAdapt = new SqlDataAdapter(cmdPre))
using (var cmdBuilder = new SqlCommandBuilder(dataAdapt))
{
dataAdapt.UpdateCommand = cmdBuilder.GetUpdateCommand();
dataAdapt.DeleteCommand = cmdBuilder.GetDeleteCommand();
dataAdapt.InsertCommand = cmdBuilder.GetInsertCommand();
using (var tbl = new DataTable(oldData.TableName))
{
dataAdapt.Fill(tbl);
dataAdapt.FillSchema(tbl, SchemaType.Source);
tbl.Merge(oldData);
foreach (DataRow row in tbl.Rows)
{
row.SetModified();
}
record = dataAdapt.Update(tbl);
}
}
return new QueryResult
{
RecordAffected = record
};
}
I Execute the code and I don't have any errors, but the data are not updated.
variable "record" contain the right number of modified (??) record, but..... on the table nothing
can someone help me?
EDIT 1:
With SQL Profiler I saw that no query is executed on DB. Only select query on .Fill(tbl) command.
EDIT 2:
Now I have made one change:
tbl.Merge(oldData) => tbl.Merge(oldData, true)
so I see perform the expected query but, with reversed parameters.
UPDATE Purchase SET price=123 where id=6 and price=22
instead of
UPDATE Purchase SET price=22 where id=6 and price=123