XTB API JSON cannot modify existing trade position - json

I am using a xAPI Playground for testing, link here:
https://playground.xapi.pro/
I want to edit/modify existing position with command: tradeTransaction
Documentation says to modify existing position I should use "type" as 3 and "cmd" should match existing position (0 for BUY and 1 for SELL)
{
"command": "tradeTransaction",
"arguments": {
"tradeTransInfo": {
"cmd": 1,
"customComment": "Some text",
"expiration": 0,
"order": order_number_as_int ,
"price": open_price_as_double,
"sl": my_double_value,
"tp": my_another_double_value,
"symbol": "f.e. OIL.WTI",
"type": 3,
"volume": 0.01
}
}
}
Error code
{
"status": false,
"errorCode": "SE199",
"errorDescr": "Internal error"
}
All possible data collected from API about existing position:
{'cmd': 1, 'order': 474325736, 'digits': 2, 'offset': 0, 'order2': 474325838, 'position': 474325736, 'symbol': 'OIL.WTI', 'comment': '', 'customComment': '', 'commission': 0.0, 'storage': 0.0, 'margin_rate': 0.0, 'close_price': 76.65, 'open_price': 76.57, 'nominalValue': 0.0, 'profit': -3.56, 'volume': 0.01, 'sl': 80.0, 'tp': 70.0, 'closed': False, 'timestamp': 1676665564666, 'spread': 0, 'taxes': 0.0, 'open_time': 1676663063081, 'open_timeString': 'Fri Feb 17 20:44:23 CET 2023', 'close_time': None, 'close_timeString': None, 'expiration': None, 'expirationString': None},
API documentation is here:
http://developers.xstore.pro/documentation/#tradeTransaction
Ofc I tried every possible value in "cmd" and "type" but it does not help.
Error code sometimes are diffrent, f. e:
{
"command": "tradeTransaction",
"arguments": {
"tradeTransInfo": {
"cmd": 3,
"customComment": "Some text",
"expiration": 0,
"order": 474325838,
"price": 0,
"sl": 0,
"tp": 0,
"symbol": "OIL.WTI",
"type": 3,
"volume": 0.01
}
}
}
Error code:
{
"status": false,
"errorCode": "BE4",
"errorDescr": "remaining nominal must be greater than zero"
}
Any ideas what I can do wrong?
I am in touch with XTB support, still waiting for response.
Thanks in advance for any help!

Related

Convert JSON list to table where one record is a list

I have a JSON list with 253 entries and 7 records where the 7th record is a list with usually 2 entries.
I'm trying to convert this in Power Query to give me a table output. I've only really ever used the basic connection in Excel to do this automatically without problems.
My current error is:
Expression.Error: We cannot convert a value of type Record to type Text.
Details:
Value=Record
Type=Type
I'm not sure where to go and I can't see examples for my specific situation, although I'm sure there are plenty of examples - just that I'm not good enough with this to understans
[
{
"Id": "lorum-ipsum1",
"Description": "sitename 1",
"Latitude": 1.0,
"Longitude": -1.0,
"Postcode": "AB1 2CD",
"CountryCode": "GB",
"Connectors": [
{
"Id": "lorum-ipsum1-a",
"Number": 1,
"Status": 1,
"ErrorCode": "NoError",
"ChargepointName": "GP00000",
"Shape": 0,
"Mode": 0,
"Volts": 240,
"Amps": 0,
"Phase": 2,
"PricingInformationUrl": "hrefhere",
"UsageRestrictions": []
},
{
"Id": "lorum-ipsum1-b",
"Number": 2,
"Status": 1,
"ErrorCode": "NoError",
"ChargepointName": "GP0000",
"Shape": 0,
"Mode": 0,
"Volts": 240,
"Amps": 0,
"Phase": 2,
"PricingInformationUrl": "hrefhere",
"UsageRestrictions": []
}
]
},
{
"Id": "lorum-ipsum2",
"Description": "sitename 2",
"Latitude": 1.0,
"Longitude": -1.0,
"Postcode": "AB1 2CD",
"CountryCode": "GB",
"Connectors": [
{
"Id": "lorum-ipsum2-a",
"Number": 1,
"Status": 1,
"ErrorCode": "NoError",
"ChargepointName": "GP00000",
"Shape": 0,
"Mode": 0,
"Volts": 240,
"Amps": 0,
"Phase": 2,
"PricingInformationUrl": "hrefhere",
"UsageRestrictions": []
},
{
"Id": "lorum-ipsum2-b",
"Number": 2,
"Status": 1,
"ErrorCode": "NoError",
"ChargepointName": "GP0000",
"Shape": 0,
"Mode": 0,
"Volts": 240,
"Amps": 0,
"Phase": 2,
"PricingInformationUrl": "hrefhere",
"UsageRestrictions": []
}
]
},
I think you want to use Table.FromRecords function to transform the JSON into a table. However, since the Connectors field of each record is itself a list of records, I think you will need to call it a second time.
To give you an example:
let
serialised = "[{""Id"":""lorum-ipsum1"",""Description"":""sitename 1"",""Latitude"":1,""Longitude"":-1,""Postcode"":""AB1 2CD"",""CountryCode"":""GB"",""Connectors"":[{""Id"":""lorum-ipsum1-a"",""Number"":1,""Status"":1,""ErrorCode"":""NoError"",""ChargepointName"":""GP00000"",""Shape"":0,""Mode"":0,""Volts"":240,""Amps"":0,""Phase"":2,""PricingInformationUrl"":""hrefhere"",""UsageRestrictions"":[]},{""Id"":""lorum-ipsum1-b"",""Number"":2,""Status"":1,""ErrorCode"":""NoError"",""ChargepointName"":""GP0000"",""Shape"":0,""Mode"":0,""Volts"":240,""Amps"":0,""Phase"":2,""PricingInformationUrl"":""hrefhere"",""UsageRestrictions"":[]}]},{""Id"":""lorum-ipsum2"",""Description"":""sitename 2"",""Latitude"":1,""Longitude"":-1,""Postcode"":""AB1 2CD"",""CountryCode"":""GB"",""Connectors"":[{""Id"":""lorum-ipsum2-a"",""Number"":1,""Status"":1,""ErrorCode"":""NoError"",""ChargepointName"":""GP00000"",""Shape"":0,""Mode"":0,""Volts"":240,""Amps"":0,""Phase"":2,""PricingInformationUrl"":""hrefhere"",""UsageRestrictions"":[]},{""Id"":""lorum-ipsum2-b"",""Number"":2,""Status"":1,""ErrorCode"":""NoError"",""ChargepointName"":""GP0000"",""Shape"":0,""Mode"":0,""Volts"":240,""Amps"":0,""Phase"":2,""PricingInformationUrl"":""hrefhere"",""UsageRestrictions"":[]}]}]",
deserialised = Json.Document(serialised),
toTable = Table.FromRecords(deserialised),
transformConnectors = Table.TransformColumns(toTable, {{"Connectors", Table.FromRecords}})
in
transformConnectors
which gives me:
From there, you can explore/continue the rest of the transformation yourself (since you haven't specified what you want).
You can expand some/all nested columns inside of the Connectors column by either clicking the icon highlighted in the image above -- or writing any necessary M code.

Amcharts does not show 2d Y axis (Json data)

I have the following Json data (extract) that I use to graph a dual Y axis chart with amchart:
[{"Day":"24-05 10H","Production":"0.82431267","USD":"482.02837415988"},{"Day":"24-05 11H","Production":"0.83045272","USD":"485.61885435808"},{"Day":"24-05 12H","Production":"0.83441691","USD":"487.93696995924"},{"Day":"24-05 01H","Production":"0.84323421","USD":"493.09300957644"},{"Day":"24-05 02H","Production":"0.85096095","USD":"497.61132896580006"},{"Day":"24-05 03H","Production":"0.85694953","USD":"501.11323496092"},{"Day":"24-05 04H","Production":"0.868104","USD":"507.635967456"},{"Day":"24-05 06H","Production":"0.8802085","USD":"519.796567173"},{"Day":"24-05 07H","Production":"0.8913847","USD":"532.3438566870001"},{"Day":"24-05 08H","Production":"0.89426695","USD":"530.7322322868499"},{"Day":"24-05 09H","Production":"0.89904346","USD":"531.08385173466"},{"Day":"24-05 10H","Production":"0.90740126","USD":"535.88759172324"},{"Day":"24-05 11H","Production":"0.91944257","USD":"554.8872687652799"},{"Day":"25-05 12H","Production":"0.92783829","USD":"554.54203862259"},{"Day":"25-05 02H","Production":"0.94182047","USD":"565.81654194143"},{"Day":"25-05 03H","Production":"0.94743531","USD":"574.52571941931"},{"Day":"25-05 04H","Production":"0.95331299","USD":"579.83927978564"},{"Day":"25-05 05H","Production":"0.9563386","USD":"580.4497132700001"},{"Day":"25-05 06H","Production":"0.96906754","USD":"594.5520078162"},{"Day":"25-05 07H","Production":"0.97823946","USD":"580.6878346533"},{"Day":"25-05 08H","Production":"0.97823946","USD":"580.6878346533"},{"Day":"25-05 09H","Production":"0.99806768","USD":"595.88932187024"},{"Day":"25-05 10H","Production":"0.00706363","USD":"4.21520001161"},{"Day":"25-05 11H","Production":"0.01715723","USD":"10.19647316008"},{"Day":"25-05 12H","Production":"0.02629501","USD":"15.77321951856"},{"Day":"25-05 01H","Production":"0.04011605","USD":"24.3299831645"}
And the following code used to graph:
<script>
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"dataLoader": {
"url": "http://x.x.x.x/json.php", "format": "json"
},
"valueAxes": [{
"id": "v1",
"startDuration": 1,
"axisColor": "#FF6600",
"axisThickness": 5,
"gridAlpha": 0.1,
"axisAlpha": 1
}, {
"id": "v2",
"axisColor": "#FCD202",
"axisThickness": 5,
"gridAlpha": 0,
"axisAlpha": 1,
"position": "right",
"synchronizeWith": "v1",
"synchronizationMultiplier": 5
}],
"graphs": [{
"valueAxis": "v1",
"type": "column",
"fillColorsField": "#B0DE09",
"balloonText": "[[category]]: <b>[[value]]</b>",
"fillAlphas": 0.8,
"lineAlpha": 0.2,
"title": "Production Crypto",
"valueField": "Production"
}, {
"valueAxis": "v2",
"type": "smoothedLine",
"lineColor": "#364cf2",
"lineThickness": 3,
"bulletBorderThickness": 1,
"hideBulletsCount": 30,
"title": "Production USD",
"valueField": "USD",
"fillAlphas": 0
}],
"chartCursor": {
"categoryBalloonEnabled": false,
"cursorAlpha": 0,
"zoomable": false
},
"categoryField": "Day",
"categoryAxis": {
"gridPosition": "start",
"gridAlpha": 0,
"tickPosition": "start",
"tickLength": 20
}
});
</script>
This is the screenshot of the graph I get:
Where the blue line for the USD series clearly does not render properly.
I have been able to get a dual Y axis graph showing properly (http://jsfiddle.net/spjem6b8/) with random generated data, so I guess this is the json part that generates this issue.
What am I doing wrong here?
Thanks
Your synchronizationMultiplier isn't high enough to make the second Y axis large enough to encapsulate your USD values in your dataset. In your current setup, your second Y axis values range from 0-6, but your USD values range from 4-600. Increase your syncrhonizationMultiplier to 600 in this case and it will work.
"valueAxes": [{
"id": "v1",
"startDuration": 1,
"axisColor": "#FF6600",
"axisThickness": 5,
"gridAlpha": 0.1,
"axisAlpha": 1
}, {
"id": "v2",
"axisColor": "#FCD202",
"axisThickness": 5,
"gridAlpha": 0,
"axisAlpha": 1,
"position": "right",
"synchronizeWith": "v1",
"synchronizationMultiplier": 600
}],
There's also an unsupported beta property called synchronizeGrid that can sometimes do this for your automatically, but it's not guaranteed to work with all value axis setting combinations so your mileage may vary. This is set at the top of the chart config:
AmCharts.makeChart("chartdiv", {
// ...
synchronizeGrid: true, //no need for synchronizeWith/Multiplier in the value axis
// ...
});
Here's an updated fiddle with the updated multiplier: http://jsfiddle.net/spjem6b8/1/

JSON data in Web_custom_request- Vugen

LR script throws warning and fails for the JSON Response.
Below is the script
char *request_json_base;
char *request_json;
web_add_header("Content-Type", "application/json; charset=utf-8");
request_json_base= "{\"GLDefaultId\":0,\"ProjectId\":{ContactProjectId},\"CoaMainId\":10,\"UserId\":{UserId},\"Notes\":\"\",\"PRO_GLDefaultValue\":[{\"GLDefaultValueId\":0,\"GLDefaultId\":0,\"SegmentId\":16,\"Alias\":\"ACT\",\"SegmentType\":\"DETAIL\",\"FunctionTypeId\":0,\"Value\":\"&&&\",\"Mask\":\"&&&\",\"IsRequired\":true,\"LastModified\":null,\"IsCoaRequired\":true},{\"GLDefaultValueId\":0,\"GLDefaultId\":0,\"SegmentId\":17,\"Alias\":\"ST\",\"SegmentType\":\"SET\",\"FunctionTypeId\":0,\"Value\":\"&&\",\"Mask\":\"&&\",\"IsRequired\":false,\"LastModified\":null,\"IsCoaRequired\":false}]}",
request_json = lr_eval_string(request_json_base);
lr_save_string(request_json, "REQUEST_JSON_PARAM");
web_custom_request("PRO_GLDefault",
"URL=https://{URL}/PayrollWebApi/V1/PRO_GLDefault?userId={UserId}",
"Method=POST",
"TargetFrame=",
"Resource=0",
"RecContentType=application/json",
"Referer=",
"Snapshot=t299.inf",
"Mode=HTML",
"EncType=application/json",
"Body={REQUEST_JSON_PARAM}",
LAST);
Below is Replay Log :
Action3_SUNP_ProjectSetup_RatesandSetupInfo.c(81): Warning: The string '"GLDefaultValueId":0,"GLDefaultId":0,"SegmentId":16,"Alias":"ACT","SegmentType":"DETAIL","FunctionTypeId":0,"Value":"&&&","Mask":"&&&","IsRequired":true,"LastModified":null,"IsCoaRequired":true' with parameter delimiters is not a parameter.
Action3_SUNP_ProjectSetup_RatesandSetupInfo.c(81): Warning: The string '"GLDefaultValueId":0,"GLDefaultId":0,"SegmentId":17,"Alias":"ST","SegmentType":"SET","FunctionTypeId":0,"Value":"&&","Mask":"&&","IsRequired":false,"LastModified":null,"IsCoaRequired":false' with parameter delimiters is not a parameter.
Action3_SUNP_ProjectSetup_RatesandSetupInfo.c(83): Notify: Saving Parameter "REQUEST_JSON_PARAM = {"GLDefaultId":0,"ProjectId":1810,"CoaMainId":10,"UserId":67,"Notes":"","PRO_GLDefaultValue":[{"GLDefaultValueId":0,"GLDefaultId":0,"SegmentId":16,"Alias":"ACT","SegmentType":"DETAIL","FunctionTypeId":0,"Value":"&&&","Mask":"&&&","IsRequired":true,"LastModified":null,"IsCoaRequired":true},{"GLDefaultValueId":0,"GLDefaultId":0,"SegmentId":17,"Alias":"ST","SegmentType":"SET","FunctionTypeId":0,"Value":"&&","Mask":"&&","IsRequired":false,"LastModified":null,"IsCoaRequired":false}]}".
Action3_SUNP_ProjectSetup_RatesandSetupInfo.c(85): {"$id":"1","Message":"An error has occurred."}
Below is Body of Original Request call:
"Body={\"GLDefaultId\":0,\"ProjectId\":{ContactProjectId},\"CoaMainId\":10,\"UserId\":{UserId},\"Notes\":\"\",\"PRO_GLDefaultValue\":[{\"GLDefaultValueId\":0,\"GLDefaultId\":0,\"SegmentId\":16,\"Alias\":\"ACT\",\"SegmentType\":\"DETAIL\",\"FunctionTypeId\":0,\"Value\":\"&&&\",\"Mask\":\"&&&\",\"IsRequired\":true,\"LastModified\":null,\"IsCoaRequired\":true},{\"GLDefaultValueId\":0,\"GLDefaultId\":0,\"SegmentId\":17,\"Alias\":\"ST\",\"SegmentType\":\"SET\",\"FunctionTypeId\":0,\"Value\":\"&&\",\"Mask\":\"&&\",\"IsRequired\":false,\"LastModified\":null,\"IsCoaRequired\":false}]}",
LAST);
Below is the Successful Response during the recording:
Request :
{
"GLDefaultId": 0,
"ProjectId": 1806,
"CoaMainId": 10,
"UserId": 2,
"Notes": "",
"PRO_GLDefaultValue": [
{
"GLDefaultValueId": 0,
"GLDefaultId": 0,
"SegmentId": 16,
"Alias": "ACT",
"SegmentType": "DETAIL",
"FunctionTypeId": 0,
"Value": "&&&",
"Mask": "&&&",
"IsRequired": true,
"LastModified": null,
"IsCoaRequired": true
},
{
"GLDefaultValueId": 0,
"GLDefaultId": 0,
"SegmentId": 17,
"Alias": "ST",
"SegmentType": "SET",
"FunctionTypeId": 0,
"Value": "&&",
"Mask": "&&",
"IsRequired": false,
"LastModified": null,
"IsCoaRequired": false
}
]
}
Response:
{
"$id": "1",
"GLDefaultId": 1,
"ProjectId": 1806,
"CoaMainId": 10,
"Notes": "",
"PRO_GLDefaultValue": [
{
"$id": "2",
"GLDefaultValueId": 1,
"GLDefaultId": 1,
"Alias": "ACT",
"FunctionTypeId": 0,
"Value": "&&&",
"SegmentId": 16,
"IsRequired": true,
"ModifiedOn": "7/1/2017 4:48:06 PM",
"ModifiedBy": 2,
"PRO_GLDefault": {
"$ref": "1"
},
"LastModified": null
},
{
"$id": "3",
"GLDefaultValueId": 2,
"GLDefaultId": 1,
"Alias": "ST",
"FunctionTypeId": 0,
"Value": "&&",
"SegmentId": 17,
"IsRequired": false,
"ModifiedOn": "7/1/2017 4:48:06 PM",
"ModifiedBy": 2,
"PRO_GLDefault": {
"$ref": "1"
},
"LastModified": null
}
]
}
Please advise me how to overcome this
Thanks,
Raj
Warning is just that, a warning, not an error, and expected if you have curly braces in your post
What is line 85, where the error is generated?
See these two lines:
request_json_base= "{\"GLDefaultId\":0,\"ProjectId\":{ContactProjectId},\"CoaMainId\":10,\"UserId\":{UserId},\"Notes\":\"\",\"PRO_GLDefaultValue\":[{\"GLDefaultValueId\":0,\"GLDefaultId\":0,\"SegmentId\":16,\"Alias\":\"ACT\",\"SegmentType\":\"DETAIL\",\"FunctionTypeId\":0,\"Value\":\"&&&\",\"Mask\":\"&&&\",\"IsRequired\":true,\"LastModified\":null,\"IsCoaRequired\":true},{\"GLDefaultValueId\":0,\"GLDefaultId\":0,\"SegmentId\":17,\"Alias\":\"ST\",\"SegmentType\":\"SET\",\"FunctionTypeId\":0,\"Value\":\"&&\",\"Mask\":\"&&\",\"IsRequired\":false,\"LastModified\":null,\"IsCoaRequired\":false}]}",
request_json = lr_eval_string(request_json_base);
They are not doing what you think they are doing. You are neither allocating space for this data ( see malloc() in combination with a char * variable), nor are you assigning the value to the variable correctly for the C language (see strcpy() )
Another reference here on Stackoverflow
How to correctly assign a new string value?

parse json output for primary and secondary hosts from replSetGetStatus

I've used pymongo to connect to mongo replica set and print the status of replica set using json dump. I want to parse this output and display "name" and "stateStr" into a list or array for the user to be able to pick a particular host.Here is my json dump output:
{
{
"replSetGetStatus": {
"date": "2016-10-07T14:21:25",
"members": [
{
"_id": 0,
"health": 1.0,
"name": "xxxxxxxxxxx:27017",
"optime": null,
"optimeDate": "2016-10-07T13:50:11",
"self": true,
"state": 1,
"stateStr": "PRIMARY",
"uptime": 32521
},
{
"_id": 1,
"health": 1.0,
"lastHeartbeat": "2016-10-07T14:21:24",
"lastHeartbeatRecv": "2016-10-07T14:21:24",
"name": "xxxxxxxxxxxx:27017",
"optime": null,
"optimeDate": "2016-10-07T13:50:11",
"pingMs": 0,
"state": 2,
"stateStr": "SECONDARY",
"syncingTo": "xxxxxxxxxxxx:27017",
"uptime": 27297
},
{
"_id": 2,
"health": 1.0,
"lastHeartbeat": "2016-10-07T14:21:24",
"lastHeartbeatRecv": "2016-10-07T14:21:24",
"name": "xxxxxxxxxxxxx:27020",
"pingMs": 0,
"state": 7,
"stateStr": "ARBITER",
"uptime": 32517
}
],
"myState": 1,
"ok": 1.0,
"set": "replica1"
}
}
Please try below Javascript code. It worked for me.
use admin;
var result = rs.status();
var length = result.members.length;
for (var i=0;i<length;i++){
print ("Server Name-" +result.members[i].name);
print ("Server State-" +result.members[i].stateStr);
}

Delete element of Solr

I deleted an item you do not need to solr, but I solr response still appears.
The json:
{
"responseHeader": {
"status": 0,
"QTime": 1,
"params": {
"facet": "true",
"q": "*:*",
"facet.limit": "-1",
"facet.field": "manufacturer",
"wt": "json",
"rows": "0"
}
},
"response": {
"numFound": 84,
"start": 0,
"docs": []
},
"facet_counts": {
"facet_queries": {},
"facet_fields": {
"manufacturer": [
"Chevrolet",
0,
"abarth",
1,
"audi",
7,
"austin",
1,
"bmw",
2,
"daewoo",
2,
"ford",
1,
"fso",
1,
"honda",
1,
"hyundai",
1,
"jaguar",
3,
"lexus",
1,
"mazda",
1,
"mitsubishi",
1,
"nissan",
1,
"pontiac",
1,
"seat",
1
]
},
"facet_dates": {},
"facet_ranges": {}
}
}
the deleted item is "chevrolet", now this to '0 'but it still appears.
"manufacturer":["Chevrolet",0,
I wish I could delete the item completely, is that possible.. Thanks.
Here is a two step approach I would follow:
Make sure changes(deletion) is committed. You may issue a commit
If it still shows facets with zero count, you may append &facet.mincount=1 to your query
&facet.mincount=1 will make sure facets with zero count do not show up.
For more details, please refer to: http://wiki.apache.org/solr/SimpleFacetParameters#facet.mincount
In your case probably it is because of uninverted index created by solr.
Pass facet.mincount=1 in your query to get rid of this problem.