diff --git a/examples/AdvancedTrade/Private/getAccounts.ts b/examples/AdvancedTrade/Private/getAccounts.ts new file mode 100644 index 0000000..e94f6ce --- /dev/null +++ b/examples/AdvancedTrade/Private/getAccounts.ts @@ -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(); diff --git a/examples/AdvancedTrade/Private/getOrders.ts b/examples/AdvancedTrade/Private/getOrders.ts new file mode 100644 index 0000000..5a2b5a3 --- /dev/null +++ b/examples/AdvancedTrade/Private/getOrders.ts @@ -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(); diff --git a/examples/AdvancedTrade/Private/submitOrderPerps.ts b/examples/AdvancedTrade/Private/submitOrderPerps.ts new file mode 100644 index 0000000..341ca1d --- /dev/null +++ b/examples/AdvancedTrade/Private/submitOrderPerps.ts @@ -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(); diff --git a/examples/AdvancedTrade/Private/submitOrderSpot.ts b/examples/AdvancedTrade/Private/submitOrderSpot.ts new file mode 100644 index 0000000..b8d6f54 --- /dev/null +++ b/examples/AdvancedTrade/Private/submitOrderSpot.ts @@ -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(); diff --git a/examples/AdvancedTrade/Public/advanced-public-rest-all.ts b/examples/AdvancedTrade/Public/advanced-public-rest-all.ts new file mode 100644 index 0000000..b7dd9cc --- /dev/null +++ b/examples/AdvancedTrade/Public/advanced-public-rest-all.ts @@ -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(); diff --git a/examples/coinbase-international-client-rest.ts b/examples/CBInternationalExchange/coinbase-international-client-rest.ts similarity index 81% rename from examples/coinbase-international-client-rest.ts rename to examples/CBInternationalExchange/coinbase-international-client-rest.ts index cf8a9d8..260130e 100644 --- a/examples/coinbase-international-client-rest.ts +++ b/examples/CBInternationalExchange/coinbase-international-client-rest.ts @@ -1,4 +1,4 @@ -import { CBInternationalClient } from '../src/index.js'; +import { CBInternationalClient } from '../../src/index.js'; const coinbaseInternational = new CBInternationalClient(); diff --git a/examples/CoinbaseApp/Private/cb-app-private.ts b/examples/CoinbaseApp/Private/cb-app-private.ts new file mode 100644 index 0000000..b026405 --- /dev/null +++ b/examples/CoinbaseApp/Private/cb-app-private.ts @@ -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(); diff --git a/examples/CoinbaseApp/Private/depositFunds.ts b/examples/CoinbaseApp/Private/depositFunds.ts new file mode 100644 index 0000000..3da52be --- /dev/null +++ b/examples/CoinbaseApp/Private/depositFunds.ts @@ -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(); diff --git a/examples/CoinbaseApp/Private/sendMoney.ts b/examples/CoinbaseApp/Private/sendMoney.ts new file mode 100644 index 0000000..490f960 --- /dev/null +++ b/examples/CoinbaseApp/Private/sendMoney.ts @@ -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(); diff --git a/examples/CoinbaseApp/Private/transferMoney.ts b/examples/CoinbaseApp/Private/transferMoney.ts new file mode 100644 index 0000000..cbf364d --- /dev/null +++ b/examples/CoinbaseApp/Private/transferMoney.ts @@ -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(); diff --git a/examples/CoinbaseApp/Private/withdrawFunds.ts b/examples/CoinbaseApp/Private/withdrawFunds.ts new file mode 100644 index 0000000..85c0853 --- /dev/null +++ b/examples/CoinbaseApp/Private/withdrawFunds.ts @@ -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(); diff --git a/examples/CoinbaseApp/Public/cbapp-public-rest-all.ts b/examples/CoinbaseApp/Public/cbapp-public-rest-all.ts new file mode 100644 index 0000000..a36b637 --- /dev/null +++ b/examples/CoinbaseApp/Public/cbapp-public-rest-all.ts @@ -0,0 +1,41 @@ +import { CBAppClient } from '../../../src/index.js'; +// import { CBAppClient } from 'coinbase-api'; + +// Initialize the client, you can pass in api keys here if you have them but they are not required for public endpoints +const client = new CBAppClient(); + +async function publicCalls() { + try { + // Get fiat currencies + const fiatCurrencies = await client.getFiatCurrencies(); + console.log('Fiat Currencies: ', fiatCurrencies); + + // Get cryptocurrencies + const cryptocurrencies = await client.getCryptocurrencies(); + console.log('Cryptocurrencies: ', cryptocurrencies); + + // Get exchange rates + const exchangeRates = await client.getExchangeRates({ currency: 'USD' }); + console.log('Exchange Rates: ', exchangeRates); + + // Get buy price + const buyPrice = await client.getBuyPrice({ currencyPair: 'BTC-USD' }); + console.log('Buy Price: ', buyPrice); + + // Get sell price + const sellPrice = await client.getSellPrice({ currencyPair: 'BTC-USD' }); + console.log('Sell Price: ', sellPrice); + + // Get spot price + const spotPrice = await client.getSpotPrice({ currencyPair: 'BTC-USD' }); + console.log('Spot Price: ', spotPrice); + + // Get current time + const currentTime = await client.getCurrentTime(); + console.log('Current Time: ', currentTime); + } catch (e) { + console.error('Error: ', e); + } +} + +publicCalls(); diff --git a/examples/advanced-private-rest.ts b/examples/advanced-private-rest.ts deleted file mode 100644 index 1afc411..0000000 --- a/examples/advanced-private-rest.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { CBAdvancedTradeClient } from '../src/index.js'; - -async function main() { - const client = new CBAdvancedTradeClient({ - // cdpApiKey: credsTradePermission, - apiKey: '', - apiSecret: '', - }); - - try { - /* const accounts = await client.getAccounts(); - console.log('req result: ', accounts.accounts[0].uuid); */ - - const newOrder = await client.submitOrder({ - product_id: 'BTC-USDT', - order_configuration: { market_market_ioc: { base_size: '20' } }, - side: 'BUY', - }); - console.log('req result: ', newOrder); - } catch (e) { - console.error('req exception: ', e); - } - - // -} - -main(); diff --git a/examples/advanced-public-rest.ts b/examples/advanced-public-rest.ts deleted file mode 100644 index d163b19..0000000 --- a/examples/advanced-public-rest.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { CBAdvancedTradeClient } from '../src/index.js'; - -const advancedTradeClient = new CBAdvancedTradeClient({}); - -async function main() { - try { - /* const res = await advancedTradeClient.getPublicProductBook({ - product_id: 'BTC-USD', - }); - - const res2 = await advancedTradeClient.listPublicProducts({}); - - const res3 = await advancedTradeClient.getPublicProduct({ - product_id: 'BTC-USD', - }); - - const res4 = await advancedTradeClient.getPublicProductCandles({ - product_id: 'BTC-USD', - granularity: 'ONE_MINUTE', - start: '1725976550', - end: '1725977550', - }); */ - - const res5 = await advancedTradeClient.getPublicMarketTrades({ - product_id: 'BTC-USD', - limit: 10, - }); - - console.log(res5); - } catch (error) { - console.error(error); - } -} - -main(); diff --git a/examples/cb-app-private.ts b/examples/cb-app-private.ts deleted file mode 100644 index 91222d0..0000000 --- a/examples/cb-app-private.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { CBAppClient } from '../src/index.js'; - -async function main() { - const client = new CBAppClient({ - // cdpApiKey: credsTradePermission, - apiKey: '', - apiSecret: '', - }); - - const res = await client.getAccounts(); - console.log(res); -} - -main(); diff --git a/examples/testfile-cbexch.ts b/examples/testfile-cbexch.ts deleted file mode 100644 index 6fd78f0..0000000 --- a/examples/testfile-cbexch.ts +++ /dev/null @@ -1,61 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ - -import { CBExchangeClient } from '../src/index.js'; - -(async () => { - //console.clear(); - - const credsViewPermission = { - key: '6e0a73cfd6e02701655d38a383dc5fcf', - secret: - 'g1uvHV/QklP+wB+cWoGXdCOYmQ5BQ1/XYMCaLDs2rH7bZ7V07X3ECroC0Zb6H5aBSa0CkMc/WMzpz5RHvqpxFQ==', - passphrase: 'gdgjgehg3i', - }; - - const client = new CBExchangeClient({ - apiKey: credsViewPermission.key, - apiSecret: credsViewPermission.secret, - apiPassphrase: credsViewPermission.passphrase, - useSandbox: true, - }); - - try { - /* const res = await client.getNewLoanPreview({ - currency: 'USDC', - native_amount: '100', - }); - console.log('req result: ', res); */ - - /* const res = await client.getProfiles({ active: true }); - console.log('req result: ', res); */ - /* const accounts = await client.getAccounts(); - console.log('req result: ', accounts); */ - const order = await client.submitOrder({ - product_id: 'BTC-GBP', - price: '1000', - side: 'buy', - type: 'limit', - size: '0.001', - }); - - console.log('order', order); - - const res = await client.getOrder({ - order_id: '2e9a5d90-84f7-4267-a6e5-722b9d43e2d0', - }); - console.log('order', res); - // console.log('res', res); - // const res = await client.cancelOrder({ order_id: 'dummyorder' }); - // console.log('cancelOrder result: ', res); - // const orderReq: SubmitAdvTradeOrderRequest = { - // product_id: 123123, - // }; - // const orderRes = await client.submitOrder({ - // product_id: 12312312, // this should throw??? - // }); - } catch (e) { - console.error('req exception: ', JSON.stringify(e, null, 2)); - } - - // -})();