How to set a Take-Profit limit order with Binance - cryptocurrency

A sample code of mine:
import ccxt
binance = ccxt.binance({
'enableRateLimit': True,
'apiKey': '****',
'secret': '****',
'options': {'defaultType': 'margin'}
})
binance.create_order('BTC/USDT', 'take_profit_limit', 'buy', 0.1, price = binance.fetch_ticker('BTC/USDT')['last'], params = {'type': 'takeProfit', 'stopPrice' : stop})
where stop > price and I get the following error:
ccxt.base.errors.OrderImmediatelyFillable: binance Stop price would
trigger immediately.
It seems to me that it is attempting to place a stop-loss at the price "stop" rather than a take-profit limit order which is what I want. I see on the documentation for the Binance API that the only extra parameter involved with the take_profit_limit order type is this stopPrice and not a similar "take_profit". I can also set a take-profit order the way I want to manually on the binance website by just setting this trigger price "stop" to be greater than the buying-in price, but I just can't get ccxt to do it.
I'm afraid I couldn't find anything to help in the Almighty Kroiter's examples either, but I may have missed something so I'm open to helpful links as well!

The take_profit_limit order type is meant to trigger a Buy when the price falls to the stop price and then you buy it at the limit price. If you want to buy after the price rises to a particular point, use the STOP_LOSS_LIMIT order type. If you want to buy right away simply use a LIMIT order.

Related

Query based on multiple filters in Firebase

I am working out the structure for a JSON database for an app like onlyFans. Basically, someone can create a club, then inside of that club, there are sections where the creator's posts are shown and another where the club members posts are shown. There is however a filter option where both can be seen.
In order to make option 1 below work, I need to be able to filter based on if isFromCreator=true and at the same time based on timstamp. How can I do this?
Here are the 2 I have written down:
ClubContent
CreatorID
clubID
postID: {isFromCreator: Bool}
OR
creatorPosts
postID: {}
MemeberPosts
postID: {}
Something like the below would be what I want:
ref.child("Content").child("jhTFin5npXeOv2fdwHBrTxTdWIi2").child("1622325513718")
.queryOrdered(byChild: "timestamp")
.queryLimited(toLast: 10)
.queryEqual(toValue: true, childKey: "isFromCreator")
I triedqueryEqual yet it did not return any of the values I know exist with the configuration I specified.
You can use additional resource locations within rules by referencing the parent/child directories specifically and comparing the val() of the respective node structure.
for example:
".write": "data.parent().child('postID').child('isFromCreator').val()"
Just be aware that Security Rules do not filter or process the data in the request, only allow or deny the requested operation.
You can read more about this from the relevant documentation:
https://firebase.google.com/docs/database/security/rules-conditions#referencing_data_in_other_paths
https://firebase.google.com/docs/database/security/core-syntax#rules-not-filters

How to tell how much an individual job costs

Is there a way to tell how much an individual training job cost?
I can see the daily / hourly costs in the billing dashboard, which is a good proxy. I looked at the usage report as well, but didn't see a way to get the UsageValues to add up, and din't see tags coming through into the usage report.
When you are calling the DescribeTrainingJob API call, you are getting the following values: TrainingStartTime and TrainingEndTime. You are billed for the time interval between these times.
Now you need to get the next two values to complete the cost calculation, under ResourceConfig (in the same API call output): InstanceType, and InstanceCount.
Lastly, you can query the pricing API for the InstanceType you are using and get the price for the region you are running.
import boto3
pricing_client = boto3.client('pricing', region_name='us-east-1')
filterValue = instanceType + "-Training"
response = pricing_client.get_products(
ServiceCode='AmazonSageMaker',
Filters=[
{
'Type': 'TERM_MATCH',
'Field': 'instanceType',
'Value': filterValue
},
]
)
## TODO: fix this line to take the right region and not the first
python_dict = json.loads(response['PriceList'][0])
pricePerHour = next(iter(next(iter(python_dict['terms']['OnDemand'].values()))["priceDimensions"].values()))["pricePerUnit"]['USD']
return float(pricePerHour)

Calculate 2 columns together in Yii2 model::find() function

I have the following working find() function in Yii2:
User::find()->select('id, name')->where(['status' => '10'])->all()
However, the User model also has the following attributes:
'credit'
'ammount'
I need to check if the 'ammount' minus 'credit' is more that a value ($price) I am passing to the function.
How can I make a User:find() query where I am only getting the user objects where the amount minus credit is larger than the value I am checking against?
Thanks
I assume the amount and credit are in the user table so you can do something like.
User::find()->select([new \yii\db\Expression('id,amount,credit')])
->where(['status' => '10'])
->andWhere('amount - credit > :yourAmount',[':yourAmount'=>$price])
->all();
or use addParams() to bind the custom value
User::find()->select([new \yii\db\Expression('id,amount,credit')])
->where(['status' => '10'])
->andWhere('amount - credit > :yourAmount')
->addParams([':yourAmount'=>$price])
->all();

Obtaining order book information from gdax api

I am trying to obtain order book (buy, sell, volume, price) info from GDAX.
I am familiar with the Bittrex api - specifically this call:
https://bittrex.com/api/v1.1/public/getmarketsummary?market=usdt-eth
which produces the following response:
{
success: true,
message: "",
result: [
{
MarketName: "USDT-ETH",
High: 770,
Low: 729.70000005,
Volume: 12847.90985907,
Last: 752,
BaseVolume: 9641897.74525487,
TimeStamp: "2017-12-27T13:49:29.463",
Bid: 751.99999999,
Ask: 752.9999,
OpenBuyOrders: 2072,
OpenSellOrders: 1933,
PrevDay: 738.99899999,
Created: "2017-04-20T17:26:37.647"
}
]
}
Does anyone know what the equivalent call would be in the gdax api ?
I am using Python and tried out Client.get_product_order_book('ETH-USD')
but its output is limited and the order book seems rather thin.
In [54]: client.get_product_order_book('ETH-USD')
Out[54]:
{'asks': [['756.97', '168.24847073', 8]],
'bids': [['756.96', '77.74495889', 14]],
'sequence': 1810832728}
Based on the docs the call above with level=1 corresponds to the inside
(i.e. best bid and ask prices)
But the output from the Bittrex api seems to be the best bid and ask prices as
well. So does anyone know the difference ?
Does anyone know what the equivalent call would be in the gdax api ?
If you want something similar, a better try would be:
>> client.get_product_24hr_stats('ETH-USD')
>> {
"open": "416.11000000",
"high": "433.83000000",
"low": "410.11000000",
"volume": "91763.71115699",
"last": "432.79000000",
"volume_30day": "4011593.85194549"
}
I am using Python and tried out Client.get_product_order_book('ETH-USD') but its output is limited and the order book seems rather thin.
Level Description
1 Only the best bid and ask
2 Top 50 bids and asks (aggregated)
3 Full order book (non aggregated)
You are calling it with the default level of 1 so you are only getting the lowest ask and the highest bid, only 2, so yes, it's thin. If you need more info, consider calling it with level 2 or 3 according to the snippet above taken from the GDAX official docs. More here.
But the output from the Bittrex api seems to be the best bid and ask prices as well. So does anyone know the difference ?
The difference is that Bittrex only gives you the best bid and ask price while GDAX api gives you the bid/ask price, the total size of all the orders, and the number of orders.

giving a string slot in Amazon alexa

I'm new to alexa. I learnt and started to build a weather app.
right now I'm able to get weather data, but on the below condition,
I've craeated a custom slot(LIST_OF_CITIES) to hold Cities as below.
{
"intents": [
{
"intent": "WeatherIntent",
"slots": [
{
"name": "city",
"type": "LIST_OF_CITIES"
}
]
},
{
"intent": "AMAZON.HelpIntent"
},
]
}
and in my custom slot I gave as below.
Type Values
LIST_OF_CITIES Hyderabad | pune | london
and below are my Utterances
WeatherIntent give me {city} climate
WeatherIntent {city}
WeatherIntent what's the climate in {city}
WeatherIntent what's the weather in {city}
WeatherIntent {city}
when I run my program using any of the three cities mentioned in the above table, I'm able to get the correct. If I use anything apart from the above, it is sending back value as -4.
If I want to get tempreature of some other city, I need to add that city in the slot list.
Please let me know how can I get the vaues dynamically, I mean with out depending on the LIST_OF_CITIES, If I enter a city name, it should send back the result.
Also I tried adding type as LITERAL and also as AMAZON.LITERAL. When I saved it, I get the exception as
Error: There was a problem with your request: Unknown slot name '{city}'. Occurred in sample 'WeatherIntent get me weather of {city}' on line 1.
Please let me know where am I going wrong and how can I fix this.
Thanks
Amazon provides some default list Slot Types for cities or even regions. E.g.
AMAZON.US_CITY
AMAZON.AT_CITY
AMAZON.DE_REGION
...
You can use these as type when defining your custom slot.
First, don't use LITERAL - it is deprecated and isn't even supported at all outside US region.
And no, you can't manage the list of words dynamically.
Alexa will try to match what the user says with your LIST_OF_CITIES, and will try to return one of those words, but might return something else if it can't match one of those (as you have seen).
There are some custom slot types for cities that you can use and build off of, see here:
https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/alexa-skills-kit-interaction-model-reference#h2_custom_syntax
But that probably won't work for you since each of them is just one country, so you will need to build your own list of cities (in your LIST_OF_CITIES).

Resources