Curve from selected vertices/edges using low level api
Walk the edges.
To give them some order walk the edges.  It may take more than one spline to make the curve, since we cannot branch.  For example the default cube when &quot;de-faced&quot; and converted to curve has 4 splines.
Here is test script to walk the selected edges. It does not make the curve, rather creates an ordered list of the edges to use in each spline.

Get all selected edges.
Pop an edge, get its two end verts. Tag the edge.
Grow spline from each end on a non tagged and selected edge, prepend at one end, append at other.
Add spline to splines.
Repeat until no more edges to process.

Script
import bpy
import bmesh
from collections import defaultdict

from bpy import context
tag = defaultdict(bool)

ob = context.edit_object
me = ob.data
bm = bmesh.from_edit_mesh(me)
edges = list(filter(lambda e: e.select, bm.edges))

splines = []
def tag_remove(edge):
    tag[edge] = True
    edges.remove(edge)

def grow(end, spline, idx):
     while True:
        nextedge = next(
            (e for e in end.link_edges if not tag[e] and  e.select), 
            None
            )
        if not nextedge:
            return
        tag_remove(nextedge)
        spline.insert(idx, nextedge.index)
        end = nextedge.other_vert(end)   
    
while edges:

    edge = edges.pop()
    spline = [edge.index]
    tag[edge] = True
    a, b = edge.verts
    grow(a, spline, 0)
    grow(b, spline, len(edges))
    splines.append(spline)
    
print(splines)

Result for default cube. Notice 4 splines as with convert.
[[5, 1, 0, 3, 6, 11, 7], [4, 10], [2, 9], [8]]

Result for default circle.  Since edge 30 shares a vert with edge 31 could make this cyclic.
[[30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31]]

To reverse order, could try swapping which end to append / prepend...