Giter VIP home page Giter VIP logo

async_v20's People

Contributors

gshklover avatar jamespeterschinner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

async_v20's Issues

Account changes doesn't work

Description of issue:

It appears that there is a limit to how far back the since_transaction_id can be for the account_changes API method. This causes an error response, which will mean that all subsequent calls to account_changes fail.

Expected behaviour:

account_changes should always return the account changes. with default parameters.

Actual behaviour:

When the default since_transaction_id becomes to far gone. OANDA will not return all changes.

Issue

After a little experimenting. It looks as though the oldest transaction for since_transaction_id is 985 previous transactions:

image

I see these options for async_v20. Either:

  • automatically poll account_changes before 985 transactions occur.
  • limit the default since_transaction_id with in 985 transactions of last_transaction_id
  • call get_account_details() to completely refresh client._account and update since_transaction_id

I think. since_transaction_id will be limited and raise a warning, When limit is applied. the client.account() method will just call get_account_details().

fetch stream_pricing out str not number

Description of issue:
Use example on async-v20.readthedocs.io, the out this is:

<Status [200]: price>
<Status [200]: price>
<Status [200]: heartbeat>

Is this normal?

Your environment(os, python, packages)
Ubuntu 18.04
Python 3.82

Complete self contained example of issue:
here is the code

import asyncio

from async_v20 import OandaClient

client = OandaClient()


async def poll_account(poll_interval=6, client=client):
    while True:
        account = await client.account()
        print(account)
        await asyncio.sleep(poll_interval)


async def stream(instruments, client=client):
    async for price in await client.stream_pricing(instruments):
        print(price)


loop = asyncio.get_event_loop()
loop.run_until_complete(
    asyncio.gather(poll_account(), stream('EUR_USD'))
    )
client.close()

OrderID type where ClientID should be used

Hi.
Attached is a patch to replace attribute type definitions for client IDs fields 'OrderID' -> 'ClientID' (OrderID is int, while client IDs could be any string).

Additionally, a couple of attributes are added to model definitions where Oanda API documentation seems to be missing definitions comparing to actual implementation.

Thanks,
Gregory.

clientid.txt

UNIX time stamp in data frame not correct type

Description of issue:

When creating a pd.DataFrame from an Array and specify False for the datetime argument. If the datetime_format parameter is set to 'UNIX' the resulting value in the data frame is a str which is not a very useful type for a Unix time stamp

Expected behaviour:

I think it would make much more sense if the value was cast to a float in this case

Actual behaviour:

time values are str

Complete self contained example of issue:

from async_v20 import OandaClient
import asyncio
client = OandaClient(datetime_format='UNIX')
loop = asyncio.get_event_loop()
run = loop.run_until_complete
rsp = run(client.get_candles('EUR_USD'))
df = rsp.candles.dataframe(datetime=False)
df.time[0]
Out[5]: '1513677115.000000000'  # str
type(df.time)
Out[6]: pandas.core.series.Series
type(df.time[0])
Out[7]: async_v20.definitions.primitives.DateTime

Model attributes are camelCase

All class definitions in async_v20.definitions.types have camelCase attributes in the doc string

Need to make them snake_case

creating duplicate Array objects

Please provide the follow

Description of issue:

Array() is created for the same object multiple times. This means there are multiple class definitions with the same code.

Need to remove the Array metaclass in place for class literals

Your environment(os, python, packages)

Expected behaviour:

Actual behaviour:

Complete self contained example of issue:

KeyError / Attribute error when parsing OANDA JSON

Description of issue:

When OANDA sends JSON object's. Occasionally the JSON data contains attributes that async_v20 wasn't expecting. This cause's a KeyError or AttributeError (depending if the JSON is in an array or not).

Expected behaviour:

async_v20 objects should contain all attributes that OANDA may send.

Actual behaviour:

async_v20 doesn't contain all attributes OANDA's v20 API sends

Explanation:

There is currently no way to test for the completeness of async_v20's object model in respect to the actual data OANDA sends in the JSON response. async_v20 has been constructed from OANDA's documentation which is not 100% perfect. OANDA has been contacted many times regarding this issue and I am awaiting there response. Where ideally the this issue can be resolved. By OANDA updating there documentation.

Some sort of automated comparison between async_v20's object definitions and OANDA's documentation could then be set up.

The other option is to handle these errors in async_v20. Which I am reluctant to do because:

  • Incomplete documentation OANDA should correct.
  • Possibility of creating other errors in async_v20
  • The ability of async_v20 to detect mistakes in user code may be compromised. Which may have real monetary cost if a mistake isn't caught early.
  • It would be a band aid of a larger problem

Having said all of that. You don't want your trading strategy to fail, due to an attribute in a JSON response that is likely irrelevant.

Until this issue can be resolved. I Encourage all users to post the stack trace of these errors here, so the async_v20's object model can be updated.

Signature annotations in documentation is hard top read

Please provide the follow

Description of issue:

API documentation is hard to read due to nested annotations

Your environment(os, python, packages)

Expected behaviour:

signature annotations should be importable from the top directory and documentation should reflect this

Actual behaviour:

signature annotations have a nested structure causing documentation to be difficult to read

Complete self contained example of issue:

No error handling on failed initialization

Please provide the follow

Description of issue:

async_v20 doesn't provide any use full information when it fails to initialize.

Your environment(os, python, packages)

Expected behaviour:

It should probably raise an error. If handled in user code, continue attempt to initialize.

Though maybe only continue to initialize if the the method was called directly?

Actual behaviour:

Just fails with a big stack trace, no idea what went wrong

Complete self contained example of issue:

RuntimeWarning When Executing First Example

Description of issue:
during execution of the first example of the readme, a RuntimeWarning occurs.

Your environment(os, python, packages)
ubuntu 14.04, python 3.6

Expected behaviour:
no warning/error occurs (perhaps by using a small try/except)
or:
README.rst cites the warning message

RuntimeWarning: coroutine 'ClientSession.close' was never awaited
  self.session.close()

instead of stating:
Doing so will automatically close the http session when we're done

Background/motivation: As a beginner, an example without warning messages makes me feel a little bit easier :-)

Actual behaviour:
.virtualenvs/py36/lib/python3.6/site-packages/async_v20/client.py:254: RuntimeWarning: coroutine 'ClientSession.close' was never awaited
self.session.close()

log file:

15:40:52,530 async_v20.client INFO Initializing client
15:40:52,530 async_v20.client INFO Initializing session
15:40:52,530 async_v20.interface.decorators INFO list_services(args=(), kwargs={})
15:40:53,184 async_v20.interface.decorators INFO list_accounts(args=(), kwargs={})
15:40:53,878 async_v20.interface.decorators INFO get_account_details(args=(), kwargs={})
15:40:54,40 async_v20.interface.decorators INFO account_instruments(args=(), kwargs={})
15:40:54,211 async_v20.client INFO account()
15:40:54,211 async_v20.interface.decorators INFO account_changes(args=(), kwargs={})
15:40:54,374 asyncio ERROR Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fe1e5c80940>
15:40:54,374 asyncio ERROR Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7fe1cf8fe128>, 52137.550035477)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7fe1ce280ba8>, 52138.738409018)]']
connector: <aiohttp.connector.TCPConnector object at 0x7fe1e7026cf8>

Complete self contained example of issue:

from async_v20 import OandaClient


async def get_account():
    async with OandaClient() as client:
        return await client.account()


loop = asyncio.get_event_loop()
account = loop.run_until_complete(get_account())

Add __slots__ to Model objects

Model objects have well defined attributes.

It would be nice to implement automatic __slots__ creation in the metaclass in order to improve memory usage

close_position does not close all positions by default

Description of issue:

API method close_position() doesn't close all positions unless either long or short units to close is specified.

Expected behaviour:

The default should be to close all positions long and short when not specified.

Actual behaviour:

The default is to send no arguments to the endpoint. Unless specified.

I have played around with making the default for long and short to units to ALL. But encountered an issue where specifying ALL for long or short units that don't exist cause an error preventing the request from closing the units that do exist.

In an ideal world async_v20 should raise an error when the user is attempting to perform an action that OANDA will reject. Thereby catching user mistakes earlier. async_v20 should check that either long_units or short_units has been specified. Need to come up with a clean way to handle this edge case.

I have also contacted OANDA suggesting that the behavior of the endpoint be changed (seems to make the most sense)

Complete self contained example of issue:
image

image

No logging

Description of issue:

async_v20 doesn't provide any access to a log stream.

Expected behavior

Users should be able to subscribe to various logs.

Currently I'm thinking:

  • info logs requests and response

  • warning logs when decimal numbers are rounded

Coroutine_3 From Example Does not get Executed

Description of issue:
Hi, I execute the below depicted example of http://async-v20.readthedocs.io/en/latest/beyond_getting_started.html

Only two of the three coroutines are executed

Your environment(os, python, packages)
ubuntu 14.04, python 3.6

Expected behaviour:
All three positions are created.

Actual behaviour:
Number three does not appear in the Oanda transaction history.
Excerpt from the transaction history (I tried it twice)

Ticket	Date				Transaction	Details	Instrument	Price	Units	Direction	Spread Cost
34	02/28/2018 04:26:00 PM CET	MARKET_ORDER	CLIENT_ORDER	AUD/USD		12	Buy	
35	02/28/2018 04:26:00 PM CET	ORDER_FILL	MARKET_ORDER	AUD/USD	0.78004	12	Buy	0.0007
36	02/28/2018 04:26:00 PM CET	MARKET_ORDER	CLIENT_ORDER	AUD/USD		11	Buy	
37	02/28/2018 04:26:00 PM CET	ORDER_FILL	MARKET_ORDER	AUD/USD	0.78004	11	Buy	0.0007
38	02/28/2018 04:28:06 PM CET	MARKET_ORDER	CLIENT_ORDER	AUD/USD		22	Buy	
39	02/28/2018 04:28:06 PM CET	ORDER_FILL	MARKET_ORDER	AUD/USD	0.78009	22	Buy	0.0012
40	02/28/2018 04:28:06 PM CET	MARKET_ORDER	CLIENT_ORDER	AUD/USD		21	Buy	
41	02/28/2018 04:28:06 PM CET	ORDER_FILL	MARKET_ORDER	AUD/USD	0.78009	21	Buy	0.0011

log file:

16:25:36,419 root INFO =================================================0
16:25:36,420 root INFO starting execution
16:25:49,264 asyncio DEBUG Using selector: EpollSelector
16:25:57,857 async_v20.client INFO Initializing client
16:25:57,857 async_v20.client INFO Initializing session
16:25:57,858 async_v20.interface.decorators INFO list_services(args=(), kwargs={})
16:25:58,630 async_v20.interface.decorators INFO list_accounts(args=(), kwargs={})
16:25:59,345 async_v20.interface.decorators INFO get_account_details(args=(), kwargs={})
16:25:59,512 async_v20.interface.decorators INFO account_instruments(args=(), kwargs={})
16:25:59,688 async_v20.interface.decorators INFO post_order(args=(), kwargs={'order_request': <OrderRequest: instrument=AUD_USD, units=13.0>})
16:25:59,873 async_v20.interface.decorators INFO post_order(args=(), kwargs={'order_request': <OrderRequest: instrument=AUD_USD, units=12.0>})
16:25:59,875 async_v20.interface.decorators INFO post_order(args=(), kwargs={'order_request': <OrderRequest: instrument=AUD_USD, units=11.0>})
16:26:00,544 asyncio ERROR Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fb5229420b8>
16:26:00,545 asyncio ERROR Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7fb54e472240>, 54842.994166733)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7fb5227b5908>, 54844.405674402), (<aiohttp.client_proto.ResponseHandler object at 0x7fb52171d710>, 54844.885130463)]']
connector: <aiohttp.connector.TCPConnector object at 0x7fb52290fcc0>
16:28:00,918 root INFO =================================================0
16:28:00,920 root INFO starting execution
16:28:03,771 asyncio DEBUG Using selector: EpollSelector
16:28:03,773 async_v20.client INFO Initializing client
16:28:03,773 async_v20.client INFO Initializing session
16:28:03,773 async_v20.interface.decorators INFO list_services(args=(), kwargs={})
16:28:04,444 async_v20.interface.decorators INFO list_accounts(args=(), kwargs={})
16:28:05,264 async_v20.interface.decorators INFO get_account_details(args=(), kwargs={})
16:28:05,427 async_v20.interface.decorators INFO account_instruments(args=(), kwargs={})
16:28:05,596 async_v20.interface.decorators INFO post_order(args=(), kwargs={'order_request': <OrderRequest: instrument=AUD_USD, units=23.0>})
16:28:05,789 async_v20.interface.decorators INFO post_order(args=(), kwargs={'order_request': <OrderRequest: instrument=AUD_USD, units=22.0>})
16:28:05,791 async_v20.interface.decorators INFO post_order(args=(), kwargs={'order_request': <OrderRequest: instrument=AUD_USD, units=21.0>})
16:28:06,573 asyncio ERROR Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fe1ef39fa90>
16:28:06,574 asyncio ERROR Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7fe216667240>, 54968.80838577)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7fe1ee1f4400>, 54970.243403963), (<aiohttp.client_proto.ResponseHandler object at 0x7fe1ee21dda0>, 54970.913812755), (<aiohttp.client_proto.ResponseHandler object at 0x7fe1ee1f4278>, 54970.914978183)]']
connector: <aiohttp.connector.TCPConnector object at 0x7fe1ef39f9e8>

Extra question: where could I find an error message, that something went wrong?

Complete self contained example of issue:

import asyncio

from async_v20 import OandaClient

client = OandaClient()

# This
coroutine_1 = client.create_order('AUD_USD', 21)

# Is the same as this
from async_v20 import InstrumentName, DecimalNumber

coroutine_2 = client.create_order(
    InstrumentName('AUD_USD'), DecimalNumber(22)
)

# Is the same as this
from async_v20 import OrderRequest

coroutine_3 = client.post_order(
    order_request=OrderRequest(
        instrument='AUD_USD', units=23
    )
)

loop = asyncio.get_event_loop()
loop.run_until_complete(
    asyncio.gather(
        coroutine_1,
        coroutine_2,
        coroutine_3
    )
)

print("done")

Decimal accuracy on OrderRequest not correct.

Description of issue:

The helper function _format_order_requests witch is responsible for formatting every OrderRequest to conform to the instruments specification. Does not format OrderRequests that don't have an instrument attribute

Expected behaviour:

All OrderRequests should be formatted correctly. Eg. correct decimal accuracy.

Actual behaviour:

TakeProifit & StopLoss OrderRequests don't get there decimal numbers rounded to the correct accuracy.

Issue

These' orders don't have an instrument attribute, Therefore OandaClient has no idea what specification the Order should be formatted to.

Client fails when reaching oanda health API

Description of issue:

Client fails when trying to reach the health API.

ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8', url=URL('http://api-status.oanda.com:80/api/v1/services')

Your environment(os, python, packages)

Python 3.7, latest async_v20.

Accuracy of floats not currently being handled

Model objects with DecimalNumber attributes, don't automatically format decimal places to correct accuracy.

DecimalNumbers are converted into strings when serialized into JSON. OANDA, only accepts decimal places to 5 points for prices represented as floats. And I believe 0 decimal places for 'units'

Problem seems to exists because of inconsistency of int and float usage in the OANDA v20 API

Requires investigation, to determine correct accuracy for each usage of the DecimalNumber.

image

Decimal number accuracy isn't automatically provided

Description of issue:

When submitting a new Market Order. OANDA Rejects order due to incorrect decimal number accuracy.
"rejectReason":"TAKE_PROFIT_ON_FILL_PRICE_PRECISION_EXCEEDED"

Current behavior

async_v20 doesn't round numbers to the instruments accuracy. It currently rounds all decimal numbers to 5 decimal places regardless of what the instrument defines

Expected behavior

async_v20 should ensure that all decimal numbers sent to OANDA comply with the instruments accuracy

close trade confusion

Please provide the follow

Description of issue:
I am getting confused on how to close the order. we see cancel order, close position, close trades, we don't know how to tell the difference so can you please clarify it?

Your environment(os, python, packages)

Expected behaviour:

Actual behaviour:

Complete self contained example of issue:

error when installing via pip

``
Collecting async_v20
Using cached https://files.pythonhosted.org/packages/79/e0/142c9c26d2fc4cadf56ca8fd596c842d5ce6fc47f6b8869c8cd900df27c
f/async_v20-7.0.0b0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-build-wmzjux0u/async-v20/setup.py", line 4, in
from async_v20 import version
File "/tmp/pip-build-wmzjux0u/async-v20/async_v20/init.py", line 3, in
from async_v20.client import OandaClient
File "/tmp/pip-build-wmzjux0u/async-v20/async_v20/client.py", line 207
msg = f'Could not get open trades. '
^
SyntaxError: invalid syntax

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-wmzjux0u/async-v20/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.