I'm trying to place a future position with /fapi/v1/order.
I keep encounter the error {'code': -1117, 'msg': 'Invalid side.'}.
More info on code 1117
Actual pseudo code
futures.orders.create(
symbol='ADAUSDT',
market_type="TRAILING_STOP_MARKET",
position='LONG',
activationPrice=1.80,
callbackRate=2.0
)
I've tried ['BOTH', 'BUY/LONG', 'SELL/SHORT', 'LONG', 'SHORT', 'BUY', 'SELL'] but the same erros keeps coming back, so what do I do wrong?
I just realized you got two side parameters; positionSide and side. positionSide was set but side was not.
Additional information:
There are only two available values for the side parameter of the order endpoint, one is BUY another is SELL.
If you want to place an order under the hedge mode, please use another parameter positionSide along with the side parameter.
positionSide=LONG&side=BUY -> represents open long position
positionSide=LONG&side=SELL -> represents close long position
positionSide=SHORT&side=SELL -> represents open short position
positionSide=SHORT&side=BUY -> represents close short position
Hope this helps future people : )
Related
I’m making changes to the transcription value of a field in my submission object based on some business logic in a custom Hyperscience flow. However, I don’t see this newly updated value on the UI during the flexible extraction afterwards - can someone help me understand why this is happening? Here’s how I’m making the change and forcing flexible extraction on this field:
for document in submission.get('documents', []):
for field in document.get('document_fields', []):
if field['output_name'] == 'some name' and field['transcription_normalized'] == 'old value':
field['transcription_normalized'] = 'new value'
field['process_flexible_extraction_type'] = 'FORCE'
I don’t see the ‘new value’ on the UI, still only the ‘old value’.
I am using Dgrid OndemandGrid with Jsonrest store.On scrolling,I am taking 40 records from the database.
var grid= new OnDemandGrid({
store: jsonstore,
columns: Layout,
minRowsPerPage : 40,
maxRowsPerPage : 40,
loadingMessage: "Loading data...",
noDataMessage: "No results found."
}, "grid");
On first time ,I am getting the response Header as
Content-Range items=0-39/132
.On further scrolling ,the response Header is
Content-Range items=38-78/132 instead of 40-79/132.
Can someone tell me how to get the response as 40-79/132 , 80-119..etc..
Add queryRowsOverlap: 0 to the object you're passing to the grid constructor.
queryRowsOverlap defaults to 1, and is the reason the queries overlap. This property is intended to counteract issues with dojo/store/Observable "dropping" items at page boundaries, though it isn't a perfect solution.
I am using security component in my projects and is there any way to get the detailed description about the error while developing ? For ex:- if any field is added in view without using cakephp's form method, it is returning error as 'auth' in my blackHoleCallback function. Instead I need beacuse of what reason it returned that error. Because it is taking so much time to rectify the problem. Is there any way to get the detailed error description ?
All you have to do is look in the right place
Check your app/tmp/logs/error.log file
If you look in the error log you'll see an entry like this:
2013-03-16 17:24:29 Error: [BadRequestException] The request has been black-holed
#0 root/lib/Cake/Controller/Component/SecurityComponent.php(228): SecurityComponent->blackHole(Object(FacebookUsersController), 'csrf')
#1 [internal function]: SecurityComponent->startup(Object(FacebookUsersController))
#2 root/lib/Cake/Utility/ObjectCollection.php(130): call_user_func_array(Array, Array)
#3 [internal function]: ObjectCollection->trigger(Object(CakeEvent))
#4 root/lib/Cake/Event/CakeEventManager.php(246): call_user_func(Array, Object(CakeEvent))
#5 root/lib/Cake/Controller/Controller.php(670): CakeEventManager->dispatch(Object(CakeEvent))
#6 root/lib/Cake/Routing/Dispatcher.php(183): Controller->startupProcess()
#7 root/lib/Cake/Routing/Dispatcher.php(161): Dispatcher->_invoke(Object(FacebookUsersController), Object(CakeRequest), Object(CakeResponse))
#8 root/app/webroot/index.php(96): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#9 {main}
Read the error that is on screen
If you are in debug mode, this error is also shown on screen when the error happens. e.g.:
The request has been black-holed
Error: The requested address '/admin/fooby/edit/1' was not found on this server.
Stack Trace
CORE/Cake/Controller/Component/SecurityComponent.php line 228 → SecurityComponent->blackHole(FacebookUsersController, string)
[internal function] → SecurityComponent->startup(FacebookUsersController)
CORE/Cake/Utility/ObjectCollection.php line 130 → call_user_func_array(array, array)
[internal function] → ObjectCollection->trigger(CakeEvent)
CORE/Cake/Event/CakeEventManager.php line 246 → call_user_func(array, CakeEvent)
CORE/Cake/Controller/Controller.php line 670 → CakeEventManager->dispatch(CakeEvent)
CORE/Cake/Routing/Dispatcher.php line 183 → Controller->startupProcess()
CORE/Cake/Routing/Dispatcher.php line 161 → Dispatcher->_invoke(FacebookUsersController, CakeRequest, CakeResponse)
APP/webroot/index.php line 96 → Dispatcher->dispatch(CakeRequest, CakeResponse)
Handling csrf errors
With the details of a specific error (i.e. the data you are posting, and the exact token data in your session at the time) it would be possible to answer what problem brought you here, in the absense of that:
look at the line throwing the error.
In the stack trace above, the error is coming from CORE/Cake/Controller/Component/SecurityComponent.php line 228 - Open the file and look what that code is:
if ($isPost && $isNotRequestAction && $this->csrfCheck) {
if ($this->_validateCsrf($controller) === false) {
return $this->blackHole($controller, 'csrf');
}
}
What should be obvious from this is that the function _validateCsrf is responsible for the request being blackholed. This should not really be much of a surprise.
Look at the source of that function:
protected function _validateCsrf(Controller $controller) {
$token = $this->Session->read('_Token');
$requestToken = $controller->request->data('_Token.key');
if (isset($token['csrfTokens'][$requestToken]) && $token['csrfTokens'][$requestToken] >= time()) {
if ($this->csrfUseOnce) {
$this->Session->delete('_Token.csrfTokens.' . $requestToken);
}
return true;
}
return false;
}
Depending on why that function returns false, determines how you continue to debug.
Correct configuration of the component
The inevitable consequence of debugging a CSRF error is you'll need to modify the configuration of the Security component.
Do you, for example, want to be reusing tokens, because your app is submitting the same form multiple times between page loads?
Are you self-invalidating the form requests by adding new fields to the form data - You can use the unlockedFields property to exclude these fields from the csrf checks.
You can also simply disable CSRF checks completey. That has obvious security consequences - but if you're struggling to work with the component, it's an easy way to work around and problems you currently face.
In order to see the mechanisms I dug into the code to see how the FormHelper hash is created vs. how the SecurityComponent validation checks the hash. Here's how to see exactly what is happening behind the scenes.
Checking the input to the FormHelper. Open CORE/Cake/View/Helper/FormHelper.php. In the secure() function add some pr lines around the $files=Security::hash line to see how the tokens are built:
pr($fields);//hashed into computed token on next line
$fields = Security::hash(serialize($fields) . $unlocked . Configure::read('Security.salt'), 'sha1');
pr($unlocked); //hashed into computed token
pr(Configure::read('Security.salt')); //hashed into computed token
pr($fields); //computed token passed via hidden token field in form
Check how form is processed
Now check how the submitted form is processed and compared to the passed token:
Open the CORE/Cake/Controller/Component/SecurityComponent.php. Insert some pr lines in the _validatePost() routine at the end:
pr($fieldList); //hashed into computed token
pr($unlocked); //hashed into computed token
pr(Configure::read('Security.salt')); //hashed into computed token
pr($token); //passed token from FormHelper
pr($check); //computed token
Hopefully this helps someone else who has problems with locked/unlocked or missing fields quickly figure out what is going on inside of your cake.
Remember also that you have to have an exact match between the Token generated by the FormHelper and that retrieved bu cake using Session. The mismatch can happen, as the doc says, when you dynamically generate input or when make ajax call: remember to serialize the form and submit it via ajax!
If you have input tag generated not generated by using the FormHelper, you have to unlock'em. For example in your beforeFilter():
$this->Security->unlockedFields =
array('MyModel.some_field1','MyModel.some_field2')
where field1 and field2 are fields generated "by hand", i.e. by not using the Helper.
To answer the question: "Is there any way to get the detailed error description?"
First thing is to add more valuable debugging to your controller when it comes to SecurityComponent. Here's one way to do it:
public function beforeFilter() {
parent::beforeFilter();
//your beforeFilter code
//Enable CSRF and other protections
$this->Security->csrfExpires = '+1 hour';
$this->Security->csrfUseOnce = true;
$this->Security->blackHoleCallback = 'blackhole';
}
public function blackhole($errorType) {
$errorMap['auth'] = 'form validation error, or a controller/action mismatch error.';
$errorMap['csrf'] = 'CSRF error.';
$errorMap['get'] = 'HTTP method restriction failure.';
$errorMap['post'] = $errorMap['get'];
$errorMap['put'] = $errorMap['get'];
$errorMap['delete'] = $errorMap['get'];
$errorMap['secure'] = 'SSL method restriction failure.';
$errorMap['myMoreValuableErrorType'] = 'My custom and very ' .
'specific reason for the error type.';
CakeLog::notice("Request to the '{$this->request->params['action']}' " .
"endpoint was blackholed by SecurityComponent due to a {$errorMap[$errorType]}");
}
As AD7six mentioned take a look at the CORE/Cake/Controller/Component/SecurityComponent.php. Specifically SecurityComponent::startup(). In that method you will notice that SecurityComponent::blackhole() method is ran a few times. It's ran whenever the criteria fails a security check and looks like this:
return $this->blackHole($controller, 'auth');
In this case 'auth' represents the type of security check that failed. You could customize the 'auth' string to be more valuable. For example instead of 'auth' use 'myMoreValuableErrorType' and then map that to something more meaningful.
So instead of running $this->blackHole($controller, 'auth') when a security check fails, you would run $this->blackHole($controller, 'myMoreValuableErrorType') and then map 'myMoreValuableErrorType' to a specific reason on why it failed by using the code above.
I currently have two sorted sets and I am trying to get all scores and members from one set and use it to remove members from the other set. The module that I am using is node_redis.
Right now I am trying to get the members and scores by calling client.zrange() and storing the reply in an array.
Am I correct in assuming the reply would be in array form? I realize the redis api says it returns a "Multi-bulk reply" but what does that mean exactly and how would I go about using it if it isn't an array?
I also have another question and that is can I use an array when using zadd()?
An example would be like this.
client.zadd(historyKey, scores, members, function(err, reply){});
Where scores and members are arrays.
EDIT:
I am working with receiving and parsing SNMP Traps. Basically I receive a trap and check its alarm type. The useful information in these traps are the alarm type and the full trap name. I check to see if the alarm is a 0,1, or 2.
If it's a 1, then I store it in my Current sorted set at the unix time I received it. If it's a 0 or 2 I know that type of alarm is done and that I need to remove all traps like it from the Current set and put them into the History set along with the one I just received.
In order to remove the traps from the Current and put them into the History I had to create a separate set for each individual trap in order to keep track of where they would be located in the Current set.
That is if I receive the trap "RGB Gamut Error( ----Bb )" at time 1346276537 and store it in Current, I also store the exact score and member in a separate set with key "IPAddress:RGB Gamut Error".
That way when I receive alarm type 0 or 2 with the name "RGB Gamut Error" I can just append the IP Address to the front of it, go do zrange on that set, then add to History and remove from Current. And lastly delete the "IPAddress:RGB Gamut Error" set so I can start fresh.
Sidenote: My members actually have two numbers added to the end in order to make each member unique and not overwrite each other. This is really there only purpose.
Ex: IPAdress::RGB Gamut Error( Rr--Bb ):5:46
Am I correct in assuming the reply would be in array form?
Yes, node_redis will give you the reply from a zrange as an array.
I also have another question and that is can I use an array when using zadd()? An example would be like this.
No. Before redis 2.4, you could only send one parameter at a time (so zadd key score member). Since redis 2.4, zadd (and many other commands) are variadic, i.e. they accept any number of parameters -- but not as an array. You still have to call it like this:
client.zadd(key, score1, member1, score2, member2, ..., function(err, reply){});
You could do some .apply trickery, but you would have to zip the scores and members arrays into one array first.
Update:
If you already have scores and members arrays, you could merge them into one array like this:
var scores = [1, 2, 3],
members = ['a', 'b', 'c'];
function merge (other) {
return function (result, current, index) {
result.push(current, other[index]);
return result;
}
}
var merged = scores.reduce(merge(members), []);
// Now merged = [1, 'a', 2, 'b', 3, 'c'];
var args = [key].concat(merged).concat(function(err, reply){});
client.zadd.apply(client, args);
I make an ajax request to couchdbwith POST method, giving a list of keys of the docs I want to retrieve.
Everything seems to work fine except the fact that I get 0 rows because the offset is set on the last line.
So it means that:
I'm communicating well with couchdb server (cloudant)
the POST method works
it seems to retrieve the list but just giving it with the offest of last element, i.e. an empty list
Also, trying to order the results differently had no success.
riList var is something like this (from google chrome dev tools):
keys: Array[194]
0: "Wire line diamond core drilling rig"
1: "VUA - isotope geochemistry laboratory"
2: "Volcanologic and Seismological Observatories"
3: "VESOG"
4: "Utrecht University - TecLab, Tectonic Laboratory"
5: "Utrecht University - Experimental and Analytical Laboratories"
.....
which basically is the same of
var riList=["Wire line diamond core drilling rig", "VUA - isotope geochemistry laboratory","Volcanologic and Seismological Observatories","VESOG","Utrecht University - TecLab, Tectonic Laboratory","Utrecht University - Experimental and Analytical Laboratories"];
Here is the code
var riList= ListOfRU.pluck('ri_name');
var queryParams={"keys":riList};
var riResponseList=[];
var ajaxURL= ('_view/'+ self.parentMcDropDownValue);
console.log(ajaxURL, queryParams);
$.ajax({ //retrieve and show on map LABORATORY coordinates
async: true,
url: ajaxURL,
type:"POST",
data:JSON.stringify(queryParams),
dataType: 'json',
timeout:5000,
success:function(response){
console.log("response",response);
riResponseList=response.rows;
},
error:function(){
alert('fetching error');
}
});
chrome developer tools output
response
Object
offset: 194
rows: Array[0]
total_rows: 194
__proto__: Object
as you can see in the output of chrome devtools the offset is 194 so that I have an array with 0 rows because it starts from the last key.
Any idea?
I was tempted to delete this question when I found the bug.
But finally I decided to let it and to explain what was wrong.
If you feel it should be deleted, please motivate this and I'll delete it.
So the answer to my question is very simple: the keys I was retrieving WERE NOT the keys I was selecting with the "keys" parameter.
The error was indeed in the map function where I wrote:
//WRONG ONE!!
function(doc){
if(doc.doctype=='ri'){
emit(doc.ri, doc);
}
}
INSTEAD OF
//RIGHT ONE!!
function(doc){
if(doc.doctype=='ri'){
emit(doc.ri_name, doc);// RI_NAME INSTEAD OF RI!!!!!
}
}
So the lesson is:
When you get an offset which equals the lenght of the array, check if the results are really the one you want to obtain with the map function.