OandaWrap: Php API interface

Discussion in 'App Development' started by Tavurth, Aug 13, 2014.

  1. Tavurth

    Tavurth

    Hello,
    As a side to my current main project, this library has emerged.
    I hope that some may find it useful in their search for ever increasing RR ratios.
    Let this topic be a discussion of the project. Any bug reports or improvements will be welcomed.
    I do not have much time, this project will be worked upon alongside my other projects,
    and less frequent, yet more concise code in releases is my goal here.
    I will endeavor to keep your client code syntax intact.
    Best,
    Will

    Example:
    Code:
    <?php
    include "OandaWrap.php";
    OandaWrap::setup(); // Setup a sandbox environment
    $audPrice = OandaWrap::price("AUD_USD"); // Return a decoded json object
    echo "The price of AUD/USD is: " . $audPrice->ask . " at the ask.";
    ?>
    
    Index

    // SETUP
    setup($server=Optional, $apiKey=Optional, $userName=Optional, $accountName=Optional)

    // DIRECT NETWORK ACCESS
    stream($url, $callback)

    // ACCOUNT WRAPPERS
    account($accountId)
    accounts($username)
    account_named($accountName, $uName)
    account_id($accountName, $uName)

    // INSTRUMENT WRAPPERS
    instruments()
    instrument($pair)
    instrument_name($home, $away)
    instrument_split($pair)
    instrument_pip($pair)

    // NAV (NET ACCOUNT VALUE) WRAPPERS
    convert($pair, $amount, $homeIndex=0)
    percent_nav ($pair, $percent, $leverage=1)

    // TRANSACTION WRAPPERS
    transaction_all($number=50, $pair="all")
    transaction_types($types, $number=50, $pair="all")
    transaction_get($transactionId)

    // ORDER WRAPPERS
    order($orderId)
    order_pair($pair, $number=50)
    order_open($side, $units, $pair, $type, $rest = Optional)
    order_open_extended($side, $units, $pair, $type, $price, $expiry, $rest = Optional)
    order_modify($orderId, $options)
    order_close($orderId)
    order_close_all($pair)

    // TRADE WRAPPERS
    trade($tradeId)
    trade_pair($pair, $number=50)
    trade_modify($tradeId, $options)
    trade_close($tradeId)
    trade_close_all($pair)
    trade_modify_all($pair, $options)

    // POSITION WRAPPERS
    position_all()
    position($pair)
    position_close($positionId)
    position_close_pair($pair)

    // BIDIRECTIONAL WRAPPERS
    market($side, $units, $pair, $rest = Optional)
    stop($side, $units, $pair, $price, $rest = Optional)
    mit($side, $units, $pair, $price, $expiry, $rest = Optional)
    limit($side, $units, $pair, $price, $expiry, $rest = Optional)

    // BUYING WRAPPERS
    buy_market($units, $pair, $rest = Optional)
    buy_stop($units, $pair, $price, $rest = Optional)
    buy_mit($units, $pair, $price, $expiry, $rest = Optional)
    buy_limit($units, $pair, $price, $expiry, $rest = Optional)

    // SELLING WRAPPERS
    sell_market($units, $pair, $rest = Optional)
    sell_limit($units, $pair, $price, $rest = Optional)
    sell_stop($units, $pair, $price, $rest = Optional)
    sell_mit($units, $pair, $price, $expiry, $rest = Optional)

    // EXPIRY WRAPPERS
    expiry($seconds=5)
    expiry_min($minutes=5)
    expiry_hour($hours=1)

    // MODIFICATION WRAPPERS
    units_set($id, $units)
    expiry_set($id, $time)
    tp_set($type, $id, $price)
    stop_set($type, $id, $price)
    trailing_stop_set($type, $id, $distance)

    // PRICE WRAPPERS
    price($pair)
    prices($pairs)
    candles($pair, $gran, $number)

    Download:
     
    Last edited: Aug 13, 2014
  2. Tavurth

    Tavurth

    Last edited: Aug 16, 2014
  3. Tavurth

    Tavurth

    OandaWrap: v102

    Convention:
    tp_set() => set_tp()
    stop_set() => set_stop()
    trailing_stop_set() => set_trailing_stop()
    transaction_all() => transactions()
    trade_modify_all() => trade_set_all()

    Added:
    order_set_stop($orderId, $price)
    order_set_tp($orderId, $price)
    order_set_trailing_stop($orderId, $price)
    trade_set_stop($orderId, $price)
    trade_set_tp($orderId, $price)
    trade_set_trailing_stop($orderId, $price)
    order_set_all($pair, array($rest))
    buy_bullish($pair, $risk, $stop, $leverage= Optional) // Allows a stop and risk tolerance to be set on trade open
    sell_bearish($pair, $risk, $stop, $leverage= Optional) // Allows a stop and risk tolerance to be set on trade open

    Fixes:
    Fixed bug with limit and stop orders
    Cleanup of setup code

    Download:
    https://github.com/tavurth/OandaWrap
     
  4. Tavurth

    Tavurth

    OandaWrap v103
    The manual is now automatically generated when code changes, fixed a few small bugs with setting trailing stops, and for converting currency.
    This is the last update for now.
    Good trading,

    Download
     
  5. In case you intend to trade and execute through OANDA, why would you want to do that? I mean, why would you want to pay 3x-5x higher execution related cost than with some other brokers such as Interactive Brokers? Spreads with OANDA are sky high (EURUSD around 1+ pip, whereas you see 0.1-0.3 pips regularly quoted at Interactive Brokers. Add around 0.2 pips for commission with IB and you are still 50% lower when going with IB. Other, less liquid currency pairs at OANDA are much wider and turn out to be at least 3x more expensive to trade than through IB. Just curious!!!


     
  6. Tavurth

    Tavurth

    Volpunter, thank you for your questions. The reason I chose Oanda is that I have a tendency to over-scalp on my trades. Previously I was working with Dukascopy and to whom I promptly lost a large amount of my capital paying commissions for their holiday lunches.

    I decided finally that a larger spread would force me to use my systems to hold for longer gains, however this is only for now. When I have traded successfully in this way for the next few months I fully intend to move half of my account to IB.
    Coding for OandaWrap also helps me decide what I want to implement first upon arriving at the doorstep of any new broker.

    Until that time, when my trend is up, why should I sell it?

    OandaWrap
    Manual
     
    Last edited: Aug 21, 2014
  7. Its not 3x as expensive. You pay the commission for entry and exit, and its USD based. So if you want to compare spreads for IB its 0.2 x 2 x 1.3280 = 0.53 pips in commission for EUR/USD + the spread. IB is cheaper, but not by 3 to 5 times. Its more like IB is 0.7 to 0.8 pips (more depending on trade size) and Oanda is like 1.1 or there abouts.
     
  8. not really a fair comparison: Your calculation does not factor in the following points:

    a) OANDA's pricing allows for much less volume to be traded than IB. If you trade 5mln in eurusd your spread and slippage will be much wider than you stated, while IB fills your 5mln on average at the spreads and prices you see on the screen

    b) OANDA exhibits much more slippage than IB does. That is especially a killer during fast moving markets where OANDA occasionally fills you many pips away from observed market prices where IB executes your orders with much less slippage. A backup of this statement can be found on various currency related chat forums when you google OANDA vs IB.

    c) OANDA quotes much much wider spreads in most other currency, eurusd probably being one of the tightest pairs. For example during normal liquid market hours I observed that in EURAUD, for example, the bid (and offer respectively) is around 1.0 pip away from the bid IB shows, meaning the spread is an additional 2 pips wider than IB's. That makes it around 3x-4 times as expensive to trade EURAUD at OANDA than executing it through IB. EURAUD by no means is an exotic pair, I am very sure that the less liquid a pair becomes the larger the discrepancy between IB's and OANDA's pricing.



     
  9. your argument is very flimsy. Your holding periods should have nothing whatsoever to do with the observed spread and cost of execution. In any and all circumstances lower cost of execution is better than higher ones. Keep in mind that depending on your turnover, risk adjusted returns, profit/loss per trade and number of winning vs losing trades, the difference of the commission and execution related cost between IB and OANDA can potentially mean that you lose money with the more expensive broker with almost 100% certainty over time while you can make a solid business case of profitability on average with the broker that executes you much more cheaply. This is particularly important the more turnover you produce and the smaller the average gross pnl per trade is.

     
  10. Tavurth

    Tavurth

    Wise words are these: "Exploit your own weaknesses to change yourself." I don't like paying the spread, I don't like slippage. The more I have to pay, the more carefully I trade, and so, the more I make.
    My argument may be flimsy in your eyes, but in my world enthroned are perception, interpretation and direction of the self.
     
    #10     Aug 22, 2014