Skip to content

Commit

Permalink
updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Pettypiece committed Oct 26, 2016
1 parent f9f1db7 commit d978ad9
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 158 deletions.
129 changes: 26 additions & 103 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,106 +127,29 @@ v20 configuration file is. If a configuration file exists in this location, no
```


## Account Scripts

The Account scripts are sample programs that interact with the v20 REST API
Account endpoints described at
http://developer.oanda.com/rest-live-v20/account-ep/.

### Account Summary

The Account Summary script is defined at `src/account/summary.py`, and is used
to fetch and display the summary of the `active_account` found in the v20
configuration file. It can be executed directly or with the provided entry
point alias:

```bash
(env)user@host: ~/v20-python-samples$ python src/account/summary.py
(env)user@host: ~/v20-python-samples$ v20-account-summary
```

### Account Details

The Account Details script is defined at `src/account/details.py`, and is used
to fetch and display the full details (including open Trades, open Positions
and pending Orders) of the `active_account` found in the v20 configuration
file. It can be executed directly or with the provided entry point alias:

```bash
(env)user@host: ~/v20-python-samples$ python src/account/details.py
(env)user@host: ~/v20-python-samples$ v20-account-details
```

### Account Instruments

The Account Instruments script is defined at `src/account/instruments.py`, and
is used to fetch and display the list of tradeable instruments for the
`active_account` found in the v20 configuration file. It can be executed
directly or with the provided entry point alias:

```bash
(env)user@host: ~/v20-python-samples$ python src/account/instruments.py
(env)user@host: ~/v20-python-samples$ v20-account-instruments
```


### Polling for Account Changes

The Account Changes script is defined at `src/account/changes.py`, and is used
to fetch and display the current Account state, and then poll repeatedly for
changes to it. This script provides a reference implementation for how OANDA
recommends that Account state be managed. It can be executed directly or with
the provided entry point alias:

```bash
(env)user@host: ~/v20-python-samples$ python src/account/changes.py
(env)user@host: ~/v20-python-samples$ v20-account-changes
```


### Account Configuration

The Account Configuration script is defined at `src/account/configure.py`, and
is used to modify client Account configuration. It can be executed directly or
with the provided entry point alias:

```bash
(env)user@host: ~/v20-python-samples$ python src/account/changes.py
(env)user@host: ~/v20-python-samples$ v20-account-changes
```


## Instrument Scripts

### Fetch Instrument Candlesticks

The script to fetch instrument candlesticks is defined at
`src/instrument/candles.py`. It can be executed directly or with the provided
entry point alias:

```bash
(env)user@host: ~/v20-python-samples$ python src/instrument/candles.py
(env)user@host: ~/v20-python-samples$ v20-instrument-candles
```


### Poll Instrument Candlesticks

The script to poll instrument candlesticks is defined at
`src/instrument/candles_poll.py`. It uses curses to redraw the current candle
while it is being updated, and moves on to the next candle when the current
candle is completed. It can be executed directly or with the provided entry
point alias:

```bash
(env)user@host: ~/v20-python-samples$ python src/instrument/candles_poll.py
(env)user@host: ~/v20-python-samples$ v20-instrument-candles-poll
```


## Orders

### Create Market Order

### Create Market Order

## Sample Code

Following is a listing of the sample code provided. More details can be found
in the READMEs provided in each src directory.

| Source File | Entry Point | Description |
| ----------- | ----------- | ----------- |
| src/configure.py | v20-configure | Create/update a v20.conf file |
| src/account/details.py | v20-account-details | Get the details of the current active Account |
| src/account/summary.py | v20-account-summary | Get the summary of the current active Account |
| src/account/instruments.py | v20-account-instruments | Get the list of tradeable instruments for the current active Account |
| src/account/changes.py | v20-account-changes | Follow changes to the current active Account |
| src/account/configure.py | v20-account-configure | Set configuration in the current active Account |
| src/instrument/candles.py | v20-instrument-candles | Fetch candles for an instrument |
| src/instrument/candles_poll.py | v20-instrument-candles-poll | Fetch and poll for candle updates for an instrument |
| src/order/get.py | v20-order-get | Get the details of an order in the current active Account |
| src/order/list_pending.py | v20-order-list-pending | List all pending Orders for the current active Account |
| src/order/cancel.py | v20-order-cancel | Cancel a pending Order in the current active Account |
| src/order/set_client_extensions.py | v20-order-set-client-extensions | Set the client extensions for a pending Order in the current active Account |
| src/order/market.py | v20-order-market | Create a Market Order in the current active Account |
| src/order/entry.py | v20-order-entry | Create or replace an Entry Order in the current active Account |
| src/order/limit.py | v20-order-limit | Create or replace a Limit Order in the current active Account |
| src/order/stop.py | v20-order-stop | Create or replace a Stop Order in the current active Account |
| src/order/take-profit.py | v20-order-take-profit | Create or replace a Take Profit Order in the current active Account |
| src/order/stop-loss.py | v20-order-stop-loss | Create or replace a Stop Loss Order in the current active Account |
| src/order/trailing-stop-loss.py | v20-order-trailing-stop-loss | Create or replace a Trailing Stop Loss Order in the current active Account |
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
'v20-account-configure = account.configure:main',
'v20-instrument-candles = instrument.candles:main',
'v20-instrument-candles-poll = instrument.candles_poll:main',
'v20-order-get = order.get:main',
'v20-order-list-pending = order.list_pending:main',
'v20-order-cancel = order.cancel:main',
'v20-order-set-client-extensions = order.set_client_extensions:main',
'v20-order-market = order.market:main',
'v20-order-entry = order.entry:main',
'v20-order-limit = order.limit:main',
'v20-order-stop = order.stop:main',
'v20-order-take-profit = order.take_profit:main',
'v20-order-stop-loss = order.stop_loss:main',
'v20-order-trailing-stop-loss = order.trailing_stop_loss:main',
'v20-order-cancel = order.cancel:main',
'v20-order-get = order.get:main',
'v20-order-set-client-extensions = order.set_client_extensions:main',
]
}
)
Expand Down
10 changes: 4 additions & 6 deletions src/account/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ point alias:
(env)user@host: ~/v20-python-samples$ v20-account-summary
```

### Account Details
## Account Details

The Account Details script is implemented in `details.py`, and is used to fetch
and display the full details (including open Trades, open Positions and pending
Expand All @@ -28,7 +28,7 @@ executed directly or with the provided entry point alias:
(env)user@host: ~/v20-python-samples$ v20-account-details
```

### Account Instruments
## Account Instruments

The Account Instruments script is implemented in `instruments.py`, and is used
to fetch and display the list of tradeable instruments for the `active_account`
Expand All @@ -40,8 +40,7 @@ provided entry point alias:
(env)user@host: ~/v20-python-samples$ v20-account-instruments
```


### Polling for Account Changes
## Polling for Account Changes

The Account Changes script is implemented in `changes.py`, and is used to fetch
and display the current Account state, and then poll repeatedly for changes to
Expand All @@ -54,8 +53,7 @@ entry point alias:
(env)user@host: ~/v20-python-samples$ v20-account-changes
```


### Account Configuration
## Account Configuration

The Account Configuration script is implemented in `configure.py`, and is used
to modify client Account configuration. It can be executed directly or with
Expand Down
93 changes: 47 additions & 46 deletions src/instrument/candles_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,8 @@ def render(self):
self.stdscr.refresh()


def main():
curses.wrapper(run)

def run(stdscr):
def main():
"""
Create an API context, and use it to fetch candles for an instrument.
Expand Down Expand Up @@ -172,64 +170,67 @@ def run(stdscr):
#
api = args.config.create_context()

kwargs = {}
def poll_candles(stdscr):
kwargs = {}

if args.granularity is not None:
kwargs["granularity"] = args.granularity
if args.granularity is not None:
kwargs["granularity"] = args.granularity

#
# Fetch the candles
#
printer = CandlePrinter(stdscr)
#
# Fetch the candles
#
printer = CandlePrinter(stdscr)

#
# The printer decides how many candles can be displayed based on the size
# of the terminal
#
kwargs["count"] = printer.max_candle_count()
#
# The printer decides how many candles can be displayed based on the size
# of the terminal
#
kwargs["count"] = printer.max_candle_count()

response = api.instrument.candles(args.instrument, **kwargs)
response = api.instrument.candles(args.instrument, **kwargs)

if response.status != 200:
print response
print response.body
return
if response.status != 200:
print response
print response.body
return

#
# Get the initial batch of candlesticks to display
#
instrument = response.get("instrument", 200)
#
# Get the initial batch of candlesticks to display
#
instrument = response.get("instrument", 200)

granularity = response.get("granularity", 200)
granularity = response.get("granularity", 200)

printer.set_instrument(instrument)
printer.set_instrument(instrument)

printer.set_granularity(granularity)
printer.set_granularity(granularity)

printer.set_candles(
response.get("candles", 200)
)
printer.set_candles(
response.get("candles", 200)
)

printer.render()

#
# Poll for candles updates every second and redraw
# the results
#
while True:
time.sleep(1)
printer.render()
#
# Poll for candles updates every second and redraw
# the results
#
while True:
time.sleep(1)

kwargs = {
'granularity': granularity,
'fromTime': printer.last_candle_time()
}
kwargs = {
'granularity': granularity,
'fromTime': printer.last_candle_time()
}

response = api.instrument.candles(args.instrument, **kwargs)
response = api.instrument.candles(args.instrument, **kwargs)

candles = response.get("candles", 200)

candles = response.get("candles", 200)
if printer.update_candles(candles):
printer.render()

if printer.update_candles(candles):
printer.render()
curses.wrapper(poll_candles)

if __name__ == "__main__":
main()

0 comments on commit d978ad9

Please sign in to comment.