Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It seems no document about the v20.functions #44

Open
david03kimo opened this issue Nov 22, 2022 · 3 comments
Open

It seems no document about the v20.functions #44

david03kimo opened this issue Nov 22, 2022 · 3 comments

Comments

@david03kimo
Copy link

david03kimo commented Nov 22, 2022

I cannot find the v20.functions documents beside cURL RESTful endpoints.But I preferred use v20.functions to trade.If I were wrong, please tell me.

I trial and error to summarize some:

import v20

#Place a market order:Market BUY EURUSD 10000 with stop loss 0.99332 and take profit 1.04718
ctx=v20.Context(
account_id, #just like 101-011-8XXXXX6-001
token='xxxxxxxxxxxxxxxxxxxxx', # get from Oanda website
)
response=ctx.order.market(
account_id,
instrument='EUR_USD',
units=10000,
type='MARKET',
side='BUY',
stopLossOnFill=v20.transaction.StopLossDetails(price=0.99332), # stop loss price
takeProfitOnFill=v20.transaction.TakeProfitDetails(price=1.04718). # take profit price
)
if response.status==201 and response.reason=='Created': # if success to place order
print(response.body['orderFillTransaction']) # check the response.body['orderFillTransaction']
print('id:',response.body['orderFillTransaction'].id) # print the order id

beside id, there's some information of order fulfillment.

print('instrument:',response.body['orderFillTransaction'].instrument)
print('type:',response.body['orderFillTransaction'].type)
print('price:',response.body['orderFillTransaction'].price)
print('orderID:',response.body['orderFillTransaction'].orderID)
print('batchID:',response.body['orderFillTransaction'].batchID)
print('requestID:',response.body['orderFillTransaction'].requestID)
print('units:',response.body['orderFillTransaction'].units)
print('requestedUnits:',response.body['orderFillTransaction'].requestedUnits)
print('commission:',response.body['orderFillTransaction'].commission)
print('accountBalance:',response.body['orderFillTransaction'].accountBalance)
print('time:',response.body['orderFillTransaction'].time)
print('reason:',response.body['orderFillTransaction'].reason)

Hope to know more who trade by Oanda v20 API.
And hope more details of documents about the v20.

@david03kimo
Copy link
Author

I found some description of v20.functions.How to use them?

import v20.Context
import v20.ContextBuilder
import v20.account.AccountID
import v20.account.AccountSummary
import v20.account.Account
import v20.account.AccountGetResponse
import v20.account.AccountListResponse
import v20.account.AccountProperties
import v20.order.LimitOrderRequest
import v20.order.OrderCreateRequest
import v20.order.OrderCreateResponse
import v20.primitives.InstrumentName
import v20.trade.TradeCloseRequest
import v20.trade.TradeCloseResponse
import v20.trade.TradeSpecifier
import v20.transaction.OrderFillTransaction
import v20.transaction.TradeReduce
import v20.transaction.TransactionID
import v20.ExecuteException
import v20.RequestException
import v20.account.AccountConfigure400RequestException
import v20.account.AccountConfigureResponse
import v20.order.MarketOrderRequest
import v20.order.Order
import v20.order.OrderID
import v20.order.OrderReplace400RequestException
import v20.order.OrderReplaceRequest
import v20.order.OrderReplaceResponse
import v20.order.OrderSpecifier
import v20.order.OrderState
import v20.order.OrderType
import v20.order.StopOrderRequest
import v20.position.Position
import v20.position.PositionCloseRequest
import v20.pricing.ClientPrice
import v20.primitives.Instrument
import v20.trade.Trade
import v20.trade.TradeSetClientExtensionsRequest
import v20.trade.TradeSetDependentOrdersRequest
import v20.trade.TradeState
import v20.transaction.ClientExtensions
import v20.transaction.OrderCancelTransaction
import v20.transaction.TakeProfitDetails
import v20.transaction.TakeProfitOrderTransaction
import v20.transaction.TradeClientExtensionsModifyTransaction
import v20.transaction.Transaction
import v20.transaction.TransactionType

@Targoyle
Copy link

Orders were placed with the following codes.
Buy or sell, can be changed by plus or minus a number of units.

OANDA does not seem to have much power to devote to this wrapper.
This repository has some parts that do not work due to some mistakes in the code.

(It's a machine translation.)

import v20

# define url and others

api = v20.Context(url, port, token=token)

response = api.pricing.get(account_id, instruments='USD_JPY')

prices = response.body['prices']
bid = prices[0].bids[0].price

kwargs = {
    'order': {
        'units': 1,
        'instrument': 'USD_JPY',
        'type': 'MARKET',
        'takeProfitOnFill': {
            'price': round(bid + 1.0, 2),
            'timeInForce': 'GTC',
        },
        'stopLossOnFill': {
            'price': round(bid - 1.0, 2),
            'timeInForce': 'GTC',
        },
    }
}

response = api.order.create(account_id, **kwargs)

print(response)

# Method = POST 
# Path = https://api-fxtrade.oanda.com:443/v3/accounts/***-***-******-***/orders
# Status = 201
# Reason = Created
# Content-Type = application/json

@david03kimo
Copy link
Author

david03kimo commented Nov 22, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants