How to import conversions in coinbase api? - coinbase-api

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!

Related

Paypal API integration for debit and Credit card with Node JS

I am tiring to add credit debit card integration that are already saved in our database and I don't want user to fill those information to the paypal debit/credit card payment form.
I want to know
Is there a way to auto populate information from my database to paypal from?
Or how can I use orders API to directly pass the information to the paypal using API integration.
The Paypal really is a mess. Can anyone please help me in the integration.
NOTE : I am using React JS as front-end and nestjs as back-end.
You can't populate a form, and storing credit card information in your database is a potentially problematic practice you should review (better to tokenize/vault it) and requires a full PCI self-assessment review.
But as for how to send credit cards to PayPal via an API, if anaccount is enabled for Advanced Credit and Debit Card processing, the below might allow you to use the v2/checkout/orders API with card details in the payment_source object
(Edit: apparently more permissions are needed from PayPal for this)
{
"intent": "CAPTURE",
"payer": {
"name":{
"given_name": "John",
"surname": "Doe"
},
"email_address":"johndoe#buyersemail.com"
},
"purchase_units": [
{
"reference_id": "0000",
"description": "Transaction description",
"custom_id": "Optional arbitrary private transaction-related ID/data, 127 chars",
"soft_descriptor": "Shows On CC statement",
"amount": {
"currency_code": "USD",
"value": "100",
"breakdown": {
"item_total": {
"currency_code": "USD",
"value": "100"
},
"shipping": {
"currency_code": "USD",
"value": "0"
}
}
},
"shipping":{
"name":{
"full_name":"John Doe"
},
"address": {
"address_line_1": "123 nowhere lane ",
"address_line_2": "Unit 123",
"admin_area_2": "San Jose",
"admin_area_1": "CA",
"postal_code": "95131",
"country_code": "US"
}
}
}
],
"payment_source": {
"card": {
"number": "4032038000494967",
"expiry": "2023-04",
"security_code":"123",
"name": "John Doe",
}
}
}

wrong value shows on sell with coinbase pro api

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.

How to get 'trades' resource from Coinbase API?

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.

Describe api for google people contact/gmail contact using client library

I want details about fields of gmail contact. Using that, i want to create a form a like what is being shown in gmail contact creation page . I could get describe for salesforce contact. i need same for google contact. i give a sample format for lastName
{
"label": "Last Name",
"name": "LastName",
"type": "string",
"createable": true,
"updateable": true,
"custom": false,
"validations": {
"required": true,
"maxlength": 80
},
"scale": 0,
"precision": 0,
"fields": []
}
is there any possible to get this?
The discovery service api describes all of the google apis you can probably get the information from that programmaticlly or you could just check the documentation
You can also check the documentation directly.
Link to People v1 discovery doc

UNKNOWN_ENVELOPE_RECIPIENT When making Embedded Signing API Call

I am making an API Call to Docusign to try to get a link for a recipient to sign his document without him having to go into his e-mail. I am doing this in APEX in a Visualforce page.
I am sending the following request to the endpoint: "https://demo.docusign.net/restapi/v2/accounts/661863/envelopes/21F02F6C-E156-46E0-BCDE-778D18DB4592/views/recipient"
My Request is:
{
"authenticationMethod": "email",
"email": "test#outlook.com",
"returnUrl": "www.docusign.net",
"userName": "LB -1 Demo 2"
}
The response I am getting is:
{
"errorCode": "UNKNOWN_ENVELOPE_RECIPIENT",
"message": "The recipient you have identified is not a valid recipient of the specified envelope. Envelope recipient could not be determined. 'clientUserId', 'email', or 'userName' in request and envelope may not match."
}
The envelope request is:
{
"signers": [
{
"name": "LB -1 Demo 2",
"email": "test#outlook.com",
"recipientId": "1",
"requireIdLookup": "false",
"userId": "05b324da-8ebb-4d4b-a58b-0ef019530214",
"routingOrder": "1",
"roleName": "Signer 1",
"status": "completed",
"signedDateTime": "2014-06-24T11:30:09.4630000Z",
"deliveredDateTime": "2014-06-24T11:29:58.5100000Z"
}
],
"agents": [],
"editors": [],
"intermediaries": [],
"carbonCopies": [],
"certifiedDeliveries": [],
"inPersonSigners": [],
"recipientCount": "1",
"currentRoutingOrder": "1"
}
The recipient information seems to match my request but the API call is still not working. Is this because I am missing a clientUserId and that is required for am embedded signing call? And if so, would I need to create the Envelope AND Recipients AND ONLY THEN can I make the embedded signer call?
This question is a duplicate, please search the DocuSignApi tag for existing answers before posting new questions. As Andrew has mentioned, this is a duplicate of this question:
Docusign Embedded Signing
You need to set the clientUserId property for any recipient who you want to be an embedded recipient. It's up to you what value to use, but make sure you include the same exact value when requesting the signing URL token.
There's also a detailed explanation of this on the DocuSign Developer Center under Features -> Embedding
https://www.docusign.com/developer-center/explore/features/embedding-docusign

Resources