-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split code into modules #29
Comments
MaybeAlthough I have a tiny bit of websocket code here, I haven't thought too hard about how I wanted to use it. The RESTful code in this library supports archival of 1 minute candles by calling Regarding the existing websocket code like I think spawning a task to contain the websocket connection was a good idea, but the implementation needs to be tightened up, and I want to rename Back to ModulesNote I'm open to introducing more modules. In an ideal world, how would you reorganize this code? Let's take Bitstamp as the test case.
|
I'd put both RESTful code and Websockets in the same module named |
This is an experiment to see if #29 is worth doing.
I made a branch called modules, and I gave it a try on just Bitstamp, but it got really awkward. The biggest problem was that these exchange-specific methods need to be in CryptoMarketData. # functions with exchange-specific methods
export csv_headers
export csv_select
export ts2datetime_fn
export candle_datetime
export short_name
export candles_max
export get_markets
export get_candles The machinery around |
You can keep these functions in the Here is a summary of how modules are working. (LLM paragraph) Modules in JuliaModules in Julia are separate namespaces that help organize code and control variable/function scope. Here's how the main module-related commands work: Creating a Modulemodule MyModule
# Module contents go here
end ExportThe module MyModule
export my_function, MyType # These will be available when using MyModule
function my_function()
println("Hello!")
end
struct MyType
x::Int
end
function internal_function() # Not exported, only accessible with MyModule.internal_function
println("Internal!")
end
end Importing Commands
using MyModule # Imports all exported names
using MyModule: my_function # Imports specific exported names
import MyModule # Imports the module, must use MyModule.function_name
import MyModule: my_function # Imports specific name, can use directly
using .MyModule # Import from submodule
using ..MyModule # Import from parent module Key Differences
Include FilesYou can split module code across multiple files using module MyModule
include("helpers.jl")
include("types.jl")
# Rest of module code
end |
Hello,
currently your code have only one module I think it's a better Julia practice to split code into modules.
If I were you I will at least create an
Exchanges
module.I don't know if I will break each separate exchange into module.
I will probably do that because I will create 2 kind of objects per exchange:
1 for dealing with REST API
1 for dealing with Websocket
and have a module surrounding them.
Any opinion?
The text was updated successfully, but these errors were encountered: