-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a575dd7
commit 0d273e3
Showing
7 changed files
with
199 additions
and
0 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,2 @@ | ||
/target | ||
Cargo.lock |
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,14 @@ | ||
{ | ||
"cSpell.words": [ | ||
"COVID", | ||
"ETFs", | ||
"Financials", | ||
"Finnhub", | ||
"Forex", | ||
"datetime", | ||
"exitfailure", | ||
"figi", | ||
"reqwest", | ||
"weburl" | ||
] | ||
} |
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,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"] } |
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,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) | ||
} | ||
} |
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,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()); | ||
} | ||
} |
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 @@ | ||
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, | ||
} |
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,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 |