Expand description
§Xylex spread tracker
spread_tracker
is a library for tracking the spread of various symbols in the forex market.
Every forex broker has a different spread for each symbol. This library is used to track the spread of various symbols in the forex market. Retrieve & scrape the spread of various symbols from different brokers.
§Features
- Track the spread of various symbols in the forex market.
- Retrieve & scrape the spread of various symbols from different brokers.
- Store the spread data in a database.
- Cache the spread data to minimize the number of requests to the broker.
§Granularity
- Query the spread of all symbols from all listed brokers.
- Query the spread of a specific symbol from all listed brokers.
- Query the spread of all symbols from a specific broker.
- Query the spread of a specific symbol from a specific broker.
§Usage
Add this to your Cargo.toml
:
[dependencies]
spread_tracker = "0.1.0"
§How to assign the correct Broker type
use spread_tracker::config::{
SpreadBrokerUrl,
Brokers
};
§How to get their spreads
use spread_tracker::config::SpreadBrokerUrl;
use spread_tracker::model::{
Symbol,
SymbolSpread
};
let config: SpreadBrokerUrl = SpreadBrokerUrl::new();
// In this example, we are tracking the spread of the symbols from the Vantage and EightCap brokers.
let brokers: Vec<Brokers> = vec![
Brokers::Vantage,
Brokers::EightCap,
];
// Get the spread of the symbols from the brokers
let spread: Value = SpreadTracker::get_spread(
config,
brokers
).await.unwrap();
println!("Spread: {:#?}", spread);
Result:
{
"spread": {
"eightcap": [
{
"ask": 2197.92,
"bid": 2209.92,
"spread": 12.0,
"symbol": "XAUUSD"
},
{
"ask": 2031.57,
"bid": 2060.8973,
"spread": 29.3273,
"symbol": "XAUEUR"
},
{
---------------- cut for brevity ----------------
§Return type
The return type is a serde_json::Value
object, which is a JSON object.
§Structure
Object[spread]Vector[broker] -> Object[symbol, ask, bid, spread]
spread
is the key for the spread data.broker
is the key for the broker name, which will differ based on the broker.
- Notes: A Vector of objects is sometimes referred to as a list of objects. It is a collection of objects that are stored in no particular order.
§Configuration
The config.yaml
is used to store the broker URLs for the spread tracking, and the model.rs
is used to store the data model for the spread tracking. The config.yaml
file should be in the following format:
BrokerSpreadUrls:
Vantage: "https://www.vantagefx.com/trading-info/forex-market-hours/"
MyFxBook: "https://www.myfxbook.com/forex-broker-quotes/vantage/6052"
Where Vantage
and MyFxBook
are the broker names and the URLs are the URLs of the brokers for spread tracking, derived from the MyFxBook website.
§Caching
wip
You can use the db
module to store the spread data in a database.
Currently, the library relies on supabase_rs
to store the data in a Supabase database.
If you want to use a different database, you can implement the Db
trait for your database.
Or simply call the store_spread
method in the model.rs
file to store the spread data in your database via a manual file like .json
§Asynchronous vs Synchronous API
The main library is already asynchronous, so you can use it in an asynchronous context. Sync API is not due to more testing being needed
§Database
wip
You can use the db
module to store the spread data in a database.
Currently, the library relies on supabase_rs
to store the data in a Supabase database.
If you want to use a different database, you can implement the Db
trait for your database.
Or simply call the store_spread
method in the model.rs
file to store the spread data in your database via a manual file like .json
§Errors
url_invalid
will be returned if the URL is invalid.url_not_reachable
will be returned if the URL is not reachable.url_not_found
will be returned if the URL is not found.invalid_body
will be returned if the body is invalid.internal_error
will be returned if there is an internal error.empty_body
will be returned if the body is empty.could_not_extract_broker_name
will be returned if the broker name could not be extracted from the URL.failed_to_open_config
will be returned if the config.yaml file is not found.failed_to_read_yaml
will be returned if the file is not in the correct format.failed_to_parse_symbol_spread
will be returned if the Veccould not be parsed into a Vec . failed_to_parse_symbol
will be returned if the Symbol could not be parsed from the string.failed_to_parse_ask_price
will be returned if the ask price could not be parsed from the string.failed_to_parse_bid_price
will be returned if the bid price could not be parsed from the string.failed_to_parse_spread
will be returned if the spread could not be parsed from the string.could_not_retrieve_spread_data
will be returned if the spread data could not be retrieved from the broker URL.failed_to_bind_json_object_to_key
will be returned if the JSON object could not be bound to the key.
§Modules
db
: This module is used to store the spread data in a database.caching
: This module is used to cache the spread data to minimize the number of requests to the broker.utils
: This module is used to save the spread data to a.json
file.config
: This module is used to load the configuration from theconfig.yaml
file.model
: This module is used to store the data model for the spread tracking.errors
: This module is used to handle the errors in the library.
Modules§
- caching
- Caching spread intelligently
- config
- The
config
module - db
- Supabase SDK implementation
- errors
- ErrorsSpread
- model
- Models, structs, enums and traits for the SpreadTracker library.
- utils
- This module contains all the utility functions like RegexFinder, Cleaner, Duplicates, etc.
Structs§
- Spread
Tracker - The
SpreadTracker
struct is used to track the spread of various symbols in the forex market.