Skip to content

Commit

Permalink
Fix coinbase prime (#86)
Browse files Browse the repository at this point in the history
* Fix wallet id lookup

* Explicitly find btc trading wallet

* Return empty array when no txs

* Return empty array when no txs

* revert

* Address name

* fix withdraw

* log full err

* fix path

* fix path

* Only throw err message

* lint
  • Loading branch information
dannydeezy authored Mar 27, 2024
1 parent 957140c commit a1b3ff6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ ACTIVE_EXCHANGE=kraken
# Note this cannot be a taproot address
#COINBASE_PRIME_WITHDRAWAL_ADDRESS=""
#COINBASE_PRIME_API_PASSPHRASE=""
#COINBASE_PRIME_WITHDRAWAL_ADDRESS_NAME=""

# Note: for Gemini you should create a "Primary" (not "Master") API Key - it should start with "account-"
#GEMINI_API_KEY=
Expand Down
16 changes: 9 additions & 7 deletions exchanges/coinbase-prime.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,15 @@ async function set_coinbase_ids() {
}

async function set_btc_wallet_id() {
const path = `/v1/portfolios/${PORTFOLIO_ID}/wallets` // ?type=TRADING&symbol=BTC
const path = `/v1/portfolios/${PORTFOLIO_ID}/wallets`
const timestamp = `${Math.floor(Date.now() / 1000)}`
const method = 'GET'
const headers = create_headers({ path, timestamp, method })
const { data } = await axios.get(`${BASE_URL}${path}`, { headers }).catch((err) => {
console.log(err)
return {}
})
console.log(data)
BTC_WALLET_ID = data.wallets[0].id
BTC_WALLET_ID = data.wallets.find((it) => it.symbol === 'BTC' && it.type === 'TRADING').id
}

async function check_and_set_credentials() {
Expand Down Expand Up @@ -90,7 +89,10 @@ async function get_btc_balance() {

async function withdraw({ amount_btc }) {
await check_and_set_credentials()
const path = '/withdrawals/crypto'
if (!process.env.COINBASE_PRIME_WITHDRAWAL_ADDRESS_NAME || !process.env.COINBASE_PRIME_WITHDRAWAL_ADDRESS) {
throw new Error('COINBASE_PRIME_WITHDRAWAL_ADDRESS_NAME and COINBASE_PRIME_WITHDRAWAL_ADDRESS must be set')
}
const path = `/v1/portfolios/${PORTFOLIO_ID}/wallets/${BTC_WALLET_ID}/withdrawals`
const timestamp = `${Math.floor(Date.now() / 1000)}`
const method = 'POST'
const body = {
Expand All @@ -102,7 +104,7 @@ async function withdraw({ amount_btc }) {
destination_type: 'DESTINATION_BLOCKCHAIN',
blockchain_address: {
address: process.env.COINBASE_PRIME_WITHDRAWAL_ADDRESS,
account_identifier: 'trezor-sat-hunter',
account_identifier: process.env.COINBASE_PRIME_WITHDRAWAL_ADDRESS_NAME,
},
}
if (process.env.COINBASE_PRIME_TOTP_SECRET) {
Expand All @@ -111,8 +113,8 @@ async function withdraw({ amount_btc }) {
const headers = create_headers({ path, timestamp, method, body: JSON.stringify(body) })
headers['Content-Type'] = 'application/json'
const { data } = await axios.post(`${BASE_URL}${path}`, body, { headers }).catch((err) => {
console.log(err.response.data)
throw new Error(JSON.stringify(err.response.data, null, 2))
console.log(err)
throw new Error(JSON.stringify(err.message, null, 2))
})
console.log(data)
}
Expand Down

0 comments on commit a1b3ff6

Please sign in to comment.