Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix coinbase prime #86

Merged
merged 13 commits into from
Mar 27, 2024
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
Loading