ByBit : API ColdFusion - api

Having trouble with ByBit By/Sell API. ColdFusion any help appreciated.
https://bybit-exchange.github.io/docs/spot/v3/?console#t-authenticationparameters
Authentication for POST
POST
rule: timestamp + api_key + recv_window + raw_request_body
param_str =
"1659073093578T0d98KyVamQ62YBzN85000{
"symbol": "BTCUSDT",
"orderQty":"0.05",
"side": "Sell",
"orderType": "LIMITT",
"timeInForce": "GTC",
"orderPrice": "24500",
"orderLinkId": "spotA0008"
}"
curl --location --request POST 'https://api-testnet.bybit.com/spot/v3/private/order' \
--header 'X-BAPI-API-KEY: {api key}'
--header 'X-BAPI-TIMESTAMP: 1659067662307'
--header 'X-BAPI-RECV-WINDOW: 5000'
--header 'X-BAPI-SIGN: cc63fb44be4a87f4b7bbd42db012ddacc1c935c3d3ae3e01c3b4be393522c213'
--header 'Content-Type: application/json'
--data-raw '{
"symbol": "BTCUSDT",
"orderQty":"0.01",
"side": "Buy",
"orderType": "LIMIT",
"timeInForce": "GTC",
"orderPrice": "21300",
"orderLinkId": "spotx006",
"orderCategory": 1,
"triggerPrice": "21700"
}'
This is the Post Example.
For Account - my signature works fine.
<cfscript>
apiKey = "#_key#";
apiSecret = "#_s#";
newbody = serializeJSON({
"symbol": "#symb#",
"orderQty":"#qty#",
"side": "#side#",
"orderType": "#type#"
});
ts_key_str = #unixdatetimeNow.getTime()# & '#apikey#' & '5000';
str_to_sign = #unixdatetimeNow.getTime()# & '#apikey#' & '5000' & '#newbody#';
HMAC = hmac(str_to_sign, apiSecret, "HMACSHA256");
</cfscript>
<cfhttp url="#base_api##req_path#" method="POST" result="result" charset="utf-8">
<cfhttpparam type="body" value="#newbody#">
<cfhttpparam type="HEADER" name="Content_Type" value="application/json">
<cfhttpparam type="header" name="X-BAPI-SIGN-TYPE" value="2">
<cfhttpparam type="header" name="X-BAPI-API-KEY" value="#_key#">
<cfhttpparam type="header" name="X-BAPI-RECV-WINDOW" value="5000">
<cfhttpparam type="header" name="X-BAPI-SIGN" value="#lhmac#">
<cfhttpparam type="header" name="X-BAPI-TIMESTAMP" value="#unixdatetimeNow.getTime()#">
</cfhttp>
Even adding the ts_key_str in front of new body does not work either.
I get bad signature. When getting account data I using this it works fine cfhttpparam type="body" value=""
Any help appreciated.

It was a timestamp issue.
Set one timestamp, and use that timestamp. So it doesn't maybe pull different timestamp on a delayed call.
Updated code.
<!--- MARKET --->
<cfset b_body = '{"symbol": "#pair#","orderQty":"#size#","side": "#side#","orderType": "MARKET"}'>
<cfset unixdatetimeNow = dateConvert( "local2Utc", now() )>
<cfset timestamp = #unixdatetimeNow.getTime()#>
<cfscript>
apiKey = "#_key#";
apiSecret = "#_s#";
str_to_sign = #timestamp# & '#apikey#' & '5000' & '#b_body#';
HMAC = hmac(str_to_sign, apiSecret, "HMACSHA256");
</cfscript>
<cfset lhmac = lCase(#hmac#)>
<cfhttp url="#base_api##req_path#" method="POST" result="result" charset="utf-8">
<cfhttpparam type="body" value="#b_body#">
<cfhttpparam type="header" name="X-BAPI-SIGN-TYPE" value="2">
<cfhttpparam type="header" name="X-BAPI-SIGN" value="#lhmac#">
<cfhttpparam type="header" name="X-BAPI-API-KEY" value="#_key#">
<cfhttpparam type="header" name="X-BAPI-TIMESTAMP" value="#timestamp#">
<cfhttpparam type="header" name="X-BAPI-RECV-WINDOW" value="5000">
<cfhttpparam type="HEADER" name="Content_Type" value="application/json">
</cfhttp>

Related

How to use user input token in Checkbox value in Splunk Dashboard?

I am on Splunk 8.1 trying to create a dynamic dashboard. I am trying to create a multisearch query, the searches for which will be based on the checkboxes that the user clicks.
<input type="time" token="field1">
<label>Time</label>
<default>
<earliest>-15m</earliest>
<latest>now</latest>
</default>
</input>
<input type="text" token="userinput1">
<label>User Input 1</label>
</input>
<input type="text" token="userinput2">
<label>User Input 2</label>
</input>
<input type="checkbox" token="indexesSelected" searchWhenChanged="true">
<label>Indexes</label>
<choice value="[search index=index1 $userinput1$ $userinput2$]">Index 1</choice>
<choice value="[search index=index2 $userinput1$ $userinput2$]">Index 2</choice>
<default></default>
<initialValue></initialValue>
<delimiter> </delimiter>
<prefix>| multisearch [eval test1="test1"] [eval test2="test2"] </prefix>
</input>
The search part looks like this:
<search>
<query>$indexesSelected$
| table _time, index, field1, field2, field3, field4
| sort Time
</query>
<earliest>$field1.earliest$</earliest>
<latest>$field1.latest$</latest>
</search>
This works as expected except that the final query looks like this:
| multisearch [eval test1="test1"] [eval test2="test2"]
[search index=index1 $userinput1$ $userinput2$]
[search index=index2 $userinput1$ $userinput2$]
How can I make these $userinput1$ and $userinput2$ be converted to their token value from the user inputs in the dashboard and not as literal strings.
I have tried to use <change> tags to use eval and set based on the <condition> that the user selects, but eval does not allow token value and replaces with literal strings only. Something like this:
<change>
<condition match="like($indexesSelected$,"%index1%")">
<eval token="finalQuery">replace($indexesSelected$,"index1", "[search index=index1 $userinput1$ $userinput2$]")</eval>
</condition>
<condition match="like($indexesSelected$,"%index2%")">
<eval token="finalQuery">replace($indexesSelected$,"index2", "[search index=index2 $userinput1$ $userinput2$]")</eval>
</condition>
</change>

How to POST JSON data using ColdFusion 10 with Rest Services?

I am using ColdFusion 10. I have registered one rest service in ColdFusion Administrator by just adding path to my cfc and service mappings in the rest services tab. I am able to simply GET the data.
Similar to this I wanted a simple example to POST the JSON data but I am having issues doing that. I am using code below and trying to POST the data.
<cfcomponent rest="true" restpath="restService">
<cffunction name="postData" access="remote" returntype="any" produces="application/json" httpmethod="POST">
<cfsavecontent variable="JSONData">
{
"customer": {
"first_name": "Steve",
"last_name": "Lastnameson",
"email": "steve.lastnameson#example.com",
"phone": "+15142546011",
"verified_email": true,
"addresses": [
{
"address1": "123 Oak St",
"city": "Ottawa",
"province": "ON",
"phone": "555-1212",
"zip": "123 ABC",
"last_name": "Lastnameson",
"first_name": "Mother",
"country": "CA"
}
]
}
}
</cfsavecontent>
<cfhttp url="http://localhost:8080/rest/restApp/restService" method="post" timeout="300" result="httpResponsePosttest">
<cfhttpparam type="header" name="content-type" value="application/json" />
<cfhttpparam type="header" name="content-length" value="#Len(Trim(JSONData))#" />
<cfhttpparam type="header" name="charset" value="utf-8" />
<cfhttpparam type="body" value="#Trim(JSONData)#" />
</cfhttp>
<cfreturn httpResponsePosttest>
</cffunction>
When I tried to dump httpResponsePosttest I am getting this with blank error message and making it hard to debug.
When I tried to hit the same URL in postman with method as POST I am getting "The request has exceeded the allowable time limit tag" as a response.
Can somebody please help me out with this?

How do i set a token based on the dropdown options in splunk dashboard

i am trying to create a Splunk dashboard, where I want to set a value to a token based on the two dropdown values(service dropdown and environment dropdown)
<input type="dropdown" token="service" searchWhenChanged="true">
<label>service</label>
<choice value="capi">capi</choice>
<choice value="crapi">crapi</choice>
<choice value="oapi">oapi</choice>
<default>capi</default>
<initialValue>capi</initialValue>
</input>
<input type="dropdown" token="environment" searchWhenChanged="true">
<label>Environment</label>
<choice value="prod">prod</choice>
<choice value="ppe">ppe</choice>
<choice value="pte">pte</choice>
<choice value="dev">dev</choice>
<default>prod</default>
<initialValue>prod</initialValue>
</input>
above are the 2 dropdowns, now i want to set a value to token "endpoint" based on value selected in service and environment dropdown values.
i tried using condition match, but i am not getting it right
<condition match="$service$==capi AND $environment$==ppe">
<set token = endpoint>"/capi/ppe"</set>
</condition>
Try doing an eval in your search proper:
<search>
<query>... | eval endpoint="/$service$/$environment$" | ...
Or try doing an <eval>...</eval> on change from both dropdowns:
<input type="dropdown" token="service" searchWhenChanged="true">
<label>service</label>
<choice value="capi">capi</choice>
<choice value="crapi">crapi</choice>
<choice value="oapi">oapi</choice>
<default>capi</default>
<initialValue>capi</initialValue>
<change>
<eval token="endpoint">"/"+$service$+"/"+$environment$</eval>
</change>
</input>
<input type="dropdown" token="environment" searchWhenChanged="true">
<label>Environment</label>
<choice value="prod">prod</choice>
<choice value="ppe">ppe</choice>
<choice value="pte">pte</choice>
<choice value="dev">dev</choice>
<default>prod</default>
<initialValue>prod</initialValue>
<change>
<eval token="endpoint">"/"+$service$+"/"+$environment$</eval>
</change>
</input>

Retrieving data from MS Access database using timestamps i.e. starting and ending date on a user form

I had a question about retrieving data from MS Access database using timestamps i.e. starting and ending date on a user form. Kindly let me know if and what's the process to do that. I'm using Microsoft Visual Studio 2015. Website user interface will be in Asp.net with VB. Although I have tried passing parameters I am not understanding why it is not reflecting on the Grid View
ASPX.VB Code
Partial Class _Default
Inherits System.Web.UI.Page
Public dad As OleDbDataAdapter
Protected Sub Page_Load(sender As Object, e As EventArgs)
End Sub
Protected Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
End Sub
Protected Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
End Sub
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim connectionString As [String] = "Provider=Microsoft.ACE.OLEDB.12.0;Data" + " Source=App_Data/VQT_GL Testing.mdb"
Dim ds As New DataSet()
Dim conn As New OleDbConnection(connectionString)
conn.Open()
Dim cmd As New OleDbCommand("SELECT AVG(POLQA_Score) AS MEAN FROM VQTPOLQA WHERE VQT_Timestamp BETWEEN ? AND ?", conn)
cmd.Parameters.AddWithValue("#StartDate", (TextBox3.Text))
cmd.Parameters.AddWithValue("#EndDate", (TextBox2.Text))
GridView1.DataSource = ds
End Sub
End Class
ASPX CODE
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>MOS FORM HOME</title>
<script src="//code.jquery.com/jquery-1.10.2.js" type="text/javascript"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"type="text/javascript"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"/>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript" ></script>
<script src="Scripts/jquery.dynDateTime.min.js" type="text/javascript"></script>
<script src="Scripts/calendar-en.min.js" type="text/javascript"></script>
<script src="Scripts/jquery-ui-timepicker-addon.js"></script>
<link href="Styles/calendar-blue.css" rel="stylesheet" type="text/css" />
<link href="Styles/jquery-ui-timepicker-addon.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
$(document).ready(function () {
$("#<%=TextBox3.ClientID %>").dynDateTime({
showsTime: true,
ifFormat: "%m/%d/%Y %H:%M:%S",
daFormat: "%l;%M %p, %e %m, %Y",
align: "BR",
electric: false,
singleClick: false,
displayArea: ".siblings('.dtcDisplayArea')",
button: ".next()"
});
$("#<%=TextBox2.ClientID %>").dynDateTime({
showsTime: true,
ifFormat: "%m/%d/%Y %H:%M:%S",
daFormat: "%l;%M %p, %e %m, %Y",
align: "BR",
electric: false,
singleClick: false,
displayArea: ".siblings('.dtcDisplayArea')",
button: ".next()"
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 74px">
MOS FORM HOME PAGE</div>
<p>
START DATE
<asp:TextBox ID="TextBox3" runat="server" TextMode="DateTime" Width="181px" BorderColor="Black" BorderStyle="Solid"></asp:TextBox><img src="calender.png" />
</p>
<p>
END DATE <asp:TextBox ID="TextBox2" runat="server" TextMode="DateTime" Width="188px" BorderColor="Black" BorderStyle="Solid"></asp:TextBox><img src="calender.png" />
</p>
<p>
</p>
<p>
<asp:Button ID="Button1" runat="server" Text="Submit" onclick="btnSave_Click"/>
</p>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4" DataSourceID="SqlDataSource2" GridLines="Horizontal" Height="146px" Width="53px">
<Columns>
<asp:BoundField DataField="MEAN" HeaderText="MEAN" ReadOnly="True" SortExpression="MEAN" />
</Columns>
<FooterStyle BackColor="White" ForeColor="#333333" />
<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#333333" />
<SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#487575" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#275353" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:VQT_GL TestingConnectionString %>" ProviderName="<%$ ConnectionStrings:VQT_GL TestingConnectionString.ProviderName %>" SelectCommand="SELECT AVG(POLQA_Score) AS MEAN FROM VQTPOLQA WHERE VQT_Timestamp BETWEEN ? AND ?">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox3" DefaultValue="" Name="?" PropertyName="Text" />
<asp:ControlParameter ControlID="TextBox2" DefaultValue="" Name="?" PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<asp:AccessDataSource runat="server" DataFile="~/App_Data/VQT_GL Testing.mdb" SelectCommand="SELECT AVG(POLQA_Score) AS MEANPOLQA FROM VQTPOLQA WHERE (VQT_Timestamp BETWEEN ? AND ?)">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox3" DefaultValue="" Name="?" PropertyName="Text" />
<asp:ControlParameter ControlID="TextBox2" Name="?" PropertyName="Text" />
</SelectParameters>
</asp:AccessDataSource>
</form>
</body>
</html>
At first sight, your problem seems to be with your parameters to your OleDbCommand. You are using cmd.Parameters.AddWithValue. This is something I tend to avoid, as the datatype of the Parameter is inferred from the value passed. In this case you are passing text. This means that the parameter is treated as a string parameter not a DateTime. This is almost certainly going to fail!
Instead you should set the type of the parameter yourself. To do this use something like:
Dim param as OleDbParameter
param = cmd.CreateParameter
param.OleDbType = OleDbType.Date
param.Value = DateTime.Parse(TextBox1.Text)
param.ParameterName = "#myDate"
cmd.Parameters.Add(param)
Note for Access OleDbType needs to be Date even though the field is DateTime.
It may be that I have a syntax error in the above - it is a very long time since I used VB, and I cannot remember when you need round brackets and when you don't, but it should be something like this (I could give it to you exactly in c# ). I am sure you can correct my VB.
Secondly you are not actually executing your OleDbCommand! Here there are different possiblilities. You can use an OleDbDataAdapter or an OleDbDataReader. Personally I prefer to use OleDbDataReader and I then build my own DataTable from the result to use as the DataSource, but you may find an Adapter easier. Please google for examples of how to do this! It should be something like:
Dim adapter as New OleDbDataAdapter(cmd)
adapter.Fill(ds)
Again my VB is not upto date!
Hope this helps

Using iText to save pdf to ColdFusion Variable

I need to use iText with ColdFusion (CF) because CFDocument won't do everything I need it to, however I would like to return the result into a CF Variable instead of saving it to a file. It seems that every example out there saves the results to a file.
I'm using the following example code to actually generate a pdf but as I said I need it in a variable (preferably without being a file first) because that variable has to be passed on to code another group has written (and I have no control over).
<cfset var document=createObject("java", "com.lowagie.text.Document") />
<cfset var PageSize = createObject("java","com.lowagie.text.Rectangle") />
<cfset var fileIO = createObject("java","java.io.FileOutputStream") />
<cfset var writer = createObject("java","com.lowagie.text.pdf.PdfWriter") />
<cfset var paragraph = createObject("java", "com.lowagie.text.Paragraph") />
<cfset var FontFactory = createObject("java","com.lowagie.text.FontFactory") />
<cfset var Font = createObject("java", "com.lowagie.text.Font") />
<cfset var Courier = Font.init(Font.COURIER, 8.0) />
<cfset var CourierB = Font.init(Font.COURIER_BOLD, 8.0) />
<cfset PageSize.init(612, 792) />
<cfset document.init(PageSize) />
<cfset fileIO.init("C:\test.pdf") />
<cfset writer.getInstance(document, fileIO) />
<cfset document.open() />
<cfset paragraph.init("Hello world.", Courier) />
<cfset document.add(paragraph) />
<cfset document.close() />
I'm not all that great with Java, just basic knowledge, so this could actually be something simple that I'm not understanding.
Thanks
Leigh's comment about using ByteArrayOutputStream was the correct answer.
Here is the updated code that works placing the generated PDF into a ColdFusion variable:
<cfset var document=createObject("java", "com.lowagie.text.Document") />
<cfset var PageSize=createObject("java","com.lowagie.text.Rectangle") />
<cfset var fileIO=createObject("java","java.io.ByteArrayOutputStream") />
<cfset var writer=createObject("java","com.lowagie.text.pdf.PdfWriter") />
<cfset var paragraph=createObject("java", "com.lowagie.text.Paragraph") />
<cfset var FontFactory=createObject("java","com.lowagie.text.FontFactory") />
<cfset var Font = createObject("java", "com.lowagie.text.Font") />
<cfset var Courier = Font.init(Font.COURIER, 8.0) />
<cfset PageSize.init(612, 792) />
<cfset document.init(PageSize) />
<cfset writer.getInstance(document, fileIO) />
<cfset document.open() />
<cfset paragraph.init("Hello world.", Courier) />
<cfset document.add(paragraph) />
<cfset document.close() />
<cfset var returnVar = fileIO.toByteArray() />