-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from tiagosiebler/jerko
feat(): added adv trade and cbapp examples
- Loading branch information
Showing
16 changed files
with
400 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { CBAdvancedTradeClient } from '../../../src/index.js'; | ||
// import { CBAdvancedTradeClient } from 'coinbase-api'; | ||
|
||
// initialise the client | ||
const client = new CBAdvancedTradeClient({ | ||
apiKey: process.env.API_KEY_NAME || 'insert_api_key_here', | ||
apiSecret: process.env.API_PRIVATE_KEY || 'insert_api_secret_here', | ||
}); | ||
|
||
async function getAccounts() { | ||
try { | ||
// Get all accounts | ||
const accounts = await client.getAccounts({ limit: 10 }); | ||
console.log('Accounts: ', accounts); | ||
|
||
// Get specific account details | ||
if (accounts.accounts.length > 0) { | ||
const accountId = accounts.accounts[0].uuid; | ||
const accountDetails = await client.getAccount({ account_id: accountId }); | ||
console.log('Account Details: ', accountDetails); | ||
} | ||
} catch (e) { | ||
console.error('Get accounts error: ', e); | ||
} | ||
} | ||
|
||
getAccounts(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { CBAdvancedTradeClient } from '../../../src/index.js'; | ||
// import { CBAdvancedTradeClient } from 'coinbase-api'; | ||
|
||
// initialise the client | ||
const client = new CBAdvancedTradeClient({ | ||
apiKey: process.env.API_KEY_NAME || 'insert_api_key_here', | ||
apiSecret: process.env.API_PRIVATE_KEY || 'insert_api_secret_here', | ||
}); | ||
|
||
async function getOrders() { | ||
try { | ||
// Get all orders | ||
const orders = await client.getOrders({ limit: 5 }); | ||
console.log('Orders: ', orders); | ||
|
||
// Get order details | ||
if (orders.orders.length > 0) { | ||
const orderId = orders.orders[0].order_id; | ||
const orderDetails = await client.getOrder({ order_id: orderId }); | ||
console.log('Order Details: ', orderDetails); | ||
} | ||
} catch (e) { | ||
console.error('Error: ', e); | ||
} | ||
} | ||
|
||
getOrders(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { CBAdvancedTradeClient } from '../../../src/index.js'; | ||
// import { CBAdvancedTradeClient } from 'coinbase-api'; | ||
|
||
// initialise the client | ||
const client = new CBAdvancedTradeClient({ | ||
apiKey: process.env.API_KEY_NAME || 'insert_api_key_here', | ||
apiSecret: process.env.API_PRIVATE_KEY || 'insert_api_secret_here', | ||
}); | ||
|
||
async function submitOrder() { | ||
try { | ||
// submit market futures order | ||
const newOrder = await client.submitOrder({ | ||
product_id: 'BTC PERP', | ||
order_configuration: { market_market_ioc: { base_size: '0.001' } }, | ||
side: 'SELL', | ||
client_order_id: client.generateNewOrderId(), | ||
}); | ||
console.log('Result: ', newOrder); | ||
} catch (e) { | ||
console.error('Send new order error: ', e); | ||
} | ||
|
||
// | ||
} | ||
|
||
async function submitLimitOrder() { | ||
try { | ||
// Submit limit futures order | ||
const limitOrder = await client.submitOrder({ | ||
product_id: 'BTC PERP', | ||
order_configuration: { | ||
limit_limit_gtc: { | ||
base_size: '0.001', | ||
limit_price: '50000.00', | ||
}, | ||
}, | ||
side: 'BUY', | ||
client_order_id: client.generateNewOrderId(), | ||
}); | ||
console.log('Limit Order Result: ', limitOrder); | ||
} catch (e) { | ||
console.error('Submit limit order error: ', e); | ||
} | ||
} | ||
|
||
submitLimitOrder(); | ||
|
||
submitOrder(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { CBAdvancedTradeClient } from '../../../src/index.js'; | ||
// import { CBAdvancedTradeClient } from 'coinbase-api'; | ||
|
||
// initialise the client | ||
const client = new CBAdvancedTradeClient({ | ||
apiKey: process.env.API_KEY_NAME || 'insert_api_key_here', | ||
apiSecret: process.env.API_PRIVATE_KEY || 'insert_api_secret_here', | ||
}); | ||
|
||
async function submitOrder() { | ||
try { | ||
// submit market spot order | ||
const newOrder = await client.submitOrder({ | ||
product_id: 'BTC-USDT', | ||
order_configuration: { market_market_ioc: { base_size: '0.001' } }, | ||
side: 'SELL', | ||
client_order_id: client.generateNewOrderId(), | ||
}); | ||
console.log('Result: ', newOrder); | ||
} catch (e) { | ||
console.error('Send new order error: ', e); | ||
} | ||
|
||
// | ||
} | ||
|
||
async function submitLimitOrder() { | ||
try { | ||
// Submit limit spot order | ||
const limitOrder = await client.submitOrder({ | ||
product_id: 'BTC-USDT', | ||
order_configuration: { | ||
limit_limit_gtc: { | ||
base_size: '0.001', | ||
limit_price: '50000.00', | ||
}, | ||
}, | ||
side: 'BUY', | ||
client_order_id: client.generateNewOrderId(), | ||
}); | ||
console.log('Limit Order Result: ', limitOrder); | ||
} catch (e) { | ||
console.error('Submit limit order error: ', e); | ||
} | ||
} | ||
|
||
submitLimitOrder(); | ||
|
||
submitOrder(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { CBAdvancedTradeClient } from '../../../src/index.js'; | ||
// import { CBAdvancedTradeClient } from 'coinbase-api'; | ||
|
||
// you can initialise public client without api keys as public calls do not require auth | ||
const client = new CBAdvancedTradeClient({}); | ||
|
||
async function publicCalls() { | ||
try { | ||
// Get server time | ||
const serverTime = await client.getServerTime(); | ||
console.log('Server Time: ', serverTime); | ||
|
||
// Get public product book | ||
const productBook = await client.getPublicProductBook({ | ||
product_id: 'BTC-USD', | ||
limit: 10, | ||
}); | ||
console.log('Public Product Book: ', productBook); | ||
|
||
// List all public products | ||
const publicProducts = await client.getPublicProducts(); | ||
console.log('Public Products: ', publicProducts); | ||
|
||
// Get single public product | ||
const publicProduct = await client.getPublicProduct({ | ||
product_id: 'BTC-USD', | ||
}); | ||
console.log('Public Product: ', publicProduct); | ||
|
||
// Get public product candles | ||
const productCandles = await client.getPublicProductCandles({ | ||
product_id: 'BTC-USD', | ||
granularity: 'ONE_MINUTE', | ||
start: '1725976550', | ||
end: '1725977550', | ||
}); | ||
console.log('Public Product Candles: ', productCandles); | ||
|
||
// Get public market trades | ||
const marketTrades = await client.getPublicMarketTrades({ | ||
product_id: 'BTC-USD', | ||
limit: 10, | ||
}); | ||
console.log('Public Market Trades: ', marketTrades); | ||
} catch (e) { | ||
console.error('Error: ', e); | ||
} | ||
} | ||
|
||
publicCalls(); |
2 changes: 1 addition & 1 deletion
2
...les/coinbase-international-client-rest.ts → ...nge/coinbase-international-client-rest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { CBAppClient } from '../../../src/index.js'; | ||
// import { CBAppClient } from 'coinbase-api'; | ||
|
||
// Initialize the client | ||
const client = new CBAppClient({ | ||
apiKey: process.env.API_KEY_NAME || 'insert_api_key_here', | ||
apiSecret: process.env.API_PRIVATE_KEY || 'insert_api_secret_here', | ||
}); | ||
|
||
async function main() { | ||
try { | ||
// Deposit funds to your fiat account | ||
const depositResult = await client.depositFunds({ | ||
account_id: 'your_fiat_account_id', | ||
amount: '100.00', | ||
currency: 'USD', | ||
payment_method: 'your_payment_method_id', | ||
}); | ||
console.log('Deposit Result: ', depositResult); | ||
|
||
// Withdraw funds from fiat account | ||
const withdrawResult = await client.withdrawFunds({ | ||
account_id: 'your_fiat_account_id', | ||
amount: '50.00', | ||
currency: 'USD', | ||
payment_method: 'your_payment_method_id', | ||
}); | ||
console.log('Withdraw Result: ', withdrawResult); | ||
|
||
// Send money to another user | ||
const sendMoneyResult = await client.sendMoney({ | ||
account_id: 'your_crypto_account_id', | ||
type: 'send', | ||
to: 'recipient_address_or_email', | ||
amount: '0.01', | ||
currency: 'BTC', | ||
}); | ||
console.log('Send Money Result: ', sendMoneyResult); | ||
|
||
// Transfer money between your own accounts | ||
const transferMoneyResult = await client.transferMoney({ | ||
account_id: 'your_source_account_id', | ||
type: 'transfer', | ||
to: 'your_destination_account_id', | ||
amount: '0.01', | ||
currency: 'BTC', | ||
}); | ||
console.log('Transfer Money Result: ', transferMoneyResult); | ||
} catch (e) { | ||
console.error('Error: ', e); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { CBAppClient } from '../../../src/index.js'; | ||
// import { CBAppClient } from 'coinbase-api'; | ||
|
||
// Initialize the client | ||
const client = new CBAppClient({ | ||
apiKey: process.env.API_KEY_NAME || 'insert_api_key_here', | ||
apiSecret: process.env.API_PRIVATE_KEY || 'insert_api_secret_here', | ||
}); | ||
|
||
async function depositFunds() { | ||
try { | ||
// Deposit funds to your fiat account | ||
const depositResult = await client.depositFunds({ | ||
account_id: 'your_fiat_account_id', | ||
amount: '100.00', | ||
currency: 'USD', | ||
payment_method: 'your_payment_method_id', | ||
}); | ||
console.log('Deposit Result: ', depositResult); | ||
} catch (e) { | ||
console.error('Deposit funds error: ', e); | ||
} | ||
} | ||
|
||
depositFunds(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { CBAppClient } from '../../../src/index.js'; | ||
// import { CBAppClient } from 'coinbase-api'; | ||
|
||
// Initialize the client | ||
const client = new CBAppClient({ | ||
apiKey: process.env.API_KEY_NAME || 'insert_api_key_here', | ||
apiSecret: process.env.API_PRIVATE_KEY || 'insert_api_secret_here', | ||
}); | ||
|
||
async function sendMoney() { | ||
try { | ||
// Send money to another user | ||
const sendMoneyResult = await client.sendMoney({ | ||
account_id: 'your_crypto_account_id', | ||
type: 'send', | ||
to: 'recipient_address_or_email', | ||
amount: '0.01', | ||
currency: 'BTC', | ||
}); | ||
console.log('Send Money Result: ', sendMoneyResult); | ||
} catch (e) { | ||
console.error('Send money error: ', e); | ||
} | ||
} | ||
|
||
sendMoney(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { CBAppClient } from '../../../src/index.js'; | ||
// import { CBAppClient } from 'coinbase-api'; | ||
|
||
// Initialize the client | ||
const client = new CBAppClient({ | ||
apiKey: process.env.API_KEY_NAME || 'insert_api_key_here', | ||
apiSecret: process.env.API_PRIVATE_KEY || 'insert_api_secret_here', | ||
}); | ||
|
||
async function transferMoney() { | ||
try { | ||
// Transfer money between your own accounts | ||
const transferMoneyResult = await client.transferMoney({ | ||
account_id: 'your_source_account_id', | ||
type: 'transfer', | ||
to: 'your_destination_account_id', | ||
amount: '0.01', | ||
currency: 'BTC', | ||
}); | ||
console.log('Transfer Money Result: ', transferMoneyResult); | ||
} catch (e) { | ||
console.error('Transfer money error: ', e); | ||
} | ||
} | ||
|
||
transferMoney(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { CBAppClient } from '../../../src/index.js'; | ||
// import { CBAppClient } from 'coinbase-api'; | ||
|
||
// Initialize the client | ||
const client = new CBAppClient({ | ||
apiKey: process.env.API_KEY_NAME || 'insert_api_key_here', | ||
apiSecret: process.env.API_PRIVATE_KEY || 'insert_api_secret_here', | ||
}); | ||
|
||
async function withdrawFunds() { | ||
try { | ||
// Withdraw funds from your fiat account | ||
const withdrawResult = await client.withdrawFunds({ | ||
account_id: 'your_fiat_account_id', | ||
amount: '50.00', | ||
currency: 'USD', | ||
payment_method: 'your_payment_method_id', | ||
}); | ||
console.log('Withdraw Result: ', withdrawResult); | ||
} catch (e) { | ||
console.error('Withdraw funds error: ', e); | ||
} | ||
} | ||
|
||
withdrawFunds(); |
Oops, something went wrong.