Skip to content

Commit

Permalink
First Public Version
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviermilla committed Jan 23, 2024
1 parent 7d07fb0 commit 1c59c70
Show file tree
Hide file tree
Showing 22 changed files with 1,040 additions and 11 deletions.
8 changes: 8 additions & 0 deletions LocalPreferences.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[DydxV3]
apiKey = "YourKey"
apiPassPhrase = "Your Passphrase"
apiSecret = "Your Secret"
starkPrivateKey = "Your PrivateKey"
starkPublicKey = "Your PublicKey"
starkPublicKeyYCoordinate = "Your Public Key Coordinate"
walletAddress = "Your 0xAddress"
23 changes: 18 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
name = "DydxV3"
uuid = "aeb184e1-2eba-4dfa-950e-27d85795a490"
authors = ["Olivier Milla <[email protected]> and contributors"]
version = "1.0.0-DEV"
uuid = "81fc79e4-7aed-40c1-9951-444e465e3245"
authors = ["Olivier Milla <[email protected]>"]
version = "0.7.1"

[compat]
julia = "1.9"
[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"

[weakdeps]
Rocket = "df971d30-c9d6-4b37-b8ff-e965b2cb3a40"

[extensions]
RocketExt = "Rocket"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# DydxV3

[![Build Status](https://github.com/oliviermilla/DydxV3.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/oliviermilla/DydxV3.jl/actions/workflows/CI.yml?query=branch%3Amain)

API integration of [dydxV3 exchange](https://dydx.exchange/) in Julia.

See the [provided](https://github.com/oliviermilla/DydxV3/blob/main/LocalPreferences.toml) [Preferences.jl](https://github.com/JuliaPackaging/Preferences.jl) file for the expected API keys.

Enjoy!
9 changes: 9 additions & 0 deletions ext/RocketExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module RocketExt

import DydxV3

using Rocket

Rocket.scalarness(::Type{DydxV3.Trade}) = Rocket.Scalar()

end
29 changes: 29 additions & 0 deletions src/Constants.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Constants

export
DATE_FORMAT,
HTTP_PRODUCTION_URL,
HTTP_STAGING_URL,
TRADE_SIDES,
WEBSOCKET_PRODUCTION_URL,
WEBSOCKET_STAGING_URL,
WEBSOCKET_CHANNELS, ACCOUNT, ORDERBOOK, TRADES, MARKETS,
ENVIRONNMENT_TYPE, PRODUCTION, STAGING

using Dates

const DATE_FORMAT = dateformat"YYYY-mm-ddTHH:MM:SS.sZ"

@enum ENVIRONNMENT_TYPE PRODUCTION STAGING

const HTTP_PRODUCTION_URL = "https://api.dydx.exchange/v3/"
const HTTP_STAGING_URL = "https://api.stage.dydx.exchange"

const WEBSOCKET_PRODUCTION_URL = "wss://api.dydx.exchange/v3/ws"
const WEBSOCKET_STAGING_URL = "wss://api.stage.dydx.exchange/v3/ws"

@enum WEBSOCKET_CHANNELS ACCOUNT ORDERBOOK TRADES MARKETS

const TRADE_SIDES = ["BUY", "SELL"]

end
231 changes: 231 additions & 0 deletions src/Data.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
module Data

export
Account,
Fill,
FundingPayment,
HistoricalPnl,
Market,
Order,
OrderBook,
OrderBookLevel,
Position,
Trade,
Transfer,
User,
UserData,
UserPreferences,
UserTradeOption,
UserWarnings

using Dates
using JSON3

struct Position
market::String
status::String
side::String
size::Float64
maxSize::Float64
entryPrice::Float64
exitPrice::Float64
unrealizedPnl::Float64
realizedPnl::Float64
createdAt::DateTime
closedAt::Union{Nothing,DateTime}
sumOpen::Float64
sumClose::Float64
netFunding::Float64
end

struct Account
starkKey::String
positionId::UInt32
equity::Float64
freeCollateral::Float64
pendingDeposits::Float64
pendingWithdrawals::Float64
openPositions::Dict{String,Position}
accountNumber::UInt16
id::String
quoteBalance::Float64
createdAt::DateTime
end

struct Fill
id::String
side::String
liquidity::String
type::String
market::String
orderId::String
price::Float64
size::Float64
fee::Float32
createdAt::DateTime
end

struct FundingPayment
market::String
payment::Float64
rate::Float64
positionSize::Float64
price::Float64
effectiveAt::DateTime
end

struct HistoricalPnl
equity::Float64
totalPnl::Float64
createdAt::DateTime
netTransfers::Float64
accountId::String
end

struct Market
market::Union{Nothing, String}
status::Union{Nothing, String}
baseAsset::Union{Nothing, String}
quoteAsset::Union{Nothing, String}
stepSize::Union{Nothing, Float16}
tickSize::Union{Nothing, Float16}
indexPrice::Union{Nothing, Float32}
oraclePrice::Union{Nothing, Float32}
priceChange24H::Union{Nothing, Float32}
nextFundingRate::Union{Nothing, Float32}
nextFundingAt::Union{Nothing, DateTime}
minOrderSize::Union{Nothing, Float16}
type::Union{Nothing, String}
initialMarginFraction::Union{Nothing, Float16}
maintenanceMarginFraction::Union{Nothing, Float16}
baselinePositionSize::Union{Nothing, UInt32}
incrementalPositionSize::Union{Nothing, UInt32}
incrementalInitialMarginFraction::Union{Nothing, Float16}
transferMarginFraction::Union{Nothing, Float32}
maxPositionSize::Union{Nothing, UInt64}
volume24H::Union{Nothing, Float32}
trades24H::Union{Nothing, UInt32}
openInterest::Union{Nothing, Float32}
assetResolution::Union{Nothing, UInt64}
syntheticAssetId::Union{Nothing, String}
end

struct Order
accountId::String
market::String
side::String
id::String
remainingSize::Float64
price::Float64
end

struct OrderBookLevel
size::Float32
price::Float32
end

struct OrderBook
bids::Vector{OrderBookLevel}
asks::Vector{OrderBookLevel}
end

struct Trade
side::String
size::Float64
price::Float64
createdAt::DateTime
liquidation::Bool
end

struct Transfer
# id::String
# type::String
# debitAsset::String
# creditAsset::String
# debitAmount::Float64
# creditAmount::Float64
# transactionHash::String
# status::String
# createdAt::DateTime
# confirmedAt::DateTime
# clientId::Union{String,Nothing}
# fromAddress::Union{String,Nothing}
# toAddress::Union{String,Nothing}
# accountId::String
# transferAccountId::Union{String,Nothing}
end

struct UserTradeOption
postOnlyChecked::Bool
goodTilTimeInput::UInt8
reduceOnlyChecked::Bool
goodTilTimeTimescale::String
selectedTimeInForceOption::String
end

struct UserWarnings
enableWarning::Bool
disableWarning::Bool
end

struct UserPreferences
userTradeOptions::Dict{String,Union{UserTradeOption,String}}
popUpNotifications::Bool
orderbookAnimations::Bool
latestConcludedEpoch::UInt16
oneTimeNotifications::Vector{String}
leaguesCurrentStartDate::String
hasSeenReduceOnlyWarning::UserWarnings
end

struct UserData
walletType::String
preferences::UserPreferences
starredMarkets::Vector{String}
end

struct User
publicId::String
ethereumAddress::String
isRegistered::Bool
email::Union{String,Nothing}
username::Union{String,Nothing}
userData::UserData
makerFeeRate::Float64
takerFeeRate::Float64
referralDiscountRate::Union{String,Nothing}
makerVolume30D::Float64
takerVolume30D::Float64
fees30D::Float32
referredByAffiliateLink::Union{String,Nothing}
isSharingUsername::Union{Nothing,Bool}
isSharingAddress::Union{Nothing,Bool}
dydxTokenBalance::Float32
stakedDydxTokenBalance::Float32
activeStakedDydxTokenBalance::Float32
isEmailVerified::Bool
country::Union{String,Nothing}
languageCode::String
hedgiesHeld::Vector{String}
livenessVerified::Union{Nothing,Bool}
livenessVerifiedAt::Union{Nothing,String}
syntheticId::String
end

JSON3.StructTypes.StructType(::Type{Account}) = JSON3.StructTypes.Struct()
JSON3.StructTypes.StructType(::Type{Fill}) = JSON3.StructTypes.Struct()
JSON3.StructTypes.StructType(::Type{FundingPayment}) = JSON3.StructTypes.Struct()
JSON3.StructTypes.StructType(::Type{HistoricalPnl}) = JSON3.StructTypes.Struct()
JSON3.StructTypes.StructType(::Type{Market}) = JSON3.StructTypes.Struct()
JSON3.StructTypes.StructType(::Type{Order}) = JSON3.StructTypes.Struct()
JSON3.StructTypes.StructType(::Type{OrderBook}) = JSON3.StructTypes.Struct()
JSON3.StructTypes.StructType(::Type{OrderBookLevel}) = JSON3.StructTypes.Struct()
JSON3.StructTypes.StructType(::Type{Position}) = JSON3.StructTypes.Struct()
JSON3.StructTypes.StructType(::Type{Trade}) = JSON3.StructTypes.Struct()
JSON3.StructTypes.StructType(::Type{Transfer}) = JSON3.StructTypes.Struct()
JSON3.StructTypes.StructType(::Type{User}) = JSON3.StructTypes.Struct()
JSON3.StructTypes.StructType(::Type{UserData}) = JSON3.StructTypes.Struct()
JSON3.StructTypes.StructType(::Type{UserPreferences}) = JSON3.StructTypes.Struct()
JSON3.StructTypes.StructType(::Type{UserTradeOption}) = JSON3.StructTypes.Struct()
JSON3.StructTypes.StructType(::Type{UserWarnings}) = JSON3.StructTypes.Struct()
end
23 changes: 21 additions & 2 deletions src/DydxV3.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
module DydxV3

# Write your package code here.
include("Constants.jl")
include("UsesPreferences.jl")
import .UsesPreferences as Preferences

end
include("Data.jl")

include("Public.jl")
include("Private.jl")

include("WebSockets.jl")

import .Constants
using .Data

using .Public
using .Private

import .WebSockets

include("Samplers.jl")

end # module DydxV3
Loading

0 comments on commit 1c59c70

Please sign in to comment.