coinbase_intx_http_private/http-private.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 Posei Systems Pty Ltd. All rights reserved.
3// https://poseitrader.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use nautilus_coinbase_intx::http::client::CoinbaseIntxHttpClient;
17use nautilus_core::env::get_env_var;
18use nautilus_model::identifiers::{AccountId, Symbol};
19use tracing::level_filters::LevelFilter;
20
21#[tokio::main]
22async fn main() -> Result<(), Box<dyn std::error::Error>> {
23 tracing_subscriber::fmt()
24 .with_max_level(LevelFilter::TRACE)
25 .init();
26
27 let mut client = CoinbaseIntxHttpClient::from_env().unwrap();
28
29 // The direct Coinbase REST API can be accessed through the inner client,
30 // these methods are prefixed with "http_" for clarity that a HTTP request is
31 // about to be initiated, as well as avoiding naming conflicts with API endpoints
32 // vs the method names which Posei needs ("cancel_order", etc).
33 // match client.inner.http_list_fee_rate_tiers().await {
34 // Ok(resp) => {
35 // tracing::info!("Received {resp:?}");
36 // }
37 // Err(e) => tracing::error!("{e:?}"),
38 // }
39
40 let symbol = Symbol::from("BTC-PERP");
41 let instrument = client.request_instrument(&symbol).await?;
42 client.add_instrument(instrument);
43
44 // Otherwise, the client can return Posei domain objects
45 let portfolio_id = get_env_var("COINBASE_INTX_PORTFOLIO_ID")?;
46 let account_id = AccountId::from(format!("COINBASE_INTX-{portfolio_id}"));
47 let reports = client
48 .request_order_status_reports(account_id, symbol)
49 .await?;
50
51 tracing::info!("Received {} reports", reports.len());
52
53 for report in reports {
54 tracing::info!("{report:?}");
55 }
56
57 Ok(())
58}