예제 #1
0
    def OrderCreate_pending(self, ticker, size, price, takeprofit=None,
                            stoploss=None, trailingstop=None,
                            requesttype='MarketIfTouchedOrder'):
        
        d = dict(instrument=ticker, units=size, price=price)

        if takeprofit:
            d['takeProfitOnFill'] = TakeProfitDetails(price=takeprofit).data

        if stoploss:
            d['stopLossOnFill'] = StopLossDetails(price=stoploss).data

        if trailingstop:
            d['trailingStopLossOnFill'] = TrailingStopLossDetails(
                distance=trailingstop).data

        if requesttype is 'MarketIfTouchedOrder':
            Order = MITOrderRequest(**d).data
        elif requesttype is 'LimitOrder':
            Order = LimitOrderRequest(**d).data
        elif requesttype is 'StopOrder':
            Order = StopOrderRequest(**d).data

        r = orders.OrderCreate(accountID=self.accountID, data=Order)

        return self.client.request(r)
예제 #2
0
 def place_limit_order(self, instrument: str, side: str, units: Union[float, int], price: float, tp: float, sl: float, expiry: str = None):
     order_request = LimitOrderRequest(
         instrument=instrument,
         units=units * (1 if side == OrderSide.LONG else -1),
         price=self._adjust_decimals(instrument, price),
         takeProfitOnFill=TakeProfitDetails(price=self._adjust_decimals(instrument, tp)).data,
         stopLossOnFill=StopLossDetails(price=self._adjust_decimals(instrument, sl)).data,
         timeInForce='GTD' if expiry else 'GTC',
         gtdTime=expiry
     )
     self._submit_order_request(order_request, self.account_id)
예제 #3
0
    def _place_order(self,
                     _type='market',
                     units=1000,
                     side='LONG',
                     instrument='EUR_USD',
                     price=None,
                     stop_loss=None,
                     take_profit=None):
        if take_profit:
            take_profit = TakeProfitDetails(price=take_profit).data

        if stop_loss:
            stop_loss = StopLossDetails(price=stop_loss).data

        if side == 'SHORT':
            units = -units

        if _type == 'market':
            mktOrder = MarketOrderRequest(instrument=instrument,
                                          units=units,
                                          takeProfitOnFill=take_profit,
                                          stopLossOnFill=stop_loss).data
            order = orders.OrderCreate(accountID=self.accountID, data=mktOrder)
        elif _type == 'stop':
            stopOrder = StopOrderRequest(instrument=instrument,
                                         units=units,
                                         price=price,
                                         takeProfitOnFill=take_profit,
                                         stopLossOnFill=stop_loss).data
            order = orders.OrderCreate(accountID=self.accountID,
                                       data=stopOrder)
        elif _type == 'limit':
            limitOrder = LimitOrderRequest(instrument=instrument,
                                           units=units,
                                           price=price,
                                           takeProfitOnFill=take_profit,
                                           stopLossOnFill=stop_loss).data
            order = orders.OrderCreate(accountID=self.accountID,
                                       data=limitOrder)

        return self.client.request(order)
예제 #4
0
파일: bot.py 프로젝트: ICLTEAM/Trady-Boi
def create_limit_order(order_instrument, order_units, order_take_profit,
                       order_stop_loss, order_price):
    """ 
    Create a limit order.
    The Limit Order will only be filled by a market price that is equal to or better than this price.
    """
    # Create the order body
    ordr = LimitOrderRequest(
        instrument=order_instrument,
        units=order_units,
        takeProfitOnFill=TakeProfitDetails(price=order_take_profit).data,
        stopLossOnFill=StopLossDetails(price=order_stop_loss).data,
        price=order_price)
    # create the OrderCreate request
    r = orders.OrderCreate(accountID, data=ordr.data)
    try:
        # create the OrderCreate request
        rv = api.request(r)
    except oandapyV20.exceptions.V20Error as err:
        print(r.status_code, err)
    else:
        print(json.dumps(rv, indent=2))
예제 #5
0
    def order(self, symbol, size, target, stop, type='mkt'):

        mktOrderLong = MarketOrderRequest(
            symbol,
            units=size,
            takeProfitOnFill=TakeProfitDetails(price=target).data,
            stopLossOnFill=StopLossDetails(price=stop).data)

        lmtOrderLong = LimitOrderRequest(
            symbol,
            units=size,
            price=round(target * 1.05, self.account_instruments(symbol)),
            takeProfitOnFill=TakeProfitDetails(price=target).data,
            stopLossOnFill=StopLossDetails(price=stop).data)

        if type == 'lmt':
            r = orders.OrderCreate(ACCOUNT_ID, lmtOrderLong.data)
        else:
            r = orders.OrderCreate(ACCOUNT_ID, mktOrderLong.data)

        data = api.request(r)

        return data
예제 #6
0
#Formule =D80*2/(20+1)+F79*(1-2/(20+1)) --- Col no D row is 80

EMA20 = float(closedVal) * 2 / (20 + 1) + float(lastVal) * (1 - 2 / (20 + 1))
#Test - EMA20=float("1.11565")*2/(20+1)+float("1.1063")*(1-2/(20+1))

print("EMA20 Price - ", round(EMA20, 5))

flgbuy = "No"
flgsell = "No"

#EMA>Closing - Sell and EMA<Closing - Buy
if float(round(EMA20, 5)) < float(closedVal):
    print("Process Buy")
    if flgLastbuy == "No":
        mktOrder = LimitOrderRequest(
            instrument="EUR_USD", units=10000,
            price=float(closedVal))  #price=float(round(EMA20,5)))

        ("#2")
        # create the OrderCreate request
        r = orders.OrderCreate(accountID, data=mktOrder.data)

        try:
            # create the OrderCreate request
            rv = api.request(r)
            print("Pass")
        except API.exceptions.V20Error as err:
            print(r.status_code, err)
        else:
            print(json.dumps(rv, indent=2))
        #After close the existing slots
예제 #7
0
 def limit_order(self, pair="AUD_USD", unit=1000, p=1.08):
     client = API(access_token=self.access_token, environment='live')
     ordr = LimitOrderRequest(instrument=pair, units=1000, price=p)
     r = orders.orderCreate(self.accountID, data=ordr.data)
     rv = client.request(r)
예제 #8
0
#accountID, access_token = exampleAuth()
#api = oandapyV20.API(access_token=access_token)

access_token = "024af7bed182e0a42a205b39cc424598-f0f1aacef36bfaeb997ce4a4ea65278c"
accountID = "101-011-12154697-001"

#access_token = "1a9a034c3e637d5721281edc1f7461e1-0b2e59994d3ef7c4fc9a5d67a67d5a65"
#accountID = "101-011-7592314-001"
api = API(access_token=access_token)

# EUR_USD (today 1.0750)
EUR_USD_STOP_LOSS = 1.09966
EUR_USD_TAKE_PROFIT = 1.10966
print("#1")
mktOrder = LimitOrderRequest(instrument="EUR_USD", units=100,
                             price=1.09880)  #price for select manual

print(json.dumps(mktOrder.data, indent=4))

("#2")
# create the OrderCreate request
r = orders.OrderCreate(accountID, data=mktOrder.data)

try:
    # create the OrderCreate request
    rv = api.request(r)
    print("Pass")
except API.exceptions.V20Error as err:
    print(r.status_code, err)
else:
    print("No Exception")
예제 #9
0
    def openLong(self, pair, price):

        #Calc Profit and Stop Order
        client = API(access_token=userVals.key)
        spacing = 1 / 1000
        takeProfitPx = price + spacing
        takeStopPx = price - spacing

        random.seed(3)

        # print a random number between 1 and 1000.
        randint = random.uniform(.95, 1)

        units = int(Trade().UnitsAvailable(pair, 'Long') * randint)

        if units > 0:

            lmtOrderLong1 = LimitOrderRequest(
                instrument=pair,
                price=price,
                units=int(units / 2),
                takeProfitOnFill=TakeProfitDetails(price=takeProfitPx).data,
                stopLossOnFill=StopLossDetails(price=takeStopPx).data)

            r = orders.OrderCreate(userVals.accountID, data=lmtOrderLong1.data)
            client.request(r)

            #print('Bought {} units of {} at {} '.format(units, pair, price))

            lmtOrderLong2 = LimitOrderRequest(
                instrument=pair,
                price=price,
                units=int(units / 4),
                takeProfitOnFill=TakeProfitDetails(price=takeProfitPx +
                                                   spacing).data,
                stopLossOnFill=StopLossDetails(price=takeStopPx).data)

            r = orders.OrderCreate(userVals.accountID, data=lmtOrderLong2.data)
            client.request(r)

            lmtOrderLong3 = LimitOrderRequest(
                instrument=pair,
                price=price,
                units=int(units / 8),
                takeProfitOnFill=TakeProfitDetails(price=takeProfitPx +
                                                   (spacing * 2)).data,
                stopLossOnFill=StopLossDetails(price=takeStopPx).data)

            r = orders.OrderCreate(userVals.accountID, data=lmtOrderLong3.data)
            client.request(r)

            lmtOrderLong4 = LimitOrderRequest(
                instrument=pair,
                price=price,
                units=int(units / 8.01),
                takeProfitOnFill=TakeProfitDetails(price=takeProfitPx +
                                                   (spacing * 3)).data,
                stopLossOnFill=StopLossDetails(price=takeStopPx).data)

            r = orders.OrderCreate(userVals.accountID, data=lmtOrderLong4.data)
            client.request(r)
예제 #10
0
    def openShort(self, pair, price):

        #Calc Profit and Stop Order
        client = API(access_token=userVals.key)
        spacing = 1 / 1000
        takeProfitPx = round(price - spacing, 4)
        takeStopPx = round(price + spacing, 4)

        # print a random number between 1 and 1000.
        randint = random.uniform(.9, 1)

        units = int(Trade().UnitsAvailable(pair, 'Short') * randint)

        if units > 0:

            lmtOrderShort1 = LimitOrderRequest(
                instrument=pair,
                price=price,
                units=int(units / 2) * -1,
                takeProfitOnFill=TakeProfitDetails(price=takeProfitPx).data,
                stopLossOnFill=StopLossDetails(price=takeStopPx).data)

            r = orders.OrderCreate(userVals.accountID,
                                   data=lmtOrderShort1.data)
            client.request(r)

            lmtOrderShort2 = LimitOrderRequest(
                instrument=pair,
                price=price,
                units=int(units / 4) * -1,
                takeProfitOnFill=TakeProfitDetails(price=takeProfitPx -
                                                   spacing).data,
                stopLossOnFill=StopLossDetails(price=takeStopPx).data)

            r = orders.OrderCreate(userVals.accountID,
                                   data=lmtOrderShort2.data)
            client.request(r)

            lmtOrderShort3 = LimitOrderRequest(
                instrument=pair,
                price=price,
                units=int(units / 8) * -1,
                takeProfitOnFill=TakeProfitDetails(price=takeProfitPx -
                                                   (spacing * 2)).data,
                stopLossOnFill=StopLossDetails(price=takeStopPx).data)

            r = orders.OrderCreate(userVals.accountID,
                                   data=lmtOrderShort3.data)
            client.request(r)

            lmtOrderShort4 = LimitOrderRequest(
                instrument=pair,
                price=price,
                units=int(units / 8.01) * -1,
                takeProfitOnFill=TakeProfitDetails(price=takeProfitPx -
                                                   (spacing * 3)).data,
                stopLossOnFill=StopLossDetails(price=takeStopPx).data)

            r = orders.OrderCreate(userVals.accountID,
                                   data=lmtOrderShort4.data)
            client.request(r)