Skip to content

Commit

Permalink
Add order models
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasbair committed Oct 3, 2024
1 parent 3e59682 commit 0ab2603
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 11 deletions.
17 changes: 6 additions & 11 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interfaces:
description: "Get a list of changes to an account."
http_method: "GET"
path: "/accounts/:account_id/changes"
response_schema: "AccountChanges"
arguments:
- "account_id"
parameters:
Expand All @@ -56,6 +57,7 @@ interfaces:
description: "Get candlestick data for an instrument."
http_method: "GET"
path: "/instruments/:instrument/candles"
response_schema: "ListCandles"
arguments:
- "instrument"
parameters:
Expand Down Expand Up @@ -97,17 +99,7 @@ interfaces:
type: "string"
doc: "The day of the week used for granularities that have weekly alignment."
default: "Friday"
- function_name: "list_order_book"
description: "Get order book data for an instrument."
http_method: "GET"
path: "/instruments/:instrument/orderBook"
arguments:
- "instrument"
parameters:
- name: "time"
type: "string"
doc: "The time of the snapshot to fetch using either RFC 3339 or Unix format. If not specified, then the most recent snapshot is fetched."
- function_name: "list_position_book"

description: "Get position book data for an instrument."
http_method: "GET"
path: "/instruments/:instrument/positionBook"
Expand All @@ -131,6 +123,7 @@ interfaces:
description: "Get a list of orders for an account."
http_method: "GET"
path: "/accounts/:account_id/orders"
response_schema: "ListOrders"
arguments:
- "account_id"
parameters:
Expand All @@ -154,12 +147,14 @@ interfaces:
description: "Get a list of pending orders for an account."
http_method: "GET"
path: "/accounts/:account_id/pendingOrders"
response_schema: "ListPendingOrders"
arguments:
- "account_id"
- function_name: "find"
description: "Get details for a single order in an account."
http_method: "GET"
path: "/accounts/:account_id/orders/:order_id"
response_schema: "FindOrder"
arguments:
- "account_id"
- "order_id"
Expand Down
File renamed without changes.
22 changes: 22 additions & 0 deletions lib/models/response/orders/find_order.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defmodule ExOanda.FindOrder do
@moduledoc """
Schema for Oanda find order response.
"""

use TypedEctoSchema
import Ecto.Changeset

@primary_key false

typed_embedded_schema do
embeds_one :order, Order
field(:last_transaction_id, :string)
end

@doc false
def changeset(struct, params) do
struct
|> cast(params, [:last_transaction_id])
|> cast_embed(:order)
end
end
23 changes: 23 additions & 0 deletions lib/models/response/orders/list_orders.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
defmodule ExOanda.ListOrders do
@moduledoc """
Schema for Oanda list orders response.
"""

use TypedEctoSchema
import Ecto.Changeset
alias ExOanda.Order

@primary_key false

typed_embedded_schema do
embeds_many :orders, Order
field(:last_transaction_id, :string)
end

@doc false
def changeset(struct, params) do
struct
|> cast(params, [:last_transaction_id])
|> cast_embed(:orders)
end
end
23 changes: 23 additions & 0 deletions lib/models/response/orders/list_pending_orders.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
defmodule ExOanda.ListPendingOrders do
@moduledoc """
Schema for Oanda list pending orders response.
"""

use TypedEctoSchema
import Ecto.Changeset
alias ExOanda.Order

@primary_key false

typed_embedded_schema do
embeds_many :orders, Order
field(:last_transaction_id, :string)
end

@doc false
def changeset(struct, params) do
struct
|> cast(params, [:last_transaction_id])
|> cast_embed(:orders)
end
end

0 comments on commit 0ab2603

Please sign in to comment.