I use coinbase-node and got transaction API response.
In this response, I can see something like:
{
...
"created_at": "2019-04-21T13:58:12Z",
"updated_at": "2019-04-21T13:58:12Z",
"resource": "transaction",
"resource_path": "/v2/accounts/68a42d04-2075-529c-8cd8-183cd148c45f/transactions/279db234-ca73-5e66-b70a-94502d44739e",
"instant_exchange": false,
"trade": {
"id": "f4ff2d5d-07b7-5c2c-807d-7b98591b488a",
"resource": "trade",
"resource_path": "/v2/accounts/68a42d04-2075-529c-8cd8-183cd148c45f/trades/f4ff2d5d-07b7-5c2c-807d-7b98591b488a"
},
"details": {
"title": "Converted to Bitcoin Cash",
"subtitle": "Using BTC Wallet",
"payment_method_name": "BTC Wallet"
},
...
}
my goal is to find a way to get a trade by ID
any ideas?
This post should help you.
How to import conversions in coinbase api?
At this moment it is impossible to get trades from API call, but you can construct object yourself using trade Id.
Related
When I run this initial query:
https://graph.microsoft.com/beta/users/delta?$select=id,displayName,manager,jobTitle&$filter=id+eq+'87fa2ed7-5e58-4ff5-85ca-42a973e103e7'
I get the following response (as expected):
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#users(id,displayName,jobTitle,manager)",
"#odata.nextLink": "https://graph.microsoft.com/beta/users/delta?$skiptoken=<removed>",
"value": [
{
"displayName": "Jane Doe",
"jobTitle": "Super Administrator",
"id": "87fa2ed7-5e58-4ff5-85ca-42a973e103e7",
"manager#delta": [
{
"#odata.type": "#microsoft.graph.user",
"id": "1ab00b74-6f7e-45ca-8629-22d64632501d"
}
]
}
]
}
I follow the #odata.nextLink URL, which returns:
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#users",
"#odata.deltaLink": "https://graph.microsoft.com/beta/users/delta?$deltatoken=<removed>",
"value": []
}
I don't really understand why it doesn't just give me the deltaLink in the first call, but that isn't the issue. At this point, I make a change to the user's job title in Azure AD (outside of Graph API) and then follow the #odata.deltaLink, which returns:
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#users",
"#odata.deltaLink": "https://graph.microsoft.com/beta/users/delta?$deltatoken=<removed>",
"value": [
{
"displayName": "Jane Doe",
"jobTitle": "Administrator",
"id": "87fa2ed7-5e58-4ff5-85ca-42a973e103e7"
}
]
}
No manager!!
The only attribute changed was the job title; Manager is unchanged. This behavior is the same in both the v1.0 and beta endpoints. Also, I am not using the "prefer:return=minimal" header (or any additional headers for that matter).
Can anyone provide some insight into this?
I have a logic app with started when there is a message in serviceBus queue. The message is being published to the service bus from the DevOps pipeline using "PublishToAzureServiceBus" as a JSON message or from the pipeline webhook.
But getting an issue while converting a message from service bus to original JSON format, not able to get valid JSON object. It's getting append with some Serialization object.
I have tried with base64 decode, and JSON converts but have not been able to get success.
Below is the content of the message it looks like.
Any pointer on how can solve this?
Sample message sent
{
"id": "76a187f3-c154-4e60-b8bc-c0b754e54191",
"eventType": "build.complete",
"publisherId": "tfs",
"message": {
"text": "Build 20220605.8 succeeded"
},
"detailedMessage": {
"text": "Build 20220605.8 succeeded"
},
"resource": {
"uri": "vstfs:///Build/Build/288",
"id": 288,
"buildNumber": "20220605.8",
"url": "https://dev.azure.com/*******/_apis/build/Builds/288",
"startTime": "2022-06-05T14:47:01.1846966Z",
"finishTime": "2022-06-05T14:47:16.7602096Z",
"reason": "manual",
"status": "succeeded",
"drop": {},
"log": {},
"sourceGetVersion": "LG:refs/heads/main:********",
"lastChangedBy": {
"displayName": "Microsoft.VisualStudio.Services.TFS",
"id": "00000000-0000-0000-0000-000000000000",
"uniqueName": "***************"
},
"retainIndefinitely": false,
"definition": {
"definitionType": "xaml",
"id": 20,
"name": "getReleaseFile",
"url": "https://dev.azure.com/************/_apis/build/Definitions/20"
},
"requests": [
{
"id": 288,
"url": "https://dev.azure.com/B*****/**********/_apis/build/Requests/288",
"requestedFor": {
"displayName": "B*****.sag",
"id": "*******",
"uniqueName": "B**********"
}
}
]
},
"resourceVersion": "1.0",
"resourceContainers": {
"collection": {
"id": "*******",
"baseUrl": "https://dev.azure.com/B*****/"
},
"account": {
"id": "******",
"baseUrl": "https://dev.azure.com/B*****/"
},
"project": {
"id": "**********",
"baseUrl": "https://dev.azure.com/B*****/"
}
},
"createdDate": "2022-06-05T14:47:28.6089499Z"
}
Message received
#string3http://schemas.microsoft.com/2003/10/Serialization/�q{"id":"****","eventType":"build.complete","publisherId":"tfs","message":{"text":"Build 20220605.8 succeeded"},"detailedMessage":{"text":"Build 20220605.8 succeeded"},"resource":{"uri":"vstfs:///Build/Build/288","id":288,"buildNumber":"20220605.8","url":"https://dev.azure.com/*****/********/_apis/build/Builds/288","startTime":"2022-06-05T14:47:01.1846966Z","finishTime":"2022-06-05T14:47:16.7602096Z","reason":"manual","status":"succeeded","drop":{},"log":{},"sourceGetVersion":"LG:refs/heads/main:f0b1a1d2bd047454066cf21dc4d4c710bca4e1d7","lastChangedBy":{"displayName":"Microsoft.VisualStudio.Services.TFS","id":"00000000-0000-0000-0000-000000000000","uniqueName":"******"},"retainIndefinitely":false,"definition":{"definitionType":"xaml","id":20,"name":"getReleaseFile","url":"https://dev.azure.com/******/_apis/build/Definitions/20"},"requests":[{"id":288,"url":"https://dev.azure.com/*****/******/_apis/build/Requests/288","requestedFor":{"displayName":"baharul.sag","id":"******","uniqueName":"baharul.*****"}}]},"resourceVersion":"1.0","resourceContainers":{"collection":{"id":"3*****","baseUrl":"https://dev.azure.com/*****/"},"account":{"id":"******","baseUrl":"https://dev.azure.com/*****/"},"project":{"id":"*******","baseUrl":"https://dev.azure.com/*****/"}},"createdDate":"2022-06-05T14:47:28.6089499Z"}
When reading message from service bus in peek mode can see as below where <#string3http://schemas.microsoft.com/2003/10/Serialization/��> is appended to json string
Publish using PublishToAzureServiceBus from Azure pipeline.
Publish from Azure DevOps project webhook
I believe what is happening is that you have two different types of serialisation in the body of the brokered message created by the PublishToAzureServiceBus task. This is because the brokered message only supports binary content.
So the json is initially serialised as a binary string using the data contract serialiser.
How to solve this? Do the following before passing to your json deserialiser - unfortunately the logic app isn't doing this:
byte[] messageContent = brokeredMessage.GetBody<byte[]>();
string messageContentStr = Encoding.UTF8.GetString(messageContent);
I probably wouldn't use a logic app to do the reading of the message because to insert c# like I suggest you're gonna need to call an azure function or similar. I'd create an azure function to read your messages as above.
I am playing with a sample Alexa Smart Home skill - I am not talking to any real hardware or back-end, just trying to get message flow working. I have set up a simple switch/plug/light that can just support turning On/Off - and I have account linked working and the skill enabled. When I try looking at it via the Alexa app on phone or web (with debug enabled) it always says the device isn't responding, or it's "Failed to Retrieve State". I can definitely see the messages in Cloud Watch as follows.
Any idea why I'd be chronically getting such a response??
Request:
"directive": {
"endpoint": {
"cookie": {},
"endpointId": "endpoint-003",
"scope": {
"token": "<<<SUPRESSING>>",
"type": "BearerToken"
}
},
"header": {
"correlationToken": "<<SHORTENED>>",
"messageId": "50397414-bb9d-412f-8a2c-15669978ab64",
"name": "ReportState",
"namespace": "Alexa",
"payloadVersion": "3"
},
"payload": {}
}
}
Response:
{
"context": {
"properties": [
{
"name": "connectivity",
"namespace": "Alexa.EndpointHealth",
"timeOfSample": "2020-06-29T16:49:59.00Z",
"uncertaintyInMilliseconds": 0,
"value": "OK"
},
{
"name": "powerState",
"namespace": "Alexa.PowerController",
"timeOfSample": "2020-06-29T16:49:59.00Z",
"uncertaintyInMilliseconds": 0,
"value": "ON"
}
]
},
"event": {
"endpoint": {
"endpointId": "endpoint-003",
"scope": {
"token": "Alexa-access-token",
"type": "BearerToken"
}
},
"header": {
"correlationToken": "<<SHORTENED>>",
"messageId": "7a8b9a71-adda-41b8-acba-4d3855374845",
"name": "Response",
"namespace": "Alexa",
"payloadVersion": "3"
},
"payload": {}
}
}
Problem was: The "name" in my header response should have been "ReportState". "Response" is only used for things that set/change values.
My general advice is to always verify that THREE things are good:
Initial "Discovery"
"Response" messages
General "ReportState" queries.
By this - I mean that:
Anything you advertised as should be reported in "discovery" better be reported in other ("ReportState") messages. If you advertise a "PowerController" - if your ReportStates don't contain status for that, you'll either not see the status, or it'll keep retrying forever (continuing to look for it) - or you might get some sort of an error.
If you CHANGED your discovery stuff - make sure that you really removed, re-discovered, and that the states (above) for the new additions/removals are okay
Always make sure that "EndpointHealth" is being reported.
I am using coinbase pro api using sandbox and testing a sell case.
The order i am placing is
const sellParams:any = {
'side': 'sell',
'product_id': 'BTC-USD',
'type': 'market',
'size': '0.009'
}
the response in order status comes as below
{
"type": "market",
"id": "5846345c-c070-44bf-9d31-ec07a1c9892c",
"product_id": "BTC-USD",
"side": "sell",
"post_only": false,
"created_at": "2019-08-12T04:08:29.845922Z",
"fill_fees": "0.0297509100000000",
"filled_size": "0.00300000",
"executed_value": "9.9169700000000000",
"status": "done",
"settled": true,
"done_at": "2019-08-12T04:08:29.853Z",
"done_reason": "canceled",
"size": "0.00900000"
}
the question is on executed value which shows 9.9169... should not it be around 100 USD ?
so basically sandbox prices are different than the actual prices and thats where the confusion was.
Right now coinbase supports so called "conversions" that allow to convert from one currency to another. For example, you can convert some of your BTC to XRP.
In CSV they return both buy & sell amount in Notes field:
Notes | Converted 0.27235696 BTC to 3,731.323138 XRP.
However, they only return buy amount of that conversion in apy /transactions endpoint:
{"id":"b...8","type":"trade","status":"completed",
"amount":{"amount":"3731.323138","currency":"XRP"},
"native_amount":{"amount":"1790.76","currency":"CAD"},
"description":null,
"...,
"instant_exchange":false,
"trade":{"id":"34...2",
"resource":"trade","resource_path":"\/v2\/accounts\/e...\/trades\/..,."},
"details":{"title":"Converted to XRP","subtitle":"Using BTC Wallet","payment_method_name":"BTC Wallet"}};
I can't find any way to find how much bitcoin was sold for such conversion using api endpoints.
There is also reference to account/id/trades endpoint, but it returns 404 to me
I have the same problem and found a way to do it.
Every transaction that is a trade has "trade" property which has "id" property.
If you converted USDC into XRP, in the XRP transactions of the specific user you will have transaction which has "trade" property with "id" that is the same as the "id" from one of the USDC transactions "trade" property's "id".
trade:
id: "0dfc2e63-21e7-5b25-99d9-49863eb37887"
resource: "trade"
resource_path: "/v2/accounts/a4b1dc86-a813-572b-9978-d1f9c9ba53bc/trades/0dfc2e63-21e7-5b25-99d9-49863eb37887"
__proto__: Object
details:
title: "Converted from USD Coin"
subtitle: "Using USDC Wallet"
payment_method_name: "USDC Wallet"
trade:
id: "0dfc2e63-21e7-5b25-99d9-49863eb37887"
resource: "trade"
resource_path: "/v2/accounts/a4b1dc86-a813-572b-9978-d1f9c9ba53bc/trades/0dfc2e63-21e7-5b25-99d9-49863eb37887"
__proto__: Object
details:
title: "Converted to XRP"
subtitle: "Using USDC Wallet"
payment_method_name: "USDC Wallet"
Look at the trade id of the two transactions. They are the same.
Hope this helps.
DISCLAIMER: it appears that the Coinbase response for a trade transaction doesn't provide the correct amounts that you'd see in the Coinbase API or other CSV reports. The "spot price" and fees don't match with what you'd be able to determine from looking at the independent transactions. The answer provided by Raskolnikov does solve this issue.
The Coinbase API documentation appears to be lacking (or Coinbase isn't publicly documenting it), but there is a /trades endpoint which will give you more information about your trade transaction.
Also, the data in the transaction response is lying to you because the trade.resource_path results in a 404. If you strip the /accounts/68a42d04-2075-529c-8cd8-183cd148c45f from the URL of trace.resource_path property, you'll end up with /v2/trades/f4ff2d5d-07b7-5c2c-807d-7b98591b488a, which I did find to work. Alternatively, you can just construct the trade URI from the trade.id property.
As an example response, here is one of mine, with some information removed:
{
"data": {
"created_at": "2022-01-01T00:00:00Z",
"display_input_amount": {
"amount": "1.43",
"currency": "USD"
},
"id": "d1feb056-2e42-4a7f-b310-807e189d2e26",
"input_amount": {
"amount": "0.02551020",
"currency": "MLN"
},
"output_amount": {
"amount": "0.02096069",
"currency": "AVAX"
},
"exchange_rate": {
"amount": "0.82165918",
"currency": "AVAX"
},
"unit_price": {
"target_to_fiat": {
"amount": "68.22",
"currency": "USD"
},
"target_to_source": {
"amount": "1.21704963",
"currency": "MLN"
}
},
"fee": {
"amount": "0.00",
"currency": "USD"
},
"status": "completed",
"updated_at": "2022-01-01T00:00:00Z",
"user_warnings": [],
"applied_subscription_benefit": false,
"fee_without_subscription_benefit": null
}
}
Watching Coinbase API from webapp I understand what endpoint you need to call:
Have to know base_id of crypto that you want to sell and base_id of crypto want to buy. You can know it by call GET "https://api.coinbase.com/v2/ /assets/prices?base=USD&filter=holdable&resolution=latest" and get from response the "base_id" of your currencies.
Make an order by calling POST "https://api.coinbase.com/v2/trade" with a request body in json like this:
{ 'amount': [amount that you want to convert], 'amount_asset': [currency of amount that you want to convert], 'amount_from': 'input', 'source_asset': ["base_id" of crypto that you want to sell], 'target_asset': ["base_id" of crypto that you want to buy] }
If previous POST "/trade" response code is 201, you have to get the "id" value of response's json and do a commit of your order by calling POST "https://api.coinbase.com/v2/trades/[id of json response of previous https://api.coinbase.com/v2/trade POST"]. If the response code of this POST commit is 201, your exchange is started and if there are not error in coinbase, your conversion is done!