Exemple #1
0
def change_the_trade(ACCESS_TOKEN, ACCOUNT_ID):
    # Sets take_profit_price condition over the newly opened trade
    trade_state = fetch_trades_info(ACCESS_TOKEN, ACCOUNT_ID)

    print(trade_state[0])
    tradeID = trade_state[0]['id']
    print('TRADE ID (__): ', tradeID)
    print('PRICE (___): ', trade_state[0]['price'])
    take_profit_price = 0
    if int(trade_state[0]['initialUnits']) > 0:
        take_profit_price = str(float(trade_state[0]['price']) + 0.0001)
    elif int(trade_state[0]['initialUnits']) < 0:
        take_profit_price = str(float(trade_state[0]['price']) - 0.0001)
    else:
        print('!!! SOMETHING WENT WRONG IN change_the_trade FUNCTION !!!')
        pass

    data = {'takeProfit': {'timeInForce': 'GTC', 'price': take_profit_price}}

    print(data)
    client = oandapyV20.API(access_token=ACCESS_TOKEN)
    r = trades.TradeCRCDO(accountID=ACCOUNT_ID, tradeID=tradeID, data=data)
    client.request(r)
    print(r.response)
    print('TAKE PROFIT PRICE: ', take_profit_price)
def change_the_trade(ACCESS_TOKEN, ACCOUNT_ID, take_profit_condition):
    # Sets take_profit_price condition over the newly opened trade
    trade_state = fetch_trades_info(ACCESS_TOKEN, ACCOUNT_ID)
    tradeID = trade_state[0]['id']
    take_profit_price = 0
    if int(trade_state[0]['initialUnits']) > 0:
        take_profit_price = format(
            float(trade_state[0]['price']) + take_profit_condition, '.5f')
        stop_loss_price = format(
            float(trade_state[0]['price']) - 0.0080, '.5f')
        # take_profit_price = trade_state[0]['price'] + 0.0001 * number_of_tr_items
    elif int(trade_state[0]['initialUnits']) < 0:
        take_profit_price = format(
            float(trade_state[0]['price']) - take_profit_condition, '.5f')
        stop_loss_price = format(
            float(trade_state[0]['price']) + 0.0080, '.5f')
    else:
        print('!!! SOMETHING WENT WRONG IN change_the_trade FUNCTION !!!')
        pass

    data = {
        'takeProfit': {
            'timeInForce': 'GTC',
            'price': take_profit_price
        },
        'stopLoss': {
            'timeInForce': 'GTC',
            'price': stop_loss_price
        }
    }
    print(data)
    client = oandapyV20.API(access_token=ACCESS_TOKEN)
    r = trades.TradeCRCDO(accountID=ACCOUNT_ID, tradeID=tradeID, data=data)
    client.request(r)
    print(r.response)
Exemple #3
0
 def test__trade_crcdo(self, mock_put):
     """trade client extensions."""
     tid = "_v3_account_accountID_trades_crcdo"
     resp, data = fetchTestData(responses, tid)
     r = trades.TradeCRCDO(accountID, tradeID=2323, data=data)
     mock_put.register_uri('PUT',
                           "{}/{}".format(api.api_url, r),
                           text=json.dumps(resp))
     result = api.request(r)
     self.assertTrue(result == resp)
Exemple #4
0
def amend_trade(trade_id, tp_price=None, sl_price=None):
    data = {}
    if tp_price is not None:
        data["takeProfit"] = {"price": "{0:.5f}".format(tp_price)}
    if sl_price is not None:
        data["stopLoss"] = {"price": "{0:.5f}".format(sl_price), "timeInForce": "GTC"}

    r = trades.TradeCRCDO(account_id, trade_id, data)
    client.request(r)

    return r.response
Exemple #5
0
def order_edit(trade_id, account_id, new_sl, currency):
    print(colored("NEW_SL: " + str(new_sl), 'green'))
    edit = {
        "stopLoss": {
            "timeInForce": "GTC",
            "price": str(round(new_sl, decimal[currency])),
        }
    }
    play_obj = wave_obj.play()
    play_obj.wait_done()
    r = trades.TradeCRCDO(accountID=account_id, tradeID=trade_id, data=edit)
    return client.request(r)
Exemple #6
0
def requestTradeCRCDOPathname(pathname):
	rParams = readParam(pathname)
	tradeId = rParams["tradeID"]
	params = rParams["trades"]
	res = None
	try:
		req = trades.TradeCRCDO(accountID=account_id, tradeID=tradeId, data=params)
		if req is not None:
			res=api.request(req)
			os.remove(pathname)
		return res
	except Exception as e:
		print(e)
	return res
Exemple #7
0
 def adjust_targets(self, instrument, takeProfit, stopLoss):
     data = {
         "takeProfit": {
             "timeInForce": "GTC",
             "price": str(takeProfit)
         },
         "stopLoss": {
             "timeInForce": "GTC",
             "price": str(stopLoss)
         }
     }
     r = trades.TradeCRCDO(accountID=accountID,
                           tradeID=self.status[instrument]['tradeID'],
                           data=data)
     self.request(r)
    
    print("---------------Open order validation--------------------------")
    
    if activeID==True and activeStatus=="OPEN" and tradeType=="Buy":          
        print("Action started for Buy stop loss")
        if float(str(currPrice))>float(str(closedVal)):    
            
            print("Tran 1")
            #Update Stop Loss with ID
            #from oandapyV20.contrib.requests import StopLossOrderRequest
            #ordr = StopLossOrderRequest(tradeID=TranID, price=closedVal)
#            ordr = StopLossOrderRequest(tradeID=TranID, price=closedVal)
#            print(json.dumps(ordr.data, indent=4))
            
            data ={"stopLoss": {"timeInForce": "GTC","price": str(closedVal)}}
            r=trades.TradeCRCDO(accountID=accountID, tradeID=TranID, data=data)
            rv = api.request(r)  
            print(json.dumps(rv, indent=4))
            query = "UPDATE tbloandaprice SET EMA20 = '"+str(round(EMA20,5))+"',Buy = '"+flgbuy+"',Sell = '"+flgsell+"',Processed_Amt = '"+str(float(closedVal))+"',Stoploss_Amt = '"+str(float(closedVal))+"',orderID = '"+TranID+"' WHERE TimeStamp = '"+str(timestamp)+"'"
            print(query)
            cursor.execute(query)
            db.commit()
        elif (float(str(currPrice))+acceptLoss)<float(str(closedVal)):    
            print("Tran 2")
            #Update Stop Loss with ID
            data ={"stopLoss": {"timeInForce": "GTC","price": str(currPrice)}}
            r=trades.TradeCRCDO(accountID=accountID, tradeID=TranID, data=data)
            rv = api.request(r)  
            print(json.dumps(rv, indent=4))
            query = "UPDATE tbloandaprice SET EMA20 = '"+str(round(EMA20,5))+"',Buy = '"+flgbuy+"',Sell = '"+flgsell+"',Processed_Amt = '"+str(float(closedVal))+"',Stoploss_Amt = '"+str(float(closedVal))+"',orderID = '"+TranID+"' WHERE TimeStamp = '"+str(timestamp)+"'"
            print(query)
Exemple #9
0
        rv = api.request(r)
        print("RESP:\n{} ".format(json.dumps(rv, indent=2)))

if chc == 'cltext':
    for O in sys.argv[2:]:  # tradeIDs
        cfg = {
            "clientExtensions": {
                "id": "myID{}".format(O),
                "comment": "myComment",
            }
        }
        r = trades.TradeClientExtensions(accountID, tradeID=O, data=cfg)
        rv = api.request(r)
        print("RESP:\n{} ".format(json.dumps(rv, indent=2)))

if chc == 'crc_do':
    X = iter(sys.argv[2:])
    for O in X:
        cfg = {
            "takeProfit": {
                "timeInForce": "GTC",
                "price": X.next(),
            },
            "stopLoss": {
                "timeInForce": "GTC",
                "price": X.next()
            }
        }
        r = trades.TradeCRCDO(accountID, tradeID=O, data=cfg)
        rv = api.request(r)
        print("RESP:\n{} ".format(json.dumps(rv, indent=2)))
Exemple #10
0
# トレードの詳細を取得する
#---------------------------
r = trades.TradeDetails(accountID, tradeID='21')
api.request(r)
r.response

#---------------------------
# トレードの決済
#---------------------------
r = trades.TradeClose(accountID, tradeID='13', data={'units': '10'})
api.request(r)
r.response

#---------------------------
# トレードに関する注文を行う
#---------------------------
r = trades.TradeCRCDO(accountID,
                      tradeID='21',
                      data={
                          'stopLoss': {
                              'timeInForce': 'GTC',
                              'price': '106.870'
                          },
                          'takeProfit': {
                              'timeInForce': 'GTC',
                              'price': '106.89'
                          }
                      })
api.request(r)
r.response
Exemple #11
0
def TradesTradeCRCDO(access_token, accountID, tradeID, data=None):
    'Trade Create Replace Cancel Dependent Orders.'
    r = trades.TradeCRCDO(accountID=accountID, tradeID=tradeID, data=data)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)