marketOrder: ~~function to do ... ~~

Description Usage Arguments Details Value Warning Note Author(s) References See Also Examples

View source: R/roanda.R

Description

~~ A concise (1-5 lines) description of what the function does. ~~

Usage

1
marketOrder(instrument = "EUR_USD", units = 10000, side, slippage = 2, SL = 10, TP = 10, acct, auth_id, acct_type = "fxpractice")

Arguments

instrument

~~Describe instrument here~~

units

~~Describe units here~~

side

~~Describe side here~~

slippage

~~Describe slippage here~~

SL

~~Describe SL here~~

TP

~~Describe TP here~~

acct

~~Describe acct here~~

auth_id

~~Describe auth_id here~~

acct_type

~~Describe acct_type here~~

Details

~~ If necessary, more details than the description above ~~

Value

~Describe the value returned If it is a LIST, use

comp1

Description of 'comp1'

comp2

Description of 'comp2'

...

Warning

....

Note

~~further notes~~

Author(s)

~~who you are~~

References

~put references to the literature/web site here ~

See Also

~~objects to See Also as help, ~~~

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (instrument = "EUR_USD", units = 10000, side, slippage = 2, 
    SL = 10, TP = 10, acct, auth_id, acct_type = "fxpractice") 
{
    type <- "market"
    curr_price <- getPrice("EUR_USD", auth_id = auth_id)
    pip_value <- getPipValue("EUR_USD", auth_id = auth_id, acct = acct)
    if (side == "buy") {
        stopLoss <- curr_price$ask - (SL * pip_value)
        takeProfit <- curr_price$ask + (TP * pip_value)
        slipUp <- curr_price$ask + (slippage * pip_value)
        slipDown <- curr_price$ask - (slippage * pip_value)
    }
    else if (side == "sell") {
        stopLoss <- curr_price$bid + (SL * pip_value)
        takeProfit <- curr_price$bid - (TP * pip_value)
        slipUp <- curr_price$bid + (slippage * pip_value)
        slipDown <- curr_price$bid - (slippage * pip_value)
    }
    else {
        stop("Need to specify whether to Buy or Sell")
    }
    auth <- c(Authorization = paste("Bearer", auth_id))
    url <- paste0("https://api-", acct_type, ".oanda.com/v1/accounts/", 
        acct, "/orders")
    order <- fromJSON(postForm(url, style = "POST", .params = c(instrument = instrument, 
        units = units, side = side, type = type, lowerBound = slipDown, 
        upperBound = slipUp, takeProfit = takeProfit, stopLoss = stopLoss), 
        .opts = list(httpheader = auth)))
    return(order)
  }

DunderChief/roanda documentation built on May 22, 2019, 4:28 p.m.