├── .gitignore ├── emeraldfundstudio ├── src │ ├── candles │ │ ├── mod.rs │ │ └── chart.rs │ ├── node_runners │ │ ├── mod.rs │ │ └── realtime.rs │ ├── types │ │ ├── mask.rs │ │ ├── signal.rs │ │ ├── mod.rs │ │ ├── decimal_sequence.rs │ │ ├── timestamp.rs │ │ └── candles.rs │ ├── node_editor │ │ ├── nodes │ │ │ ├── mod.rs │ │ │ ├── execute_position.rs │ │ │ ├── sma.rs │ │ │ ├── market_data.rs │ │ │ ├── preview.rs │ │ │ ├── fuse_signals.rs │ │ │ ├── split_candles.rs │ │ │ ├── to_signal.rs │ │ │ └── compare.rs │ │ ├── style.rs │ │ ├── node_trait.rs │ │ └── mod.rs │ ├── traits.rs │ ├── lib.rs │ ├── macros.rs │ ├── consts.rs │ ├── main.rs │ └── app.rs ├── Trunk.toml ├── assets │ ├── favicon.ico │ ├── icon-256.png │ ├── icon-1024.png │ ├── icon_ios_touch_192.png │ ├── maskable_icon_x512.png │ ├── sw.js │ └── manifest.json ├── .typos.toml ├── .gitignore ├── check.sh ├── .github │ └── workflows │ │ ├── typos.yml │ │ ├── pages.yml │ │ └── rust.yml ├── fill_template.sh ├── fill_template.ps1 ├── flake.nix ├── Cargo.toml └── index.html ├── resources ├── EmeraldFundLogo.png ├── gui_mockup.drawio.pdf └── LICENSE ├── .github └── FUNDING.yml ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | __pycache__ 3 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/candles/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod chart; 2 | -------------------------------------------------------------------------------- /emeraldfundstudio/Trunk.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | filehash = false 3 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/node_runners/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod realtime; 2 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/types/mask.rs: -------------------------------------------------------------------------------- 1 | pub type Mask = Vec; 2 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/types/signal.rs: -------------------------------------------------------------------------------- 1 | pub type Signal = Vec; 2 | -------------------------------------------------------------------------------- /resources/EmeraldFundLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterwilli/EmeraldFund/HEAD/resources/EmeraldFundLogo.png -------------------------------------------------------------------------------- /resources/gui_mockup.drawio.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterwilli/EmeraldFund/HEAD/resources/gui_mockup.drawio.pdf -------------------------------------------------------------------------------- /emeraldfundstudio/assets/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterwilli/EmeraldFund/HEAD/emeraldfundstudio/assets/favicon.ico -------------------------------------------------------------------------------- /emeraldfundstudio/assets/icon-256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterwilli/EmeraldFund/HEAD/emeraldfundstudio/assets/icon-256.png -------------------------------------------------------------------------------- /emeraldfundstudio/assets/icon-1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterwilli/EmeraldFund/HEAD/emeraldfundstudio/assets/icon-1024.png -------------------------------------------------------------------------------- /emeraldfundstudio/src/types/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod candles; 2 | pub mod decimal_sequence; 3 | pub mod mask; 4 | pub mod signal; 5 | pub mod timestamp; 6 | -------------------------------------------------------------------------------- /emeraldfundstudio/assets/icon_ios_touch_192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterwilli/EmeraldFund/HEAD/emeraldfundstudio/assets/icon_ios_touch_192.png -------------------------------------------------------------------------------- /emeraldfundstudio/assets/maskable_icon_x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterwilli/EmeraldFund/HEAD/emeraldfundstudio/assets/maskable_icon_x512.png -------------------------------------------------------------------------------- /emeraldfundstudio/src/types/decimal_sequence.rs: -------------------------------------------------------------------------------- 1 | 2 | use polars::prelude::{ChunkedArray, Float64Type}; 3 | 4 | pub type DecimalSequence = ChunkedArray; 5 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/types/timestamp.rs: -------------------------------------------------------------------------------- 1 | use chrono::Utc; 2 | 3 | pub type TimeStamp = u64; 4 | 5 | pub fn get_unix_time() -> TimeStamp { 6 | let now = Utc::now(); 7 | now.timestamp().try_into().unwrap() 8 | } 9 | -------------------------------------------------------------------------------- /emeraldfundstudio/.typos.toml: -------------------------------------------------------------------------------- 1 | # https://github.com/crate-ci/typos 2 | # install: cargo install typos-cli 3 | # run: typos 4 | 5 | [default.extend-words] 6 | egui = "egui" # Example for how to ignore a false positive 7 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/node_editor/nodes/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod compare; 2 | pub mod execute_position; 3 | pub mod fuse_signals; 4 | pub mod market_data; 5 | pub mod preview; 6 | pub mod sma; 7 | pub mod split_candles; 8 | pub mod to_signal; 9 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/traits.rs: -------------------------------------------------------------------------------- 1 | use std::sync::Arc; 2 | 3 | pub trait IntoArc { 4 | fn into_arc(self) -> Arc; 5 | } 6 | 7 | impl IntoArc for T { 8 | fn into_arc(self) -> Arc { 9 | Arc::new(self) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /emeraldfundstudio/.gitignore: -------------------------------------------------------------------------------- 1 | # Mac stuff: 2 | .DS_Store 3 | 4 | # trunk output folder 5 | dist 6 | 7 | # Rust compile target directories: 8 | target 9 | target_ra 10 | target_wasm 11 | 12 | # https://github.com/lycheeverse/lychee 13 | .lycheecache 14 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![warn(clippy::all, rust_2018_idioms)] 2 | 3 | mod app; 4 | mod candles; 5 | mod consts; 6 | mod macros; 7 | mod node_editor; 8 | mod node_runners; 9 | mod traits; 10 | mod types; 11 | 12 | pub use app::EmeraldFundStudioApp; 13 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/macros.rs: -------------------------------------------------------------------------------- 1 | #[macro_export] 2 | macro_rules! create_nodes { 3 | ($self:ident, $($node_name:ident),*) => { 4 | match $self.node_name.as_str() { 5 | $( 6 | stringify!($node_name) => Box::new(serde_json::from_value::<$node_name>($self.arguments.clone())?), 7 | )* 8 | _ => return Err(anyhow!("Node {} not found", $self.node_name)), 9 | } 10 | }; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /emeraldfundstudio/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # This scripts runs various CI-like checks in a convenient way. 3 | set -eux 4 | 5 | cargo check --quiet --workspace --all-targets 6 | cargo check --quiet --workspace --all-features --lib --target wasm32-unknown-unknown 7 | cargo fmt --all -- --check 8 | cargo clippy --quiet --workspace --all-targets --all-features -- -D warnings -W clippy::all 9 | cargo test --quiet --workspace --all-targets --all-features 10 | cargo test --quiet --workspace --doc 11 | trunk build 12 | -------------------------------------------------------------------------------- /emeraldfundstudio/.github/workflows/typos.yml: -------------------------------------------------------------------------------- 1 | # Copied from https://github.com/rerun-io/rerun_template 2 | 3 | # https://github.com/crate-ci/typos 4 | # Add exceptions to `.typos.toml` 5 | # install and run locally: cargo install typos-cli && typos 6 | 7 | name: Spell Check 8 | on: [pull_request] 9 | 10 | jobs: 11 | run: 12 | name: Spell Check 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout Actions Repository 16 | uses: actions/checkout@v4 17 | 18 | - name: Check spelling of entire workspace 19 | uses: crate-ci/typos@master 20 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/node_editor/nodes/execute_position.rs: -------------------------------------------------------------------------------- 1 | use crate::node_editor::node_trait::{EFNodeFn, NodeDataType}; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | #[derive(Debug, Serialize, Deserialize, Default)] 5 | pub struct ExecutePositionNode; 6 | 7 | impl EFNodeFn for ExecutePositionNode { 8 | fn get_name(&self) -> &'static str { 9 | "ExecutePositionNode" 10 | } 11 | 12 | fn get_inputs(&self) -> &[(&'static str, crate::node_editor::node_trait::NodeDataType)] { 13 | return &[("Signal", NodeDataType::Signal)]; 14 | } 15 | 16 | fn get_outputs(&self) -> &[(&'static str, crate::node_editor::node_trait::NodeDataType)] { 17 | return &[]; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /emeraldfundstudio/assets/sw.js: -------------------------------------------------------------------------------- 1 | var cacheName = 'egui-template-pwa'; 2 | var filesToCache = [ 3 | './', 4 | './index.html', 5 | './emerald_fund_2_dashboard.js', 6 | './emerald_fund_2_dashboard_bg.wasm', 7 | ]; 8 | 9 | /* Start the service worker and cache all of the app's content */ 10 | self.addEventListener('install', function (e) { 11 | e.waitUntil( 12 | caches.open(cacheName).then(function (cache) { 13 | return cache.addAll(filesToCache); 14 | }) 15 | ); 16 | }); 17 | 18 | /* Serve cached content when offline */ 19 | self.addEventListener('fetch', function (e) { 20 | e.respondWith( 21 | caches.match(e.request).then(function (response) { 22 | return response || fetch(e.request); 23 | }) 24 | ); 25 | }); 26 | -------------------------------------------------------------------------------- /emeraldfundstudio/assets/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "egui Template PWA", 3 | "short_name": "egui-template-pwa", 4 | "icons": [ 5 | { 6 | "src": "./assets/icon-256.png", 7 | "sizes": "256x256", 8 | "type": "image/png" 9 | }, 10 | { 11 | "src": "./assets/maskable_icon_x512.png", 12 | "sizes": "512x512", 13 | "type": "image/png", 14 | "purpose": "any maskable" 15 | }, 16 | { 17 | "src": "./assets/icon-1024.png", 18 | "sizes": "1024x1024", 19 | "type": "image/png" 20 | } 21 | ], 22 | "lang": "en-US", 23 | "id": "/index.html", 24 | "start_url": "./index.html", 25 | "display": "standalone", 26 | "background_color": "white", 27 | "theme_color": "white" 28 | } 29 | -------------------------------------------------------------------------------- /emeraldfundstudio/fill_template.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | set -e 4 | 5 | echo "To fill the template tell me your egui project crate name: " 6 | 7 | read crate 8 | 9 | echo "To fill the template tell me your name (for author in Cargo.toml): " 10 | 11 | read name 12 | 13 | echo "To fill the template tell me your e-mail address (also for Cargo.toml): " 14 | 15 | read email 16 | 17 | echo "Patching files..." 18 | 19 | sed -i "s/eframe_template/$crate/g" Cargo.toml 20 | sed -i "s/eframe_template/$crate/g" src/main.rs 21 | sed -i "s/eframe template/$crate/g" index.html 22 | sed -i "s/eframe_template/$crate/g" assets/sw.js 23 | sed -i "s/Emil Ernerfeldt/$name/g" Cargo.toml 24 | sed -i "s/emil.ernerfeldt@gmail.com/$email/g" Cargo.toml 25 | 26 | echo "Done." 27 | 28 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: emerald_show 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /emeraldfundstudio/fill_template.ps1: -------------------------------------------------------------------------------- 1 | $crate = Read-Host "To fill the template, tell me your egui project crate name: " 2 | $name = Read-Host "To fill the template, tell me your name (for author in Cargo.toml): " 3 | $email = Read-Host "To fill the template, tell me your e-mail address (also for Cargo.toml): " 4 | 5 | Write-Host "Patching files..." 6 | 7 | (Get-Content "Cargo.toml") -replace "eframe_template", $crate | Set-Content "Cargo.toml" 8 | (Get-Content "src\main.rs") -replace "eframe_template", $crate | Set-Content "src\main.rs" 9 | (Get-Content "index.html") -replace "eframe template", $crate -replace "eframe_template", $crate | Set-Content "index.html" 10 | (Get-Content "assets\sw.js") -replace "eframe_template", $crate | Set-Content "assets\sw.js" 11 | (Get-Content "Cargo.toml") -replace "Emil Ernerfeldt", $name -replace "emil.ernerfeldt@gmail.com", $email | Set-Content "Cargo.toml" 12 | 13 | Write-Host "Done." -------------------------------------------------------------------------------- /emeraldfundstudio/src/node_editor/nodes/sma.rs: -------------------------------------------------------------------------------- 1 | use crate::node_editor::node_trait::{EFNodeFn, NodeDataType}; 2 | use anyhow::Result; 3 | use serde::{Deserialize, Serialize}; 4 | 5 | #[derive(Debug, Serialize, Deserialize, Default)] 6 | pub struct SMANode; 7 | 8 | impl EFNodeFn for SMANode { 9 | fn get_name(&self) -> &'static str { 10 | "SMANode" 11 | } 12 | 13 | fn get_inputs(&self) -> &[(&'static str, crate::node_editor::node_trait::NodeDataType)] { 14 | return &[("Input", NodeDataType::DecimalSequence)]; 15 | } 16 | 17 | fn get_outputs(&self) -> &[(&'static str, crate::node_editor::node_trait::NodeDataType)] { 18 | return &[("Output", NodeDataType::DecimalSequence)]; 19 | } 20 | 21 | fn process_data( 22 | &self, 23 | input_args: &[crate::node_editor::node_trait::CheapCloneNodeDataTypeWithValue], 24 | ) -> Result> { 25 | return Ok(vec![input_args[0].clone()]); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Peter Willemsen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/node_editor/nodes/market_data.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | node_editor::node_trait::{EFNodeFn, NodeDataType, NodeDataTypeWithValue}, 3 | traits::IntoArc, 4 | types::candles::generate_candles, 5 | }; 6 | use anyhow::Result; 7 | use serde::{Deserialize, Serialize}; 8 | 9 | #[derive(Debug, Serialize, Deserialize, Default)] 10 | pub struct MarketDataNode; 11 | 12 | impl EFNodeFn for MarketDataNode { 13 | fn get_name(&self) -> &'static str { 14 | "MarketDataNode" 15 | } 16 | 17 | fn get_inputs(&self) -> &[(&'static str, crate::node_editor::node_trait::NodeDataType)] { 18 | return &[]; 19 | } 20 | 21 | fn get_outputs(&self) -> &[(&'static str, crate::node_editor::node_trait::NodeDataType)] { 22 | return &[("Candles", NodeDataType::Candles)]; 23 | } 24 | fn process_data( 25 | &self, 26 | input_args: &[crate::node_editor::node_trait::CheapCloneNodeDataTypeWithValue], 27 | ) -> Result> { 28 | let candles = generate_candles(21, 500)?; 29 | return Ok(vec![NodeDataTypeWithValue::Candles(candles).into_arc()]); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/node_editor/style.rs: -------------------------------------------------------------------------------- 1 | use egui::CornerRadius; 2 | use egui_snarl::ui::{NodeLayout, PinPlacement, SnarlStyle}; 3 | 4 | pub const fn default_style() -> SnarlStyle { 5 | SnarlStyle { 6 | node_layout: Some(NodeLayout::FlippedSandwich), 7 | pin_placement: Some(PinPlacement::Edge), 8 | pin_size: Some(7.0), 9 | node_frame: Some(egui::Frame { 10 | inner_margin: egui::Margin::same(8), 11 | outer_margin: egui::Margin { 12 | left: 0, 13 | right: 0, 14 | top: 0, 15 | bottom: 4, 16 | }, 17 | fill: egui::Color32::from_gray(30), 18 | stroke: egui::Stroke::NONE, 19 | shadow: egui::Shadow::NONE, 20 | corner_radius: CornerRadius::same(8), 21 | }), 22 | bg_frame: Some(egui::Frame { 23 | inner_margin: egui::Margin::same(2), 24 | outer_margin: egui::Margin::ZERO, 25 | fill: egui::Color32::from_gray(40), 26 | stroke: egui::Stroke::NONE, 27 | shadow: egui::Shadow::NONE, 28 | corner_radius: CornerRadius::same(8), 29 | }), 30 | ..SnarlStyle::new() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /emeraldfundstudio/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "eframe devShell"; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 6 | rust-overlay.url = "github:oxalica/rust-overlay"; 7 | flake-utils.url = "github:numtide/flake-utils"; 8 | }; 9 | 10 | outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }: 11 | flake-utils.lib.eachDefaultSystem (system: 12 | let 13 | overlays = [ (import rust-overlay) ]; 14 | pkgs = import nixpkgs { inherit system overlays; }; 15 | in with pkgs; { 16 | devShells.default = mkShell rec { 17 | buildInputs = [ 18 | # Rust 19 | rust-bin.stable.latest.default 20 | trunk 21 | 22 | # misc. libraries 23 | openssl 24 | pkg-config 25 | 26 | # GUI libs 27 | libxkbcommon 28 | libGL 29 | fontconfig 30 | 31 | # wayland libraries 32 | wayland 33 | 34 | # x11 libraries 35 | xorg.libXcursor 36 | xorg.libXrandr 37 | xorg.libXi 38 | xorg.libX11 39 | 40 | ]; 41 | 42 | LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}"; 43 | }; 44 | }); 45 | } 46 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/consts.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | use once_cell::sync::Lazy; 4 | use serde_json::Value; 5 | 6 | use crate::node_editor::{ 7 | node_trait::EFNodeFn, 8 | nodes::{ 9 | compare::CompareNode, execute_position::ExecutePositionNode, fuse_signals::FuseSignalsNode, 10 | market_data::MarketDataNode, preview::PreviewNode, sma::SMANode, 11 | split_candles::SplitCandlesNode, to_signal::ToSignalNode, 12 | }, 13 | }; 14 | 15 | pub static NODE_DEFAULT_VALUES: Lazy> = Lazy::new(|| { 16 | let mut m = HashMap::new(); 17 | m.insert("SMANode", SMANode::default().export_data()); 18 | m.insert("CompareNode", CompareNode::default().export_data()); 19 | m.insert("MarketDataNode", MarketDataNode::default().export_data()); 20 | m.insert("ToSignalNode", ToSignalNode::default().export_data()); 21 | m.insert("FuseSignalsNode", FuseSignalsNode::default().export_data()); 22 | m.insert( 23 | "SplitCandlesNode", 24 | SplitCandlesNode::default().export_data(), 25 | ); 26 | m.insert( 27 | "ExecutePositionNode", 28 | ExecutePositionNode::default().export_data(), 29 | ); 30 | m.insert("PreviewNode", PreviewNode::default().export_data()); 31 | m 32 | }); 33 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/node_editor/nodes/preview.rs: -------------------------------------------------------------------------------- 1 | use std::any::Any; 2 | 3 | use crate::node_editor::node_trait::{EFNodeFn, NodeDataType}; 4 | use serde::{Deserialize, Serialize}; 5 | 6 | #[derive(Debug, Serialize, Deserialize, Default)] 7 | #[serde(default)] 8 | pub struct PreviewNode { 9 | pub(crate) output_color: [u8; 3], 10 | } 11 | 12 | impl EFNodeFn for PreviewNode { 13 | fn get_name(&self) -> &'static str { 14 | "PreviewNode" 15 | } 16 | 17 | fn get_inputs(&self) -> &[(&'static str, crate::node_editor::node_trait::NodeDataType)] { 18 | return &[("Input", NodeDataType::DecimalSequence)]; 19 | } 20 | 21 | fn get_outputs(&self) -> &[(&'static str, crate::node_editor::node_trait::NodeDataType)] { 22 | return &[]; 23 | } 24 | 25 | fn show_header( 26 | &mut self, 27 | node_id: egui_snarl::NodeId, 28 | _inputs: &[egui_snarl::InPin], 29 | _outputs: &[egui_snarl::OutPin], 30 | ui: &mut egui::Ui, 31 | scale: f32, 32 | ) -> bool { 33 | let mut result = false; 34 | let response = ui.color_edit_button_srgb(&mut self.output_color); 35 | if response.changed() { 36 | result = true; 37 | } 38 | result 39 | } 40 | 41 | fn export_data(&self) -> serde_json::Value { 42 | return serde_json::to_value(self).unwrap(); 43 | } 44 | 45 | fn as_any(&self) -> &dyn Any { 46 | self 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/types/candles.rs: -------------------------------------------------------------------------------- 1 | use anyhow::Result; 2 | use polars::{df, frame::DataFrame}; 3 | use rand::{Rng, SeedableRng}; 4 | use rand_chacha::ChaCha8Rng; 5 | 6 | use super::timestamp::get_unix_time; 7 | 8 | pub fn generate_candles(seed: u64, len: usize) -> Result { 9 | let mut rng = ChaCha8Rng::seed_from_u64(seed); 10 | 11 | let mut opens = Vec::with_capacity(len); 12 | let mut highs = Vec::with_capacity(len); 13 | let mut lows = Vec::with_capacity(len); 14 | let mut closes = Vec::with_capacity(len); 15 | let mut volumes = Vec::with_capacity(len); 16 | let mut timestamps = Vec::with_capacity(len); 17 | 18 | if len == 0 { 19 | return Ok(DataFrame::new(vec![])?); 20 | } 21 | 22 | // Start with a random price for the first candle 23 | let mut prev_close = rng.gen_range(0.0..1.0); 24 | let mut timestamp = get_unix_time(); // Starting timestamp 25 | 26 | for _ in 0..len { 27 | let open: f64 = prev_close; 28 | let close = (open + rng.gen_range(-0.05..0.05)).max(0.0); // Ensure price doesn't go negative 29 | let high = close + rng.gen_range(0.00..0.02); 30 | let low = close - rng.gen_range(0.00..0.02); 31 | let volume = rng.gen_range(50.0..150.0); // Random volume between 50 and 150 32 | 33 | opens.push(open); 34 | highs.push(high); 35 | lows.push(low); 36 | closes.push(close); 37 | volumes.push(volume); 38 | timestamps.push(timestamp); 39 | 40 | prev_close = close; 41 | timestamp += 60; // Increase timestamp by 1 minute 42 | } 43 | 44 | let df = df![ 45 | "open" => opens, 46 | "high" => highs, 47 | "low" => lows, 48 | "close" => closes, 49 | "volume" => volumes, 50 | "timestamp" => timestamps, 51 | ]?; 52 | 53 | Ok(df) 54 | } 55 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/node_editor/nodes/fuse_signals.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | node_editor::node_trait::{EFNodeFn, NodeDataType, NodeDataTypeWithValue}, 3 | traits::IntoArc, 4 | types::signal::Signal, 5 | }; 6 | use anyhow::{anyhow, Result}; 7 | use serde::{Deserialize, Serialize}; 8 | use strum::IntoEnumIterator; 9 | 10 | #[derive(Debug, Serialize, Deserialize, Default)] 11 | #[serde(default)] 12 | pub struct FuseSignalsNode {} 13 | 14 | impl EFNodeFn for FuseSignalsNode { 15 | fn get_name(&self) -> &'static str { 16 | "FuseSignalsNode" 17 | } 18 | 19 | fn get_inputs(&self) -> &[(&'static str, crate::node_editor::node_trait::NodeDataType)] { 20 | return &[ 21 | ("Signal 1", NodeDataType::Signal), 22 | ("Signal 2", NodeDataType::Signal), 23 | ]; 24 | } 25 | 26 | fn get_outputs(&self) -> &[(&'static str, crate::node_editor::node_trait::NodeDataType)] { 27 | return &[("Fused Signal", NodeDataType::Signal)]; 28 | } 29 | 30 | fn process_data( 31 | &self, 32 | input_args: &[crate::node_editor::node_trait::CheapCloneNodeDataTypeWithValue], 33 | ) -> Result> { 34 | if input_args.len() != 2 { 35 | return Err(anyhow!("should have 2 inputs!")); 36 | } 37 | 38 | if let NodeDataTypeWithValue::Signal(sig0) = &*input_args[0] { 39 | if let NodeDataTypeWithValue::Signal(sig1) = &*input_args[1] { 40 | let fused_signal: Signal = sig0 41 | .iter() 42 | .zip(sig1.iter()) 43 | .map(|(sig0, sig1)| { 44 | if *sig0 == 0 { 45 | return *sig1; 46 | } else { 47 | return *sig0; 48 | } 49 | }) 50 | .collect(); 51 | return Ok(vec![NodeDataTypeWithValue::Signal(fused_signal).into_arc()]); 52 | } 53 | } 54 | return Err(anyhow!("Unknown input")); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /emeraldfundstudio/.github/workflows/pages.yml: -------------------------------------------------------------------------------- 1 | name: Github Pages 2 | 3 | # By default, runs if you push to main. keeps your deployed app in sync with main branch. 4 | on: 5 | push: 6 | branches: 7 | - main 8 | # to only run when you do a new github release, comment out above part and uncomment the below trigger. 9 | # on: 10 | # release: 11 | # types: 12 | # - published 13 | 14 | permissions: 15 | contents: write # for committing to gh-pages branch. 16 | 17 | jobs: 18 | build-github-pages: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v4 # repo checkout 22 | - name: Setup toolchain for wasm 23 | run: | 24 | rustup update stable 25 | rustup default stable 26 | rustup set profile minimal 27 | rustup target add wasm32-unknown-unknown 28 | - name: Rust Cache # cache the rust build artefacts 29 | uses: Swatinem/rust-cache@v2 30 | - name: Download and install Trunk binary 31 | run: wget -qO- https://github.com/thedodd/trunk/releases/latest/download/trunk-x86_64-unknown-linux-gnu.tar.gz | tar -xzf- 32 | - name: Build # build 33 | # Environment $public_url resolves to the github project page. 34 | # If using a user/organization page, remove the `${{ github.event.repository.name }}` part. 35 | # using --public-url something will allow trunk to modify all the href paths like from favicon.ico to repo_name/favicon.ico . 36 | # this is necessary for github pages where the site is deployed to username.github.io/repo_name and all files must be requested 37 | # relatively as eframe_template/favicon.ico. if we skip public-url option, the href paths will instead request username.github.io/favicon.ico which 38 | # will obviously return error 404 not found. 39 | run: ./trunk build --release --public-url $public_url 40 | env: 41 | public_url: "https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}" 42 | - name: Deploy 43 | uses: JamesIves/github-pages-deploy-action@v4 44 | with: 45 | folder: dist 46 | # this option will not maintain any history of your previous pages deployment 47 | # set to false if you want all page build to be committed to your gh-pages branch history 48 | single-commit: true 49 | -------------------------------------------------------------------------------- /emeraldfundstudio/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "emeraldfundstudio" 3 | version = "0.1.0" 4 | authors = ["Peter Willemsen "] 5 | edition = "2021" 6 | include = ["LICENSE-APACHE", "LICENSE-MIT", "**/*.rs", "Cargo.toml"] 7 | 8 | [package.metadata.docs.rs] 9 | all-features = true 10 | targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] 11 | 12 | [dependencies] 13 | egui = "0.31.0" 14 | eframe = { version = "0.31.0", default-features = false, features = [ 15 | "accesskit", # Make egui compatible with screen readers. NOTE: adds a lot of dependencies. 16 | "default_fonts", # Embed the default egui fonts. 17 | "glow", # Use the glow rendering backend. Alternative: "wgpu". 18 | "persistence", # Enable restoring app state when restarting the app. 19 | "wayland", # To support Linux (and CI) 20 | ] } 21 | ecolor = "0.31.0" 22 | egui_plot = "0.31.0" 23 | epaint = "0.31.0" 24 | egui-snarl = { version = "0.7.1", features = ["serde"] } 25 | log = "0.4" 26 | 27 | # You only need serde if you want app persistence: 28 | serde = { version = "1", features = ["derive"] } 29 | syn = "2.0.95" 30 | chrono = "0.4.39" 31 | random = "0.14.0" 32 | rand = "0.8.5" 33 | rand_chacha = "0.3.1" 34 | strum = { version = "0.26.3", features = ["derive"] } 35 | parking_lot = "0.12.3" 36 | dashmap = { version = "6.1.0", features = ["serde"] } 37 | once_cell = "1.20.3" 38 | serde_json = "1.0.138" 39 | anyhow = "1.0.95" 40 | rayon = "1.10.0" 41 | polars = { version = "0.46.0", features = ["lazy"], default-features = false } 42 | itertools = "0.14.0" 43 | 44 | # native: 45 | [target.'cfg(not(target_arch = "wasm32"))'.dependencies] 46 | env_logger = "0.11" 47 | 48 | # web: 49 | [target.'cfg(target_arch = "wasm32")'.dependencies] 50 | wasm-bindgen-futures = "0.4" 51 | web-sys = "0.3.70" # to access the DOM (to hide the loading text) 52 | 53 | [profile.release] 54 | opt-level = 2 # fast and small wasm 55 | 56 | # Optimize all dependencies even in debug builds: 57 | [profile.dev.package."*"] 58 | opt-level = 2 59 | 60 | 61 | [patch.crates-io] 62 | 63 | # If you want to use the bleeding edge version of egui and eframe: 64 | # egui = { git = "https://github.com/emilk/egui", branch = "master" } 65 | # eframe = { git = "https://github.com/emilk/egui", branch = "master" } 66 | 67 | # If you fork https://github.com/emilk/egui you can test with: 68 | # egui = { path = "../egui/crates/egui" } 69 | # eframe = { path = "../egui/crates/eframe" } 70 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/node_editor/nodes/split_candles.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | node_editor::node_trait::{ 3 | CheapCloneNodeDataTypeWithValue, EFNodeFn, NodeDataType, NodeDataTypeWithValue, 4 | }, 5 | traits::IntoArc, 6 | }; 7 | use anyhow::{anyhow, Result}; 8 | use polars::prelude::{ChunkedArray, Float64Type}; 9 | use serde::{Deserialize, Serialize}; 10 | 11 | #[derive(Debug, Serialize, Deserialize, Default)] 12 | pub struct SplitCandlesNode; 13 | 14 | fn nd_column_to_decimal_sequence( 15 | series: &ChunkedArray, 16 | ) -> CheapCloneNodeDataTypeWithValue { 17 | NodeDataTypeWithValue::DecimalSequence(series.clone()).into_arc() 18 | } 19 | 20 | impl EFNodeFn for SplitCandlesNode { 21 | fn get_name(&self) -> &'static str { 22 | "SplitCandlesNode" 23 | } 24 | 25 | fn get_inputs(&self) -> &[(&'static str, crate::node_editor::node_trait::NodeDataType)] { 26 | return &[("Candles", NodeDataType::Candles)]; 27 | } 28 | 29 | fn get_outputs(&self) -> &[(&'static str, crate::node_editor::node_trait::NodeDataType)] { 30 | return &[ 31 | ("Open", NodeDataType::DecimalSequence), 32 | ("High", NodeDataType::DecimalSequence), 33 | ("Low", NodeDataType::DecimalSequence), 34 | ("Close", NodeDataType::DecimalSequence), 35 | ("Volume", NodeDataType::DecimalSequence), 36 | ]; 37 | } 38 | 39 | fn process_data( 40 | &self, 41 | input_args: &[crate::node_editor::node_trait::CheapCloneNodeDataTypeWithValue], 42 | ) -> Result> { 43 | if input_args.len() < 1 { 44 | return Err(anyhow!("should have 1 input!")); 45 | } 46 | 47 | if let NodeDataTypeWithValue::Candles(df) = &*input_args[0] { 48 | let opens = df.column("open").unwrap().f64().unwrap(); 49 | let highs = df.column("high").unwrap().f64().unwrap(); 50 | let lows = df.column("low").unwrap().f64().unwrap(); 51 | let closes = df.column("close").unwrap().f64().unwrap(); 52 | let volumes = df.column("volume").unwrap().f64().unwrap(); 53 | // let timestamps = df.column("timestamp").unwrap().u64().unwrap(); 54 | 55 | return Ok(vec![ 56 | nd_column_to_decimal_sequence(opens), 57 | nd_column_to_decimal_sequence(highs), 58 | nd_column_to_decimal_sequence(lows), 59 | nd_column_to_decimal_sequence(closes), 60 | nd_column_to_decimal_sequence(volumes), 61 | ]); 62 | } 63 | 64 | Err(anyhow!("First argument must be a DataFrame")) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Emerald Fund Logo](resources/EmeraldFundLogo.png) 2 | 3 | # "Bring the magic of giving back" 4 | 5 | Allow yourself to express the fullest creativity possible when making your next strategy! 6 | Emerald Fund 2 is the trusted partner that empowers you to craft strategies with finesse and vision. Because making strategies isn't just a task—it's an art form, and you are the artist. 7 | 8 | EF2 embodies automated trading as a way of life, a passion that never sleeps. From sunrise to sunset, from brainstorming to execution, you are crafting smarter, better strategies that open new possibilities. 9 | 10 | Whether you're refining ideas late into the night or striking inspiration on the go, EF2 is your constant companion. Let your creativity flow, explore new frontiers, and turn your visions into reality with Emerald Fund 2. 11 | 12 | # Alpha stage notice 13 | 14 | We're currently in Alpha mode! Many things are not finished and we're open for testing and feedback! 15 | 16 | Current demo is hosted here: 17 | 18 | - Feel free to [join my Discord server](https://discord.gg/dCjH8zZXuM) for questions, testing, contributing or feedback (you can also tag @emerald in the Hummingbot Discord!) 19 | 20 | # Tutorial + Demo 21 | 22 | Here's everything you need to know: 23 | 24 | # Features 25 | 26 | - Ridiculously fast, backtests and modifications to strategies show real-time 27 | - Design, test, update and share strategies from 1 interface 28 | - Beginner friendly - uses visual building blocks to design your strategy, 100% no-code! 29 | - The fastest solution available thanks to the multifunctional node execution engine, multithreading and GPU acceleration 30 | - Export your strategies directly into Hummingbot and run at near-native speed 31 | 32 | # Changelog 🏗 33 | 34 | ## 2025-02-22 35 | 36 | First release 37 | 38 | # Coming soon 👀 39 | 40 | - SMA implemented + visual feedback? 41 | 42 | # Support / contribute 43 | 44 | - Feel free to [join my Discord server](https://discord.gg/dCjH8zZXuM), we can chat! 45 | - I'm open for feedback and contributions, feel free to join in! 46 | - [Financial contributions are welcome on my Patreon](https://www.patreon.com/c/emerald_show), you'll get exclusive access to early content + a special role on my server 💚 47 | 48 | # Thanks 49 | 50 | - The members on discord, Patreon subscribers and all that put the word out, it gave me warm fuzzy vibes! 51 | - dardonacci and fengtality for showing me the Dashboard and giving me a crash course 52 | - dardonacci for answering all my questions I had during the development. It would otherwise not have been possible 53 | 54 | # Sister projects 55 | 56 | - [Hummingbot Discord Bot](https://github.com/peterwilli/HummingDiscordBot) 57 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/main.rs: -------------------------------------------------------------------------------- 1 | #![warn(clippy::all, rust_2018_idioms)] 2 | #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release 3 | 4 | // When compiling natively: 5 | #[cfg(not(target_arch = "wasm32"))] 6 | fn main() -> eframe::Result { 7 | env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). 8 | 9 | let native_options = eframe::NativeOptions { 10 | viewport: egui::ViewportBuilder::default() 11 | .with_inner_size([400.0, 300.0]) 12 | .with_min_inner_size([300.0, 220.0]) 13 | .with_icon( 14 | // NOTE: Adding an icon is optional 15 | eframe::icon_data::from_png_bytes(&include_bytes!("../assets/icon-256.png")[..]) 16 | .expect("Failed to load icon"), 17 | ), 18 | ..Default::default() 19 | }; 20 | eframe::run_native( 21 | "Emerald Fund Studio", 22 | native_options, 23 | Box::new(|cc| Ok(Box::new(emeraldfundstudio::EmeraldFundStudioApp::new(cc)))), 24 | ) 25 | } 26 | 27 | // When compiling to web using trunk: 28 | #[cfg(target_arch = "wasm32")] 29 | fn main() { 30 | use eframe::wasm_bindgen::JsCast as _; 31 | 32 | // Redirect `log` message to `console.log` and friends: 33 | eframe::WebLogger::init(log::LevelFilter::Debug).ok(); 34 | 35 | let web_options = eframe::WebOptions::default(); 36 | 37 | wasm_bindgen_futures::spawn_local(async { 38 | let document = web_sys::window() 39 | .expect("No window") 40 | .document() 41 | .expect("No document"); 42 | 43 | let canvas = document 44 | .get_element_by_id("the_canvas_id") 45 | .expect("Failed to find the_canvas_id") 46 | .dyn_into::() 47 | .expect("the_canvas_id was not a HtmlCanvasElement"); 48 | 49 | let start_result = eframe::WebRunner::new() 50 | .start( 51 | canvas, 52 | web_options, 53 | Box::new(|cc| Ok(Box::new(emeraldfundstudio::EmeraldFundStudioApp::new(cc)))), 54 | ) 55 | .await; 56 | 57 | // Remove the loading text and spinner: 58 | if let Some(loading_text) = document.get_element_by_id("loading_text") { 59 | match start_result { 60 | Ok(_) => { 61 | loading_text.remove(); 62 | } 63 | Err(e) => { 64 | loading_text.set_inner_html( 65 | "

The app has crashed. See the developer console for details.

", 66 | ); 67 | panic!("Failed to start eframe: {e:?}"); 68 | } 69 | } 70 | } 71 | }); 72 | } 73 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/node_editor/nodes/to_signal.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | node_editor::node_trait::{EFNodeFn, NodeDataType, NodeDataTypeWithValue}, 3 | traits::IntoArc, 4 | }; 5 | use anyhow::{anyhow, Result}; 6 | use egui::ComboBox; 7 | use serde::{Deserialize, Serialize}; 8 | use strum::{AsRefStr, Display, EnumIter, IntoEnumIterator}; 9 | 10 | #[derive( 11 | Debug, Serialize, Deserialize, Default, AsRefStr, EnumIter, PartialEq, Eq, Clone, Display, 12 | )] 13 | pub enum ToSignalMode { 14 | #[default] 15 | Buy, 16 | Sell, 17 | } 18 | 19 | #[derive(Debug, Serialize, Deserialize, Default)] 20 | #[serde(default)] 21 | pub struct ToSignalNode { 22 | mode: ToSignalMode, 23 | } 24 | 25 | impl EFNodeFn for ToSignalNode { 26 | fn get_name(&self) -> &'static str { 27 | "ToSignalNode" 28 | } 29 | 30 | fn get_inputs(&self) -> &[(&'static str, crate::node_editor::node_trait::NodeDataType)] { 31 | return &[("Mask", NodeDataType::Mask)]; 32 | } 33 | 34 | fn get_outputs(&self) -> &[(&'static str, crate::node_editor::node_trait::NodeDataType)] { 35 | return &[("Signal", NodeDataType::Signal)]; 36 | } 37 | 38 | fn process_data( 39 | &self, 40 | input_args: &[crate::node_editor::node_trait::CheapCloneNodeDataTypeWithValue], 41 | ) -> Result> { 42 | if input_args.len() != 1 { 43 | return Err(anyhow!("should have 1 inputs!")); 44 | } 45 | 46 | if let NodeDataTypeWithValue::Mask(mask) = &*input_args[0] { 47 | let result: Vec = mask 48 | .iter() 49 | .map(|m| { 50 | if *m { 51 | match self.mode { 52 | ToSignalMode::Buy => 1, 53 | ToSignalMode::Sell => -1, 54 | } 55 | } else { 56 | 0 57 | } 58 | }) 59 | .collect(); 60 | return Ok(vec![NodeDataTypeWithValue::Signal(result).into_arc()]); 61 | } 62 | return Err(anyhow!("Unknown input")); 63 | } 64 | 65 | fn show_header( 66 | &mut self, 67 | node_id: egui_snarl::NodeId, 68 | _inputs: &[egui_snarl::InPin], 69 | _outputs: &[egui_snarl::OutPin], 70 | ui: &mut egui::Ui, 71 | scale: f32, 72 | ) -> bool { 73 | let mut result = false; 74 | ComboBox::from_id_salt(0) 75 | .selected_text(self.mode.to_string()) 76 | .show_ui(ui, |ui| { 77 | for v in ToSignalMode::iter() { 78 | let response = ui.selectable_value(&mut self.mode, v.clone(), v.to_string()); 79 | if response.changed() { 80 | result = true; 81 | } 82 | } 83 | }); 84 | result 85 | } 86 | 87 | fn export_data(&self) -> serde_json::Value { 88 | return serde_json::to_value(self).unwrap(); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/node_editor/node_trait.rs: -------------------------------------------------------------------------------- 1 | use super::nodes::{ 2 | compare::CompareNode, execute_position::ExecutePositionNode, fuse_signals::FuseSignalsNode, 3 | market_data::MarketDataNode, preview::PreviewNode, sma::SMANode, 4 | split_candles::SplitCandlesNode, to_signal::ToSignalNode, 5 | }; 6 | use crate::{ 7 | create_nodes, 8 | types::{decimal_sequence::DecimalSequence, mask::Mask, signal::Signal}, 9 | }; 10 | use anyhow::{anyhow, Result}; 11 | use egui::{TextBuffer, Ui}; 12 | use egui_snarl::{InPin, NodeId, OutPin}; 13 | use polars::frame::DataFrame; 14 | use serde::{Deserialize, Serialize}; 15 | use std::{any::Any, borrow::Cow, sync::Arc}; 16 | 17 | pub enum NodeDataType { 18 | Mask, 19 | Signal, 20 | DecimalSequence, 21 | Candles, 22 | } 23 | 24 | #[derive(Clone, Debug)] 25 | pub enum NodeDataTypeWithValue { 26 | Mask(Mask), 27 | Signal(Signal), 28 | DecimalSequence(DecimalSequence), 29 | Candles(DataFrame), 30 | } 31 | 32 | pub type CheapCloneNodeDataTypeWithValue = Arc; 33 | 34 | #[derive(Serialize, Deserialize)] 35 | pub struct EFNodeFNSerialized<'a> { 36 | pub node_name: Cow<'a, str>, 37 | pub arguments: serde_json::Value, 38 | #[serde(skip)] 39 | pub loaded_node: Option>, 40 | } 41 | 42 | impl EFNodeFNSerialized<'_> { 43 | pub fn load_node(&mut self) -> Result<()> { 44 | let loaded_node: Box = create_nodes!( 45 | self, 46 | SMANode, 47 | CompareNode, 48 | MarketDataNode, 49 | ExecutePositionNode, 50 | SplitCandlesNode, 51 | ToSignalNode, 52 | FuseSignalsNode, 53 | PreviewNode 54 | ); 55 | self.loaded_node = Some(loaded_node); 56 | Ok(()) 57 | } 58 | 59 | pub fn save_node(&mut self) { 60 | self.arguments = self.get_node().export_data(); 61 | } 62 | 63 | pub fn get_node_mut(&mut self) -> &mut Box { 64 | return self 65 | .loaded_node 66 | .as_mut() 67 | .expect("Node should be loaded when calling get_node!"); 68 | } 69 | 70 | pub fn get_node(&self) -> &Box { 71 | return self 72 | .loaded_node 73 | .as_ref() 74 | .expect("Node should be loaded when calling get_node!"); 75 | } 76 | } 77 | 78 | pub trait EFNodeFn: Send + Sync { 79 | fn export_data(&self) -> serde_json::Value { 80 | serde_json::Value::Null 81 | } 82 | fn get_name(&self) -> &'static str; 83 | fn get_inputs(&self) -> &[(&'static str, NodeDataType)]; 84 | fn get_outputs(&self) -> &[(&'static str, NodeDataType)]; 85 | fn show_header( 86 | &mut self, 87 | node_id: NodeId, 88 | _inputs: &[InPin], 89 | _outputs: &[OutPin], 90 | ui: &mut Ui, 91 | scale: f32, 92 | ) -> bool { 93 | false 94 | } 95 | fn process_data( 96 | &self, 97 | input_args: &[crate::node_editor::node_trait::CheapCloneNodeDataTypeWithValue], 98 | ) -> Result> { 99 | Ok(vec![]) 100 | } 101 | 102 | fn as_any(&self) -> &dyn Any { 103 | todo!("If this fails you need to implement this"); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/node_editor/nodes/compare.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | node_editor::node_trait::{EFNodeFn, NodeDataType, NodeDataTypeWithValue}, 3 | traits::IntoArc, 4 | }; 5 | use anyhow::{anyhow, Result}; 6 | use egui::ComboBox; 7 | use polars::{prelude::ChunkCompareIneq, series::ChunkCompareEq}; 8 | use serde::{Deserialize, Serialize}; 9 | use strum::{AsRefStr, Display, EnumIter, IntoEnumIterator}; 10 | 11 | #[derive( 12 | Debug, Serialize, Deserialize, Default, AsRefStr, EnumIter, PartialEq, Eq, Clone, Display, 13 | )] 14 | pub enum CompareMode { 15 | #[strum(serialize = "Bigger Than")] 16 | BiggerThan, 17 | #[strum(serialize = "Less Than")] 18 | LessThan, 19 | #[strum(serialize = "Equal")] 20 | #[default] 21 | Equal, 22 | #[strum(serialize = "Not Equal")] 23 | NotEqual, 24 | } 25 | 26 | #[derive(Debug, Serialize, Deserialize, Default)] 27 | #[serde(default)] 28 | pub struct CompareNode { 29 | pub mode: CompareMode, 30 | } 31 | 32 | impl EFNodeFn for CompareNode { 33 | fn get_name(&self) -> &'static str { 34 | "Compare" 35 | } 36 | 37 | fn get_inputs(&self) -> &[(&'static str, crate::node_editor::node_trait::NodeDataType)] { 38 | return &[ 39 | ("Seq 1", NodeDataType::DecimalSequence), 40 | ("Seq 2", NodeDataType::DecimalSequence), 41 | ]; 42 | } 43 | 44 | fn get_outputs(&self) -> &[(&'static str, crate::node_editor::node_trait::NodeDataType)] { 45 | return &[("Mask", NodeDataType::Mask)]; 46 | } 47 | 48 | fn process_data( 49 | &self, 50 | input_args: &[crate::node_editor::node_trait::CheapCloneNodeDataTypeWithValue], 51 | ) -> Result> { 52 | if input_args.len() < 1 { 53 | return Err(anyhow!("should have 1 input!")); 54 | } 55 | 56 | if let NodeDataTypeWithValue::DecimalSequence(df0) = &*input_args[0] { 57 | if let NodeDataTypeWithValue::DecimalSequence(df1) = &*input_args[1] { 58 | let result = match self.mode { 59 | CompareMode::Equal => df0.equal(df1), 60 | CompareMode::NotEqual => df0.not_equal(df1), 61 | CompareMode::LessThan => df0.lt(df1), 62 | CompareMode::BiggerThan => df0.gt(df1), 63 | }; 64 | return Ok(vec![NodeDataTypeWithValue::Mask( 65 | result.iter().map(|x| x.unwrap()).collect(), 66 | ) 67 | .into_arc()]); 68 | } 69 | } 70 | return Err(anyhow!("Unknown input")); 71 | } 72 | 73 | fn show_header( 74 | &mut self, 75 | node_id: egui_snarl::NodeId, 76 | _inputs: &[egui_snarl::InPin], 77 | _outputs: &[egui_snarl::OutPin], 78 | ui: &mut egui::Ui, 79 | scale: f32, 80 | ) -> bool { 81 | let mut result = false; 82 | ComboBox::from_id_salt(0) 83 | .selected_text(self.mode.to_string()) 84 | .show_ui(ui, |ui| { 85 | for v in CompareMode::iter() { 86 | let value = ui.selectable_value(&mut self.mode, v.clone(), v.to_string()); 87 | if value.changed() { 88 | result = true; 89 | } 90 | } 91 | }); 92 | result 93 | } 94 | 95 | fn export_data(&self) -> serde_json::Value { 96 | return serde_json::to_value(self).unwrap(); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/node_runners/realtime.rs: -------------------------------------------------------------------------------- 1 | use dashmap::DashMap; 2 | use egui_snarl::{InPinId, NodeId, Snarl}; 3 | use itertools::Itertools; 4 | use once_cell::sync::Lazy; 5 | use rayon::iter::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator}; 6 | 7 | use crate::node_editor::node_trait::{CheapCloneNodeDataTypeWithValue, EFNodeFNSerialized}; 8 | 9 | pub static NODE_COMPUTE_CACHE: Lazy>> = 10 | Lazy::new(|| Default::default()); 11 | 12 | pub fn filter_already_executed(nodes: &mut Vec) { 13 | nodes.retain(|n| !NODE_COMPUTE_CACHE.contains_key(&n.0)); 14 | } 15 | 16 | pub fn clear_cache_from_node_onward(snarl: &Snarl>, id: &NodeId) { 17 | // TODO: Need to remove only it and dependencies 18 | NODE_COMPUTE_CACHE.clear(); 19 | run_nodes(snarl); 20 | } 21 | 22 | pub fn is_node_realtime_executable( 23 | snarl: &Snarl>, 24 | id: NodeId, 25 | node: &EFNodeFNSerialized<'_>, 26 | ) -> bool { 27 | let n_inputs = node.get_node().get_inputs().len(); 28 | 29 | let has_all_inputs_connected = (0..n_inputs).into_par_iter().all(|pin_id| { 30 | let in_pin = snarl.in_pin(InPinId { 31 | node: id, 32 | input: pin_id, 33 | }); 34 | 35 | let has_at_least_one_input_connection = in_pin.remotes.len() > 0; 36 | if !has_at_least_one_input_connection { 37 | return false; 38 | } 39 | let has_computed_result = NODE_COMPUTE_CACHE 40 | .get(&in_pin.remotes.first().unwrap().node.0) 41 | .is_some(); 42 | if has_computed_result { 43 | return true; 44 | } 45 | false 46 | }); 47 | 48 | has_all_inputs_connected 49 | } 50 | 51 | fn get_executable_nodes(snarl: &Snarl>) -> Vec { 52 | snarl 53 | .node_ids() 54 | .filter_map(|(id, node)| { 55 | if is_node_realtime_executable(snarl, id, node) { 56 | Some(id) 57 | } else { 58 | None 59 | } 60 | }) 61 | .collect() 62 | } 63 | 64 | pub fn run_nodes(snarl: &Snarl>) { 65 | let mut executable_nodes = get_executable_nodes(snarl); 66 | filter_already_executed(&mut executable_nodes); 67 | while executable_nodes.len() > 0 { 68 | executable_nodes.par_iter().for_each(|id| { 69 | let node = snarl.get_node(*id).unwrap(); 70 | let inner_node = node.get_node(); 71 | let n_inputs = node.get_node().get_inputs().len(); 72 | let input_args = (0..n_inputs) 73 | .into_par_iter() 74 | .map(|pin_id| { 75 | let in_pin = snarl.in_pin(InPinId { 76 | node: *id, 77 | input: pin_id, 78 | }); 79 | 80 | let remote_output_pin = in_pin.remotes.first().unwrap(); 81 | let output_values = NODE_COMPUTE_CACHE.get(&remote_output_pin.node.0).unwrap(); 82 | output_values.get(remote_output_pin.output).unwrap().clone() 83 | }) 84 | .collect::>(); 85 | let results = inner_node.process_data(&input_args).unwrap(); 86 | NODE_COMPUTE_CACHE.insert(id.0, results); 87 | }); 88 | executable_nodes = get_executable_nodes(snarl); 89 | filter_already_executed(&mut executable_nodes); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/app.rs: -------------------------------------------------------------------------------- 1 | use eframe::egui::{self}; 2 | use egui_snarl::Snarl; 3 | 4 | use crate::{ 5 | candles::chart::candlestick_chart, 6 | node_editor::{node_trait::EFNodeFNSerialized, style::default_style, EFViewer}, 7 | node_runners::realtime::run_nodes, 8 | }; 9 | 10 | /// We derive Deserialize/Serialize so we can persist app state on shutdown. 11 | #[derive(serde::Deserialize, serde::Serialize)] 12 | #[serde(default)] // if we add new fields, give them default values when deserializing old state 13 | pub struct EmeraldFundStudioApp<'a> { 14 | snarl: Snarl>, 15 | } 16 | 17 | impl Default for EmeraldFundStudioApp<'_> { 18 | fn default() -> Self { 19 | Self { 20 | snarl: Snarl::new(), 21 | } 22 | } 23 | } 24 | 25 | impl EmeraldFundStudioApp<'_> { 26 | /// Called once before the first frame. 27 | pub fn new(cc: &eframe::CreationContext<'_>) -> Self { 28 | // This is also where you can customize the look and feel of egui using 29 | // `cc.egui_ctx.set_visuals` and `cc.egui_ctx.set_fonts`. 30 | 31 | // Load previous app state (if any). 32 | // Note that you must enable the `persistence` feature for this to work. 33 | if let Some(storage) = cc.storage { 34 | let mut result: Self = eframe::get_value(storage, eframe::APP_KEY).unwrap_or_default(); 35 | for node in result.snarl.nodes_mut() { 36 | node.load_node().unwrap(); 37 | } 38 | run_nodes(&result.snarl); 39 | return result; 40 | } 41 | 42 | Default::default() 43 | } 44 | } 45 | 46 | impl eframe::App for EmeraldFundStudioApp<'_> { 47 | /// Called by the frame work to save state before shutdown. 48 | fn save(&mut self, storage: &mut dyn eframe::Storage) { 49 | for node in self.snarl.nodes_mut() { 50 | node.save_node(); 51 | } 52 | 53 | eframe::set_value(storage, eframe::APP_KEY, self); 54 | } 55 | 56 | /// Called each time the UI needs repainting, which may be many times per second. 57 | fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { 58 | // Put your widgets into a `SidePanel`, `TopBottomPanel`, `CentralPanel`, `Window` or `Area`. 59 | // For inspiration and more examples, go to https://emilk.github.io/egui 60 | 61 | egui::TopBottomPanel::top("top_panel").show(ctx, |ui| { 62 | // The top panel is often a good place for a menu bar: 63 | 64 | egui::menu::bar(ui, |ui| { 65 | // NOTE: no File->Quit on web pages! 66 | let is_web = cfg!(target_arch = "wasm32"); 67 | if !is_web { 68 | ui.menu_button("File", |ui| { 69 | if ui.button("Quit").clicked() { 70 | ctx.send_viewport_cmd(egui::ViewportCommand::Close); 71 | } 72 | if ui.button("Reset").clicked() { 73 | self.snarl = Default::default(); 74 | ctx.memory_mut(|mem| *mem = Default::default()); 75 | } 76 | }); 77 | ui.add_space(16.0); 78 | } 79 | }); 80 | }); 81 | 82 | egui::CentralPanel::default().show(ctx, |ui| { 83 | // The central panel the region left after adding TopPanel's and SidePanel's 84 | ui.heading("Emerald Fund Studio"); 85 | egui::TopBottomPanel::top("top") 86 | .resizable(true) 87 | .min_height(256.0) 88 | .show(ctx, |ui| { 89 | candlestick_chart(ui, &self.snarl); 90 | }); 91 | egui::CentralPanel::default().show(ctx, |ui| { 92 | self.snarl 93 | .show(&mut EFViewer, &default_style(), "snarl", ui); 94 | }); 95 | }); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /emeraldfundstudio/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | emerald_fund_2_dashboard 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 |
128 |

129 | Loading… 130 |

131 |
132 |
133 | 134 | 135 | 136 | 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /emeraldfundstudio/.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request, workflow_dispatch] 2 | 3 | name: CI 4 | 5 | env: 6 | RUSTFLAGS: -D warnings 7 | RUSTDOCFLAGS: -D warnings 8 | 9 | jobs: 10 | check: 11 | name: Check 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v4 15 | - uses: actions-rs/toolchain@v1 16 | with: 17 | profile: minimal 18 | toolchain: stable 19 | override: true 20 | - uses: actions-rs/cargo@v1 21 | with: 22 | command: check 23 | args: --all-features 24 | 25 | check_wasm: 26 | name: Check wasm32 27 | runs-on: ubuntu-latest 28 | steps: 29 | - uses: actions/checkout@v4 30 | - uses: actions-rs/toolchain@v1 31 | with: 32 | profile: minimal 33 | toolchain: stable 34 | target: wasm32-unknown-unknown 35 | override: true 36 | - uses: actions-rs/cargo@v1 37 | with: 38 | command: check 39 | args: --all-features --lib --target wasm32-unknown-unknown 40 | 41 | test: 42 | name: Test Suite 43 | runs-on: ubuntu-latest 44 | steps: 45 | - uses: actions/checkout@v4 46 | - uses: actions-rs/toolchain@v1 47 | with: 48 | profile: minimal 49 | toolchain: stable 50 | override: true 51 | - run: sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev 52 | - uses: actions-rs/cargo@v1 53 | with: 54 | command: test 55 | args: --lib 56 | 57 | fmt: 58 | name: Rustfmt 59 | runs-on: ubuntu-latest 60 | steps: 61 | - uses: actions/checkout@v4 62 | - uses: actions-rs/toolchain@v1 63 | with: 64 | profile: minimal 65 | toolchain: stable 66 | override: true 67 | components: rustfmt 68 | - uses: actions-rs/cargo@v1 69 | with: 70 | command: fmt 71 | args: --all -- --check 72 | 73 | clippy: 74 | name: Clippy 75 | runs-on: ubuntu-latest 76 | steps: 77 | - uses: actions/checkout@v4 78 | - uses: actions-rs/toolchain@v1 79 | with: 80 | profile: minimal 81 | toolchain: stable 82 | override: true 83 | components: clippy 84 | - uses: actions-rs/cargo@v1 85 | with: 86 | command: clippy 87 | args: -- -D warnings 88 | 89 | trunk: 90 | name: trunk 91 | runs-on: ubuntu-latest 92 | steps: 93 | - uses: actions/checkout@v4 94 | - uses: actions-rs/toolchain@v1 95 | with: 96 | profile: minimal 97 | toolchain: 1.81.0 98 | target: wasm32-unknown-unknown 99 | override: true 100 | - name: Download and install Trunk binary 101 | run: wget -qO- https://github.com/thedodd/trunk/releases/latest/download/trunk-x86_64-unknown-linux-gnu.tar.gz | tar -xzf- 102 | - name: Build 103 | run: ./trunk build 104 | 105 | build: 106 | runs-on: ${{ matrix.os }} 107 | strategy: 108 | fail-fast: false 109 | matrix: 110 | include: 111 | - os: macos-latest 112 | TARGET: aarch64-apple-darwin 113 | 114 | - os: ubuntu-latest 115 | TARGET: aarch64-unknown-linux-gnu 116 | 117 | - os: ubuntu-latest 118 | TARGET: armv7-unknown-linux-gnueabihf 119 | 120 | - os: ubuntu-latest 121 | TARGET: x86_64-unknown-linux-gnu 122 | 123 | - os: windows-latest 124 | TARGET: x86_64-pc-windows-msvc 125 | EXTENSION: .exe 126 | 127 | steps: 128 | - name: Building ${{ matrix.TARGET }} 129 | run: echo "${{ matrix.TARGET }}" 130 | 131 | - uses: actions/checkout@master 132 | - name: Install build dependencies - Rustup 133 | run: | 134 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain stable --profile default --target ${{ matrix.TARGET }} -y 135 | echo "$HOME/.cargo/bin" >> $GITHUB_PATH 136 | 137 | # For linux, it's necessary to use cross from the git repository to avoid glibc problems 138 | # Ref: https://github.com/cross-rs/cross/issues/1510 139 | - name: Install cross for linux 140 | if: contains(matrix.TARGET, 'linux') 141 | run: | 142 | cargo install cross --git https://github.com/cross-rs/cross --rev 1b8cf50d20180c1a394099e608141480f934b7f7 143 | 144 | - name: Install cross for mac and windows 145 | if: ${{ !contains(matrix.TARGET, 'linux') }} 146 | run: | 147 | cargo install cross 148 | 149 | - name: Build 150 | run: | 151 | cross build --verbose --release --target=${{ matrix.TARGET }} 152 | 153 | - name: Rename 154 | run: cp target/${{ matrix.TARGET }}/release/eframe_template${{ matrix.EXTENSION }} eframe_template-${{ matrix.TARGET }}${{ matrix.EXTENSION }} 155 | 156 | - uses: actions/upload-artifact@master 157 | with: 158 | name: eframe_template-${{ matrix.TARGET }}${{ matrix.EXTENSION }} 159 | path: eframe_template-${{ matrix.TARGET }}${{ matrix.EXTENSION }} 160 | 161 | - uses: svenstaro/upload-release-action@v2 162 | name: Upload binaries to release 163 | if: ${{ github.event_name == 'push' }} 164 | with: 165 | repo_token: ${{ secrets.GITHUB_TOKEN }} 166 | file: eframe_template-${{ matrix.TARGET }}${{ matrix.EXTENSION }} 167 | asset_name: eframe_template-${{ matrix.TARGET }}${{ matrix.EXTENSION }} 168 | tag: ${{ github.ref }} 169 | prerelease: ${{ !startsWith(github.ref, 'refs/tags/') }} 170 | overwrite: true 171 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/node_editor/mod.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::use_self)] 2 | 3 | pub mod node_trait; 4 | pub mod nodes; 5 | pub mod style; 6 | 7 | use egui::{Align, Color32, Layout, RichText, Ui}; 8 | use egui_snarl::{ 9 | ui::{PinInfo, SnarlViewer}, 10 | InPin, NodeId, OutPin, OutPinId, Snarl, 11 | }; 12 | use log::debug; 13 | use node_trait::{EFNodeFNSerialized, NodeDataType}; 14 | use strum::{Display, EnumIter}; 15 | 16 | use crate::{ 17 | consts::NODE_DEFAULT_VALUES, 18 | node_runners::realtime::{ 19 | clear_cache_from_node_onward, is_node_realtime_executable, run_nodes, 20 | }, 21 | }; 22 | 23 | const DECIMAL_SEQUENCE_COLOR: Color32 = Color32::from_rgb(0x00, 0xb0, 0x00); 24 | const SIGNAL_COLOR: Color32 = Color32::from_rgb(0x00, 0x00, 0xb0); 25 | const MASK_COLOR: Color32 = Color32::from_rgb(0xb0, 0x00, 0xb0); 26 | const CANDLES_COLOR: Color32 = Color32::from_rgb(0x00, 0xb0, 0xb0); 27 | const DEBUG_COLOR_EXECUTABLE: Color32 = Color32::from_rgba_premultiplied(32, 128, 0, 128); 28 | const DEBUG_COLOR: Color32 = Color32::from_rgba_premultiplied(128, 0, 0, 128); 29 | 30 | fn node_row_to_color(node_row: &NodeDataType) -> Color32 { 31 | match node_row { 32 | node_trait::NodeDataType::Candles => CANDLES_COLOR, 33 | node_trait::NodeDataType::Signal => SIGNAL_COLOR, 34 | node_trait::NodeDataType::DecimalSequence => DECIMAL_SEQUENCE_COLOR, 35 | node_trait::NodeDataType::Mask => MASK_COLOR, 36 | } 37 | } 38 | 39 | fn get_input_color(snarl: &Snarl>, pin: &InPin) -> Color32 { 40 | let node = &snarl[pin.id.node].get_node(); 41 | let (_, input_type) = node 42 | .get_inputs() 43 | .get(pin.id.input) 44 | .expect("output pin not found"); 45 | node_row_to_color(input_type) 46 | } 47 | 48 | fn get_output_color(snarl: &Snarl>, pin: &OutPin) -> Color32 { 49 | let node = &snarl[pin.id.node].get_node(); 50 | let (_, output_type) = node 51 | .get_outputs() 52 | .get(pin.id.output) 53 | .expect("output pin not found"); 54 | node_row_to_color(output_type) 55 | } 56 | 57 | #[derive(Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq, Display, EnumIter)] 58 | pub enum Comparison { 59 | #[strum(serialize = "Bigger Than")] 60 | BiggerThan, 61 | #[strum(serialize = "Less Than")] 62 | LessThan, 63 | #[strum(serialize = "Equal")] 64 | Equal, 65 | #[strum(serialize = "Not Equal")] 66 | NotEqual, 67 | } 68 | 69 | #[derive(Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq, Display, EnumIter)] 70 | pub enum OrderDirection { 71 | Buy, 72 | Sell, 73 | } 74 | 75 | #[derive(Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq, Display, EnumIter)] 76 | pub enum OrderType { 77 | #[strum(serialize = "Limit Maker")] 78 | LimitMaker, 79 | Limit, 80 | Market, 81 | } 82 | 83 | pub struct EFViewer; 84 | 85 | impl<'a> SnarlViewer> for EFViewer { 86 | #[inline] 87 | fn connect(&mut self, from: &OutPin, to: &InPin, snarl: &mut Snarl>) { 88 | // Make sure this connection is not to the same node 89 | if from.id.node == to.id.node { 90 | debug!( 91 | "Not connecting #{:?} to #{:?} (Same)", 92 | from.id.node, to.id.node 93 | ); 94 | 95 | return; 96 | } 97 | 98 | // Make sure this connection does not create a cyclic node graph 99 | { 100 | let mut node_ids = vec![]; 101 | node_ids.push(to.id.node); 102 | 103 | while let Some(node_id) = node_ids.pop() { 104 | for node_id in snarl 105 | .out_pin(OutPinId { 106 | node: node_id, 107 | output: 0, 108 | }) 109 | .remotes 110 | .iter() 111 | .map(|remote| remote.node) 112 | { 113 | if node_id == from.id.node { 114 | debug!( 115 | "Not connecting #{:?} to #{:?} (Cyclic)", 116 | from.id.node, to.id.node 117 | ); 118 | 119 | // We found a cycle 120 | return; 121 | } 122 | 123 | node_ids.push(node_id); 124 | } 125 | } 126 | } 127 | 128 | // Enforce the same type by checking the color 129 | let color_from = get_output_color(snarl, from); 130 | let color_to = get_input_color(snarl, to); 131 | if color_from != color_to { 132 | return; 133 | } 134 | 135 | for &remote in &to.remotes { 136 | snarl.disconnect(remote, to.id); 137 | } 138 | 139 | snarl.connect(from.id, to.id); 140 | run_nodes(snarl); 141 | } 142 | 143 | fn title(&mut self, node: &EFNodeFNSerialized<'_>) -> String { 144 | node.get_node().get_name().to_owned() 145 | } 146 | 147 | fn inputs(&mut self, node: &EFNodeFNSerialized<'_>) -> usize { 148 | node.get_node().get_inputs().len() 149 | } 150 | 151 | fn show_input( 152 | &mut self, 153 | pin: &InPin, 154 | ui: &mut Ui, 155 | scale: f32, 156 | snarl: &mut Snarl>, 157 | ) -> PinInfo { 158 | let color = get_input_color(snarl, pin); 159 | let (label, _) = snarl[pin.id.node].get_node().get_inputs()[pin.id.input]; 160 | ui.label(label); 161 | PinInfo::circle().with_fill(color) 162 | } 163 | 164 | fn outputs(&mut self, node: &EFNodeFNSerialized<'_>) -> usize { 165 | node.get_node().get_outputs().len() 166 | } 167 | 168 | fn show_output( 169 | &mut self, 170 | pin: &OutPin, 171 | ui: &mut Ui, 172 | scale: f32, 173 | snarl: &mut Snarl>, 174 | ) -> PinInfo { 175 | let color = get_output_color(snarl, pin); 176 | let (label, _) = snarl[pin.id.node].get_node().get_outputs()[pin.id.output]; 177 | ui.label(label); 178 | PinInfo::circle().with_fill(color) 179 | } 180 | 181 | fn has_graph_menu( 182 | &mut self, 183 | _pos: egui::Pos2, 184 | _snarl: &mut Snarl>, 185 | ) -> bool { 186 | true 187 | } 188 | 189 | fn show_graph_menu( 190 | &mut self, 191 | pos: egui::Pos2, 192 | ui: &mut Ui, 193 | _scale: f32, 194 | snarl: &mut Snarl>, 195 | ) { 196 | ui.label("Add node"); 197 | 198 | for node in NODE_DEFAULT_VALUES.keys() { 199 | if ui.button(*node).clicked() { 200 | let mut node = EFNodeFNSerialized { 201 | loaded_node: None, 202 | node_name: (*node).into(), 203 | arguments: NODE_DEFAULT_VALUES.get(node).unwrap().clone(), 204 | }; 205 | node.load_node().expect("Loading node failed"); 206 | snarl.insert_node(pos, node); 207 | ui.close_menu(); 208 | } 209 | } 210 | } 211 | 212 | fn show_header( 213 | &mut self, 214 | node_id: NodeId, 215 | inputs: &[InPin], 216 | outputs: &[OutPin], 217 | ui: &mut Ui, 218 | scale: f32, 219 | snarl: &mut Snarl>, 220 | ) { 221 | ui.set_height(16.0 * scale); 222 | ui.set_width(128.0 * scale); 223 | ui.with_layout( 224 | Layout::top_down(Align::Min).with_cross_align(Align::Center), 225 | |ui| { 226 | let node = snarl.get_node(node_id).unwrap(); 227 | 228 | #[cfg(debug_assertions)] 229 | ui.label( 230 | RichText::new(format!("{} #{}", self.title(node), node_id.0)).color( 231 | if is_node_realtime_executable(snarl, node_id, node) { 232 | DEBUG_COLOR_EXECUTABLE 233 | } else { 234 | DEBUG_COLOR 235 | }, 236 | ), 237 | ); 238 | #[cfg(not(debug_assertions))] 239 | ui.label(RichText::new(self.title(node)).color( 240 | if is_node_realtime_executable(snarl, node_id, node) { 241 | DEBUG_COLOR_EXECUTABLE 242 | } else { 243 | DEBUG_COLOR 244 | }, 245 | )); 246 | 247 | let node = snarl.get_node_mut(node_id).unwrap(); 248 | let changed = node 249 | .get_node_mut() 250 | .show_header(node_id, inputs, outputs, ui, scale); 251 | if changed { 252 | clear_cache_from_node_onward(snarl, &node_id); 253 | } 254 | }, 255 | ); 256 | } 257 | } 258 | -------------------------------------------------------------------------------- /emeraldfundstudio/src/candles/chart.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | node_editor::{ 3 | node_trait::{ 4 | CheapCloneNodeDataTypeWithValue, EFNodeFNSerialized, EFNodeFn, NodeDataTypeWithValue, 5 | }, 6 | nodes::preview::PreviewNode, 7 | }, 8 | node_runners::realtime::NODE_COMPUTE_CACHE, 9 | types::candles::generate_candles, 10 | }; 11 | use chrono::{DateTime, Utc}; 12 | use ecolor::Color32; 13 | use egui_plot::{BoxElem, BoxPlot, BoxSpread, Legend, Line, MarkerShape, Plot, PlotPoints, Points}; 14 | use egui_snarl::{InPinId, Snarl}; 15 | use epaint::Stroke; 16 | use itertools::izip; 17 | use polars::frame::DataFrame; 18 | 19 | const CANDLE_RED: Color32 = Color32::from_rgb(255, 0, 0); 20 | const CANDLE_GREEN: Color32 = Color32::from_rgb(0, 255, 0); 21 | 22 | const MARKER_BUY: Color32 = Color32::from_rgb(12, 116, 169); 23 | const MARKER_SELL: Color32 = Color32::from_rgb(163, 43, 138); 24 | 25 | pub fn candles_to_box_chart(df: &DataFrame) -> Vec { 26 | let opens = df.column("open").unwrap().f64().unwrap(); 27 | let highs = df.column("high").unwrap().f64().unwrap(); 28 | let lows = df.column("low").unwrap().f64().unwrap(); 29 | let closes = df.column("close").unwrap().f64().unwrap(); 30 | let volumes = df.column("volume").unwrap().f64().unwrap(); 31 | let timestamps = df.column("timestamp").unwrap().u64().unwrap(); 32 | 33 | izip!( 34 | opens.into_iter(), 35 | highs.into_iter(), 36 | lows.into_iter(), 37 | closes.into_iter(), 38 | volumes.into_iter(), 39 | timestamps.into_iter().enumerate() 40 | ) 41 | .map(|(open, high, low, close, _volume, (idx, _timestamp))| { 42 | let open = open.unwrap(); 43 | let high = high.unwrap(); 44 | let low = low.unwrap(); 45 | let close = close.unwrap(); 46 | // let volume = volume.unwrap(); 47 | let color = if close > open { 48 | CANDLE_GREEN 49 | } else { 50 | CANDLE_RED 51 | }; 52 | BoxElem::new( 53 | idx as f64 * 0.01, 54 | BoxSpread::new(low, close, (close + open) / 2.0, open, high), 55 | ) 56 | .box_width(0.007) 57 | .whisker_width(0.0) 58 | .fill(color) 59 | .stroke(Stroke::new(2.0, color)) 60 | }) 61 | .collect() 62 | } 63 | 64 | pub fn signals_as_markers<'a>( 65 | snarl: &Snarl>, 66 | box_chart: &[BoxElem], 67 | ) -> Vec> { 68 | let mut result: Vec> = Vec::new(); 69 | snarl.node_ids().for_each(|(id, node)| { 70 | match node.get_node().get_name() { 71 | "ExecutePositionNode" => { 72 | // get input of this node, then traverse corresponding output id 73 | let in_pin = snarl.in_pin(InPinId { node: id, input: 0 }); 74 | if in_pin.remotes.is_empty() { 75 | return; 76 | } 77 | let outpin_id = in_pin.remotes.first().unwrap(); 78 | if !NODE_COMPUTE_CACHE.contains_key(&outpin_id.node.0) { 79 | return; 80 | } 81 | let cached_result = NODE_COMPUTE_CACHE.get(&outpin_id.node.0).unwrap(); 82 | if cached_result.is_empty() { 83 | return; 84 | } 85 | let cached_result = cached_result.first().unwrap(); 86 | if let NodeDataTypeWithValue::Signal(signal) = &**cached_result { 87 | let mut pt_sell = vec![]; 88 | let mut pt_buy = vec![]; 89 | signal.iter().enumerate().for_each(|(idx, signal)| { 90 | match *signal { 91 | -1 => { 92 | pt_sell.push([(idx as f64) * 0.01, box_chart[idx].spread.median]); 93 | } 94 | 1 => { 95 | pt_buy.push([(idx as f64) * 0.01, box_chart[idx].spread.median]); 96 | } 97 | _ => {} 98 | }; 99 | }); 100 | if !pt_sell.is_empty() { 101 | result.push( 102 | Points::new(pt_sell) 103 | .name("Sell") 104 | .color(MARKER_SELL) 105 | .filled(true) 106 | .radius(5.0) 107 | .shape(MarkerShape::Down), 108 | ); 109 | } 110 | if !pt_buy.is_empty() { 111 | result.push( 112 | Points::new(pt_buy) 113 | .name("Buy") 114 | .color(MARKER_BUY) 115 | .filled(true) 116 | .radius(5.0) 117 | .shape(MarkerShape::Up), 118 | ); 119 | } 120 | } 121 | } 122 | _ => {} 123 | } 124 | }); 125 | return result; 126 | } 127 | 128 | fn get_preview_outputs<'a>( 129 | snarl: &'a Snarl>, 130 | ) -> impl Iterator + use<'a> { 131 | snarl.node_ids().filter_map(|(id, node)| { 132 | if node.get_node().get_name() != "PreviewNode" { 133 | return None; 134 | } 135 | let in_pin = snarl.in_pin(InPinId { node: id, input: 0 }); 136 | if in_pin.remotes.is_empty() { 137 | return None; 138 | } 139 | let idx_of_node_connected_to_preview = in_pin.remotes[0].node.0; 140 | if !NODE_COMPUTE_CACHE.contains_key(&idx_of_node_connected_to_preview) { 141 | return None; 142 | } 143 | let cache_of_node_connected_to_preview = NODE_COMPUTE_CACHE 144 | .get(&idx_of_node_connected_to_preview) 145 | .unwrap(); 146 | let output_value = cache_of_node_connected_to_preview[in_pin.remotes[0].output].clone(); 147 | let preview_node = node 148 | .get_node() 149 | .as_any() 150 | .downcast_ref::() 151 | .unwrap(); 152 | return Some((preview_node.output_color, output_value)); 153 | }) 154 | } 155 | 156 | pub fn candlestick_chart(ui: &mut eframe::egui::Ui, snarl: &Snarl>) { 157 | let candles = generate_candles(21, 500).unwrap(); 158 | let first_timestamp = candles 159 | .column("timestamp") 160 | .unwrap() 161 | .u64() 162 | .unwrap() 163 | .get(0) 164 | .unwrap() as u64; 165 | let box_chart = candles_to_box_chart(&candles); 166 | let markers = signals_as_markers(snarl, &box_chart); 167 | let data = BoxPlot::new(box_chart) 168 | // TODO: finish this formatter 169 | .element_formatter(Box::new(|elm, _| { 170 | format!( 171 | "High = {max:.decimals$}\ 172 | \nOpen = {q3:.decimals$}\ 173 | \nClose = {q1:.decimals$}\ 174 | \nLow = {min:.decimals$}", 175 | max = elm.spread.upper_whisker, 176 | q3 = elm.spread.quartile3, 177 | q1 = elm.spread.quartile1, 178 | min = elm.spread.lower_whisker, 179 | decimals = 5 180 | ) 181 | })); 182 | 183 | let plot = Plot::new("candlestick chart") 184 | .legend(Legend::default()) 185 | .x_axis_formatter(|grid, _| { 186 | let d = (first_timestamp + ((grid.value * 100.0 * 60.0) as u64)) as i64; 187 | let datetime = DateTime::::from_timestamp(d, 0).unwrap(); 188 | datetime.format("%Y-%m-%d %H:%M").to_string() 189 | }); 190 | ui.with_layout( 191 | eframe::egui::Layout::right_to_left(eframe::egui::Align::TOP), 192 | |ui| { 193 | plot.show(ui, |plot_ui| { 194 | plot_ui.box_plot(data); 195 | for marker in markers.into_iter() { 196 | plot_ui.points(marker); 197 | } 198 | for output in get_preview_outputs(&snarl) { 199 | if let NodeDataTypeWithValue::DecimalSequence(seq) = &*output.1 { 200 | let f64_iter = seq.iter().enumerate().filter_map(|(i, x)| { 201 | if let Some(x) = x { 202 | return Some([i as f64 * 0.01, x]); 203 | } 204 | None 205 | }); 206 | let line_points = PlotPoints::from_iter(f64_iter); 207 | let line = Line::new(line_points) 208 | .color(Color32::from_rgb(output.0[0], output.0[1], output.0[2])) 209 | .style(egui_plot::LineStyle::Solid); 210 | plot_ui.line(line); 211 | } 212 | } 213 | }); 214 | }, 215 | ); 216 | } 217 | -------------------------------------------------------------------------------- /resources/LICENSE: -------------------------------------------------------------------------------- 1 | Attribution-ShareAlike 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution-ShareAlike 4.0 International Public 58 | License 59 | 60 | By exercising the Licensed Rights (defined below), You accept and agree 61 | to be bound by the terms and conditions of this Creative Commons 62 | Attribution-ShareAlike 4.0 International Public License ("Public 63 | License"). To the extent this Public License may be interpreted as a 64 | contract, You are granted the Licensed Rights in consideration of Your 65 | acceptance of these terms and conditions, and the Licensor grants You 66 | such rights in consideration of benefits the Licensor receives from 67 | making the Licensed Material available under these terms and 68 | conditions. 69 | 70 | 71 | Section 1 -- Definitions. 72 | 73 | a. Adapted Material means material subject to Copyright and Similar 74 | Rights that is derived from or based upon the Licensed Material 75 | and in which the Licensed Material is translated, altered, 76 | arranged, transformed, or otherwise modified in a manner requiring 77 | permission under the Copyright and Similar Rights held by the 78 | Licensor. For purposes of this Public License, where the Licensed 79 | Material is a musical work, performance, or sound recording, 80 | Adapted Material is always produced where the Licensed Material is 81 | synched in timed relation with a moving image. 82 | 83 | b. Adapter's License means the license You apply to Your Copyright 84 | and Similar Rights in Your contributions to Adapted Material in 85 | accordance with the terms and conditions of this Public License. 86 | 87 | c. BY-SA Compatible License means a license listed at 88 | creativecommons.org/compatiblelicenses, approved by Creative 89 | Commons as essentially the equivalent of this Public License. 90 | 91 | d. Copyright and Similar Rights means copyright and/or similar rights 92 | closely related to copyright including, without limitation, 93 | performance, broadcast, sound recording, and Sui Generis Database 94 | Rights, without regard to how the rights are labeled or 95 | categorized. For purposes of this Public License, the rights 96 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 97 | Rights. 98 | 99 | e. Effective Technological Measures means those measures that, in the 100 | absence of proper authority, may not be circumvented under laws 101 | fulfilling obligations under Article 11 of the WIPO Copyright 102 | Treaty adopted on December 20, 1996, and/or similar international 103 | agreements. 104 | 105 | f. Exceptions and Limitations means fair use, fair dealing, and/or 106 | any other exception or limitation to Copyright and Similar Rights 107 | that applies to Your use of the Licensed Material. 108 | 109 | g. License Elements means the license attributes listed in the name 110 | of a Creative Commons Public License. The License Elements of this 111 | Public License are Attribution and ShareAlike. 112 | 113 | h. Licensed Material means the artistic or literary work, database, 114 | or other material to which the Licensor applied this Public 115 | License. 116 | 117 | i. Licensed Rights means the rights granted to You subject to the 118 | terms and conditions of this Public License, which are limited to 119 | all Copyright and Similar Rights that apply to Your use of the 120 | Licensed Material and that the Licensor has authority to license. 121 | 122 | j. Licensor means the individual(s) or entity(ies) granting rights 123 | under this Public License. 124 | 125 | k. Share means to provide material to the public by any means or 126 | process that requires permission under the Licensed Rights, such 127 | as reproduction, public display, public performance, distribution, 128 | dissemination, communication, or importation, and to make material 129 | available to the public including in ways that members of the 130 | public may access the material from a place and at a time 131 | individually chosen by them. 132 | 133 | l. Sui Generis Database Rights means rights other than copyright 134 | resulting from Directive 96/9/EC of the European Parliament and of 135 | the Council of 11 March 1996 on the legal protection of databases, 136 | as amended and/or succeeded, as well as other essentially 137 | equivalent rights anywhere in the world. 138 | 139 | m. You means the individual or entity exercising the Licensed Rights 140 | under this Public License. Your has a corresponding meaning. 141 | 142 | 143 | Section 2 -- Scope. 144 | 145 | a. License grant. 146 | 147 | 1. Subject to the terms and conditions of this Public License, 148 | the Licensor hereby grants You a worldwide, royalty-free, 149 | non-sublicensable, non-exclusive, irrevocable license to 150 | exercise the Licensed Rights in the Licensed Material to: 151 | 152 | a. reproduce and Share the Licensed Material, in whole or 153 | in part; and 154 | 155 | b. produce, reproduce, and Share Adapted Material. 156 | 157 | 2. Exceptions and Limitations. For the avoidance of doubt, where 158 | Exceptions and Limitations apply to Your use, this Public 159 | License does not apply, and You do not need to comply with 160 | its terms and conditions. 161 | 162 | 3. Term. The term of this Public License is specified in Section 163 | 6(a). 164 | 165 | 4. Media and formats; technical modifications allowed. The 166 | Licensor authorizes You to exercise the Licensed Rights in 167 | all media and formats whether now known or hereafter created, 168 | and to make technical modifications necessary to do so. The 169 | Licensor waives and/or agrees not to assert any right or 170 | authority to forbid You from making technical modifications 171 | necessary to exercise the Licensed Rights, including 172 | technical modifications necessary to circumvent Effective 173 | Technological Measures. For purposes of this Public License, 174 | simply making modifications authorized by this Section 2(a) 175 | (4) never produces Adapted Material. 176 | 177 | 5. Downstream recipients. 178 | 179 | a. Offer from the Licensor -- Licensed Material. Every 180 | recipient of the Licensed Material automatically 181 | receives an offer from the Licensor to exercise the 182 | Licensed Rights under the terms and conditions of this 183 | Public License. 184 | 185 | b. Additional offer from the Licensor -- Adapted Material. 186 | Every recipient of Adapted Material from You 187 | automatically receives an offer from the Licensor to 188 | exercise the Licensed Rights in the Adapted Material 189 | under the conditions of the Adapter's License You apply. 190 | 191 | c. No downstream restrictions. You may not offer or impose 192 | any additional or different terms or conditions on, or 193 | apply any Effective Technological Measures to, the 194 | Licensed Material if doing so restricts exercise of the 195 | Licensed Rights by any recipient of the Licensed 196 | Material. 197 | 198 | 6. No endorsement. Nothing in this Public License constitutes or 199 | may be construed as permission to assert or imply that You 200 | are, or that Your use of the Licensed Material is, connected 201 | with, or sponsored, endorsed, or granted official status by, 202 | the Licensor or others designated to receive attribution as 203 | provided in Section 3(a)(1)(A)(i). 204 | 205 | b. Other rights. 206 | 207 | 1. Moral rights, such as the right of integrity, are not 208 | licensed under this Public License, nor are publicity, 209 | privacy, and/or other similar personality rights; however, to 210 | the extent possible, the Licensor waives and/or agrees not to 211 | assert any such rights held by the Licensor to the limited 212 | extent necessary to allow You to exercise the Licensed 213 | Rights, but not otherwise. 214 | 215 | 2. Patent and trademark rights are not licensed under this 216 | Public License. 217 | 218 | 3. To the extent possible, the Licensor waives any right to 219 | collect royalties from You for the exercise of the Licensed 220 | Rights, whether directly or through a collecting society 221 | under any voluntary or waivable statutory or compulsory 222 | licensing scheme. In all other cases the Licensor expressly 223 | reserves any right to collect such royalties. 224 | 225 | 226 | Section 3 -- License Conditions. 227 | 228 | Your exercise of the Licensed Rights is expressly made subject to the 229 | following conditions. 230 | 231 | a. Attribution. 232 | 233 | 1. If You Share the Licensed Material (including in modified 234 | form), You must: 235 | 236 | a. retain the following if it is supplied by the Licensor 237 | with the Licensed Material: 238 | 239 | i. identification of the creator(s) of the Licensed 240 | Material and any others designated to receive 241 | attribution, in any reasonable manner requested by 242 | the Licensor (including by pseudonym if 243 | designated); 244 | 245 | ii. a copyright notice; 246 | 247 | iii. a notice that refers to this Public License; 248 | 249 | iv. a notice that refers to the disclaimer of 250 | warranties; 251 | 252 | v. a URI or hyperlink to the Licensed Material to the 253 | extent reasonably practicable; 254 | 255 | b. indicate if You modified the Licensed Material and 256 | retain an indication of any previous modifications; and 257 | 258 | c. indicate the Licensed Material is licensed under this 259 | Public License, and include the text of, or the URI or 260 | hyperlink to, this Public License. 261 | 262 | 2. You may satisfy the conditions in Section 3(a)(1) in any 263 | reasonable manner based on the medium, means, and context in 264 | which You Share the Licensed Material. For example, it may be 265 | reasonable to satisfy the conditions by providing a URI or 266 | hyperlink to a resource that includes the required 267 | information. 268 | 269 | 3. If requested by the Licensor, You must remove any of the 270 | information required by Section 3(a)(1)(A) to the extent 271 | reasonably practicable. 272 | 273 | b. ShareAlike. 274 | 275 | In addition to the conditions in Section 3(a), if You Share 276 | Adapted Material You produce, the following conditions also apply. 277 | 278 | 1. The Adapter's License You apply must be a Creative Commons 279 | license with the same License Elements, this version or 280 | later, or a BY-SA Compatible License. 281 | 282 | 2. You must include the text of, or the URI or hyperlink to, the 283 | Adapter's License You apply. You may satisfy this condition 284 | in any reasonable manner based on the medium, means, and 285 | context in which You Share Adapted Material. 286 | 287 | 3. You may not offer or impose any additional or different terms 288 | or conditions on, or apply any Effective Technological 289 | Measures to, Adapted Material that restrict exercise of the 290 | rights granted under the Adapter's License You apply. 291 | 292 | 293 | Section 4 -- Sui Generis Database Rights. 294 | 295 | Where the Licensed Rights include Sui Generis Database Rights that 296 | apply to Your use of the Licensed Material: 297 | 298 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 299 | to extract, reuse, reproduce, and Share all or a substantial 300 | portion of the contents of the database; 301 | 302 | b. if You include all or a substantial portion of the database 303 | contents in a database in which You have Sui Generis Database 304 | Rights, then the database in which You have Sui Generis Database 305 | Rights (but not its individual contents) is Adapted Material, 306 | including for purposes of Section 3(b); and 307 | 308 | c. You must comply with the conditions in Section 3(a) if You Share 309 | all or a substantial portion of the contents of the database. 310 | 311 | For the avoidance of doubt, this Section 4 supplements and does not 312 | replace Your obligations under this Public License where the Licensed 313 | Rights include other Copyright and Similar Rights. 314 | 315 | 316 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 317 | 318 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 319 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 320 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 321 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 322 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 323 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 324 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 325 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 326 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 327 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 328 | 329 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 330 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 331 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 332 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 333 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 334 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 335 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 336 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 337 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 338 | 339 | c. The disclaimer of warranties and limitation of liability provided 340 | above shall be interpreted in a manner that, to the extent 341 | possible, most closely approximates an absolute disclaimer and 342 | waiver of all liability. 343 | 344 | 345 | Section 6 -- Term and Termination. 346 | 347 | a. This Public License applies for the term of the Copyright and 348 | Similar Rights licensed here. However, if You fail to comply with 349 | this Public License, then Your rights under this Public License 350 | terminate automatically. 351 | 352 | b. Where Your right to use the Licensed Material has terminated under 353 | Section 6(a), it reinstates: 354 | 355 | 1. automatically as of the date the violation is cured, provided 356 | it is cured within 30 days of Your discovery of the 357 | violation; or 358 | 359 | 2. upon express reinstatement by the Licensor. 360 | 361 | For the avoidance of doubt, this Section 6(b) does not affect any 362 | right the Licensor may have to seek remedies for Your violations 363 | of this Public License. 364 | 365 | c. For the avoidance of doubt, the Licensor may also offer the 366 | Licensed Material under separate terms or conditions or stop 367 | distributing the Licensed Material at any time; however, doing so 368 | will not terminate this Public License. 369 | 370 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 371 | License. 372 | 373 | 374 | Section 7 -- Other Terms and Conditions. 375 | 376 | a. The Licensor shall not be bound by any additional or different 377 | terms or conditions communicated by You unless expressly agreed. 378 | 379 | b. Any arrangements, understandings, or agreements regarding the 380 | Licensed Material not stated herein are separate from and 381 | independent of the terms and conditions of this Public License. 382 | 383 | 384 | Section 8 -- Interpretation. 385 | 386 | a. For the avoidance of doubt, this Public License does not, and 387 | shall not be interpreted to, reduce, limit, restrict, or impose 388 | conditions on any use of the Licensed Material that could lawfully 389 | be made without permission under this Public License. 390 | 391 | b. To the extent possible, if any provision of this Public License is 392 | deemed unenforceable, it shall be automatically reformed to the 393 | minimum extent necessary to make it enforceable. If the provision 394 | cannot be reformed, it shall be severed from this Public License 395 | without affecting the enforceability of the remaining terms and 396 | conditions. 397 | 398 | c. No term or condition of this Public License will be waived and no 399 | failure to comply consented to unless expressly agreed to by the 400 | Licensor. 401 | 402 | d. Nothing in this Public License constitutes or may be interpreted 403 | as a limitation upon, or waiver of, any privileges and immunities 404 | that apply to the Licensor or You, including from the legal 405 | processes of any jurisdiction or authority. 406 | 407 | 408 | ======================================================================= 409 | 410 | Creative Commons is not a party to its public licenses. 411 | Notwithstanding, Creative Commons may elect to apply one of its public 412 | licenses to material it publishes and in those instances will be 413 | considered the “Licensor.” The text of the Creative Commons public 414 | licenses is dedicated to the public domain under the CC0 Public Domain 415 | Dedication. Except for the limited purpose of indicating that material 416 | is shared under a Creative Commons public license or as otherwise 417 | permitted by the Creative Commons policies published at 418 | creativecommons.org/policies, Creative Commons does not authorize the 419 | use of the trademark "Creative Commons" or any other trademark or logo 420 | of Creative Commons without its prior written consent including, 421 | without limitation, in connection with any unauthorized modifications 422 | to any of its public licenses or any other arrangements, 423 | understandings, or agreements concerning use of licensed material. For 424 | the avoidance of doubt, this paragraph does not form part of the public 425 | licenses. 426 | 427 | Creative Commons may be contacted at creativecommons.org. 428 | --------------------------------------------------------------------------------