Skip to content

Commit

Permalink
Added an extension to create TimeSeries from HistoricalPnl data
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviermilla committed Jan 24, 2024
1 parent ef13f6f commit 8f2e0e2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"

[weakdeps]
Rocket = "df971d30-c9d6-4b37-b8ff-e965b2cb3a40"
TimeSeries = "9e3dc215-6440-5c97-bce1-76c03772f85e"

[extensions]
RocketExt = "Rocket"
TimeSeriesExt = "TimeSeries"

[compat]
julia = "1.9"
HTTP = "1.9.15"
JSON3 = "1.13.2"
Preferences = "1.4.1"
URIs = "1.5.0"

[extensions]
RocketExt = "Rocket"
julia = "1.9"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["Test", "Rocket", "TimeSeries"]
31 changes: 31 additions & 0 deletions ext/TimeSeriesExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module TimeSeriesExt

using DydxV3

using TimeSeries

function TimeSeries.TimeArray(pnl::Vector{DydxV3.HistoricalPnl})
timestamp = Vector{DateTime}()
equity = Vector{Float64}()
totalPnl = Vector{Float64}()
netTransfers = Vector{Float64}()
accountId = Vector{String}()

for idx in eachindex(pnl)
push!(timestamp, pnl[idx].createdAt)
push!(equity, pnl[idx].equity)
push!(totalPnl, pnl[idx].totalPnl)
push!(netTransfers, pnl[idx].netTransfers)
push!(accountId, pnl[idx].accountId)
end

return TimeArray((
timestamp=timestamp,
equity=equity,
totalPnl=totalPnl,
netTransfers=netTransfers,
accountId=accountId
))
end

end

0 comments on commit 8f2e0e2

Please sign in to comment.