Skip to content

Commit

Permalink
added sl, ss, cp2, mn
Browse files Browse the repository at this point in the history
  • Loading branch information
henryboisdequin committed Jan 19, 2021
1 parent a575dd7 commit 0d273e3
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
/target
Cargo.lock
14 changes: 14 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 1,14 @@
{
"cSpell.words": [
"COVID",
"ETFs",
"Financials",
"Finnhub",
"Forex",
"datetime",
"exitfailure",
"figi",
"reqwest",
"weburl"
]
}
14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 1,14 @@
[package]
name = "finnhub-rs"
version = "0.1.0"
authors = ["Henry Boisdequin"]
edition = "2018"

[dependencies]
structopt = "0.3.21"
exitfailure = "0.5.1"
reqwest = { version = "0.11.0", features = ["json"] }
serde = "1.0.119"
serde_json = "1.0.61"
serde_derive = "1.0.119"
tokio = { version = "1.0.2", features = ["full"] }
64 changes: 64 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,64 @@
use super::types::*;
use exitfailure::ExitFailure;
use reqwest::Url;
use serde_derive::{Deserialize, Serialize};

/// Finnhub API Client object.
#[derive(Debug)]
pub struct Client {
pub api_key: String,
}

impl Client {
pub fn new(api_key: String) -> Self {
Self { api_key }
}

pub async fn symbol_lookup(self, query: String) -> Result<SymbolLookup, ExitFailure> {
let url = format!(
"https://finnhub.io/api/v1/search?q={}&token={}",
query, self.api_key
);

let url = Url::parse(&*url)?;
let res = reqwest::get(url).await?.json::<SymbolLookup>().await?;

Ok(res)
}

pub async fn stock_symbol(self, exchange: String) -> Result<Vec<StockSymbol>, ExitFailure> {
let url = format!(
"https://finnhub.io/api/v1/stock/symbol?exchange={}&token={}",
exchange, self.api_key
);

let url = Url::parse(&*url)?;
let res = reqwest::get(url).await?.json::<Vec<StockSymbol>>().await?;

Ok(res)
}

pub async fn company_profile2(self, symbol: String) -> Result<CompanyProfile, ExitFailure> {
let url = format!(
"https://finnhub.io/api/v1/stock/profile2?symbol={}&token={}",
symbol, self.api_key
);

let url = Url::parse(&*url)?;
let res = reqwest::get(url).await?.json::<CompanyProfile>().await?;

Ok(res)
}

pub async fn market_news(self, category: String) -> Result<Vec<MarketNews>, ExitFailure> {
let url = format!(
"https://finnhub.io/api/v1/news?category={}&token={}",
category, self.api_key
);

let url = Url::parse(&*url)?;
let res = reqwest::get(url).await?.json::<Vec<MarketNews>>().await?;

Ok(res)
}
}
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,19 @@
#![warn(missing_debug_implementations, rust_2018_idioms, missing_docs)]

//! Finnhub-rs is a client for the Finnhub API implemented in Rust.
mod client;
mod types;

#[cfg(test)]
mod test {
use super::client::*;
use super::types::*;
use exitfailure::ExitFailure;

#[test]
fn test_create_client() {
let client = Client::new("API_KEY".to_string());
assert_eq!(client.api_key, "API_KEY".to_string());
}
}
54 changes: 54 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,54 @@
use serde_derive::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
pub struct SymbolLookup {
count: usize,
result: Vec<Results>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Results {
description: String,
displaySymbol: String,
symbol: String,
r#type: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct StockSymbol {
description: String,
displaySymbol: String,
symbol: String,
r#type: String,
mic: String,
figi: String,
currency: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct CompanyProfile {
country: String,
currency: String,
exchange: String,
ipo: String,
name: String,
phone: String,
shareOutstanding: f64,
ticker: String,
weburl: String,
logo: String,
finnhubIndustry: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct MarketNews {
category: String,
datetime: u128,
headline: String,
id: u128,
image: String,
related: String,
source: String,
summary: String,
url: String,
}
32 changes: 32 additions & 0 deletions todo.md
Original file line number Diff line number Diff line change
@@ -0,0 1,32 @@
company news
News Sentiment
Peers
Basic Financials
Financials As Reported
SEC Filings
IPO Calendar
Recommendation Trends
Price Target
Earnings Surprises
Earnings Calendar
Quote
Stock Candles
Splits
Indices Constituents
ETFs Industry Exposure
ETFs Country Exposure
Forex Exchanges
Forex Symbol
Forex Candles
Forex rates
Crypto Exchanges
Crypto Symbol
Crypto Candles
Pattern Recognition
Support/Resistance
Aggregate Indicators
Technical Indicators
COVID-19
FDA Committee Meeting Calendar
Country Metadata
Economic Calendar

0 comments on commit 0d273e3

Please sign in to comment.