I am getting familiar with working with APIs. I have the following question:
Error is:
Fatal error: Uncaught Larislackers\BinanceApi\Exception\BinanceApiException: [-1102]: Mandatory parameter 'timestamp' was not sent, was empty/null, or malformed. thrown in C:\Users\Francisco\vendor\larislackers\php-binance\src\BinanceApiContainer.php on line 568
Edit: This is the class: https://larislackers.github.io/php-binance/source-class-Larislackers.BinanceApi.BinanceApiContainer.html#276-291
I can notice it's because the TIMESTAMP is mandatory:
https://www.binance.com/restapipub.html#current-open-orders-signed
Can someone provide me an example of how would they fill the timestamp?
This is my code so far:
$orders = $bac->getOpenOrders(['symbol' => 'XVGETH']);
var_dump($orders->getBody()->getContents());
Add a timestamp key to the $params array.
$orders = $bac->getOpenOrders(['symbol' => 'XVGETH', 'timestamp' => time()]);
time() returns the current time. If you want some other time, there are many date-time functions that can be used. It's also just a number that represents the time in seconds, you can perform ordinary arithmetic like time() - 86400 to get the current time yesterday.
See https://www.binance.com/restapipub.html for how the Binance API uses the timestamp option.
Related
I save the user photo with Carbon in laravel 9
$user->photo_verified_at = Carbon::now()->timestamp;
But I get this output from database:
Error Message : ORA-01843: not a valid month
Position : 42
Statement : update "USERS" set "PHOTO_VERIFIED_AT" = :p0, "USERS"."UPDATED_AT" = :p1 where "ID" = :p2
Bindings : [1672340645,2022-12-29 19:04:05,25]
If you a look at the data for created_at and updated_at in the database, they have the following format:
29/12/22 18:30:43,000000000
How is it possible to set Carbon to return in that format?
Carbon::now()->timestamp->format('dd/mm/yy H:i:s')
it returns
Error: Call to a member function format() on int
You should be fine with just Carbon::now() or now() (it is a helper function calling Carbon::now())
I am not exactly sure what you are storing there, if it is a timestamp that is literally a number, for example, 13102321 (just a made up number from me), it is the seconds that literally passed since a known date (I think it is January 1st, 1970 or something like that).
So, if you exactly want that fomat, it is as easy as reading the documentation, it will state that you can use the normal PHP's Date format:
$formatedString = now()->format('d/m/Y H:i:s,u000');
You have to add 3 more 0, as it has 9 0, that is nano seconds, super weird, but it is exactly the format you want...
You can also try out just using now() or any method that returns a literal Carbon object, it can or cannot work, depends how you have your model's attribute casted/declared.
I have this code:
$ah = date("H:i:s Y-m-d");
$ahseg=mktime($ah);
and this error:
Fatal error: Uncaught TypeError: mktime(): Argument #1 ($hour) must be of type int, string given in /var/www/vhosts/dominio.com/httpdocs/admin/maniobra.php:8 Stack trace: #0 /var/www/vhosts/dminio.com/httpdocs/admin/maniobra.php(8): mktime() #1 {main} thrown in /var/www/vhosts/dominio.com/httpdocs/admin/maniobra.php on line 8
This code was working on other hosting, but when I pass it to the new server that uses plesk it throws me this error
Because of a php version change:
see: https://3v4l.org/she2g
If you want to have a timestamp, use time(), if you want to use mktime(), check the dox, you are giving a string date to the hour (int) parameter:
https://www.php.net/manual/en/function.mktime.php
Regardless of whether it used to work, the error message is quite straight forward: the first argument is supposed to be an int, but you are passing a string.
The documentation for mktime confirms that while it's possible to call it with one argument, that one argument is the hour, not a formatted date time string.
The only reason this used to work is that in earlier PHP versions, the string was "coerced" to an integer, so you were running this:
$ah = date("H:i:s Y-m-d");
$ahseg=mktime((int)$ah);
If the string in $ah is "10:59:00 2022-02-02", then the integer passed to mktime is 10, which happens to be the hour. The rest of the string is thrown away, and other fields are left at their default values ("now").
It's unclear what this code was trying to do, but for an integer representing "now", you can just use time(); for an integer representing some other date, use something like strtotime('2020-01-01 19:45');.
I'm having some troubles using the format function in Symfony2 when trying to insert a date interval into a table, for the purpose of setting due dates for created invoices.
Here is what I have:
$today = new \DateTime();
$interval = $today->add(new \DateInterval('P1M'));
$invoice->setDueDate($interval->format('Y-m-d H:i:s'));
However, when I hover over the format parameter in PHPStorm, it tells me that it's expecting a DateTime object not a string, and I get the following error in my profiler:
Error: Call to a member function format() on string
So, I changed the line to this:
$invoice->setDueDate($interval->format(new \DateTime()));
But when I run that, my profiler gives this error:
Warning: DateTime::format() expects parameter 1 to be string, object given
It almost seems like a catch 22 situation! I am really baffled, do I use a string or a DateTime object, because either one fails yet warns me I need to use one or the other..
Any ideas?
I’d guess that $invoice->setDueDate() is the one expecting a DateTime instance. So the line should be $invoice->setDueDate($interval);
Hi I have a problem where I am trying to get a total time that a job has taken (using database fields job_start and job_end time(7))
then adding this to another model's field,
the code i have is
if (isset($_POST['Jobs'])) {
$model->attributes = $_POST['Jobs'];
$model->setScenario('closejob');
$model->status = 2; //set status to closed
//date time difference - this is the part I need help with
$diff = $model->job_start - $model->job_end;
//need to get customer model and add time diff to it
$customermodel = Customers::model()->findByPk($model->customer_ID);
$customermodel->total_time = $customermodel->total_time + $diff;
$customermodel->save();
if ($model->save())
$this->redirect(array('view', 'id' => $model->job_ID));
}
I have tried string to time and other date functions but to no avail , the above code throws the following error
CDbCommand failed to execute the SQL statement: SQLSTATE[22007]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Conversion failed when converting date and/or time from character string..
Any ideas on the proper way to do this ?
i.e am I going about the adding of time and calculating the differences all wrong ?
I think it has something to do with converting the string to a time format but I am unsure how to do this
Maybe you have to do
$diff = $model->job_end - $model->job_start;
Instead of
$diff = $model->job_start - $model->job_end;
Unless you have an attached behavior for that model, it is likely that your job_start and job_end attributes are strings that are formatted according to MSSQL, assuming the column types are a date/time representation. This is certainly the way CActiveRecord models work with MySQL and Yii with DATETIME type.
To do differences, you would need to convert first. Take a look at CDateFormatter and use it to convert your attributes to numerical representations that allow for arithmetic.
If you cannot get Xdebug to work, then invest time in getting the Yii::log() function working (it will output to runtime/application.log by default.
In a DB table I have several fields with datetime as field type. So I need to persist data only as date time object.
From a form I get date time as string like
2012-10-05 17:45:54
Now when ever I persist my entity I get following error:
Fatal error: Call to a member function format() on a non-object in
..\DateTimeType.php on line 44
I tried with
$protocol->setStartedAt(strtotime($post['started_at']));
or
$from = \DateTime::createFromFormat('yy-mm-dd hh:mm:ss', $post['started_at']);
$protocol->setStartedAt($from);
or just
$from = new \DateTime($post['started_at']);
$protocol->setStartedAt($from);
The last code works but it does not uses the timestamp passed as arguement but just gets the current time.
Any ideas?
I always create a DateTime object with its constructor, in your case it would be:
$protocol->setStartedAt(new \DateTime($post['started_at']));
if this works but does not use the timestamp posted you probably do not have the value in $post['started_at']. Try debugging it or just do the dirty trick:
die($post['started_at']);
For the sake of future readers who surely will someday encounter this problem (this is the first post if you google "symfony 2 datetime from string"), keep in mind that in Symfony 2 the DateTime object does NOT accept a string with that format : "d/m/Y H:i:s", and probably doesn't support many others either.
For the sake of not becoming mad at that, I've actually found out that the easiest and safest solution to avoid such errors is this one:
First, get your date string from whatever kind of request you are doing (In my case a generic AJAX request) and convert it to a DateTime Object, this example assumes that we need to create a dateTime object for 25/04/2015 15:00, which is the format of the jQuery UI italian DateTimePicker (that's just an example):
$literalTime = \DateTime::createFromFormat("d/m/Y H:i","25/04/2015 15:00");
(note: use \ to use php's DateTime object, else you will be using Symfony's datetime object that will throw you an exception)
Then, once you did it, create a date string using the comfort format function, by giving to the first parameter the output format expected (Y-m-d H:i:s):
$expire_date = $literalTime->format("Y-m-d H:i:s");
In this way you are 100% sure that whatever kind of format you are passing or receiving this will properly be converted and you won't get any kind of exception from the DateTime symfony object, as long as you provide what you are expecting as an input.
Knowing that this post is actually quite old, I've just decided to post that because I didn't find any other valuable source but this one to understand where the problem could have been.
Please note that the best solution is still to send the datetime string in the correct format already, but if you literally have no ways to do that the safest way to convert such a string is the one above.
How about createFromFormat?
http://uk.php.net/manual/en/datetime.createfromformat.php
$from = DateTime::createFromFormat($post['started_at'], 'Y-m-d H:i:s');